Exemplo n.º 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");
        }
      }
    }
  }
Exemplo n.º 2
0
  private static void setUsedForVpodCommBought() {
    for (VPod vpod : rg.getInstances(VPod.class)) {

      if (vpod.isIsTemplate()
          || vpod.getParticipatesIn() == null
          || !vpod.getParticipatesIn().isMainMarket()) continue;

      float used = 0;
      for (Commodity comm : vpod.getCommoditiesBought()) {

        if (comm instanceof Flow) continue;

        if (!comm.getConsumes().isEmpty()) {

          Commodity commSoldByProvider = comm.getConsumes().get(0);
          ServiceEntity provider = commSoldByProvider.getSoldBy();
          for (ServiceEntity vmtObj : vpod.getUnderlying()) {

            if (vmtObj instanceof VirtualMachine) {
              VirtualMachine vm = (VirtualMachine) vmtObj;

              if (!isVmInDpod(vm, (DPod) provider)) {
                continue;
              }

              float entityCommmodityUsed = 0;
              List<Commodity> entityCommodities =
                  vm.getCommoditiesBoughtByKey(comm.eClass(), CommodityImpl.dynCommKey(vpod));
              if (!entityCommodities.isEmpty()) {
                entityCommmodityUsed = entityCommodities.get(0).getUsed();
              }

              used += entityCommmodityUsed;
            }
          }

          comm.setUsed(used);
          used = 0;
        } else {
          logger.warn("The commodity " + comm.getDisplayName() + " is not consuming anything");
        }
      }
    }
  }