@Override
 public void deallocateHostForVm(Vm vm) {
   Host host = getVmTable().remove(vm.getUid());
   if (host != null) {
     host.vmDestroy(vm);
   }
 }
  /*
   * (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;
  }
 boolean tryToAllocateVmToHost(Host host, Vm vm) {
   if (host.isSuitableForVm(vm)) {
     boolean result = host.vmCreate(vm);
     if (result) {
       printLogMsg("Vm created successfuly");
       getVmTable().put(vm.getUid(), host);
       return true;
     } else {
       printLogMsg("Vm creation failed");
     }
   }
   return false;
 }
예제 #4
0
  /**
   * Prints the metric history.
   *
   * @param hosts the hosts
   * @param vmAllocationPolicy the vm allocation policy
   */
  public static void printMetricHistory(
      List<? extends Host> hosts, PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy) {
    for (int i = 0; i < 10; i++) {
      Host host = hosts.get(i);

      Log.printLine("Host #" + host.getId());
      Log.printLine("Time:");
      if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) {
        continue;
      }
      for (Double time : vmAllocationPolicy.getTimeHistory().get(host.getId())) {
        Log.format("%.2f, ", time);
      }
      Log.printLine();

      for (Double utilization : vmAllocationPolicy.getUtilizationHistory().get(host.getId())) {
        Log.format("%.2f, ", utilization);
      }
      Log.printLine();

      for (Double metric : vmAllocationPolicy.getMetricHistory().get(host.getId())) {
        Log.format("%.2f, ", metric);
      }
      Log.printLine();
    }
  }
예제 #5
0
  /**
   * Write metric history.
   *
   * @param hosts the hosts
   * @param vmAllocationPolicy the vm allocation policy
   * @param outputPath the output path
   */
  public static void writeMetricHistory(
      List<? extends Host> hosts,
      PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy,
      String outputPath) {
    // for (Host host : hosts) {
    for (int j = 0; j < 10; j++) {
      Host host = hosts.get(j);

      if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) {
        continue;
      }
      File file = new File(outputPath + "_" + host.getId() + ".csv");
      try {
        file.createNewFile();
      } catch (IOException e1) {
        e1.printStackTrace();
        System.exit(0);
      }
      try {
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        List<Double> timeData = vmAllocationPolicy.getTimeHistory().get(host.getId());
        List<Double> utilizationData = vmAllocationPolicy.getUtilizationHistory().get(host.getId());
        List<Double> metricData = vmAllocationPolicy.getMetricHistory().get(host.getId());

        for (int i = 0; i < timeData.size(); i++) {
          writer.write(
              String.format(
                  "%.2f,%.2f,%.2f\n", timeData.get(i), utilizationData.get(i), metricData.get(i)));
        }
        writer.close();
      } catch (IOException e) {
        e.printStackTrace();
        System.exit(0);
      }
    }
  }