layout: page title: "Writing Custom VM allocation Policy" permalink: /examples/writing-custom-vm-allocation-policy
CloudSim Express introduces enhanced extensions, in which researchers can provide custom properties to the extension via the system model script.
In this example, we are writing a classic CloudSim extension, a vm allocation policy, as a CloudSim Express extension. We explore configuring the vm allocation policy by feeding custom properties via the script.
A CloudSim Express extension needs to implement the CloudSimExpressExtension.
We implement the vm allocation policy in a separate java project. We use Maven-based 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-vm-allocation-policy
- version =
1.0-SNAPSHOT
- package =
org.cloudbus.cloudsim.express.examples
- Press Enter to confirm.
- groupId =
- Configure dependencies.
- Go to the
custom-vm-allocation-policy
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-core</artifactId> <groupId>org.cloudbus.cloudsim.cloudsim-express</groupId> <version>0.1-SNAPSHOT</version> </dependency>
- Pre-requisite: You must build
- Create the custom vm allocation policy class in the
/src/main/java/org/cloudbus/cloudsim/express/examples/
folder by creating a new fileCustomVMAllocationPolicy.java
.- Delete the generated
App.java
file.
- Delete the generated
- Implement the vm allocation policy, which implements the
CloudSimExpressExtension
interface.- The policy,
- Prints out the extension resolver class name.
- Prints out the property as it reads.
- The sample code is available in the custom-vm-allocation-policy project.
- The policy,
- Build the project by executing
mvn clean install
from the project root directory (i.e., where thepom.xml
file resides).
- Go to the
- Copy the vm allocation policy jar file from
<custom-vm-allocation-policy>/target/custom-vm-allocation-policy-1.0-SNAPSHOT.jar
, tocloudsim-express-tool-location/extensions
. - Modify the
system-model.yaml
to use the vm allocation policy.- From:
... Datacenter: &Datacenter variant: className: "org.cloudbus.cloudsim.Datacenter" characteristics: *Characteristics vmAllocationPolicy: className: "org.cloudbus.cloudsim.VmAllocationPolicySimple" storage: "" schedulingInterval: 0 name: "regional-datacenter" ...
- To:
... Datacenter: &Datacenter variant: className: "org.cloudbus.cloudsim.Datacenter" characteristics: *Characteristics vmAllocationPolicy: className: "org.cloudbus.cloudsim.express.examples.CustomVMAllocationPolicy" extensionProperties: - key: "PROPERTY_KEY" value: "PROPERTY_VALUE" storage: "" schedulingInterval: 0 name: "regional-datacenter" ...
- From:
- Executes the simulation via
sh ./cloudsim-express.sh
- Check logs. You can observe that the custom vm allocation policy component printing
out the property.
... [main] INFO org.cloudbus.cloudsim.express.manager.impl.DefaultScenarioManager - Building the scenario using class org.cloudbus.cloudsim.express.handler.impl.cloudsim.DefaultZoneHandler class org.cloudbus.cloudsim.express.resolver.impl.JARExtensionsResolver [(PROPERTY_KEY,PROPERTY_VALUE)] [main] INFO org.cloudbus.cloudsim.express.manager.impl.CloudSimSimulationManager - Starting CloudSim simulation ...
The related materials are included in the resources folder.