예제 #1
0
  /**
   * This function updates the dynamic values for VMs from tha DataCenter
   *
   * @param siteIndex
   * @param datacenterIndex
   * @param rackIndex
   * @param enclosureIndex
   * @param hostIndex
   * @param vmIndex
   * @param operationSet
   * @author jclegea
   */
  private void updateVMDynamicValues(
      int siteIndex,
      int datacenterIndex,
      int rackIndex,
      int enclosureIndex,
      int hostIndex,
      int vmIndex,
      ComOperationCollector operationSet) {
    ComOperation operation;
    double cpuUsage;
    double diskUsage;
    double memoryUsage;
    double storageUsage;
    String hostVirtualMachineName = null;

    // get all virtual machines dynamic values from the datacenter
    // and add an update operation for each value

    // get the name of the virtual machine
    hostVirtualMachineName =
        datacenterInformation_.getVmName(
            siteIndex, datacenterIndex, rackIndex, enclosureIndex, hostIndex, vmIndex);

    // get the CPU usage
    try {
      cpuUsage =
          datacenterInformation_.getActualVMCPUUsage(
              siteIndex, datacenterIndex, rackIndex, enclosureIndex, hostIndex, vmIndex);
      operation =
          new ComOperation(
              ComOperation.TYPE_UPDATE,
              "/nativeHypervisor/virtualMachine[frameworkID='"
                  + hostVirtualMachineName
                  + "']/actualCPUUsage",
              String.valueOf(cpuUsage));
      operationSet.add(operation);
    } catch (NullPointerException exception) {
      // in case that is impossible to get the information, whatever the reason
      // simply don't update the model
      log.debug("Cannot retrieve CPU information from the DC");
    }

    // get the Disk usage
    try {
      diskUsage =
          datacenterInformation_.getActualVMDiskIORate(
              siteIndex, datacenterIndex, rackIndex, enclosureIndex, hostIndex, vmIndex);
      operation =
          new ComOperation(
              ComOperation.TYPE_UPDATE,
              "/nativeHypervisor/virtualMachine[frameworkID='"
                  + hostVirtualMachineName
                  + "']/actualDiskIORate",
              String.valueOf(diskUsage));
      operationSet.add(operation);
    } catch (NullPointerException exception) {
      // in case that is impossible to get the information, whatever the reason
      // simply don't update the model
      log.debug("Cannot retrieve Disk information from the DC");
    }

    // get the Memory usage
    try {
      memoryUsage =
          datacenterInformation_.getActualVMMemoryUsage(
              siteIndex, datacenterIndex, rackIndex, enclosureIndex, hostIndex, vmIndex);
      operation =
          new ComOperation(
              ComOperation.TYPE_UPDATE,
              "/nativeHypervisor/virtualMachine[frameworkID='"
                  + hostVirtualMachineName
                  + "']/actualMemoryUsage",
              String.valueOf(memoryUsage));
      operationSet.add(operation);
    } catch (NullPointerException exception) {
      // in case that is impossible to get the information, whatever the reason
      // simply don't update the model
      log.debug("Cannot retrieve Memory information from the DC");
    }

    // get the storage usage
    try {
      storageUsage =
          datacenterInformation_.getActualVMStorageUsage(
              siteIndex, datacenterIndex, rackIndex, enclosureIndex, hostIndex, vmIndex);
      operation =
          new ComOperation(
              ComOperation.TYPE_UPDATE,
              "/nativeHypervisor/virtualMachine[frameworkID='"
                  + hostVirtualMachineName
                  + "']/actualStorageUsage",
              String.valueOf(storageUsage));
      operationSet.add(operation);
    } catch (NullPointerException exception) {
      // in case that is impossible to get the information, whatever the reason
      // simply don't update the model
      log.debug("Cannot retrieve storage information from the DC");
    }
  }
예제 #2
0
  /**
   * get the information from the datacenter and inserts them into FIT4Green metamodel
   *
   * @author jclegea
   */
  private void insertInformationDatamodel() {
    ComOperation operation;
    ComOperationCollector operations = new ComOperationCollector();
    ComOperationCollector operationSet = null;
    ArrayList actualHostList = new ArrayList();
    String key = null;
    String hostVirtualMachineName = null;
    String hostName = null;
    boolean isInserted = false;

    try {

      // See if there are new virtual machines with respect to the metamodel
      // iterate all the sites, datacenters, racks availables to find the servers
      for (int i = 0; i < datacenterInformation_.getSiteListSize(); i++) {
        for (int j = 0; j < datacenterInformation_.getDatacenterListSize(i); j++) {
          for (int k = 0; k < datacenterInformation_.getRackListSize(i, j); k++) {
            for (int l = 0; l < datacenterInformation_.getEnclosureListSize(i, j, k); l++) {
              for (int m = 0; m < datacenterInformation_.getHostListSize(i, j, k, l); m++) {
                hostName = datacenterInformation_.getHostName(i, j, k, l, m);

                log.debug(
                    "host: "
                        + hostName
                        + " virtual machines: "
                        + datacenterInformation_.getVmListSize(i, j, k, l, m));

                key = this.comName + "_" + hostName;
                log.debug("queueHashmap: " + this.getQueuesHashMap().size());

                // Test if host is in the model
                if (((ConcurrentLinkedQueue<ComOperationCollector>)
                        this.getQueuesHashMap().get(key))
                    != null) {
                  createHostVirtualMachineList(actualHostList, i, j, k, l, m);
                  // datacenterInformation_.getHostVirtualMachines(i);
                  operationSet = new ComOperationCollector();
                  log.debug("actualHostList size: " + actualHostList.size());

                  log.debug(
                      "virtual machine list: "
                          + datacenterInformation_.getVmListSize(i, j, k, l, m));
                  // ADD virtual machines for host in fit4green model
                  for (int n = 0; n < datacenterInformation_.getVmListSize(i, j, k, l, m); n++) {
                    hostVirtualMachineName = datacenterInformation_.getVmName(i, j, k, l, m, n);
                    if (actualHostList.contains(hostVirtualMachineName) == false
                        && hostVirtualMachineName != null) {
                      // ADD a virtual machine to the model
                      operation =
                          new ComOperation(
                              ComOperation.TYPE_ADD,
                              "./nativeHypervisor/virtualMachine/frameworkID",
                              hostVirtualMachineName
                                  + " a a "
                                  + datacenterInformation_.getVmNumCpus(i, j, k, l, m, n)
                                  + " "
                                  + hostVirtualMachineName);
                      operations.add(operation);
                      ((ConcurrentLinkedQueue<ComOperationCollector>)
                              this.getQueuesHashMap().get(key))
                          .add(operations);
                      monitor.updateNode(key, this);
                      operations.remove(operation);
                      ((ConcurrentLinkedQueue<ComOperationCollector>)
                              this.getQueuesHashMap().get(key))
                          .poll();
                    } else {
                      // Remove Virtual machine from actualHostList
                      actualHostList.remove(hostVirtualMachineName);
                    }
                  }

                  // DELETE virtual machines for host in fit4green model
                  for (int n = 0; n < actualHostList.size(); n++) {
                    log.debug("DELETING Virtual machine " + (String) actualHostList.get(j));
                    operation =
                        new ComOperation(
                            ComOperation.TYPE_REMOVE,
                            "./nativeHypervisor/virtualMachine/frameworkID",
                            (String) actualHostList.get(j)
                                + " a a "
                                + datacenterInformation_.getVmNumCpus(i, j, k, l, m, n));
                    operations.add(operation);
                    ((ConcurrentLinkedQueue<ComOperationCollector>)
                            this.getQueuesHashMap().get(key))
                        .add(operations);
                    monitor.updateNode(key, this);
                    operations.remove(operation);
                    ((ConcurrentLinkedQueue<ComOperationCollector>)
                            this.getQueuesHashMap().get(key))
                        .poll();
                  }

                  // Update values for virtual machines in a host
                  for (int n = 0; n < datacenterInformation_.getVmListSize(i, j, k, l, m); n++) {
                    updateVMDynamicValues(i, j, k, l, m, n, operationSet);
                  }

                  // Update values for the host
                  updateHostDynamicValues(i, j, k, l, m, operationSet, hostName);

                  log.debug("operation list size: " + operationSet.getOperations().size());
                  if (operationSet != null) {
                    isInserted = monitor.simpleUpdateNode(key, operationSet);
                  }
                }
              } // m
            } // l
          } // k
        } // j
      } // i

      monitor.logModel();
    } catch (Exception exception) {
      log.error("Exception inserting data on to the fit4green model", exception);
    }
  }