Building an open-source playground for the CloudSim Framework

Young boy digs with his hands in the sand at the playground (Many thanks to https://unsplash.com/photos/mlwM6legtwY?utm_source=unsplash&utm_medium=referral&utm_content=creditShareLink)

In my previous article about the CloudSim framework, I talked about configuring the popular JAVA IDE, IntelliJ IDEA to implement CloudSim simulation scenarios.

Which is a more up-to date approach.

But what I felt while working on this fun project is that depending on an IDE to use the framework makes it IDE-bounded!

This is a fun word that I just came up with ;) The more accurate word would be the Vendor lock-in.

The risk associated with an IDE-bounded scenario is that we are building on top of the IntelliJ IDEA thus depending on the decisions taken by IDE developers. Say they decides to deprecate the IDE and move on to a completely new platform… At that point, we have to find another way of configuring our framework.

In this blog post we will discuss on how to solve this problem by building an open-source playground where researchers or developers can straightaway jump and start writing simulation scenarios without worrying about any specific IDE-dependency issues.

Our intention here is to eliminate the IDE dependency by creating a project that allows users to focus on writing simulation scenarios, rather than spending much time on configuring tasks.

Since CloudSim is a community driven JAVA based open-source framework, first, let’s choose a platform that is open-source, already popular and easy to use. This platform should allow us to inject CloudSim as a dependency and use it as a toolkit.

By looking at these requirements, first thing that comes to my mind is the Apache Maven. Maven is a popular framework based on the concept of a project object model (POM), and it allows running plugins in various lifecycles to build a project. You may jump in to the mentioned link and read more about the Apache Maven framework.

https://maven.apache.org/download.cgi

First, I will create a new Maven project and with a simulation scenario. In this blog I will not go into much details about the simulation scenario since I plan to write a separate blog about it!

The project structure looks like this.

Do notice that Builders and the scenario classes are not from the CloudSim toolkit, but they belong to my simulation scenario. These classes include code that uses the CloudSim toolkit APIs. Here is a once such code snippet from the CreateDatacenter class.

I decided to make the project available under MIT licence which allows free usage. Also, I added a comprehensive README.md file with information on building, and it’s usages. This is crucial for community driven, developer focused projects.

Maven manages dependency in a specific way. It has repositories of dependencies.

The common dependency repository which is publicly available is called the Maven central repository. This contain a large number of open-source libraries. Likewise, repositories can be used to manage dependencies and they can even be private repositories also.

When working on a local computer, Maven creates a specific folder in your computer which is called the local Maven repository. If we specify a dependency version in the project pom file, during the project build, the Maven framework will download and install that in its local repository. These libraries are organised based on their group id, artefact id, and its version.

The CloudSim framework is currently not available in a publicly available Maven repository. Therefore we cannot directly mention this in the Maven pom file and expect it to take care of the dependency, since Maven would not know where to look for.

To overcome this, I’m going to download the CloudSim JAR file manually from the GitHub releases. And then I will provide the location of this JAR file and instruct Maven framework to install this locally downloaded JAR file as a Maven dependency. All this is done in the parent pom file.

Here is the property I used to point the CloudSim JAR file in the Maven framework. Please note the <cloudsim-framework-jar-location> property.

And I used the Maven Install plugin to install the downloaded JAR file as a Maven dependency. This task has to be done before building the project. Therefore, it will happen in the Maven initialize lifecycle.

Since CloudSim is now available as a Maven dependency, we can instruct Maven to use it in our project.

You may remember that simulations with CloudSim may also depend on the Apache Commons Math utils library. Earlier we provided this to the IDE itself. However, this dependency is already available as a Maven dependency thus we can easily mention that in the pom file. Afterwards, Maven can take care of it.

At this point, the project is ready to be built. First, let’s initialize the project to install CloudSim as a Maven dependency by executing the following command.

mvn initialize

This will shows the logs installing the CloudSim.

[INFO] Scanning for projects...
[INFO]
[INFO] ------< org.crunchycookie.playground.cloudsim:cloudsim-examples >-------
[INFO] Building cloudsim-examples 0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install-file (default) @ cloudsim-examples ---
[INFO] Installing /Users/test-user/Downloads/cloudsim-3.0.3.jar to /Users/test-user/.m2/repository/org/cloudbus/cloudsim/cloudsim-toolkit/3.0.3/cloudsim-toolkit-3.0.3.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.155 s
[INFO] Finished at: 2021-05-18T03:43:04+05:30
[INFO] ------------------------------------------------------------------------

Afterwards, we can run the simulation. My simulation scenario needs to be run as a simple Java Application. Therefore I’m going to use the Maven execution plugin to do this. Since I will execute this multiple time over the course of the testing, I am going to add an alias to link the simulation main class.

Finally, let’s execute the following to run the simulation scenario,

mvn exec:java@CreateDatacenterScenario

This will successfully run the scenario.

[INFO] Scanning for projects...
[INFO]
[INFO] ------< org.crunchycookie.playground.cloudsim:cloudsim-examples >-------
[INFO] Building cloudsim-examples 0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (CreateDatacenterScenario) @ cloudsim-examples ---
Initialising...
Successfully created the datacenter. Here are some stats.
Number of Hosts: 500. Let's check stats of a host.
Number of cores: 8
Amount of Ram(GB): 64
Amount of Storage(TB): 10
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.244 s
[INFO] Finished at: 2021-05-18T03:48:10+05:30
[INFO] ------------------------------------------------------------------------

The playground that we just built here is now available as a community driven , open source project under the MIT licence. You can find it from the cloudsim-playground project Hosted in GitHub.

As explained earlier, anyone can clone this repository and easily implement and execute their simulation scenarios with minimum configuration tasks.

But most importantly, it does not rely on an IDE!

In this blog post, we went through on building a CloudSim playground.

We understood the issues with running CloudSim based simulations bounded to a particular IDE. Then we investigated open source frameworks to solve this problem, and gradually built a playground project where anyone can easily test their CloudSim based simulations.

In the end, we were able to solve the problem of IDE-bound by using open-source technologies 🎉 🎉 🎉

That concludes this blog post. It has gotten a bit longer in terms of the content length, but I trust that all the explanations are kind of mandatory even for a beginner to understand.

Let’s meet on another blog post explaining how to write a CloudSim based simulation. Now we can easily utilise our freshly built playground for that task.

Until then, Cheers! 🍻

Cloud and AI Researcher | Former Senior Full-Stack Engineer@WSO2 | IAM Specialist | Ph.D. Candidate