use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method getAssetByID.
public ResponseEntity<Asset> getAssetByID() {
Asset asset = createAsset();
asset.setId("5x4ff46982db22e1b040e0f2");
return new ResponseEntity<Asset>(asset, HttpStatus.OK);
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGenerateNewAsset2.
@Test
public void testGenerateNewAsset2() {
List<NlyteAsset> nlyteAssets = getNlyteAsset();
HashMap<Integer, LocationGroup> locationMap = getLocationMap();
HashMap<Integer, Material> materialMap = new HashMap<Integer, Material>();
Material material = new Material();
material.setMaterialID(6251);
material.setManufacturerID(14);
material.setMaterialName("Cisco 1721 Modular Access Router");
material.setMaterialType(AssetCategory.Networks);
materialMap.put(6251, material);
HashMap<Integer, Manufacturer> manufacturerMap = new HashMap<Integer, Manufacturer>();
Manufacturer manufacturer = new Manufacturer();
manufacturer.setManufacturerID(14);
manufacturer.setDetail("Cisco");
manufacturerMap.put(14, manufacturer);
Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType("l9i8728d55368540fcba1692", AssetCategory.Server)).thenReturn(new ArrayList<Asset>());
HashMap<Long, String> chassisMountedAssetNumberAndChassisIDMap = new HashMap<Long, String>();
chassisMountedAssetNumberAndChassisIDMap.put(197L, "asdqe945kjsdf09uw45ms");
List<Asset> assets = nlyteDataService.generateAssets("l9i8728d55368540fcba1692", nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Networks, chassisMountedAssetNumberAndChassisIDMap);
for (Asset asset : assets) {
if ("sin2-blrqeops-esxstress024".equals(asset.getAssetName())) {
TestCase.assertEquals(197, asset.getAssetNumber());
TestCase.assertEquals("SG-07-04", asset.getRoom());
TestCase.assertEquals("Cisco 1721 Modular Access Router", asset.getModel());
TestCase.assertEquals("Cisco", asset.getManufacturer());
TestCase.assertEquals("asdqe945kjsdf09uw45ms", asset.getParent().getParentId());
}
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleAssets2.
@Test
public void testHandleAssets2() {
List<Asset> toUpdateAssets = new ArrayList<Asset>();
Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
Asset asset = createAsset();
asset.setAssetNumber(127);
asset.setTag("tag1");
toUpdateAssets.add(asset);
Asset asset2 = createAsset();
asset2.setAssetNumber(128);
asset2.setTag("tag2");
asset2.setCabinetName("cabinet1");
Tenant tenant = new Tenant();
tenant.setOwner("admin");
tenant.setTenant("tenant");
tenant.setTenantManager("manager");
asset2.setTenant(tenant);
asset2.setRoom("room1");
asset2.setRow("r2");
asset2.setCol("c2");
asset2.setMountingSide(MountingSide.Front);
asset2.setCategory(AssetCategory.Chassis);
HashMap<String, String> justficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> slots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
slots.add(slot1);
Map<String, String> chassisInfoMap = new HashMap<String, String>();
chassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
ObjectMapper mapper = new ObjectMapper();
try {
String slotsString = mapper.writeValueAsString(slots);
chassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, slotsString);
String chassisInfo = mapper.writeValueAsString(chassisInfoMap);
justficationMap.put(FlowgateConstant.CHASSIS, chassisInfo);
asset2.setJustificationfields(justficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
toUpdateAssets.add(asset2);
Asset oldAsset1 = createAsset();
oldAsset1.setAssetNumber(127);
oldAsset1.setTag("oldtag1");
exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
Asset oldAsset2 = createAsset();
oldAsset2.setAssetNumber(128);
oldAsset2.setTag("oldtag2");
HashMap<String, String> oldjustficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> oldslots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot oldslot1 = createFlowgateChassisSlot();
oldslot1.setMountingSide("Back");
oldslot1.setMountedAssetNumber(5523);
oldslots.add(oldslot1);
Map<String, String> oldChassisInfoMap = new HashMap<String, String>();
oldChassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
try {
String oldSlotsString = mapper.writeValueAsString(oldslots);
oldChassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, oldSlotsString);
String oldChassisInfo = mapper.writeValueAsString(oldChassisInfoMap);
oldjustficationMap.put(FlowgateConstant.CHASSIS, oldChassisInfo);
oldAsset2.setJustificationfields(oldjustficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
HandleAssetUtil util = new HandleAssetUtil();
List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
for (Asset assetTosave : assets) {
if (assetTosave.getAssetNumber() == 128) {
TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
HashMap<String, String> justfications = assetTosave.getJustificationfields();
String chassisInfo = justfications.get(FlowgateConstant.CHASSIS);
try {
Map<String, String> newChassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
});
TestCase.assertEquals(chassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE));
String chassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
List<FlowgateChassisSlot> flowgateSlots = mapper.readValue(chassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
TestCase.assertEquals(slot1.getMountingSide(), flowgateSlots.get(0).getMountingSide());
TestCase.assertEquals(slot1.getMountedAssetNumber(), flowgateSlots.get(0).getMountedAssetNumber());
TestCase.assertEquals(slot1.getColumnPosition(), flowgateSlots.get(0).getColumnPosition());
TestCase.assertEquals(slot1.getRowPosition(), flowgateSlots.get(0).getRowPosition());
TestCase.assertEquals(slot1.getSlotName(), flowgateSlots.get(0).getSlotName());
} catch (Exception e) {
TestCase.fail(e.getMessage());
}
} else if (assetTosave.getAssetNumber() == 127) {
TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
} else {
TestCase.fail("Invalid assetNumber");
}
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGenerateMountedAssetNumberAndChassisAssetIdMap.
@Test
public void testGenerateMountedAssetNumberAndChassisAssetIdMap() {
List<Asset> assets = new ArrayList<Asset>();
Asset chassisAsset = createAsset();
chassisAsset.setAssetNumber(127);
chassisAsset.setTag("oldtag1");
chassisAsset.setId("asdoiqawe129012fdsfpa");
HashMap<String, String> justficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> slots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot = createFlowgateChassisSlot();
slot.setMountingSide("Back");
slot.setMountedAssetNumber(5523);
slots.add(slot);
Map<String, String> chassisInfoMap = new HashMap<String, String>();
chassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
try {
ObjectMapper mapper = new ObjectMapper();
String slotsString = mapper.writeValueAsString(slots);
chassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, slotsString);
String oldChassisInfo = mapper.writeValueAsString(chassisInfoMap);
justficationMap.put(FlowgateConstant.CHASSIS, oldChassisInfo);
chassisAsset.setJustificationfields(justficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
assets.add(chassisAsset);
HashMap<Long, String> map = nlyteDataService.generateMountedAssetNumberAndChassisAssetIdMap(assets);
TestCase.assertEquals(true, map.containsKey(slot.getMountedAssetNumber().longValue()));
TestCase.assertEquals(chassisAsset.getId(), map.get(slot.getMountedAssetNumber().longValue()));
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class VROAsyncJob method syncVROMetricData.
private void syncVROMetricData(SDDCSoftwareConfig config) {
if (!config.checkIsActive()) {
return;
}
VROConfig vro = new VROConfig(config);
long currentTime = System.currentTimeMillis();
MetricClient metricClient = null;
List<ResourceDto> hosts = null;
try {
metricClient = new MetricClient(vro, publisher);
hosts = metricClient.getHostSystemsResources();
} catch (AuthException authException) {
logger.error("Failed to connect to VROps manager ", authException);
IntegrationStatus integrationStatus = config.getIntegrationStatus();
if (integrationStatus == null) {
integrationStatus = new IntegrationStatus();
}
integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
integrationStatus.setDetail(authException.getMessage());
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
updateIntegrationStatus(config);
return;
} catch (Exception e) {
if (e.getCause() instanceof UndeclaredThrowableException) {
UndeclaredThrowableException undeclaredThrowableException = (UndeclaredThrowableException) e.getCause();
if (undeclaredThrowableException.getUndeclaredThrowable().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(config, undeclaredThrowableException.getUndeclaredThrowable().getCause().getMessage());
return;
}
}
throw e;
}
// read all host/asset maaping from apiserver
Map<String, Asset> assetDictionary = new HashMap<String, Asset>();
try {
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
Asset[] servers = restClient.getAssetsByVRO(vro.getId()).getBody();
for (Asset server : servers) {
assetDictionary.put(server.getId(), server);
}
} catch (HttpClientErrorException clientError) {
if (clientError.getRawStatusCode() != HTTP_NOTFOUND) {
throw clientError;
}
}
ServerMapping[] mappings = null;
try {
mappings = restClient.getServerMappingsByVRO(vro.getId()).getBody();
} catch (HttpClientErrorException clientError) {
if (clientError.getRawStatusCode() != HTTP_NOTFOUND) {
throw clientError;
}
mappings = new ServerMapping[0];
}
HashMap<String, ServerMapping> entityNameDictionary = new HashMap<String, ServerMapping>();
HashMap<String, ServerMapping> objectIDDictionary = new HashMap<String, ServerMapping>();
for (ServerMapping mapping : mappings) {
entityNameDictionary.put(mapping.getVroVMEntityName(), mapping);
objectIDDictionary.put(mapping.getVroVMEntityObjectID(), mapping);
// vcIDDictionary.put(mapping.getVroVMEntityVCID(), mapping);
}
List<ServerMapping> validMapping = new ArrayList<ServerMapping>();
for (ResourceDto host : hosts) {
// There are several things that can be used as a identifier of a host.
// the first is the Name
// beside that there are three other identifier
// VMEntityName -- 10.112.113.160
// VMEntityObjectID host-81 the mobID of the host.
// VMEntityVCID this is the uuid of the vc object.
// currently we only add new servers and don't delete servers
List<ResourceIdentifier> identifiers = host.getResourceKey().getResourceIdentifiers();
boolean newHost = true;
String entityName = "";
String objectID = "";
String vcID = "";
ServerMapping refer = null;
for (ResourceIdentifier identifier : identifiers) {
if (!newHost) {
break;
}
switch(identifier.getIdentifierType().getName()) {
case EntityName:
entityName = identifier.getValue();
if (entityNameDictionary.containsKey(entityName)) {
newHost = false;
refer = entityNameDictionary.get(entityName);
}
break;
case VMEntityObjectID:
objectID = identifier.getValue();
if (objectIDDictionary.containsKey(objectID)) {
newHost = false;
refer = objectIDDictionary.get(objectID);
}
break;
case VMEntityVCID:
vcID = identifier.getValue();
break;
default:
break;
}
}
if (newHost) {
// try to notify the other system.
String ipaddress = IPAddressUtil.getIPAddress(entityName);
if (null != ipaddress) {
publisher.publish(null, ipaddress);
ipaddress = entityName;
}
ServerMapping newMapping = new ServerMapping();
newMapping.setVroID(vro.getId());
newMapping.setVroResourceName(host.getResourceKey().getName());
newMapping.setVroVMEntityName(entityName);
newMapping.setVroVMEntityObjectID(objectID);
newMapping.setVroVMEntityVCID(vcID);
newMapping.setVroResourceID(host.getIdentifier().toString());
AssetIPMapping[] ipMappings = restClient.getHostnameIPMappingByIP(ipaddress).getBody();
if (null != ipMappings && ipMappings.length > 0) {
// update the mapping
String assetName = ipMappings[0].getAssetname();
Asset asset = restClient.getAssetByName(assetName).getBody();
if (asset != null) {
newMapping.setAsset(asset.getId());
}
}
restClient.saveServerMapping(newMapping);
validMapping.add(newMapping);
} else {
if (refer.getAsset() == null) {
String ipaddress = IPAddressUtil.getIPAddress(refer.getVroVMEntityName());
AssetIPMapping[] ipMappings = restClient.getHostnameIPMappingByIP(ipaddress).getBody();
if (null != ipMappings && ipMappings.length > 0) {
// update the mapping
String assetName = ipMappings[0].getAssetname();
Asset asset = restClient.getAssetByName(assetName).getBody();
if (asset != null) {
refer.setAsset(asset.getId());
restClient.saveServerMapping(refer);
validMapping.add(refer);
}
} else {
if (null != ipaddress) {
logger.info("Notify Infoblox to query the assetname");
publisher.publish(null, ipaddress);
}
}
} else {
validMapping.add(refer);
}
}
}
// validMapping.stream().map(ServerMapping::getAssetID).collect(Collectors.toSet());
if (validMapping.isEmpty()) {
logger.info("No Mapping find.Sync nothing for this execution.");
return;
}
Long latencyFactor = latencyFactorMap.get(config.getServerURL());
if (latencyFactor == null) {
latencyFactor = 24L;
}
Long lastUpdateTimeStamp = lastUpdateTimeMap.get(config.getServerURL());
if (lastUpdateTimeStamp == null) {
lastUpdateTimeStamp = currentTime - FIVE_MINUTES * latencyFactor;
}
boolean hasNewData = false;
logger.info(String.format("Start prepare data.%s, lastUpdateTime:%s, latencyFactor:%s", executionCount, lastUpdateTimeStamp, latencyFactor));
long newUpdateTimeStamp = lastUpdateTimeStamp;
for (ServerMapping mapping : validMapping) {
if (mapping.getAsset() != null) {
MetricData[] sensorDatas = restClient.getServerRelatedSensorDataByServerID(mapping.getAsset(), lastUpdateTimeStamp, FIVE_MINUTES * latencyFactor).getBody();
Asset server = restClient.getAssetByID(mapping.getAsset()).getBody();
List<String> pdus = server.getPdus();
StatContents contents = new StatContents();
StatContent frontTemp = new StatContent();
List<Double> frontValues = new ArrayList<Double>();
List<Long> frontTimes = new ArrayList<Long>();
StatContent backTemp = new StatContent();
List<Double> backValues = new ArrayList<Double>();
List<Long> backTimes = new ArrayList<Long>();
StatContent pduAMPSValue = new StatContent();
List<Double> pduAMPSValues = new ArrayList<Double>();
List<Long> pduAMPSTimes = new ArrayList<Long>();
StatContent pduRealtimeVoltage = new StatContent();
List<Double> voltageValues = new ArrayList<Double>();
List<Long> voltageTimes = new ArrayList<Long>();
StatContent pduRealtimePower = new StatContent();
List<Double> powerValues = new ArrayList<Double>();
List<Long> powerTimes = new ArrayList<Long>();
StatContent frontHumidityPercent = new StatContent();
List<Double> frontHumidityValues = new ArrayList<Double>();
List<Long> frontHumidityTimes = new ArrayList<Long>();
StatContent backHumidityPercent = new StatContent();
List<Double> backHumidityValues = new ArrayList<Double>();
List<Long> backHumidityTimes = new ArrayList<Long>();
StatContent currentLoad = new StatContent();
List<Double> currentLoadValues = new ArrayList<Double>();
List<Long> currentLoadTimes = new ArrayList<Long>();
StatContent powerLoad = new StatContent();
List<Double> powerLoadValues = new ArrayList<Double>();
List<Long> powerLoadTimes = new ArrayList<Long>();
String pduId = null;
String currentMetricName = MetricName.SERVER_CONNECTED_PDU_CURRENT;
String powerMetricName = MetricName.SERVER_CONNECTED_PDU_POWER;
String voltageMetricName = MetricName.SERVER_VOLTAGE;
String currentLoadMetricName = MetricName.PDU_CURRENT_LOAD;
String powerLoadMetricName = MetricName.PDU_POWER_LOAD;
if (pdus != null && !pdus.isEmpty()) {
pduId = pdus.get(0);
currentMetricName = String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_CURRENT, pduId);
powerMetricName = String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_POWER, pduId);
currentLoadMetricName = String.format(MetricKeyName.SERVER_CONNECTED_PDUX_CURRENT_LOAD, pduId);
powerLoadMetricName = String.format(MetricKeyName.SERVER_CONNECTED_PDUX_POWER_LOAD, pduId);
}
for (MetricData data : sensorDatas) {
if (data.getTimeStamp() > newUpdateTimeStamp) {
newUpdateTimeStamp = data.getTimeStamp();
hasNewData = true;
}
String metricName = data.getMetricName();
if (metricName.equals(currentMetricName)) {
pduAMPSValues.add(data.getValueNum());
pduAMPSTimes.add(data.getTimeStamp());
continue;
} else if (metricName.equals(powerMetricName)) {
powerValues.add(data.getValueNum());
powerTimes.add(data.getTimeStamp());
continue;
} else if (metricName.equals(voltageMetricName)) {
voltageValues.add(data.getValueNum());
voltageTimes.add(data.getTimeStamp());
continue;
} else if (metricName.equals(currentLoadMetricName)) {
currentLoadValues.add(data.getValueNum());
currentLoadTimes.add(data.getTimeStamp());
continue;
} else if (metricName.equals(powerLoadMetricName)) {
powerLoadValues.add(data.getValueNum());
powerLoadTimes.add(data.getTimeStamp());
continue;
} else if (metricName.contains(MetricName.SERVER_FRONT_HUMIDITY)) {
frontHumidityValues.add(data.getValueNum());
frontHumidityTimes.add(data.getTimeStamp());
continue;
} else if (metricName.contains(MetricName.SERVER_FRONT_TEMPERATURE)) {
frontValues.add(data.getValueNum());
frontTimes.add(data.getTimeStamp());
continue;
} else if (metricName.contains(MetricName.SERVER_BACK_TEMPREATURE)) {
backValues.add(data.getValueNum());
backTimes.add(data.getTimeStamp());
continue;
} else if (metricName.contains(MetricName.SERVER_BACK_HUMIDITY)) {
backHumidityValues.add(data.getValueNum());
backHumidityTimes.add(data.getTimeStamp());
continue;
}
}
if (!frontValues.isEmpty()) {
frontTemp.setStatKey(VROConsts.ENVRIONMENT_FRONT_TEMPERATURE_METRIC);
frontTemp.setData(frontValues.stream().mapToDouble(Double::valueOf).toArray());
frontTemp.setTimestamps(frontTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(frontTemp);
}
if (!backValues.isEmpty()) {
backTemp.setStatKey(VROConsts.ENVRIONMENT_BACK_TEMPERATURE_METRIC);
backTemp.setData(backValues.stream().mapToDouble(Double::valueOf).toArray());
backTemp.setTimestamps(backTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(backTemp);
}
if (!pduAMPSValues.isEmpty()) {
pduAMPSValue.setStatKey(VROConsts.ENVRIONMENT_PDU_AMPS_METRIC);
pduAMPSValue.setData(pduAMPSValues.stream().mapToDouble(Double::valueOf).toArray());
pduAMPSValue.setTimestamps(pduAMPSTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(pduAMPSValue);
}
if (!voltageValues.isEmpty()) {
pduRealtimeVoltage.setStatKey(VROConsts.ENVRIONMENT_PDU_VOLTS_METRIC);
pduRealtimeVoltage.setData(voltageValues.stream().mapToDouble(Double::valueOf).toArray());
pduRealtimeVoltage.setTimestamps(voltageTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(pduRealtimeVoltage);
}
if (!powerValues.isEmpty()) {
pduRealtimePower.setStatKey(VROConsts.ENVRIONMENT_PDU_POWER_METRIC);
pduRealtimePower.setData(powerValues.stream().mapToDouble(Double::valueOf).toArray());
pduRealtimePower.setTimestamps(powerTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(pduRealtimePower);
}
if (!frontHumidityValues.isEmpty()) {
frontHumidityPercent.setStatKey(VROConsts.ENVRIONMENT_FRONT_HUMIDITY_METRIC);
frontHumidityPercent.setData(frontHumidityValues.stream().mapToDouble(Double::valueOf).toArray());
frontHumidityPercent.setTimestamps(frontHumidityTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(frontHumidityPercent);
}
if (!backHumidityValues.isEmpty()) {
backHumidityPercent.setStatKey(VROConsts.ENVRIONMENT_BACK_HUMIDITY_METRIC);
backHumidityPercent.setData(backHumidityValues.stream().mapToDouble(Double::valueOf).toArray());
backHumidityPercent.setTimestamps(backHumidityTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(backHumidityPercent);
}
if (!currentLoadValues.isEmpty()) {
currentLoad.setStatKey(VROConsts.ENVRIONMENT_PDU_AMPS_LOAD_METRIC);
currentLoad.setData(currentLoadValues.stream().mapToDouble(Double::valueOf).toArray());
currentLoad.setTimestamps(currentLoadTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(currentLoad);
}
if (!powerLoadValues.isEmpty()) {
powerLoad.setStatKey(VROConsts.ENVRIONMENT_PDU_POWER_LOAD_METRIC);
powerLoad.setData(powerLoadValues.stream().mapToDouble(Double::valueOf).toArray());
powerLoad.setTimestamps(powerLoadTimes.stream().mapToLong(Long::valueOf).toArray());
contents.addStatContent(powerLoad);
}
if (!contents.getStatContents().isEmpty()) {
logger.info("Push data to VRO: " + config.getServerURL());
metricClient.addStats(null, UUID.fromString(mapping.getVroResourceID()), contents, false);
}
// UPDATE THE PROPERTIES
if (executionCount % 1000 == 0) {
PropertyContents propertyContents = new PropertyContents();
packagingPropertyContent(assetDictionary.get(mapping.getAsset()), propertyContents);
metricClient.addProperties(null, UUID.fromString(mapping.getVroResourceID()), propertyContents);
}
}
}
if (hasNewData) {
Long factor = (currentTime - newUpdateTimeStamp) / FIVE_MINUTES + 1;
if (factor > 24) {
factor = 24L;
} else if (factor < 0) {
factor = 1L;
}
latencyFactorMap.put(config.getServerURL(), factor);
if (newUpdateTimeStamp > currentTime) {
newUpdateTimeStamp = currentTime;
}
lastUpdateTimeMap.put(config.getServerURL(), newUpdateTimeStamp);
} else {
latencyFactor = latencyFactor + 1;
if (latencyFactor > 24) {
latencyFactor = 24L;
}
latencyFactorMap.put(config.getServerURL(), latencyFactor);
}
executionCount++;
logger.info("Finished Sync metric data for VRO: " + config.getServerURL());
}
Aggregations