Search code examples
javacloudsim

Cloudsim: Update VM


I am working on an algorithm to select the VM for deploying the Cloudlet(task). Now, I need to update the VM's current allocated ram whenever a cloudlet finished it's execution.

I don't know where I need to do this.

I tried this in processCloudletReturn() method in DataCenterbroker class

but it is called only after all cloudlets are submitted to the VMs.

I need to update the VM's Ram whenever a cloudlet executed successfully.

For, ex:

Let us consider, I have 100 tasks to be deployed and now I submitted 20 tasks then, before submitting 21st task if 1st task finishes its execution I need to update the corresponding VM.

Can anyone help me.. Thank you..


Solution

  • You can do as below:

    for(Cloudlet cloudlet: getCloudletSubmittedList()){
            if(!finishedCloudlets.contains(cloudlet) && cloudlet.isFinished()){
            Vm vm = getVmsCreatedList().get(cloudlet.getVmId()-1);                        
            vm.setCurrentAllocatedRam(vm.getCurrentAllocatedRam() - (int)(cloudlet.getUtilizationOfRam(CloudSim.clock())*100));
            vm.updateVmProcessing(CloudSim.clock(), null);
            finishedCloudlets.add(cloudlet);
        }
    }
    

    where you can check whether already submitted tasks are finished if so you can update your VM.