コード例 #1
0
  /**
   *
   * <!-- begin-user-doc -->
   * This method is used to store daily values of some commodities in db. There are two types of
   * values written in this method. One which are rolled up in memory over the course of day and one
   * which are directly written to db as no roll up is required.
   *
   * @param dayChanged boolean to find whether the day has changed from the start
   *     <!-- end-user-doc -->
   * @generated NOT
   */
  @Override
  public EList<ReportingRecord> getDailyRecordList(boolean dayChanged) {
    EList<ReportingRecord> returnList = new BasicEList<ReportingRecord>();
    long dailyTimeStamp = 0l;
    try {
      RepositoryRegistry rg = RepositoryRegistry.vmtMANAGER;
      Set<VMTRootObject> vObjList = rg.getInstances(getSEType());

      if (dayChanged) {
        dailyTimeStamp = System.currentTimeMillis() - (1000 * 60 * 60);
      }

      for (VMTRootObject vObj : vObjList) {
        boolean constraintfailed = false;
        // Check constraints
        for (Constraint constraint : getMatchingCriteria()) {
          if (!constraint.match(vObj)) {
            constraintfailed = true;
            break;
          }
        }

        // and skip if any of the constraints do not match
        if (constraintfailed) continue;

        ServiceEntity se = (ServiceEntity) vObj;
        if (DeployManager.vmtMANAGER.inDeploy(se)) {
          continue;
        }

        for (NamedElementList neList : getNamedElementList()) {
          if (neList.getNamedElement().size() == 1) {
            if (dayChanged) {
              EStructuralFeature attribute = (EStructuralFeature) neList.getNamedElement().get(0);
              // Only create a record if the attribute has been set already
              if (vObj.eIsSet(attribute)) {
                Object attributeValue = vObj.eGet(attribute);
                ReportingRecord record = ReportingFactory.eINSTANCE.createReportingRecord();
                // logger.info("comm att " + vObj.getName() + " " + attribute.getName() + " value =
                // " + attributeValue);
                record.setTimeStamp(dailyTimeStamp);
                record.setSeUuId(vObj.getUuid());
                record.setPropertyType(attribute.getName());
                record.setPropertySubType(attribute.getName());
                record.setMinUtilization((Short) attributeValue);
                record.setMaxUtilization((Short) attributeValue);
                record.setAvgUtilization((Short) attributeValue);

                returnList.add(record);
              }
            }
          } else {
            // To be supported later : as needed
            // EReference reference = (EReference)neList.getNamedElement().get(0);
            ENamedElement commodity = neList.getNamedElement().get(1);
            EStructuralFeature attribute =
                (EStructuralFeature)
                    neList.getNamedElement().get(neList.getNamedElement().size() - 1);

            List<ENamedElement> nesCommodity =
                new ArrayList<ENamedElement>(neList.getNamedElement());
            nesCommodity.remove(neList.getNamedElement().size() - 1);
            List<Object> commodityList = vObj.getValues(nesCommodity);

            for (int i = 0; i < commodityList.size(); i++) {
              Commodity comm = (Commodity) commodityList.get(i);
              // get the attribute value from the commodity if it is set
              if (comm.eIsSet(attribute)) {
                Object attributeValue = comm.eGet(attribute);
                // logger.info("comm att " + comm.getName() + " " + attribute.getName() + " value =
                // " + attributeValue);
                CommodityReportingExt crExt = null;
                for (Extension ext : comm.getExtendedBy()) {
                  if (ext instanceof CommodityReportingExt) {
                    crExt = (CommodityReportingExt) ext;
                    if (crExt.getAttribute() == attribute) {
                      break;
                    } else {
                      crExt = null;
                    }
                  }
                }
                if (crExt == null) {
                  crExt = ReportingExtensionsFactory.eINSTANCE.createCommodityReportingExt();
                  crExt.setAttribute(attribute);
                  comm.getExtendedBy().add(crExt);
                }

                if (dayChanged) {
                  // Record Object
                  ReportingRecord record =
                      this.createReportingRecord(
                          crExt, vObj, attribute, commodity, comm, false, dailyTimeStamp);
                  if (record != null) {
                    returnList.add(record);
                  }
                  crExt.resetValues();
                }
                // this condition for capacity, used and utilization values
                crExt.setMinUtilization(Double.parseDouble(attributeValue.toString()));
                if (attribute.equals(AnalysisPackage.eINSTANCE.getCommodity_Used())
                    && comm.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_Peak())) {
                  crExt.setMaxUtilization(comm.getPeak());
                } else if (attribute.equals(AnalysisPackage.eINSTANCE.getCommodity_Utilization())
                    && comm.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_PeakUtilization())) {
                  crExt.setMaxUtilization(comm.getPeakUtilization());
                } else {
                  crExt.setMaxUtilization(Double.parseDouble(attributeValue.toString()));
                }
                crExt.setUtilSum(Double.parseDouble(attributeValue.toString()));
                crExt.setCapacity(comm.getCapacity());
                // logger.info(vObj.getDisplayName() + " -> comm -> " + commodity.getName() + " min
                // = " + crExt.getMinUtilization() + " max = " + crExt.getMaxUtilization() + " sum =
                // " + crExt.getUtilSum() + " cap = " + crExt.getCapacity());
              }
            }
          }
        }
      }
    } catch (Exception e) {
      logger.error("Exception in MetaRecordImpl.getDailyRecordList() ", e);
    }
    return returnList;
  }
コード例 #2
0
  /**
   * This method creates a {@link ReportingRecord} object with values from commodity , service
   * entity and attribute provided to it every hour.
   *
   * @param reportingExtension Extension object
   * @param vObj ServiceEntity object
   * @param attribute attribute reported on
   * @param commodityName Commodity named element
   * @param commodity {@link Commodity} object to get provider uuid
   * @param isNumProduces whether reporting on numProduces attribute
   * @return {@link ReportingRecord} object
   */
  private ReportingRecord createReportingRecord(
      ReportingExtension reportingExtension,
      VMTRootObject vObj,
      EStructuralFeature attribute,
      ENamedElement commodityName,
      Commodity commodity,
      boolean isNumProduces,
      long snapshotTime) {
    ReportingRecord record = ReportingFactory.eINSTANCE.createReportingRecord();
    try {
      // long snapshotTime = (System.currentTimeMillis() - (1000*60*60));
      if (reportingExtension.eClass()
          == ReportingExtensionsPackage.eINSTANCE.getCommodityReportingExt()) {
        CommodityReportingExt crExt = (CommodityReportingExt) reportingExtension;
        if (crExt.getMinUtilization() == -1d || crExt.getMaxUtilization() == -1d) {
          return null;
        }
        record.setTimeStamp(snapshotTime);
        record.setSeUuId(vObj.getUuid());
        record.setPropertyType(commodityName.getName());
        record.setPropertySubType(attribute.getName());
        record.setMinUtilization(crExt.getMinUtilization());
        record.setMaxUtilization(crExt.getMaxUtilization());
        record.setAvgUtilization(crExt.getAvgUtilization());
        record.setCapacity(crExt.getCapacity());
        record.setRelation(crExt.getRelation());

        if (crExt.getCommodityKey() != null) {
          String commodityKey = truncateString(crExt.getCommodityKey(), 80);
          record.setCommodityKey(commodityKey);
        }

        if (!commodity.getConsumes().isEmpty()
            && commodity.getConsumes().get(0).getSoldBy() != null) {
          record.setProviderUuId(commodity.getConsumes().get(0).getSoldBy().getUuid());
        }
        // record.setStdDev(0);
      } else if (reportingExtension.eClass()
          == ReportingExtensionsPackage.eINSTANCE.getServiceEntityReportingExt()) {
        ServiceEntityReportingExt seExt = (ServiceEntityReportingExt) reportingExtension;
        if (isNumProduces) {
          if (seExt.getMinNumProduces() == -1 || seExt.getMaxNumProduces() == -1) {
            return null;
          }
          record.setTimeStamp(snapshotTime);
          record.setSeUuId(vObj.getUuid());
          record.setPropertyType(attribute.getName());
          record.setPropertySubType(attribute.getName());
          record.setMinUtilization(seExt.getMinNumProduces());
          record.setMaxUtilization(seExt.getMaxNumProduces());
          record.setAvgUtilization(seExt.getAvgProduces());
          record.setRelation(-1);
          record.setCommodityKey(null);
          // record.setStdDev(0);
        } else {

          if (seExt.getMinPropValue() == -1d || seExt.getMaxPropValue() == -1d) {
            return null;
          }

          if (attribute == AnalysisPackage.eINSTANCE.getServiceEntity_PriceIndex()) {
            if ((seExt.getMinPropValue() < 0)
                || (seExt.getMaxPropValue() < 0)
                || (seExt.getAvgPropValue() < 0)) {
              if (logger.isDebugEnabled()) {
                logger.error(
                    "SE : "
                        + vObj.toVMTString()
                        + " has max, min and avg PriceIndex values of "
                        + seExt.getMaxPropValue()
                        + ", "
                        + seExt.getMinPropValue()
                        + " and "
                        + seExt.getAvgPropValue()
                        + " respectively");
              }
              return null;
            }
          }

          record.setTimeStamp(snapshotTime);
          record.setSeUuId(vObj.getUuid());
          record.setPropertyType(attribute.getName());
          record.setPropertySubType(attribute.getName());
          record.setRelation(-1);
          record.setCommodityKey(null);
          record.setMinUtilization(seExt.getMinPropValue());
          record.setMaxUtilization(seExt.getMaxPropValue());
          record.setAvgUtilization(seExt.getAvgPropValue());
        }
      }
    } catch (Exception e) {
      logger.error("Exception in creating record ", e);
    }
    return record;
  }