Exemple #1
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);
      }
    }
  }
Exemple #2
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();
        }
      }
    }
  }