/** * * <!-- 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; }
/** * 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; }
/** * * <!-- begin-user-doc --> * This method goes over a provided SEType (config file) entities with matching criteria defined * in config file. It goes over the attributes required to report on and collects min,max and avg * into extension objects for commodity and service entity. * * <p>Every hour it creates a list of {@link ReportingRecord} objects with data and returns this * list. * <!-- end-user-doc --> * * @param hourChanged true if the hour changed from the previous gathering of values. * @generated NOT */ @Override public EList<ReportingRecord> getReportingRecordList(boolean hourChanged) { EList<ReportingRecord> returnList = new BasicEList<ReportingRecord>(); long hourlyTimeStamp = 0l; try { RepositoryRegistry rg = RepositoryRegistry.vmtMANAGER; Set<VMTRootObject> vObjList = rg.getInstances(getSEType()); if (hourChanged) { hourlyTimeStamp = (System.currentTimeMillis() - (1000 * 60 * 30)); // Give the record TS of the middle of the last hour } 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; } // Get the Extension for ServiceEntity ServiceEntityReportingExt seExt = (ServiceEntityReportingExt) se.findExtension( ReportingExtensionsPackage.eINSTANCE.getServiceEntityReportingExt()); if (seExt == null) { seExt = ReportingExtensionsFactory.eINSTANCE.createServiceEntityReportingExt(); se.getExtendedBy().add(seExt); } for (NamedElementList neList : getNamedElementList()) { if (neList.getNamedElement().size() == 1) { 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); if (attributeValue instanceof List<?>) { if (hourChanged) { // Record Object ReportingRecord record = this.createReportingRecord( seExt, vObj, attribute, null, null, true, hourlyTimeStamp); if (record != null) { returnList.add(record); } // reset only numProduces fields seExt.resetValues(attribute); } // this condition for numProduces value seExt.setMinNumProduces(((List<?>) attributeValue).size()); seExt.setMaxNumProduces(((List<?>) attributeValue).size()); seExt.setProducesSum(((List<?>) attributeValue).size()); // if(logger.isDebugEnabled())logger.debug("numProduces : min = " + // seExt.getMinNumProduces() + " max = " + seExt.getMaxNumProduces() + " sum = " + // seExt.getProducesSum()); } else { double val = Double.parseDouble(attributeValue.toString()); if (val > PRICE_THRESHOLD) { val = PRICE_THRESHOLD; } if (attribute == AnalysisPackage.eINSTANCE.getServiceEntity_PriceIndex()) { if (val < 0) { if (logger.isDebugEnabled()) { logger.error( "SE : " + vObj.toVMTString() + " has a negative value of " + val); for (StackTraceElement element : Thread.currentThread().getStackTrace()) { logger.debug(element.toString()); } } continue; } } List<EAttribute> atts = seExt.getExtAttributes(attribute); for (EAttribute att : atts) { seExt.eSet(att, val); } if (hourChanged) { // Record Object ReportingRecord record = this.createReportingRecord( seExt, vObj, attribute, null, null, false, hourlyTimeStamp); if (record != null) { returnList.add(record); } // reset only UtilIndex fields seExt.resetValues(attribute); } } } // Or get the list of attribute values and create a record for each } else { 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 (hourChanged) { // Record Object ReportingRecord record = this.createReportingRecord( crExt, vObj, attribute, commodity, comm, false, hourlyTimeStamp); 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())); float capacity = comm.getCapacity(); if (capacity > CAPACITY_THRESHOLD) { if (logger.isDebugEnabled()) { logger.debug( "Capacity for " + se.getDisplayName() + "::" + comm.getDisplayName() + " is " + capacity + ". Capping it to " + CAPACITY_THRESHOLD); } capacity = CAPACITY_THRESHOLD; } crExt.setCapacity(capacity); crExt.setRelation( RelationType.valueOf(reference.getName().toUpperCase()).getValue()); crExt.setCommodityKey(comm.getKey()); // if(logger.isDebugEnabled())logger.debug("comm -> " + attribute.getName() + " min // = " + crExt.getMinUtilization() + " max = " + crExt.getMaxUtilization() + " sum = // " + crExt.getUtilSum() + " cap = " + crExt.getCapacity()); } } } } } } catch (Exception e) { logger.error("Exception in MetaRecordImpl.getReportingRecordList()", e); } return returnList; }
/** * 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); }