@Override
  protected void processVmCreate(SimEvent ev) {
    int[] data = (int[]) ev.getData();
    int result = data[2];

    if (result != CloudSimTags.TRUE) {
      int datacenterId = data[0];
      int vmId = data[1];
      System.out.println(
          CloudSim.clock()
              + ": "
              + getName()
              + ": Creation of VM #"
              + vmId
              + " failed in Datacenter #"
              + datacenterId);
      System.exit(0);
    }
    super.processVmCreate(ev);
  }
  /*
   * (non-Javadoc)
   * @see org.cloudbus.cloudsim.VmAllocationPolicy#allocateHostForVm(org.cloudbus.cloudsim.Vm,
   * org.cloudbus.cloudsim.Host)
   */
  @Override
  public boolean allocateHostForVm(Vm vm, Host host) {
    if (host == null) {
      Log.formatLine("%.2f: No suitable host found for VM #" + vm.getId() + "\n", CloudSim.clock());
      return false;
    }
    if (host.vmCreate(vm)) { // if vm has been succesfully created in the host
      getVmTable().put(vm.getUid(), host);

      /*
       * update host cache pain information
       * in CacheMatrix.HOST_PAIN_LIST
       */
      CacheMatrix.update_host_pain_add_vm(vm, host);
      /*
       * end update host cache pain information
       */

      Log.formatLine(
          "%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
          CloudSim.clock());
      return true;
    }
    Log.formatLine(
        "%.2f: Creation of VM #" + vm.getId() + " on the host #" + host.getId() + " failed\n",
        CloudSim.clock());
    return false;
  }
 /**
  * Process a request for the characteristics of a PowerDatacenter.
  *
  * @param ev a SimEvent object
  * @pre ev != $null
  * @post $none
  */
 @Override
 protected void processResourceCharacteristicsRequest(SimEvent ev) {
   setDatacenterCharacteristicsList(new HashMap<>());
   Log.printLine(
       CloudSim.clock()
           + ": "
           + getName()
           + ": Cloud Resource List received with "
           + getDatacenterIdsList().size()
           + " resource(s)");
   for (Integer datacenterId : getDatacenterIdsList()) {
     sendNow(datacenterId, CloudSimTags.RESOURCE_CHARACTERISTICS, getId());
   }
 }
Example #4
0
 /**
  * Updates the processing of cloudlets running on this VM.
  *
  * @param currentTime current simulation time
  * @param mipsShare array with MIPS share of each Pe available to the scheduler
  * @return time predicted completion time of the earliest finishing cloudlet, or 0 if there is no
  *     next events
  * @pre currentTime >= 0
  * @post $none
  */
 @Override
 public double updateVmProcessing(final double currentTime, final List<Double> mipsShare) {
   double time = super.updateVmProcessing(currentTime, mipsShare);
   double schedulerPerviousTime = getCloudletScheduler().getPreviousTime();
   double utilization = getTotalUtilizationOfCpu(schedulerPerviousTime);
   double ramUtilization = getCloudletScheduler().getTotalUtilizationOfRam(schedulerPerviousTime);
   double bwUtilization = getCloudletScheduler().getTotalUtilizationOfBw(schedulerPerviousTime);
   if (currentTime > getPreviousTime() && (currentTime - 0.1) % getSchedulingInterval() == 0) {
     // double utilization = getTotalUtilizationOfCpu(getCloudletScheduler().getPreviousTime());
     if (CloudSim.clock() != 0 || utilization != 0) {
       addUtilizationHistoryValue(utilization);
       addRamUtilizationHistoryValue(ramUtilization);
       addBwUtilizationHistoryValue(bwUtilization);
     }
   }
   return time;
 }
  /**
   * Resumes execution of a paused cloudlet.
   *
   * @param cloudletId ID of the cloudlet being resumed
   * @return $true if the cloudlet was resumed, $false otherwise
   * @pre $none
   * @post $none
   */
  @Override
  public double cloudletResume(int cloudletId) {
    boolean found = false;
    int position = 0;

    // look for the cloudlet in the paused list
    for (ResCloudlet rcl : getCloudletPausedList()) {
      if (rcl.getCloudletId() == cloudletId) {
        found = true;
        break;
      }
      position++;
    }

    if (found) {
      ResCloudlet rcl = getCloudletPausedList().remove(position);

      // it can go to the exec list
      if ((currentCpus - usedPes) >= rcl.getNumberOfPes()) {
        rcl.setCloudletStatus(Cloudlet.INEXEC);
        for (int i = 0; i < rcl.getNumberOfPes(); i++) {
          rcl.setMachineAndPeId(0, i);
        }

        long size = rcl.getRemainingCloudletLength();
        size *= rcl.getNumberOfPes();
        rcl.getCloudlet().setCloudletLength(size);

        getCloudletExecList().add(rcl);
        usedPes += rcl.getNumberOfPes();

        // calculate the expected time for cloudlet completion
        double capacity = 0.0;
        int cpus = 0;
        for (Double mips : getCurrentMipsShare()) {
          capacity += mips;
          if (mips > 0) {
            cpus++;
          }
        }
        currentCpus = cpus;
        capacity /= cpus;

        long remainingLength = rcl.getRemainingCloudletLength();
        double estimatedFinishTime =
            CloudSim.clock() + (remainingLength / (capacity * rcl.getNumberOfPes()));

        return estimatedFinishTime;
      } else { // no enough free PEs: go to the waiting queue
        rcl.setCloudletStatus(Cloudlet.QUEUED);

        long size = rcl.getRemainingCloudletLength();
        size *= rcl.getNumberOfPes();
        rcl.getCloudlet().setCloudletLength(size);

        getCloudletWaitingList().add(rcl);
        return 0.0;
      }
    }

    // not found in the paused list: either it is in in the queue, executing or not exist
    return 0.0;
  }
  /**
   * Process the ack received due to a request for VM creation.
   *
   * @param ev a SimEvent object
   * @pre ev != null
   * @post $none
   */
  @Override
  protected void processVmCreate(SimEvent ev) {
    int[] data = (int[]) ev.getData();
    int datacenterId = data[0];
    int vmId = data[1];
    int result = data[2];

    if (result == CloudSimTags.TRUE) {
      getVmsToDatacentersMap().put(vmId, datacenterId);
      /** Fix a bug of cloudsim Don't add a null to getVmsCreatedList() June 15, 2013 */
      if (VmList.getById(getVmList(), vmId) != null) {
        getVmsCreatedList().add(VmList.getById(getVmList(), vmId));
        Log.printLine(
            CloudSim.clock()
                + ": "
                + getName()
                + ": VM #"
                + vmId
                + " has been created in Datacenter #"
                + datacenterId
                + ", Host #"
                + VmList.getById(getVmsCreatedList(), vmId).getHost().getId());
      }
    } else {
      Log.printLine(
          CloudSim.clock()
              + ": "
              + getName()
              + ": Creation of VM #"
              + vmId
              + " failed in Datacenter #"
              + datacenterId);
    }

    incrementVmsAcks();

    // all the requested VMs have been created
    if (getVmsCreatedList().size() == getVmList().size() - getVmsDestroyed()) {
      submitCloudlets();
    } else {
      // all the acks received, but some VMs were not created
      if (getVmsRequested() == getVmsAcks()) {
        // find id of the next datacenter that has not been tried
        for (int nextDatacenterId : getDatacenterIdsList()) {
          if (!getDatacenterRequestedIdsList().contains(nextDatacenterId)) {
            createVmsInDatacenter(nextDatacenterId);
            return;
          }
        }

        // all datacenters already queried
        if (getVmsCreatedList().size() > 0) { // if some vm were created
          submitCloudlets();
        } else { // no vms created. abort
          Log.printLine(
              CloudSim.clock()
                  + ": "
                  + getName()
                  + ": none of the required VMs could be created. Aborting");
          finishExecution();
        }
      }
    }
  }