use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method readAssetBySourceExample.
@Test
public void readAssetBySourceExample() throws Exception {
Asset asset = createAsset();
asset.setAssetName("testReadAssetBySource");
asset = assetRepository.save(asset);
try {
this.mockMvc.perform(get("/v1/assets/source/{source}", asset.getAssetSource()).param("currentPage", "1").param("pageSize", "5")).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].assetName").value("testReadAssetBySource")).andDo(document("assets-getBySource-example", pathParameters(parameterWithName("source").description("The source of asset")), 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())));
} finally {
assetRepository.deleteById(asset.getId());
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method readAssetBySourceAndTypeExample.
@Test
public void readAssetBySourceAndTypeExample() throws Exception {
Asset asset = createAsset();
asset = assetRepository.save(asset);
try {
this.mockMvc.perform(get("/v1/assets/source/{source}/type/{category}", asset.getAssetSource(), asset.getCategory()).param("currentPage", "1").param("pageSize", "5")).andExpect(status().isOk()).andDo(document("assets-getBySourceAndType-example", pathParameters(parameterWithName("source").description("The source of asset"), 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 mappingFacility.
@Test
public void mappingFacility() throws JsonProcessingException, Exception {
Asset asset = createAsset();
asset = assetRepository.save(asset);
Asset newAsset = new Asset();
newAsset.setId(asset.getId());
List<String> pdus = new ArrayList<String>();
pdus.add("oqwen812321093asdmgtqawee1");
newAsset.setPdus(pdus);
List<String> switches = new ArrayList<String>();
switches.add("ow23aw312e3nr3d2a57788i");
newAsset.setSwitches(switches);
Map<String, String> metricsformulars = new HashMap<String, String>();
Map<String, Map<String, String>> sensorMap = new HashMap<String, Map<String, String>>();
Map<String, String> positionInfo = new HashMap<String, String>();
Asset humiditySensorAsset = createAsset();
humiditySensorAsset.setCategory(AssetCategory.Sensors);
humiditySensorAsset.setSubCategory(AssetSubCategory.Humidity);
humiditySensorAsset.setCabinetUnitPosition(12);
HashMap<String, String> sensorAssetJustfication = new HashMap<String, String>();
Map<String, String> sensorInfo = new HashMap<String, String>();
sensorInfo.put(FlowgateConstant.POSITION, "INLET");
try {
sensorAssetJustfication.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfo));
humiditySensorAsset.setJustificationfields(sensorAssetJustfication);
} catch (JsonProcessingException e) {
TestCase.fail();
}
humiditySensorAsset = assetRepository.save(humiditySensorAsset);
positionInfo.put(humiditySensorAsset.getId(), humiditySensorAsset.getId());
sensorMap.put(MetricName.SERVER_FRONT_HUMIDITY, positionInfo);
String sensorFormulaInfo = null;
try {
sensorFormulaInfo = mapper.writeValueAsString(sensorMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
metricsformulars.put(FlowgateConstant.SENSOR, sensorFormulaInfo);
newAsset.setMetricsformulars(metricsformulars);
this.mockMvc.perform(put("/v1/assets/mappingfacility").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(newAsset))).andExpect(status().isOk()).andDo(document("assets-mappingFacility-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("assetNumber").description("A unique number that can identify an asset from third part DCIM/CMDB systems.").type(long.class), 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"), fieldWithPath("assetSource").description("From which third part systems does this asset comes from. It will refer to a source collection which contains all the thirdpart systems"), fieldWithPath("category").description("The category of the asset. Can only be one of :Server, PDU, Cabinet, Networks, Sensors, UPS").type(AssetCategory.class), fieldWithPath("subCategory").description("The subcategory of the asset. Only apply to some systems.").type(AssetSubCategory.class).optional(), fieldWithPath("manufacturer").description("The manufacture name"), fieldWithPath("model").description("The model of the asset"), fieldWithPath("serialnumber").description("The SN number of the asset, this number can be used to identify an asset. But only some systems have this number.").optional(), fieldWithPath("tag").description("Some system will use tag to identify an asset. It can be either an number or a string.").type(String.class).optional(), fieldWithPath("assetAddress").description("The access address of the asset").type(AssetAddress.class).optional(), fieldWithPath("region").description("The location region of the asset").optional(), fieldWithPath("country").description("The location country of the asset").optional(), fieldWithPath("city").description("The location city of the asset").optional(), fieldWithPath("building").description("The location building of the asset").optional(), fieldWithPath("floor").description("The location floor of the asset").optional(), fieldWithPath("room").description("The location room of the asset"), fieldWithPath("row").description("The location row of the asset").optional(), fieldWithPath("col").description("The location col of the asset").optional(), fieldWithPath("extraLocation").description("Extra location information. Only valid for some system.").optional(), fieldWithPath("cabinetName").description("The cabinet name where this asset is located. If the asset is cabinet then this filed is empty.").optional(), fieldWithPath("cabinetUnitPosition").description("The cabinet unit number").type(int.class).optional(), fieldWithPath("mountingSide").description("The cabinet unit number").type(MountingSide.class).optional(), fieldWithPath("cabinetAssetNumber").description("The asset number of the cabinet. Will be used to search more detail information about the cabinet.").type(long.class).optional(), fieldWithPath("assetRealtimeDataSpec").description("Only valid for sensor type of asset.").type(AssetRealtimeDataSpec.class).optional(), fieldWithPath("justificationfields").ignored(), subsectionWithPath("metricsformulars").description("Possible PDUs And sensors that this server connected with"), fieldWithPath("pdus").description("Possible PDUs that this server connected with"), fieldWithPath("switches").description("Physical switchs that this host connected with"), fieldWithPath("lastupdate").ignored(), fieldWithPath("created").ignored(), fieldWithPath("capacity").description("The capacity of asset.").type(int.class).optional(), fieldWithPath("freeCapacity").description("The free capacity of asset.").type(int.class).optional(), fieldWithPath("parent").description("The parent of asset,it will be null unless the asset's category is Sensors").type(Parent.class).optional(), fieldWithPath("tenant").description("Tenant information for the asset").type(Tenant.class).optional(), subsectionWithPath("status").description("This is a collection of states, including the state of the asset, " + "the state of the pdu mapping, and the state of the switch mapping."))));
Asset testAsset = assetRepository.findById(asset.getId()).get();
TestCase.assertEquals(1, testAsset.getPdus().size());
TestCase.assertEquals("oqwen812321093asdmgtqawee1", testAsset.getPdus().get(0));
TestCase.assertEquals(1, testAsset.getSwitches().size());
TestCase.assertEquals("ow23aw312e3nr3d2a57788i", testAsset.getSwitches().get(0));
Map<String, Map<String, String>> sensorFormulaMap = null;
try {
sensorFormulaMap = mapper.readValue(testAsset.getMetricsformulars().get(FlowgateConstant.SENSOR), new TypeReference<Map<String, Map<String, String>>>() {
});
} catch (IOException e) {
TestCase.fail(e.getMessage());
}
TestCase.assertEquals(FlowgateConstant.RACK_UNIT_PREFIX + humiditySensorAsset.getCabinetUnitPosition() + FlowgateConstant.SEPARATOR + "INLET", sensorFormulaMap.get(MetricName.SERVER_FRONT_HUMIDITY).keySet().iterator().next());
assetRepository.deleteById(testAsset.getId());
assetRepository.deleteById(humiditySensorAsset.getId());
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method testSearchAssetNames.
@Test
public void testSearchAssetNames() throws Exception {
SetOperations<String, String> setOperations = Mockito.mock(SetOperations.class);
when(template.hasKey(anyString())).thenReturn(false);
when(template.opsForSet()).thenReturn(setOperations);
when(template.opsForSet().add(anyString(), any())).thenReturn(0l);
Asset asset = createAsset();
asset.setAssetName("cloud_server_01");
assetRepository.save(asset);
this.mockMvc.perform(get("/v1/assets/names").param("queryParam", String.valueOf("cloud"))).andExpect(status().isOk()).andExpect(jsonPath("$[0]").value("cloud_server_01")).andDo(document("assets-fuzzyQueryServerAssetNames-example", requestParameters(parameterWithName("queryParam").description("A part of asset name")), responseFields(fieldWithPath("[]").description("An array of server names")))).andReturn();
assetRepository.deleteById(asset.getId());
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class AssetControllerTest method testGetServerMetricsByID.
@Test
public void testGetServerMetricsByID() {
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);
List<MetricData> metricDatas = assetService.getMetricsByID(asset.getId(), startTime, duration);
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());
}
Aggregations