use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method createHostNameIPMappingExample.
@Test
public void createHostNameIPMappingExample() throws Exception {
SetOperations<String, String> setOperations = Mockito.mock(SetOperations.class);
when(template.hasKey(anyString())).thenReturn(false);
when(template.opsForSet()).thenReturn(setOperations);
when(setOperations.add(anyString(), any())).thenReturn(1l);
Asset server = createAsset();
server.setCategory(AssetCategory.Server);
server.setAssetName("cloud-sha1-esx2");
server = assetRepository.save(server);
AssetIPMapping assetipmapping = createAssetIPMapping();
assetipmapping.setAssetname(server.getAssetName());
assetipmapping.setIp("192.168.0.1");
assetipmapping.setMacAddress("50:00:56:ge:64:62");
this.mockMvc.perform(post("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(assetipmapping))).andExpect(status().isCreated()).andDo(document("assets-createHostNameIPMapping-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("ip").description("ip of hostname"), fieldWithPath("macAddress").description("macAddress of IP"), fieldWithPath("assetname").description("The name of the asset in the third part DCIM/CMDB systems. Usually it will be a unique identifier of an asset"))));
assetipmapping = assetIPMappingRepository.findById(assetipmapping.getId()).get();
assetRepository.deleteById(server.getId());
assetIPMappingRepository.deleteById(assetipmapping.getId());
TestCase.assertEquals(server.getAssetName(), assetipmapping.getAssetname());
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method updateHostNameIPMappingExample.
@Test
public void updateHostNameIPMappingExample() throws Exception {
SetOperations<String, String> setOperations = Mockito.mock(SetOperations.class);
when(template.hasKey(anyString())).thenReturn(false);
when(template.opsForSet()).thenReturn(setOperations);
when(setOperations.add(anyString(), any())).thenReturn(1l);
Asset server = createAsset();
server.setCategory(AssetCategory.Server);
server.setAssetName("cloud-sha1-esx2");
server = assetRepository.save(server);
Asset server1 = createAsset();
server1.setCategory(AssetCategory.Server);
server1.setAssetName("cloud-sha1-esx8");
server1 = assetRepository.save(server1);
AssetIPMapping assetipmapping = createAssetIPMapping();
assetipmapping.setAssetname(server.getAssetName());
assetipmapping = assetIPMappingRepository.save(assetipmapping);
AssetIPMapping newAssetIPMapping = createAssetIPMapping();
newAssetIPMapping.setAssetname(server1.getAssetName());
newAssetIPMapping.setId(assetipmapping.getId());
newAssetIPMapping.setMacAddress("00:50:56:be:60:62");
newAssetIPMapping.setIp("192.168.0.1");
this.mockMvc.perform(put("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(newAssetIPMapping))).andExpect(status().isOk()).andDo(document("assets-updateHostNameIPMapping-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("ip").description("ip of hostname"), fieldWithPath("macAddress").description("macAddress of IP"), fieldWithPath("assetname").description("The name of the asset in the third part DCIM/CMDB systems. Usually it will be a unique identifier of an asset"))));
assetipmapping = assetIPMappingRepository.findById(assetipmapping.getId()).get();
assetRepository.deleteById(server.getId());
assetRepository.deleteById(server1.getId());
assetIPMappingRepository.deleteById(assetipmapping.getId());
TestCase.assertEquals(server1.getAssetName(), assetipmapping.getAssetname());
TestCase.assertEquals("00:50:56:be:60:62", assetipmapping.getMacAddress());
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method testGetMetricsDurationAPI.
@Test
public void testGetMetricsDurationAPI() throws Exception {
FieldDescriptor[] fieldpath = new FieldDescriptor[] { fieldWithPath("metricName").description("metric name").type(JsonFieldType.STRING), fieldWithPath("valueNum").description("valueNum.").type(JsonFieldType.NUMBER), fieldWithPath("value").description("value").type(JsonFieldType.NULL), fieldWithPath("unit").description("metric unit").type(JsonFieldType.STRING), fieldWithPath("timeStamp").description("timeStamp").type(JsonFieldType.NUMBER) };
Asset asset = createAsset();
List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
long time = System.currentTimeMillis();
int duration = 30 * 60 * 1000;
long startTime = time - duration;
RealTimeData pduUsageMetricData = createPduAllRealTimeData(startTime);
pduUsageMetricData.setAssetID("0001bdc8b25d4c2badfd045ab61aabfa");
RealTimeData tempRealTimeData = createTemperatureSensorRealtimeData(startTime, "00027ca37b004a9890d1bf20349d5ac1");
RealTimeData humdityRealTimeData = createHumiditySensorRealtimeData(startTime, "34527ca37b004a9890d1bf20349d5ac1");
RealTimeData backTemperature = createBackTemperatureSensorRealtimeData(startTime, "968765a37b004a9890d1bf20349d5ac1");
RealTimeData backHumidity = createBackHumiditySensorRealtimeData(startTime, "486970a37b004a9890d1bf20349d5ac1");
RealTimeData hostRealTimeData = createServerHostRealTimeData(startTime);
hostRealTimeData.setAssetID(asset.getId());
realTimeDatas.add(hostRealTimeData);
realTimeDatas.add(humdityRealTimeData);
realTimeDatas.add(tempRealTimeData);
realTimeDatas.add(backHumidity);
realTimeDatas.add(backTemperature);
realTimeDatas.add(pduUsageMetricData);
realtimeDataRepository.saveAll(realTimeDatas);
asset = fillingMetricsformula(asset);
HashMap<String, String> justificationfields = new HashMap<>();
justificationfields.put(FlowgateConstant.PDU_PORT_FOR_SERVER, "power-2_FIELDSPLIT_CAN1-MDF-R01-PDU-BUILDING_FIELDSPLIT_OUTLET:1_FIELDSPLIT_0001bdc8b25d4c2badfd045ab61aabfa");
asset.setJustificationfields(justificationfields);
asset = assetRepository.save(asset);
MvcResult result = this.mockMvc.perform(get("/v1/assets/{assetId}/metrics", asset.getId()).param("starttime", String.valueOf(startTime)).param("duration", String.valueOf(duration))).andDo(document("assets-getAllMetricsDataInDuration-Server-example", pathParameters(parameterWithName("assetId").description("The id of asset,generated by flowgate.")), requestParameters(parameterWithName("starttime").description("Start time of you want to query.Default value: the system current time in Millis").optional(), parameterWithName("duration").description("Duration of you want to query.Default value: 300000 ms").optional()), responseFields(fieldWithPath("[]").description("An array of realTimeDatas")).andWithPrefix("[].", fieldpath))).andReturn();
String res = result.getResponse().getContentAsString();
MetricData[] metricDatas = mapper.readValue(res, MetricData[].class);
Set<String> specialMetricNames = new HashSet<String>();
specialMetricNames.add(MetricName.SERVER_AVERAGE_USED_POWER);
specialMetricNames.add(MetricName.SERVER_PEAK_USED_POWER);
specialMetricNames.add(MetricName.SERVER_MINIMUM_USED_POWER);
specialMetricNames.add(MetricName.SERVER_AVERAGE_TEMPERATURE);
specialMetricNames.add(MetricName.SERVER_PEAK_TEMPERATURE);
for (MetricData serverdata : metricDatas) {
String metricName = serverdata.getMetricName();
if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_CURRENT, "0001bdc8b25d4c2badfd045ab61aabfa", "OUTLET:1").equals(metricName)) {
TestCase.assertEquals(0.365, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_POWER, "0001bdc8b25d4c2badfd045ab61aabfa", "OUTLET:1").equals(metricName)) {
TestCase.assertEquals(0.081, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_OUTLETX_VOLTAGE, "0001bdc8b25d4c2badfd045ab61aabfa", "OUTLET:1").equals(metricName)) {
TestCase.assertEquals(221.0, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_POWER_LOAD, "0001bdc8b25d4c2badfd045ab61aabfa").equals(metricName)) {
TestCase.assertEquals(0.05, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_CURRENT_LOAD, "0001bdc8b25d4c2badfd045ab61aabfa").equals(metricName)) {
TestCase.assertEquals(0.05, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_CURRENT, "0001bdc8b25d4c2badfd045ab61aabfa").equals(metricName)) {
TestCase.assertEquals(1.455, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_CONNECTED_PDUX_TOTAL_POWER, "0001bdc8b25d4c2badfd045ab61aabfa").equals(metricName)) {
TestCase.assertEquals(0.322, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_BACK_HUMIDITY_LOCATIONX, "OUTLET").equals(metricName)) {
TestCase.assertEquals(19.0, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_BACK_TEMPREATURE_LOCATIONX, "OUTLET").equals(metricName)) {
TestCase.assertEquals(25.0, serverdata.getValueNum());
} else if (String.format(MetricKeyName.SERVER_FRONT_HUMIDITY_LOCATIONX, "INLET").equals(metricName)) {
TestCase.assertEquals(serverdata.getValueNum(), 20.0);
} else if (String.format(MetricKeyName.SERVER_FRONT_TEMPERATURE_LOCATIONX, "INLET").equals(metricName)) {
TestCase.assertEquals(serverdata.getValueNum(), 32.0);
} else if (MetricName.SERVER_VOLTAGE.equals(metricName)) {
TestCase.assertEquals(221.0, serverdata.getValueNum());
} else if (MetricName.SERVER_STORAGEUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 240000) {
TestCase.assertEquals(65.0, serverdata.getValueNum());
}
} else if (MetricName.SERVER_MEMORYUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(87.22, serverdata.getValueNum());
}
} else if (MetricName.SERVER_CPUUSEDINMHZ.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(746.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_CPUUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(4.67, serverdata.getValueNum());
}
} else if (MetricName.SERVER_ACTIVEMEMORY.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(1561416.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_SHAREDMEMORY.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(8.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_CONSUMEDMEMORY.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(18291220.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_SWAPMEMORY.equals(metricName)) {
TestCase.assertEquals(0.00, serverdata.getValueNum());
} else if (MetricName.SERVER_BALLOONMEMORY.equals(metricName)) {
TestCase.assertEquals(0.0, serverdata.getValueNum());
} else if (MetricName.SERVER_NETWORKUTILIZATION.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(146.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_STORAGEIORATEUSAGE.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(330.00, serverdata.getValueNum());
}
} else if (MetricName.SERVER_POWER.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime + 20000) {
TestCase.assertEquals(0.069, serverdata.getValueNum());
}
} else if (MetricName.SERVER_ENERGY_CONSUMPTION.equals(metricName)) {
if (serverdata.getTimeStamp() == startTime) {
TestCase.assertEquals(0.00038805555555555555, serverdata.getValueNum());
}
} else if (specialMetricNames.contains(metricName)) {
TestCase.fail("Duration API not support this metric " + metricName);
}
}
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(pduUsageMetricData.getId());
realtimeDataRepository.deleteById(tempRealTimeData.getId());
realtimeDataRepository.deleteById(humdityRealTimeData.getId());
realtimeDataRepository.deleteById(backHumidity.getId());
realtimeDataRepository.deleteById(backTemperature.getId());
realtimeDataRepository.deleteById(hostRealTimeData.getId());
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetService method getPduMetricsDataById.
public List<MetricData> getPduMetricsDataById(String assetID, long starttime, int duration) {
Optional<Asset> pduAssetOptional = assetRepository.findById(assetID);
if (!pduAssetOptional.isPresent()) {
return null;
}
List<RealTimeData> pduMetricsRealtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetID, starttime, duration);
List<ValueUnit> valueunits = new ArrayList<>();
List<String> metricNames = new ArrayList<String>();
metricNames.add(MetricName.PDU_TOTAL_POWER);
metricNames.add(MetricName.PDU_APPARENT_POWER);
metricNames.add(MetricName.PDU_ACTIVE_POWER);
metricNames.add(MetricName.PDU_CURRENT);
metricNames.add(MetricName.PDU_VOLTAGE);
metricNames.add(MetricName.PDU_FREE_CAPACITY);
metricNames.add(MetricName.PDU_POWER_LOAD);
metricNames.add(MetricName.PDU_CURRENT_LOAD);
// pdu metrics data,such as power/current/voltage
valueunits.addAll(getValueUnits(pduMetricsRealtimeDatas, metricNames));
Asset pdu = pduAssetOptional.get();
// sensor metrics data, such as temperature or humidity
Map<String, String> formulars = pdu.getMetricsformulars();
String sensorFormulasInfo = formulars.get(FlowgateConstant.SENSOR);
Map<String, Map<String, String>> sensorFormulasMap = null;
if (sensorFormulasInfo != null) {
sensorFormulasMap = pdu.metricsFormulaToMap(sensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
}
if (sensorFormulasMap != null) {
Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap = new HashMap<String, List<RealTimeData>>();
Map<String, String> humidityLocationAndIdMap = sensorFormulasMap.get(MetricName.PDU_HUMIDITY);
if (humidityLocationAndIdMap != null && !humidityLocationAndIdMap.isEmpty()) {
valueunits.addAll(generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, humidityLocationAndIdMap, MetricName.PDU_HUMIDITY));
}
Map<String, String> temperatureLocationAndIdMap = sensorFormulasMap.get(MetricName.PDU_TEMPERATURE);
if (temperatureLocationAndIdMap != null && !temperatureLocationAndIdMap.isEmpty()) {
valueunits.addAll(generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, temperatureLocationAndIdMap, MetricName.PDU_TEMPERATURE));
}
}
return generateMetricsDataForPDU(valueunits);
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetService method mappingFacilityForServerAsset.
public void mappingFacilityForServerAsset(Asset asset) {
Optional<Asset> oldAssetOptional = assetRepository.findById(asset.getId());
if (!oldAssetOptional.isPresent()) {
throw new WormholeRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "Asset not found", null);
}
Asset oldAsset = oldAssetOptional.get();
List<String> pdus = asset.getPdus();
if (pdus != null) {
oldAsset.setPdus(pdus);
}
List<String> switchs = asset.getSwitches();
if (switchs != null) {
oldAsset.setSwitches(switchs);
}
Map<String, String> newMetricsformulas = asset.getMetricsformulars();
if (newMetricsformulas != null && newMetricsformulas.containsKey(FlowgateConstant.SENSOR)) {
Map<String, String> oldMetricsformulas = oldAsset.getMetricsformulars();
Map<String, Map<String, String>> oldSensorformulasMap = null;
String oldSensorFormulasInfo = null;
if (oldMetricsformulas.containsKey(FlowgateConstant.SENSOR)) {
oldSensorFormulasInfo = oldMetricsformulas.get(FlowgateConstant.SENSOR);
oldSensorformulasMap = asset.metricsFormulaToMap(oldSensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
} else {
oldSensorformulasMap = new HashMap<String, Map<String, String>>();
}
String newSensorFormulaInfo = newMetricsformulas.get(FlowgateConstant.SENSOR);
Map<String, Map<String, String>> newSensorformulasMap = asset.metricsFormulaToMap(newSensorFormulaInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
generateSensorFormula(oldSensorformulasMap, newSensorformulasMap);
oldSensorFormulasInfo = asset.metricsFormulaToString(oldSensorformulasMap);
oldMetricsformulas.put(FlowgateConstant.SENSOR, oldSensorFormulasInfo);
oldAsset.setMetricsformulars(oldMetricsformulas);
}
oldAsset.setLastupdate(System.currentTimeMillis());
assetRepository.save(oldAsset);
}
Aggregations