Exemplo n.º 1
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;
 }
Exemplo n.º 2
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);
      }
    }
  }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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");
        }
      }
    }
  }
Exemplo n.º 5
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();
        }
      }
    }
  }