예제 #1
0
  /**
   * If a pair between the source and destination containers already exists - update it. If one
   * doesn't exist - create a new one
   *
   * @param source
   * @param dest
   * @param containerPairUuid
   * @param f
   * @return
   */
  public static ContainerPair createOrUpdateContainerPair(
      VirtualMachine source, VirtualMachine dest, String containerPairUuid, float f) {

    if (logger.isTraceEnabled())
      logger.trace(
          "Discovered "
              + f
              + " Flow between "
              + source.getDisplayName()
              + " and "
              + dest.getDisplayName());
    ContainerPair pair = null;
    // Go over all of the Flow commodities bought by either the source or the destination and look
    // for a pair containing these two entities
    for (Commodity comm : source.getCommoditiesBought()) {
      if (PodUtil.isInstanceOfFlow(comm)) {

        EList<ContainerPair> communicationMat = source.getCommunicationMatrix();
        for (ContainerPair cp : communicationMat) {
          // If a pair already exists between these two entities, update the traffic value
          if (cp.getObjectId().equals(containerPairUuid)) {
            updateTrafficValue(cp, f);
            pair = cp;
          }
        }
        FlowImpl flow = (FlowImpl) comm;
        flow.calculateUsed();
      }
    }
    for (Commodity comm : dest.getCommoditiesBought()) {
      if (PodUtil.isInstanceOfFlow(comm)) {
        FlowImpl flow = (FlowImpl) comm;
        flow.calculateUsed();
      }
    }
    if (pair != null) {
      return pair;
    }
    // If an existing pair was not found, create a new one with the relevant traffic
    ContainerPair vmPair = new ContainerPair(source, dest);
    vmPair.setTrafficAmount(f);

    // Attach the new pair to the communication matrix of both the source and the destination
    updateContainerCommunicationMatrix(source, vmPair);
    updateContainerCommunicationMatrix(dest, vmPair);

    return vmPair;
  }
예제 #2
0
  /**
   * Update the container pair list inside the monitoring extension, adding the entry to the list
   *
   * @param source The container we want to add the pair to
   * @param vmPair The container pair we want to add
   */
  public static void updateContainerCommunicationMatrix(
      VirtualMachine source, ContainerPair vmPair) {

    for (Commodity comm : source.getCommoditiesBought()) {
      if (PodUtil.isInstanceOfFlow(comm)) {

        // For each flow commodity bought by the container update the communication matrix
        EList<ContainerPair> communicationMat = source.getCommunicationMatrix();
        communicationMat.add(vmPair);
      }
    }
  }
예제 #3
0
 public static boolean updateFlowForVmPair(String srcIp, String dstIp, float value) {
   // Extract the ips from the Flow
   float threshold = DiscoveryManager.vmtMANAGER.getFlowThreshold();
   String ipUuid1 = DiscoveryUtil.getIpUuid(srcIp);
   VMTRootObject vmt1 = rg.getObject(ipUuid1);
   String ipUuid2 = DiscoveryUtil.getIpUuid(dstIp);
   VMTRootObject vmt2 = rg.getObject(ipUuid2);
   // fetch the vms matching the ips
   VirtualMachine source = DiscoveryUtil.getVmFromIP((IP) vmt1);
   VirtualMachine dest = DiscoveryUtil.getVmFromIP((IP) vmt2);
   // create or update the pair
   if (source != null && dest != null) {
     String containerPairUuid = formContainerPairUuid(source, dest);
     createOrUpdateContainerPair(source, dest, containerPairUuid, (float) (value / Units.KILO));
   }
   if (value > threshold && !PodUtil.sameVPod(source, dest)) {
     return true;
   } else {
     return false;
   }
 }
예제 #4
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;
  }
예제 #5
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);
  }