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