public void createBufferCommodities(PhysicalMachine pm) {
    // The pm sells buffer to all the vms that it hosts
    BufferCommodity pmBufferSold =
        (BufferCommodity)
            createObject(
                AbstractionPackage.eINSTANCE.getBufferCommodity(), "Buffer/" + pm.getName());

    if (!pmBufferSold.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_Capacity()))
      pmBufferSold.setCapacity(100000);

    pm.getCommodities().add(pmBufferSold);

    for (VMTManagedEntity managedEntity : pm.getHosts()) {
      if (managedEntity instanceof ServiceEntity) {
        ServiceEntity vm = (ServiceEntity) managedEntity;
        BufferCommodity vmBufferBought =
            (BufferCommodity)
                createObject(
                    AbstractionPackage.eINSTANCE.getBufferCommodity(),
                    "Buffer/" + managedEntity.getName());

        vm.getCommoditiesBought().add(vmBufferBought);
        vmBufferBought.getConsumes().add(pmBufferSold);
      }
    }
  }
Пример #2
0
 /**
  * Check if the vm belonging to the dpod
  *
  * @param dpod The dpod
  * @param vm The VM
  */
 public static boolean isVmInDpod(VirtualMachine vm, DPod dpod) {
   for (ServiceEntity se : dpod.getLayeredOver()) {
     if (se instanceof PhysicalMachine && se.getHosts().contains(vm)) {
       return true;
     }
   }
   return false;
 }
Пример #3
0
  public static <M extends VMTRootObject> void setUsedForPod(
      @Nonnull Class<M> cls,
      EReference classCommRef,
      EReference pod2EntityRef,
      EReference entityCommRef) {

    @SuppressWarnings("unchecked")
    Iterable<ServiceEntity> ses = (Iterable<ServiceEntity>) rg.getInstances(cls);
    for (ServiceEntity se : ses) {
      if (se.isIsTemplate()
          || se.getParticipatesIn() == null
          || !se.getParticipatesIn().isMainMarket()) continue;

      float cpuUsed = 0f, memUsed = 0f, stAmount = 0f, flow1Used = 0f, flow2Used = 0f;
      for (VMTRootObject vmtObj :
          se.getRef(pod2EntityRef, AnalysisPackage.eINSTANCE.getServiceEntity())) {
        for (VMTRootObject commObj :
            vmtObj.getRef(entityCommRef, AnalysisPackage.eINSTANCE.getCommodity())) {

          Commodity comm = (Commodity) commObj;
          if (comm instanceof CPU) cpuUsed += comm.getUsed();
          else if (comm instanceof Mem) memUsed += comm.getUsed();
          else if (comm instanceof StorageAmount) stAmount += comm.getUsed();
          else if (comm instanceof Flow) {
            if (comm.getKey().contains(PodUtil.FLOW_KEYS[1])) flow1Used += comm.getUsed();
            else if (comm.getKey().contains(PodUtil.FLOW_KEYS[2])) flow2Used += comm.getUsed();
          }
        }
      }

      CPUAllocation cpuAllocation =
          (CPUAllocation)
              se.getRef(classCommRef, AbstractionPackage.eINSTANCE.getCPUAllocation()).get(0);
      MemAllocation memAllocation =
          (MemAllocation)
              se.getRef(classCommRef, AbstractionPackage.eINSTANCE.getMemAllocation()).get(0);
      List<VMTRootObject> flowAllocation =
          se.getRef(classCommRef, AbstractionPackage.eINSTANCE.getFlowAllocation());

      cpuAllocation.setUsed(cpuUsed);
      memAllocation.setUsed(memUsed);
      if (se.getRef(classCommRef, AbstractionPackage.eINSTANCE.getStorageAllocation()).size() > 0) {
        StorageAllocation stAllocation =
            (StorageAllocation)
                se.getRef(classCommRef, AbstractionPackage.eINSTANCE.getStorageAllocation()).get(0);
        stAllocation.setUsed(stAmount);
      }
      for (VMTRootObject flowAllocObj : flowAllocation) {

        Commodity flowComm = (Commodity) flowAllocObj;
        if (flowComm.getKey().contains(PodUtil.FLOW_KEYS[1])) flowComm.setUsed(flow1Used);
        else if (flowComm.getKey().contains(PodUtil.FLOW_KEYS[2])) flowComm.setUsed(flow2Used);
      }
    }
  }
Пример #4
0
 /**
  *
  * <!-- begin-user-doc -->
  * The capacity of the ballooning commodity sold by a PM is the sum of configured memory on all
  * powered-on VMs hosted by this PM times 65%. It is capped below by the size of physical memory.
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 @Override
 public float getCapacity() {
   if (capacity != CAPACITY_EDEFAULT) {
     return capacity;
   }
   ServiceEntity host = getSoldBy();
   if (host == null) {
     return super.getCapacity();
   }
   if (host instanceof PhysicalMachine) {
     PhysicalMachine pm = (PhysicalMachine) host;
     if (pm.isRecalculateBallooning() || cachedCapacity == 0) {
       float sum_vm_mem_size = 0.0F;
       float pm_mem_size = 0;
       List<VMTRootObject> mems =
           host.getRef(
               AnalysisPackage.eINSTANCE.getServiceEntity_Commodities(),
               AbstractionPackage.eINSTANCE.getMem());
       if (mems.size() > 0) {
         Mem mem = (Mem) mems.get(0);
         pm_mem_size = mem.getCapacity();
       }
       for (VMTManagedEntity me : host.getHosts()) {
         if (me instanceof VirtualMachine) {
           VirtualMachine vm = (VirtualMachine) me;
           ServiceEntityState state = vm.getState();
           if (state.equals(ServiceEntityState.ACTIVE)
               || state.equals(ServiceEntityState.SUSPEND_PENDING)
               || state.equals(ServiceEntityState.TERMINATE_PENDING)) {
             List<VMTRootObject> vmems =
                 vm.getRef(
                     ManagedEntitiesPackage.eINSTANCE.getVMTManagedEntity_ComposedOf(),
                     AbstractionPackage.eINSTANCE.getVMemory());
             for (VMTRootObject vmt : vmems) { // there should be only one
               VMemory vmem = (VMemory) vmt;
               sum_vm_mem_size += vmem.getCapacity();
             }
           }
         }
       }
       cachedCapacity = (float) Math.max(pm_mem_size, sum_vm_mem_size * 1024.0 * FACTOR);
       pm.setRecalculateBallooning(false);
     }
   }
   return cachedCapacity;
 }
Пример #5
0
 /**
  * Search the entity's layeredOver relationship for an attached VPod
  *
  * @param se The se to find the VPod for
  * @return The VPod found for the Service Entity
  */
 public static VPod findVPod(ServiceEntity se) {
   List<VMTRootObject> vPods =
       se.getRef(
           AnalysisPackage.eINSTANCE.getServiceEntity_LayeredOver(),
           AbstractionPackage.eINSTANCE.getVPod());
   if (!vPods.isEmpty()) return (VPod) vPods.get(0);
   return null;
 }
Пример #6
0
  private static void setUsedForDpodCommBought() {
    for (DPod se : rg.getInstances(DPod.class)) {

      if (se.isIsTemplate()
          || se.getParticipatesIn() == null
          || !se.getParticipatesIn().isMainMarket()) continue;

      float used = 0;
      for (Commodity comm : se.getCommoditiesBought()) {

        if (!comm.getConsumes().isEmpty()) {

          Commodity commSoldByProvider = comm.getConsumes().get(0);
          ServiceEntity provider = commSoldByProvider.getSoldBy();

          for (VMTRootObject vmtObj :
              provider.getRef(
                  getRelatedEntitiesRef(provider), AnalysisPackage.eINSTANCE.getServiceEntity())) {

            if (vmtObj instanceof VirtualMachine) {

              VirtualMachine vm = (VirtualMachine) vmtObj;
              float entityCommmodityUsed = 0;
              for (Commodity entityCommodity : vm.getCommoditiesBought()) {

                if (entityCommodity.eClass() == commAllocation2CommMap.get(comm.eClass())) {

                  if (entityCommodity.getKey() != null
                      && !comm.getKey().contains(entityCommodity.getKey())) continue;

                  entityCommmodityUsed = entityCommodity.getUsed();
                  break;
                }
              }
              used += entityCommmodityUsed;
            }
          }
          comm.setUsed(used);

          used = 0;
        } else {
          logger.warn("The commodity " + comm.getDisplayName() + " is not consuming anything");
        }
      }
    }
  }
Пример #7
0
  /**
   * At the end of each polling cycle, we need to set the used for all the pms, vpods and dpods,
   * which accumulates the used
   *
   * @param class1
   */
  public static <M extends VMTRootObject> void updateAccumulatedFlow(
      @Nonnull Class<M> cls, EReference commRef) {
    @SuppressWarnings("unchecked")
    Iterable<ServiceEntity> ses = (Iterable<ServiceEntity>) rg.getInstances(cls);
    for (ServiceEntity se : ses) {

      // Ignore templates and plan entities
      if (se.isIsTemplate()
          || se.getParticipatesIn() == null
          || !se.getParticipatesIn().isMainMarket()) continue;

      for (VMTRootObject comm : se.getRef(commRef, AnalysisPackage.eINSTANCE.getCommodity())) {
        if (comm instanceof Flow) {
          FlowImpl f = (FlowImpl) comm;
          f.calculateUsed();
        }
      }
    }
  }
Пример #8
0
  /**
   * The UUID is generated by concatenating the uuid of the two SEs in lexicographical order.
   *
   * @param endPoint1
   * @param endPoint2
   * @return
   */
  public static String formContainerPairUuid(ServiceEntity endPoint1, ServiceEntity endPoint2) {

    String containerPairUuid = "";
    if (endPoint1.getUuid().compareTo(endPoint2.getUuid()) >= 0)
      containerPairUuid = endPoint1.getUuid() + endPoint2.getUuid();
    else containerPairUuid = endPoint2.getUuid() + endPoint1.getUuid();

    return containerPairUuid;
  }
  protected Commodity getCommodityBoughtByKey(
      ServiceEntity se, EClass eClass, String key, ServiceEntity provider) {
    Commodity commBought = null;
    for (Commodity comm : se.getCommoditiesBought()) {
      boolean hasSameKey =
          (comm.getKey() == null && key == null)
              || (comm.getKey() != null && key != null && comm.getKey().equals(key));
      boolean isSameClass = comm.eClass() == eClass;
      boolean hasSameProvider =
          !comm.getConsumes().isEmpty() && comm.getConsumes().get(0).getSoldBy() == provider;
      if (hasSameKey && isSameClass && hasSameProvider) {
        commBought = comm;
        break;
      }
    }

    return commBought;
  }
Пример #10
0
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated NOT
   */
  @Override
  public EList<HistoricalValues> updateHistoryExtensions(SnapshotCollection snapshotCollection) {
    // long start = System.currentTimeMillis();
    // String typeName = ((EClass)getSEType()).getName();
    EList<HistoricalValues> histValsList = new BasicEList<HistoricalValues>();
    RepositoryRegistry rg = RepositoryRegistry.vmtMANAGER;
    // long start4 = System.currentTimeMillis();
    Set<VMTRootObject> vObj = rg.getInstances(getSEType());
    // logger.info("getting SE instances fo SE type "+typeName +" took:
    // "+(System.currentTimeMillis()-start4));

    EList<EObject> attrList = getAttribute();
    EList<ENamedElement> nes = new BasicEList<ENamedElement>();
    ServiceEntityHistoryExt histExt;

    // long start5 = System.currentTimeMillis();
    for (VMTRootObject obj : vObj) {
      // long start3 = System.currentTimeMillis();
      boolean constraintFailed = false;
      ServiceEntity se = (ServiceEntity) obj;
      // Check constraints + that the se participates in the main market and not a template
      if ((se.getServiceEntityOf() != null)
          && se.getServiceEntityOf().isMainMarket()
          && (se.getTemplateForMarket() == null)) {

        for (Constraint constraint : getMatchingCriteria()) {
          if (!constraint.match(obj)) {
            constraintFailed = true;
            break;
          }
        }
      } else {
        constraintFailed = true;
      }

      // and skip if any of the constraints do not match
      if (constraintFailed) continue;

      histExt =
          (ServiceEntityHistoryExt)
              se.createExtension(ReportingExtensionsPackage.eINSTANCE.getServiceEntityHistoryExt());
      histExt.setSnapshotCollection(snapshotCollection);
      if (scLogger.isTraceEnabled())
        scLogger.trace(String.format("%s: Updating ServiceEntityHistoryExt", se.toVMTString()));

      // Get the attribute value and create/add to the historical values
      if (attrList.size() == 1) {
        EStructuralFeature attribute = (EStructuralFeature) attrList.get(0);

        HistoricalValues vals;
        EList<HistoricalValues> valuesList = histExt.getHistoricalValues(attribute.getName());
        // if the attribute was not added to the extension yet create it
        if (valuesList == null || valuesList.isEmpty()) {
          vals = ReportingFactory.eINSTANCE.createHistoricalValues();
          vals.initValues(snapshotCollection);
          histExt.addHistoricalValues(attribute.getName(), vals);
          if (scLogger.isTraceEnabled())
            scLogger.trace(
                String.format(
                    "%s: Adding historicalValues for attribute %s",
                    se.toVMTString(), attribute.getName()));
        } else {
          // There cannot be more than 1 value for an attribute.
          vals = histExt.getHistoricalValues(attribute.getName()).get(0);
        }

        // Only add a value if the attribute has been set already - otherwise add no value
        if (obj.eIsSet(attribute)) {
          Object attributeValue = obj.eGet(attribute);
          vals.addValue((Float) attributeValue);
          histValsList.add(vals);
          if (scLogger.isTraceEnabled())
            scLogger.trace(
                String.format(
                    "%s: Adding value %f to historicalValues for attribute %s",
                    se.toVMTString(), attributeValue, attribute.getName()));
        } else {
          vals.addValue(HistoricalValuesImpl.NO_VALUE);
          if (scLogger.isTraceEnabled())
            scLogger.trace(
                String.format(
                    "%s: Adding no value to historicalValues for attribute %s",
                    se.toVMTString(), attribute.getName()));
        }
      }
      // Or get the list of attribute values and create/add to historical values for each
      else {
        nes.clear();
        /* previously we assumed a list of size 3 [reference, commodity, attribute], now we assume
         * the last entry is the attribute and the third to last entry is the commodity. */
        EStructuralFeature attribute = (EStructuralFeature) attrList.get(attrList.size() - 1);
        EReference reference = (EReference) attrList.get(attrList.size() - 3);

        // instead of: nes.addAll((Collection<? extends ENamedElement>) attrList.subList(0,
        // attrList.size()-1));
        for (int i = 0; i < attrList.size() - 1; i++) nes.add((ENamedElement) attrList.get(i));

        List<Object> matchedCommodities = obj.getValues(nes);
        for (Object commObj : matchedCommodities) {

          // long start2 = System.currentTimeMillis();

          if (commObj instanceof Commodity) {
            Commodity comm = (Commodity) commObj;

            // if a history extension already exists use it, otherwise create a new one and
            // initialize it.
            if (comm.getHistoryExtension() == null) {
              CommodityHistoryExt commHistExt =
                  (CommodityHistoryExt)
                      comm.createExtension(
                          ReportingExtensionsPackage.eINSTANCE.getCommodityHistoryExt());
              commHistExt.init(snapshotCollection, histExt);
              if (scLogger.isTraceEnabled())
                scLogger.trace(
                    String.format(
                        "%s: Updating CommodityHistoryExt for %s",
                        se.toVMTString(), comm.toVMTString()));
            }

            // update the snapshot collection accumulated used values
            snapshotCollection.updateOverallCommodityUsage(comm);

            try {
              // add the value to the historical ext - insert to the proper historical values
              HistoricalValues vals =
                  comm.getHistoryExtension().getFeatureHistory(attribute, reference);

              // Only add a value for the attributes that have been set already
              if (comm.eIsSet(attribute)) {
                vals.addValue((Float) comm.eGet(attribute));
                histValsList.add(vals);
                if (scLogger.isTraceEnabled())
                  scLogger.trace(
                      String.format(
                          "%s: Adding value %f to historicalValues of commodity %s for attribute %s",
                          se.toVMTString(),
                          comm.eGet(attribute),
                          comm.toVMTString(),
                          attribute.getName()));
              }
              // otherwise - set to NO VALUE
              else {
                vals.addValue(HistoricalValuesImpl.NO_VALUE);
                if (scLogger.isTraceEnabled())
                  scLogger.trace(
                      String.format(
                          "%s: Adding no value to historicalValues of commodity %s for attribute %s",
                          se.toVMTString(), comm.toVMTString(), attribute.getName()));
              }
            } catch (Exception e) {
              logger.error(
                  "Exception trying to update history extension for "
                      + comm.getName()
                      + "::"
                      + attribute.getName(),
                  e);
            }
          } else {
            logger.error(
                "Missconfigured MetaReacord. Penultimate argument should be a Commodity: "
                    + commObj);
          }

          // logger.info("updating a single commodity for SE type "+typeName +" took:
          // "+(System.currentTimeMillis()-start2));
        }
      }
      // logger.info("updating a single entity for SE type "+typeName +" took:
      // "+(System.currentTimeMillis()-start3));
    }
    // logger.info("iterating over all entities of type "+typeName +" took:
    // "+(System.currentTimeMillis()-start5));

    // logger.info("update history extension for SE type "+typeName +" took:
    // "+(System.currentTimeMillis()-start));
    return histValsList;
  }
Пример #11
0
  /**
   *
   * <!-- begin-user-doc -->
   * This method goes over a provided SEType (config file) entities with matching criteria defined
   * in config file. It goes over the attributes required to report on and collects min,max and avg
   * into extension objects for commodity and service entity.
   *
   * <p>Every hour it creates a list of {@link ReportingRecord} objects with data and returns this
   * list.
   * <!-- end-user-doc -->
   *
   * @param hourChanged true if the hour changed from the previous gathering of values.
   * @generated NOT
   */
  @Override
  public EList<ReportingRecord> getReportingRecordList(boolean hourChanged) {
    EList<ReportingRecord> returnList = new BasicEList<ReportingRecord>();
    long hourlyTimeStamp = 0l;
    try {
      RepositoryRegistry rg = RepositoryRegistry.vmtMANAGER;
      Set<VMTRootObject> vObjList = rg.getInstances(getSEType());

      if (hourChanged) {
        hourlyTimeStamp =
            (System.currentTimeMillis()
                - (1000 * 60 * 30)); // Give the record TS of the middle of the last hour
      }

      for (VMTRootObject vObj : vObjList) {
        boolean constraintfailed = false;
        // Check constraints
        for (Constraint constraint : getMatchingCriteria()) {
          if (!constraint.match(vObj)) {
            constraintfailed = true;
            break;
          }
        }

        // and skip if any of the constraints do not match
        if (constraintfailed) {
          continue;
        }

        ServiceEntity se = (ServiceEntity) vObj;
        if (DeployManager.vmtMANAGER.inDeploy(se)) {
          continue;
        }

        // Get the Extension for ServiceEntity
        ServiceEntityReportingExt seExt =
            (ServiceEntityReportingExt)
                se.findExtension(
                    ReportingExtensionsPackage.eINSTANCE.getServiceEntityReportingExt());
        if (seExt == null) {
          seExt = ReportingExtensionsFactory.eINSTANCE.createServiceEntityReportingExt();
          se.getExtendedBy().add(seExt);
        }

        for (NamedElementList neList : getNamedElementList()) {
          if (neList.getNamedElement().size() == 1) {
            EStructuralFeature attribute = (EStructuralFeature) neList.getNamedElement().get(0);
            // Only create a record if the attribute has been set already
            if (vObj.eIsSet(attribute)) {
              Object attributeValue = vObj.eGet(attribute);
              if (attributeValue instanceof List<?>) {
                if (hourChanged) {
                  // Record Object
                  ReportingRecord record =
                      this.createReportingRecord(
                          seExt, vObj, attribute, null, null, true, hourlyTimeStamp);
                  if (record != null) {
                    returnList.add(record);
                  }
                  // reset only numProduces fields
                  seExt.resetValues(attribute);
                }
                // this condition for numProduces value
                seExt.setMinNumProduces(((List<?>) attributeValue).size());
                seExt.setMaxNumProduces(((List<?>) attributeValue).size());
                seExt.setProducesSum(((List<?>) attributeValue).size());
                // if(logger.isDebugEnabled())logger.debug("numProduces : min = " +
                // seExt.getMinNumProduces() + " max = " + seExt.getMaxNumProduces() + " sum = " +
                // seExt.getProducesSum());
              } else {
                double val = Double.parseDouble(attributeValue.toString());
                if (val > PRICE_THRESHOLD) {
                  val = PRICE_THRESHOLD;
                }

                if (attribute == AnalysisPackage.eINSTANCE.getServiceEntity_PriceIndex()) {
                  if (val < 0) {
                    if (logger.isDebugEnabled()) {
                      logger.error(
                          "SE : " + vObj.toVMTString() + " has a negative value of " + val);
                      for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
                        logger.debug(element.toString());
                      }
                    }
                    continue;
                  }
                }

                List<EAttribute> atts = seExt.getExtAttributes(attribute);
                for (EAttribute att : atts) {
                  seExt.eSet(att, val);
                }
                if (hourChanged) {
                  // Record Object
                  ReportingRecord record =
                      this.createReportingRecord(
                          seExt, vObj, attribute, null, null, false, hourlyTimeStamp);
                  if (record != null) {
                    returnList.add(record);
                  }
                  // reset only UtilIndex fields
                  seExt.resetValues(attribute);
                }
              }
            }
            // Or get the list of attribute values and create a record for each
          } else {
            EReference reference = (EReference) neList.getNamedElement().get(0);
            ENamedElement commodity = neList.getNamedElement().get(1);
            EStructuralFeature attribute =
                (EStructuralFeature)
                    neList.getNamedElement().get(neList.getNamedElement().size() - 1);

            List<ENamedElement> nesCommodity =
                new ArrayList<ENamedElement>(neList.getNamedElement());
            nesCommodity.remove(neList.getNamedElement().size() - 1);
            List<Object> commodityList = vObj.getValues(nesCommodity);

            for (int i = 0; i < commodityList.size(); i++) {
              Commodity comm = (Commodity) commodityList.get(i);
              // get the attribute value from the commodity if it is set
              if (comm.eIsSet(attribute)) {
                Object attributeValue = comm.eGet(attribute);
                // logger.info("comm att " + comm.getName() + " " + attribute.getName() + " value =
                // " + attributeValue);
                CommodityReportingExt crExt = null;
                for (Extension ext : comm.getExtendedBy()) {
                  if (ext instanceof CommodityReportingExt) {
                    crExt = (CommodityReportingExt) ext;
                    if (crExt.getAttribute() == attribute) {
                      break;
                    } else {
                      crExt = null;
                    }
                  }
                }
                if (crExt == null) {
                  crExt = ReportingExtensionsFactory.eINSTANCE.createCommodityReportingExt();
                  crExt.setAttribute(attribute);
                  comm.getExtendedBy().add(crExt);
                }

                if (hourChanged) {
                  // Record Object
                  ReportingRecord record =
                      this.createReportingRecord(
                          crExt, vObj, attribute, commodity, comm, false, hourlyTimeStamp);
                  if (record != null) {
                    returnList.add(record);
                  }
                  crExt.resetValues();
                }
                // this condition for capacity, used and utilization values
                crExt.setMinUtilization(Double.parseDouble(attributeValue.toString()));
                if (attribute.equals(AnalysisPackage.eINSTANCE.getCommodity_Used())
                    && comm.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_Peak())) {
                  crExt.setMaxUtilization(comm.getPeak());
                } else if (attribute.equals(AnalysisPackage.eINSTANCE.getCommodity_Utilization())
                    && comm.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_PeakUtilization())) {
                  crExt.setMaxUtilization(comm.getPeakUtilization());
                } else {
                  crExt.setMaxUtilization(Double.parseDouble(attributeValue.toString()));
                }
                crExt.setUtilSum(Double.parseDouble(attributeValue.toString()));

                float capacity = comm.getCapacity();
                if (capacity > CAPACITY_THRESHOLD) {
                  if (logger.isDebugEnabled()) {
                    logger.debug(
                        "Capacity for "
                            + se.getDisplayName()
                            + "::"
                            + comm.getDisplayName()
                            + " is "
                            + capacity
                            + ". Capping it to "
                            + CAPACITY_THRESHOLD);
                  }
                  capacity = CAPACITY_THRESHOLD;
                }
                crExt.setCapacity(capacity);
                crExt.setRelation(
                    RelationType.valueOf(reference.getName().toUpperCase()).getValue());
                crExt.setCommodityKey(comm.getKey());
                // if(logger.isDebugEnabled())logger.debug("comm -> " + attribute.getName() + " min
                // = " + crExt.getMinUtilization() + " max = " + crExt.getMaxUtilization() + " sum =
                // " + crExt.getUtilSum() + " cap = " + crExt.getCapacity());
              }
            }
          }
        }
      }
    } catch (Exception e) {
      logger.error("Exception in MetaRecordImpl.getReportingRecordList()", e);
    }
    return returnList;
  }
Пример #12
0
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated NOT
   */
  @Override
  public EList<Record> getRecords() {
    EList<Record> recordList = new BasicEList<Record>();
    RepositoryRegistry rg = RepositoryRegistry.vmtMANAGER;
    Set<VMTRootObject> vObj = rg.getInstances(getSEType());

    EList<EObject> attrList = getAttribute();
    EList<ENamedElement> nes = new BasicEList<ENamedElement>();

    for (VMTRootObject obj : vObj) {
      boolean constraintfailed = false;
      ServiceEntity se = (ServiceEntity) obj;
      // Check constraints + that the se participates in the main market and not a template
      if ((se.getServiceEntityOf() != null)
          && se.getServiceEntityOf().isMainMarket()
          && (se.getTemplateForMarket() == null)) {

        for (Constraint constraint : getMatchingCriteria()) {
          if (!constraint.match(obj)) {
            constraintfailed = true;
            break;
          }
        }
      } else {
        constraintfailed = true;
      }

      // and skip if any of the constraints do not match
      if (constraintfailed) continue;

      // Get the attribute value and create a single record
      if (attrList.size() == 1) {
        EStructuralFeature attribute = (EStructuralFeature) attrList.get(0);
        // Only create a record if the attribute has been set already
        if (obj.eIsSet(attribute)) {
          Object attributeValue = obj.eGet(attribute);
          RecordFromMetaRecord rec = ReportingFactory.eINSTANCE.createRecordFromMetaRecord();
          rec.setObject(obj);
          rec.setFeature(attribute);
          if (trackSize && attributeValue instanceof List<?>) {
            rec.setValueObject(((List<?>) attributeValue).size());
          } else if (trackSize) {
            rec.setValueObject(1);
          } else {
            rec.setValueObject(attributeValue);
          }
          recordList.add(rec);
        }
        // Or get the list of attribute values and create a record for each
      } else {
        nes.clear();
        EReference reference = (EReference) attrList.get(attrList.size() - 3);
        ENamedElement commodity = (ENamedElement) attrList.get(attrList.size() - 2);
        EStructuralFeature attribute = (EStructuralFeature) attrList.get(attrList.size() - 1);

        for (EObject attrib : attrList) {
          nes.add((ENamedElement) attrib);
        }
        // Only creating a record for the attributes that has been set already, otherwise getValues
        // returns no elements in the list
        List<Object> attributeValueList = obj.getValues(nes);
        for (Object attributeValue : attributeValueList) {
          RecordFromMetaRecord2 rec = ReportingFactory.eINSTANCE.createRecordFromMetaRecord2();
          rec.setObject(obj);
          rec.setFeature(attribute);
          rec.setCommodity(commodity);
          rec.setReference(reference);
          if (trackSize && attributeValue instanceof List<?>) {
            rec.setValueObject(((List<?>) attributeValue).size());
          } else if (trackSize) {
            rec.setValueObject(1);
          } else {
            rec.setValueObject(attributeValue);
          }
          recordList.add(rec);
        }
      }
    }
    return recordList;
  }
Пример #13
0
  /**
   * Create a DPod object layered over the given list of entities.
   *
   * @param seList A list of entities layered over the DPod
   * @param scName The name of the Storage Controller that defined this DPod
   * @return The DPod created
   */
  public static DPod createDPod(
      DPod dPod,
      final Set<ServiceEntity> seList,
      HistoryUtil historyLayeredOver,
      HistoryUtil historyUnderlying) {

    // Need a naming method for DPod
    dPod.setDisplayName(dPod.getName());

    // Create all the relationships between the providers and the dPod
    Map<String, Float> key2flowCap = new HashMap<String, Float>();
    key2flowCap.put(PodUtil.FLOW_KEYS[1], 0f);
    key2flowCap.put(PodUtil.FLOW_KEYS[2], 0f);
    float cpuCap = 0f, memCap = 0f, stCap = 0f;
    for (ServiceEntity se : seList) {
      attachDPodToProvider(se, dPod, historyLayeredOver);

      // calculate the sum of the capacities for each type of commodity
      for (Commodity comm : se.getCommodities()) {
        if (comm.eClass() == AbstractionPackage.eINSTANCE.getFlow()) {
          if (comm.getKey().contains(PodUtil.FLOW_KEYS[1])) {
            key2flowCap.put(
                PodUtil.FLOW_KEYS[1], key2flowCap.get(PodUtil.FLOW_KEYS[1]) + comm.getCapacity());
            logger.trace(
                "Flow-1 Commodity: "
                    + comm.getDisplayName()
                    + " has capacity "
                    + comm.getCapacity());
            logger.trace(
                "Flow-1 capacity (after addition): " + key2flowCap.get(PodUtil.FLOW_KEYS[1]));
          } else if (comm.getKey().contains(PodUtil.FLOW_KEYS[2])) {
            key2flowCap.put(
                PodUtil.FLOW_KEYS[2], key2flowCap.get(PodUtil.FLOW_KEYS[2]) + comm.getCapacity());
            logger.trace("Flow-2 Commodity has capacity " + comm.getCapacity());
            logger.trace(
                "Flow-2 capacity (after addition): " + key2flowCap.get(PodUtil.FLOW_KEYS[2]));
          }
        } else if (comm.eClass() == AbstractionPackage.eINSTANCE.getCPU()) {
          cpuCap += comm.getCapacity();
        } else if (comm.eClass() == AbstractionPackage.eINSTANCE.getMem()) {
          memCap += comm.getCapacity();
        } else if (comm.eClass() == AbstractionPackage.eINSTANCE.getStorageAmount()) {
          stCap += comm.getCapacity();
        }
      }
    }

    // Create commodities sold by the DPod
    // The capacity of the commodities is equal to the sum of the capacities on all underlying
    // entities
    StorageAllocation stAlloc =
        (StorageAllocation)
            createObject(
                AbstractionPackage.eINSTANCE.getStorageAllocation(), "ST-" + dPod.getName());
    stAlloc.setCapacity(stCap);
    stAlloc.setKey(CommodityImpl.dynCommKey(dPod));
    stAlloc.setResizeable(false);
    dPod.getCommodities().add(stAlloc);

    CPUAllocation cpuAlloc =
        (CPUAllocation)
            createObject(AbstractionPackage.eINSTANCE.getCPUAllocation(), "CPU-" + dPod.getName());
    cpuAlloc.setCapacity(cpuCap);
    cpuAlloc.setKey(CommodityImpl.dynCommKey(dPod));
    cpuAlloc.setResizeable(false);
    dPod.getCommodities().add(cpuAlloc);

    MemAllocation memAlloc =
        (MemAllocation)
            createObject(AbstractionPackage.eINSTANCE.getMemAllocation(), "MEM-" + dPod.getName());
    memAlloc.setCapacity(memCap);
    memAlloc.setKey(CommodityImpl.dynCommKey(dPod));
    memAlloc.setResizeable(false);
    dPod.getCommodities().add(memAlloc);

    for (int level = 1; level < PodUtil.FLOW_KEYS.length; level++) {
      FlowAllocation flowAlloc =
          (FlowAllocation)
              createObject(
                  AbstractionPackage.eINSTANCE.getFlowAllocation(),
                  "FlowAllocation-" + level + "-" + dPod.getName());
      logger.info(
          "Flow-" + level + " Allocation capacity " + key2flowCap.get(PodUtil.FLOW_KEYS[level]));
      if (key2flowCap.get(PodUtil.FLOW_KEYS[level]) >= 9e14) {
        logger.trace("Flow-" + level + " Allocation capacity is too high.");
        logger.trace(
            "Flow-"
                + level
                + " Allocation Capacity is "
                + key2flowCap.get(PodUtil.FLOW_KEYS[level]));
      }
      flowAlloc.setCapacity(key2flowCap.get(PodUtil.FLOW_KEYS[level]));
      flowAlloc.setKey(PodUtil.getFlowKey(CommodityImpl.dynCommKey(dPod), level));
      flowAlloc.setResizeable(false);
      dPod.getCommodities().add(flowAlloc);
    }

    return dPod;
  }
Пример #14
0
  /**
   * Creates all the necessary commodities and relationships between a provider and the DPod layered
   * over it.
   *
   * @param provider The provider (Physical Machine or Storage)
   * @param dPod The DPod
   * @param historyLayeredOver
   */
  public static void attachDPodToProvider(
      final ServiceEntity provider, final DPod dPod, final HistoryUtil historyLayeredOver) {

    String providerName = provider.getName();
    String commKey = providerName + ":" + dPod.getName();
    if (provider instanceof PhysicalMachine) {
      // Create dPod commodities bought and commodities sold from the provider to the DPod
      CPUAllocation cpuAllocBought =
          (CPUAllocation)
              dPod.buyDynamicCommodity(AbstractionPackage.eINSTANCE.getCPUAllocation(), commKey, 0);
      cpuAllocBought.setName(
          commKey + ":" + AbstractionPackage.eINSTANCE.getCPUAllocation().getName() + "Bought");
      cpuAllocBought.setResizeable(false);
      dPod.getCommoditiesBought().add(cpuAllocBought);

      Commodity cpuAlloc =
          provider.sellDynamicCommodity(
              AbstractionPackage.eINSTANCE.getCPUAllocation(), commKey, 0, null);
      provider.getCommodities().add(cpuAlloc);
      cpuAllocBought.getConsumes().clear();
      cpuAllocBought.getConsumes().add(cpuAlloc);

      MemAllocation memAllocBought =
          (MemAllocation)
              dPod.buyDynamicCommodity(AbstractionPackage.eINSTANCE.getMemAllocation(), commKey, 0);
      memAllocBought.setName(
          commKey + ":" + AbstractionPackage.eINSTANCE.getMemAllocation().getName() + "Bought");
      memAllocBought.setResizeable(false);
      dPod.getCommoditiesBought().add(memAllocBought);

      Commodity memAlloc =
          provider.sellDynamicCommodity(
              AbstractionPackage.eINSTANCE.getMemAllocation(), commKey, 0, null);
      provider.getCommodities().add(memAlloc);
      memAllocBought.getConsumes().clear();
      memAllocBought.getConsumes().add(memAlloc);

      Map<String, Commodity> key2FlowAlloc = new HashMap<>();
      for (int level = 1; level < PodUtil.FLOW_KEYS.length; level++) {
        String commFlowKey = PodUtil.getFlowKey(commKey, level);
        FlowAllocation flowAllocBought =
            (FlowAllocation)
                dPod.buyDynamicCommodity(
                    AbstractionPackage.eINSTANCE.getFlowAllocation(), commFlowKey, 0);
        flowAllocBought.setName(
            commFlowKey
                + ":"
                + AbstractionPackage.eINSTANCE.getFlowAllocation().getName()
                + "Bought");
        flowAllocBought.setResizeable(false);
        dPod.getCommoditiesBought().add(flowAllocBought);

        Commodity flowAlloc =
            provider.sellDynamicCommodity(
                AbstractionPackage.eINSTANCE.getFlowAllocation(), commFlowKey, 0, null);
        provider.getCommodities().add(flowAlloc);
        flowAllocBought.getConsumes().clear();
        flowAllocBought.getConsumes().add(flowAlloc);
        key2FlowAlloc.put(PodUtil.FLOW_KEYS[level], flowAlloc);
      }

      // set the capacity of the provider sold allocation commodities to match the capacity
      // of the regular commodities
      for (Commodity comm : provider.getCommodities()) {
        if (comm.eClass() == AbstractionPackage.eINSTANCE.getMem())
          memAlloc.setCapacity(comm.getCapacity());
        else if (comm.eClass() == AbstractionPackage.eINSTANCE.getCPU())
          cpuAlloc.setCapacity(comm.getCapacity());
        else if (comm.eClass()
            == AbstractionPackage.eINSTANCE.getFlow()) { // update the alloc comm for the same level
          if (key2FlowAlloc.containsKey(comm.getKey()))
            logger.trace(
                "The Dpod "
                    + dPod.getName()
                    + "Flow-"
                    + comm.getKey()
                    + " capacity is "
                    + key2FlowAlloc.get(comm.getKey()).getCapacity());
          logger.trace(
              "The Provider "
                  + provider.getName()
                  + "Flow-"
                  + comm.getKey()
                  + "capacity is "
                  + comm.getCapacity());
          if (key2FlowAlloc.get(comm.getKey()) != null)
            key2FlowAlloc.get(comm.getKey()).setCapacity(comm.getCapacity());
        }
      }
    } else if (provider instanceof Storage) {
      StorageAllocation stAllocBought =
          (StorageAllocation)
              dPod.buyDynamicCommodity(
                  AbstractionPackage.eINSTANCE.getStorageAllocation(), commKey, 0);
      stAllocBought.setName(
          commKey + ":" + AbstractionPackage.eINSTANCE.getStorageAllocation().getName() + "Bought");
      stAllocBought.setResizeable(false);
      dPod.getCommoditiesBought().add(stAllocBought);

      Commodity stAlloc =
          provider.sellDynamicCommodity(
              AbstractionPackage.eINSTANCE.getStorageAllocation(), commKey, 0, null);
      provider.getCommodities().add(stAlloc);
      stAllocBought.getConsumes().clear();
      stAllocBought.getConsumes().add(stAlloc);

      for (Commodity comm : provider.getCommodities()) {
        if (comm.eClass() == AbstractionPackage.eINSTANCE.getStorageAmount())
          stAlloc.setCapacity(comm.getCapacity());
      }
    }

    dPod.getLayeredOver().add(provider);
    historyLayeredOver.remove(provider);
  }
Пример #15
0
 /**
  * Finds the DPod underlying the given service entity or null if there isn't one
  *
  * @param se The service entity to search
  * @return The DPod underlying the given service entity or null if there isn't one
  */
 public static DPod getDPodFromProvider(ServiceEntity se) {
   for (ServiceEntity underlying : se.getUnderlying()) {
     if (underlying instanceof DPod) return (DPod) underlying;
   }
   return null;
 }