layout: page title: "Introducing a new re-usable component with CloudSim Express" permalink: /examples/introducing-new-reusable-component
Please refer to README.md for a detailed description about re-usable components.
In this example, we are going to introduce a new re-usable component and use it in the system model script.
We will create a new component to represent a zone monitor. It is a part of the zone, alongside wih the datacenter, broker, and workload generator.
Unlike in other examples that we worked with extensions, this task involves extending CloudSim Express. Therefore, it is recommended to avoid this approach as much as possible to avoid excess development overhead, if there is an alternative approach to define the scenario using existing components.
- CloudSim Express needs to know the schematics of the new component. To add that information, open simulation-elements.yaml file.
- Add the following object.
ZoneMonitor: type: object properties: name: type: string
- Add our
ZoneMonitor
as an attribute of theZone
.Zone: ~ Everything else monitor: $ref: '#/components/schemas/ZoneMonitor'
- Build the core component by executing
mvn clean install
inside the module folder. This will generate PoJo for the new component. - In our design, the
ZoneMonitor
will do nothing but print its name, for the simplicity. Even to do that, we need to integrate it into the system model building process. Here are the steps of system model building with default component and their handlers.- When a
Zone
component is set as the simulation system model, then at first, its handler'shandle
method is called. With vanilla CloudSim Express, thehandle
method of DefaultZoneHandler.java is called. Within that, the subsequent handlers are called to build the CloudSim system model in a top-down approach. Feel free to traverse through the code of the DefaultZoneHandler.java.
- When a
- Therefore, firstly we need to create a custom handler for our new component to convert YAML object into Java logic.
Afterward, to integrate the custom handler, we need to override the default zone handler and call our custom handler
in it's
handle
method. For both, we create a custom handler and an extended zone handler as extensions, in a new java project.- Create a simple Maven project.
- Go to a new folder.
- Execute
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-simple -DarchetypeVersion=1.4
- Pre-requisite: Maven
- Enter followings when prompted.
- groupId =
org.cloudbus.cloudsim.express.examples
- artifactId =
custom-reusable-component
- version =
1.0-SNAPSHOT
- package =
org.cloudbus.cloudsim.express.examples
- Press Enter to confirm.
- groupId =
- Configure dependencies.
- Go to the
custom-reusable-component
project folder. - Open
pom.xml
- Within the
<dependencies>
tag, copy the following to declare CloudSim Express as a dependency- Pre-requisite: You must build
cloudsim-express
project at least once. - Copy and paste the following.
<dependency> <artifactId>cloudsim-express-extensions</artifactId> <groupId>org.cloudbus.cloudsim.cloudsim-express</groupId> <version>0.1-SNAPSHOT</version> </dependency>
- Pre-requisite: You must build
- Create the custom component handler class in the
/src/main/java/org/cloudbus/cloudsim/express/examples/
folder by creating a new fileCustomZoneMonitorHandler.java
. Also create the extended zone handler by creating a new fileCustomZoneHandler.java
- Delete the generated
App.java
file.
- Delete the generated
- Implement the logic accordingly.
- The sample code is available in the custom-reusable-component project.
- Build the project by executing
mvn clean install
from the project root directory (i.e., where thepom.xml
file resides).
- Go to the
- Create a simple Maven project.
- Build the CloudSim Express project by executing
mvn clean install
at its root. - Extract the
<cloudsim-express-root>/release-artifacts/cloudsim-express.zip
, and copy the updatedsimulator.jar
file to the CloudSim Express tool that we used for previous examples, and replace the existingsimulator.jar
with that.- Alternatively, you can get the whole new release, extract, and use. But then again we need to update the system model script in that case. Therefore, we only update the simulator component to make it much easier.
- Copy the custom-reusable-component jar file from
<custom-workload-generator>/target/custom-reusable-component-1.0-SNAPSHOT.jar
, tocloudsim-express-tool-location/extensions
. - Modify the
system-model.yaml
to use the custom workload generator.- From:
... Zone: &Zone name: "default zone" datacenter: *Datacenter broker: variant: className: "org.cloudbus.cloudsim.DatacenterBroker" name: "RegionalBroker" workloadGenerator: variant: className: "org.crunchycookie.research.distributed.computing.cloudsim.workload.impl.DummyWorkloadGenerator" ...
- To:
... Zone: &Zone name: "default zone" datacenter: *Datacenter broker: variant: className: "org.cloudbus.cloudsim.DatacenterBroker" name: "RegionalBroker" workloadGenerator: variant: className: "org.crunchycookie.research.distributed.computing.cloudsim.workload.impl.DummyWorkloadGenerator" monitor: name: "This is the newly introduced re-usable component" ...
- From:
- Register new element handlers with high priority. Open
configs.properties
file, and add both custom handlers before the default zone handler. From:
# priority list is used to determine which handler to select.
element.handler.priority.1=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultDatacenterCharacteristicsHandler
element.handler.priority.2=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultDatacenterHandler
element.handler.priority.3=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultGlobalDatacenterNetworkHandler
element.handler.priority.4=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultHostHandler
element.handler.priority.5=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultProcessingElementHandler
element.handler.priority.6=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultZoneHandler
To:
# priority list is used to determine which handler to select.
element.handler.priority.1=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultDatacenterCharacteristicsHandler
element.handler.priority.2=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultDatacenterHandler
element.handler.priority.3=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultGlobalDatacenterNetworkHandler
element.handler.priority.4=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultHostHandler
element.handler.priority.5=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultProcessingElementHandler
element.handler.priority.6=org.cloudbus.cloudsim.express.examples.CustomZoneHandler
element.handler.priority.7=org.cloudbus.cloudsim.express.examples.CustomZoneMonitorHandler
element.handler.priority.8=org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultZoneHandler
- Executes the simulation via
sh ./cloudsim-express.sh
- Check the CloudSim Express logs and observe the printed message by the custom component handler.
... This is the newly introduced re-usable component [main] INFO org.cloudbus.cloudsim.express.manager.impl.CloudSimSimulationManager - Starting CloudSim simulation ...
The newly introduced component ZoneMonitor
, can now be used to defined different system models.
The related materials are included in the resources folder.