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