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