Esempio n. 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;
 }
Esempio n. 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);
  }