Search in sources :

Example 56 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class AssetControllerTest method createPDU.

Asset createPDU() {
    Asset asset = new Asset();
    BaseDocumentUtil.generateID(asset);
    asset.setAssetName("pdu-02");
    asset.setAssetNumber(12345);
    asset.setAssetSource("5b7d208d55368540fcba1692");
    asset.setCategory(AssetCategory.PDU);
    asset.setSerialnumber("Serialnumber");
    asset.setRegion("Region");
    asset.setCountry("china");
    asset.setCity("beijing");
    asset.setBuilding("Raycom");
    asset.setFloor("9F");
    asset.setRoom("901");
    asset.setRow("9");
    asset.setCol("9");
    String pduAssetId = asset.getId();
    Map<String, String> formulas = new HashMap<String, String>();
    Map<String, String> pduFormulaMap = new HashMap<>();
    pduFormulaMap.put(MetricName.PDU_VOLTAGE, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_CURRENT, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_TOTAL_POWER, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_CURRENT_LOAD, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_POWER_LOAD, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_XLET_ACTIVE_POWER, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_XLET_APPARENT_POWER, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_XLET_FREE_CAPACITY, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_XLET_CURRENT, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_XLET_VOLTAGE, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_INLET_XPOLE_FREE_CAPACITY, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_INLET_XPOLE_CURRENT, pduAssetId);
    pduFormulaMap.put(MetricName.PDU_INLET_XPOLE_VOLTAGE, pduAssetId);
    Map<String, Map<String, String>> sensorMetricFormulas = new HashMap<String, Map<String, String>>();
    Map<String, String> tempSensor = new HashMap<String, String>();
    tempSensor.put("INLET", "00027ca37b004a9890d1bf20349d5ac1");
    sensorMetricFormulas.put(MetricName.PDU_TEMPERATURE, tempSensor);
    Map<String, String> humiditySensor = new HashMap<String, String>();
    humiditySensor.put("OUTLET", "34527ca37b004a9890d1bf20349d5ac1");
    sensorMetricFormulas.put(MetricName.PDU_HUMIDITY, humiditySensor);
    formulas.put(FlowgateConstant.PDU, asset.metricsFormulaToString(pduFormulaMap));
    formulas.put(FlowgateConstant.SENSOR, asset.metricsFormulaToString(sensorMetricFormulas));
    asset.setMetricsformulars(formulas);
    return asset;
}
Also used : HashMap(java.util.HashMap) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class AssetControllerTest method testGetHostSpecialMetricsExample.

@Test
public void testGetHostSpecialMetricsExample() throws Exception {
    Asset asset = createAsset();
    List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
    Long time = System.currentTimeMillis();
    List<ValueUnit> valueUnits = new ArrayList<ValueUnit>();
    ValueUnit valueUnit = new ValueUnit();
    String sinceTime = String.valueOf(time - 900000l);
    valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR);
    valueUnit.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.5);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR);
    valueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.8);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
    valueUnit.setUnit(MetricUnit.kW.toString());
    valueUnit.setValueNum(0.6);
    valueUnits.add(valueUnit);
    valueUnit = new ValueUnit();
    valueUnit.setTime(time);
    valueUnit.setExtraidentifier(sinceTime);
    valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
    valueUnit.setUnit(MetricUnit.kWh.toString());
    valueUnit.setValueNum(356);
    valueUnits.add(valueUnit);
    RealTimeData hostRealTimeData = new RealTimeData();
    hostRealTimeData.setValues(valueUnits);
    hostRealTimeData.setTime(time);
    hostRealTimeData.setId("00027ca37b004a9890d1bf20349d5ac99");
    hostRealTimeData.setAssetID(asset.getId());
    realTimeDatas.add(hostRealTimeData);
    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:7_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(time)).param("duration", "300000")).andReturn();
    String res = result1.getResponse().getContentAsString();
    MetricData[] datas = mapper.readValue(res, MetricData[].class);
    // In mock metrics data, SERVER_MINIMUM_USED_POWER/SERVER_PEAK_USED_POWER/SERVER_AVERAGE_USED_POWER is invalid
    try {
        for (MetricData serverdata : datas) {
            String metricName = serverdata.getMetricName();
            if (MetricName.SERVER_ENERGY_CONSUMPTION.equals(metricName)) {
                TestCase.assertEquals(serverdata.getValueNum(), 356.00);
            } else {
                TestCase.fail("Unknown metric :" + metricName);
            }
        }
    } finally {
        assetRepository.deleteById(asset.getId());
        realtimeDataRepository.deleteById(hostRealTimeData.getId());
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) Asset(com.vmware.flowgate.common.model.Asset) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) MetricData(com.vmware.flowgate.common.model.MetricData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 58 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class AssetControllerTest method readAssetExample.

@Test
public void readAssetExample() throws Exception {
    Asset asset = createAsset();
    asset = assetRepository.save(asset);
    try {
        this.mockMvc.perform(get("/v1/assets/{assetId}", asset.getId())).andExpect(status().isOk()).andExpect(jsonPath("assetName", is(asset.getAssetName()))).andExpect(jsonPath("assetNumber", is((int) asset.getAssetNumber()))).andExpect(jsonPath("category", is(asset.getCategory().toString()))).andExpect(jsonPath("model", is(asset.getModel()))).andExpect(jsonPath("manufacturer", is(asset.getManufacturer()))).andDo(document("assets-getByID-example", pathParameters(parameterWithName("assetId").description("The id of asset,generated by flowgate.")), responseFields(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(), subsectionWithPath("justificationfields").description("Justification fields that input by user."), subsectionWithPath("metricsformulars").description("The sensor data generator logic for this asset."), fieldWithPath("lastupdate").description("When this asset was last upated"), fieldWithPath("created").description("When this asset was created"), 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("pdus").description("Possible PDUs that this server connected with"), fieldWithPath("switches").description("Physical switchs that this host connected with"), 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."))));
    } finally {
        assetRepository.deleteById(asset.getId());
    }
}
Also used : Asset(com.vmware.flowgate.common.model.Asset) AssetCategory(com.vmware.flowgate.common.AssetCategory) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 59 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class AssetControllerTest method testRealtimedataNotDataExample.

@Test
public void testRealtimedataNotDataExample() throws Exception {
    Asset asset = createAsset();
    fillingMetricsformula(asset);
    asset.setId("00027ca37b004a9890d1bf20349d5ac1");
    asset.setCategory(AssetCategory.Sensors);
    asset = assetRepository.save(asset);
    List<RealTimeData> realTimeDatas = new ArrayList<>();
    long currentTime = System.currentTimeMillis();
    RealTimeData sensorRealTimeData = createSensorRealtimeData(currentTime);
    sensorRealTimeData.setAssetID("00027ca37b004a9890d1bf20349d5ac1");
    sensorRealTimeData.setValues(new ArrayList<>());
    realTimeDatas.add(sensorRealTimeData);
    realtimeDataRepository.saveAll(realTimeDatas);
    try {
        MvcResult result = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata")).andExpect(status().isOk()).andReturn();
        MetricData[] datas = getMetricDataByJsonString(result.getResponse().getContentAsString());
        TestCase.assertEquals(0, datas.length);
        MvcResult result1 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime)).param("duration", "300000")).andExpect(status().isOk()).andReturn();
        MetricData[] datas1 = getMetricDataByJsonString(result1.getResponse().getContentAsString());
        TestCase.assertEquals(0, datas1.length);
        MvcResult result2 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime + 30000000)).param("duration", "1")).andExpect(status().isOk()).andReturn();
        MetricData[] data2 = getMetricDataByJsonString(result2.getResponse().getContentAsString());
        TestCase.assertEquals(0, data2.length);
        asset.setCategory(AssetCategory.Server);
        asset = assetRepository.save(asset);
        MvcResult result3 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime + 30000000)).param("duration", "1")).andExpect(status().isOk()).andReturn();
        asset.setCategory(AssetCategory.PDU);
        asset = assetRepository.save(asset);
        MvcResult result4 = this.mockMvc.perform(get("/v1/assets/" + asset.getId() + "/realtimedata").param("starttime", String.valueOf(currentTime + 30000000)).param("duration", "1")).andExpect(status().isOk()).andReturn();
    } finally {
        assetRepository.deleteById(asset.getId());
        realtimeDataRepository.deleteById(sensorRealTimeData.getId());
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) MvcResult(org.springframework.test.web.servlet.MvcResult) MetricData(com.vmware.flowgate.common.model.MetricData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 60 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class AssetControllerTest method updateAssetExample.

@Test
public void updateAssetExample() throws Exception {
    Asset asset = createAsset();
    asset = assetRepository.save(asset);
    asset.setAssetName("pek-wor-server-04");
    asset.setManufacturer("VMware");
    asset.setAssetSource("4");
    try {
        this.mockMvc.perform(put("/v1/assets").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(asset))).andExpect(status().isOk()).andDo(document("assets-update-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(), subsectionWithPath("justificationfields").ignored(), subsectionWithPath("metricsformulars").ignored(), 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(), subsectionWithPath("parent").description("The parent of asset,it will be null unless the asset's category is Sensors").type(Parent.class).optional(), fieldWithPath("pdus").description("Possible PDUs that this server connected with"), fieldWithPath("switches").description("Physical switchs that this host connected with"), 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."))));
    } finally {
        assetRepository.deleteById(asset.getId());
    }
}
Also used : Asset(com.vmware.flowgate.common.model.Asset) AssetCategory(com.vmware.flowgate.common.AssetCategory) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

Asset (com.vmware.flowgate.common.model.Asset)173 Test (org.junit.Test)96 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)90 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)82 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)36 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)35 Map (java.util.Map)34 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)31 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)23 IOException (java.io.IOException)23 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)22 MetricData (com.vmware.flowgate.common.model.MetricData)16 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)16 HashSet (java.util.HashSet)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)13 List (java.util.List)12 MvcResult (org.springframework.test.web.servlet.MvcResult)12 TypeReference (com.fasterxml.jackson.core.type.TypeReference)10