use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method testRealtimedataServerExample.
@Test
public void testRealtimedataServerExample() 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<>();
long time = System.currentTimeMillis();
int duration = 30 * 60 * 1000;
long startTime = time - duration;
long latestTime = startTime + 300000;
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 result1 = this.mockMvc.perform(get("/v1/assets/{assetId}/realtimedata", asset.getId()).param("starttime", String.valueOf(startTime)).param("duration", String.valueOf(duration))).andDo(document("assets-getLatestAssetMetricsData-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 = result1.getResponse().getContentAsString();
MetricData[] datas = mapper.readValue(res, MetricData[].class);
try {
for (MetricData serverdata : datas) {
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)) {
TestCase.assertEquals(65.0, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_MEMORYUSAGE.equals(metricName)) {
TestCase.assertEquals(87.22, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_CPUUSEDINMHZ.equals(metricName)) {
TestCase.assertEquals(570.0, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_CPUUSAGE.equals(metricName)) {
TestCase.assertEquals(3.57, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_ACTIVEMEMORY.equals(metricName)) {
TestCase.assertEquals(2063852.0, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_SHAREDMEMORY.equals(metricName)) {
TestCase.assertEquals(8.00, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_CONSUMEDMEMORY.equals(metricName)) {
TestCase.assertEquals(18291188.0, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_SWAPMEMORY.equals(metricName)) {
TestCase.assertEquals(0.00, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_BALLOONMEMORY.equals(metricName)) {
TestCase.assertEquals(0.0, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_NETWORKUTILIZATION.equals(metricName)) {
TestCase.assertEquals(146.00, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_STORAGEIORATEUSAGE.equals(metricName)) {
TestCase.assertEquals(61.0, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_POWER.equals(metricName)) {
TestCase.assertEquals(0.069, serverdata.getValueNum());
TestCase.assertEquals(latestTime, serverdata.getTimeStamp());
} else if (MetricName.SERVER_PEAK_USED_POWER.equals(metricName)) {
TestCase.assertEquals(0.80, serverdata.getValueNum());
} else if (MetricName.SERVER_MINIMUM_USED_POWER.equals(metricName)) {
TestCase.assertEquals(0.069, serverdata.getValueNum());
} else if (MetricName.SERVER_AVERAGE_USED_POWER.equals(metricName)) {
TestCase.assertEquals(0.60, serverdata.getValueNum());
} else if (MetricName.SERVER_ENERGY_CONSUMPTION.equals(metricName)) {
TestCase.assertEquals(356.0, serverdata.getValueNum());
} else if (MetricName.SERVER_AVERAGE_TEMPERATURE.equals(metricName)) {
TestCase.assertEquals(24.00, serverdata.getValueNum());
} else if (MetricName.SERVER_PEAK_TEMPERATURE.equals(metricName)) {
TestCase.assertEquals(30.00, serverdata.getValueNum());
}
}
} finally {
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 AssetControllerTest method testGetServerMetricsOutLetisNull.
@Test
public void testGetServerMetricsOutLetisNull() {
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");
realTimeDatas.add(pduUsageMetricData);
realtimeDataRepository.saveAll(realTimeDatas);
asset = fillingMetricsformula(asset);
asset = assetRepository.save(asset);
List<MetricData> metricDatas = assetService.getMetricsByID(asset.getId(), startTime, duration);
for (MetricData serverdata : metricDatas) {
String metricName = serverdata.getMetricName();
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 {
TestCase.fail("Unkown metric: " + metricName);
}
}
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(pduUsageMetricData.getId());
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method createAssetBatchExample.
@Test
public void createAssetBatchExample() throws JsonProcessingException, Exception {
List<Asset> assets = new ArrayList<Asset>();
Asset asset1 = createAsset();
asset1.setAssetName("assetname");
asset1.setAssetNumber(18);
assets.add(asset1);
Asset asset2 = createAsset();
asset2.setAssetName("assetname2");
asset2.setAssetNumber(17);
assets.add(asset2);
this.mockMvc.perform(post("/v1/assets/batchoperation").contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(assets))).andExpect(status().isCreated()).andDo(document("assets-createBatch-example", requestFields(fieldWithPath("[]").description("An array of assets")).andWithPrefix("[].", fieldpath)));
assetRepository.deleteById(asset1.getId());
assetRepository.deleteById(asset2.getId());
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method readAssetByTypeExample.
@Test
public void readAssetByTypeExample() throws Exception {
Asset asset = createAsset();
asset = assetRepository.save(asset);
try {
this.mockMvc.perform(get("/v1/assets/type/{category}", asset.getCategory()).param("currentPage", "1").param("pageSize", "5")).andExpect(status().isOk()).andDo(document("assets-getByType-example", pathParameters(parameterWithName("category").description("The category of asset, generated by flowgate.Sample value : Server/Sensors/PDU/Cabinet/Networks/Chassis/UPS")), requestParameters(parameterWithName("currentPage").description("The page you want to get"), parameterWithName("pageSize").description("The number of assets you want to get by every request.Default value: 20")), responseFields(subsectionWithPath("content").description("An assets array."), fieldWithPath("totalPages").description("content's total pages."), fieldWithPath("totalElements").description("content's total elements."), fieldWithPath("last").description("Is the last."), fieldWithPath("number").description("The page number."), fieldWithPath("size").description("The page size."), fieldWithPath("sort").description("The sort."), fieldWithPath("numberOfElements").description("The number of Elements."), fieldWithPath("first").description("Is the first."), subsectionWithPath("pageable").description("pageable.").ignored(), subsectionWithPath("sort").description("sorted.").ignored(), fieldWithPath("empty").description("Is empty.").ignored()))).andReturn();
} finally {
assetRepository.deleteById(asset.getId());
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method insertRealtimeDataExample.
@Test
public void insertRealtimeDataExample() throws JsonProcessingException, Exception {
Asset asset = createAsset();
asset = assetRepository.save(asset);
long time = System.currentTimeMillis();
RealTimeData realtimedata = createServerPDURealTimeData(time);
List<ValueUnit> valueunits = realtimedata.getValues();
valueunits.addAll(createServerHostRealTimeData(time).getValues());
ValueUnit tempValue = new ValueUnit();
tempValue.setValueNum(32);
tempValue.setTime(time);
tempValue.setUnit(MetricUnit.C.toString());
tempValue.setKey(MetricName.TEMPERATURE);
valueunits.add(tempValue);
ValueUnit humidityValue = new ValueUnit();
humidityValue.setValueNum(20);
humidityValue.setTime(time);
humidityValue.setUnit("%");
humidityValue.setKey(MetricName.HUMIDITY);
valueunits.add(humidityValue);
realtimedata.setId(UUID.randomUUID().toString());
realtimedata.setAssetID(asset.getId());
realtimeDataRepository.save(realtimedata);
this.mockMvc.perform(post("/v1/assets/" + asset.getId() + "/sensordata").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(realtimedata))).andExpect(status().isOk()).andDo(document("assets-insertRealtimeData-example", requestFields(fieldWithPath("id").description("ID of the realtime, created by flowgate"), fieldWithPath("assetID").description("ID of the asset, created by flowgate"), subsectionWithPath("values").description("A list of sensor data. eg. Humidity , Electric... ").type(ValueUnit[].class), fieldWithPath("time").description("The time of generate sensor data."))));
assetRepository.deleteById(asset.getId());
realtimeDataRepository.deleteById(realtimedata.getId());
}
Aggregations