Search in sources :

Example 36 with Asset

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

the class OpenManageJobTest method executeJobTest.

@Test
public void executeJobTest() {
    FacilitySoftwareConfig config = new FacilitySoftwareConfig();
    config.setId("executeJob");
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
    doNothing().when(this.openManageAPIClient).getToken();
    doNothing().when(this.wormholeAPIClient).setServiceKey(any(String.class));
    Mockito.when(this.openmanageJobService.createClient(config)).thenReturn(this.openManageAPIClient);
    Mockito.when(this.wormholeAPIClient.saveAssets(any(Asset.class))).thenReturn(saveAsset());
    Mockito.when(this.wormholeAPIClient.saveAssets(ArgumentMatchers.anyList())).thenReturn(null);
    Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType(config.getId(), AssetCategory.Server)).thenReturn(getAllAssetsBySourceAndType());
    Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType(config.getId(), AssetCategory.Chassis)).thenReturn(new ArrayList<Asset>());
    Mockito.when(this.openManageAPIClient.getDevices(any(Integer.class), any(Integer.class), ArgumentMatchers.eq(Server.class))).thenReturn(getCommonResultServer());
    Mockito.when(this.openManageAPIClient.getDevices(any(Integer.class), any(Integer.class), ArgumentMatchers.eq(Chassis.class))).thenReturn(new CommonResult<Chassis>());
    openmanageJobService.executeJob(EventMessageUtil.OpenManage_SyncAssetsMetaData, config);
}
Also used : Chassis(com.vmware.flowgate.openmanage.datamodel.Chassis) Server(com.vmware.flowgate.openmanage.datamodel.Server) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 37 with Asset

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

the class SyncPduAssetJobTest method testGetAssetIdfromformular.

@Test
public void testGetAssetIdfromformular() throws JsonProcessingException {
    List<Asset> assets = new ArrayList<>();
    Asset asset = createAsset();
    Map<String, String> formulars = new HashMap<>();
    Map<String, Map<String, String>> sensorFormulars = new HashMap<String, Map<String, String>>();
    Map<String, String> humidityLocationAndIdMap = new HashMap<String, String>();
    humidityLocationAndIdMap.put("1", "po09imkhdplbvf540fwusy67n");
    Map<String, String> tempreatureLocationAndIdMap = new HashMap<String, String>();
    tempreatureLocationAndIdMap.put("2", "asdasd2s2gxvf5wfwudwadbn");
    sensorFormulars.put(MetricName.PDU_HUMIDITY, humidityLocationAndIdMap);
    sensorFormulars.put(MetricName.PDU_TEMPERATURE, tempreatureLocationAndIdMap);
    formulars.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorFormulars));
    asset.setMetricsformulars(formulars);
    assets.add(asset);
    Set<String> assetIDs = powerIQService.getAssetIdfromformular(assets);
    TestCase.assertEquals(2, assetIDs.size());
    Map<String, String> map = new HashMap<String, String>();
    map.put("po09imkhdplbvf540fwusy67n", "po09imkhdplbvf540fwusy67n");
    map.put("asdasd2s2gxvf5wfwudwadbn", "asdasd2s2gxvf5wfwudwadbn");
    for (String assetid : assetIDs) {
        TestCase.assertEquals(map.get(assetid), assetid);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 38 with Asset

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

the class SyncPduAssetJobTest method createAsset.

Asset createAsset() {
    Asset asset = new Asset();
    ObjectMapper mapper = new ObjectMapper();
    asset.setAssetName("pek-wor-pdu-02");
    asset.setAssetNumber(89765);
    asset.setAssetSource("po09imkhdplbvf540fwusy67n");
    asset.setCategory(AssetCategory.PDU);
    asset.setModel("Dell 750");
    asset.setManufacturer("Dell");
    Map<String, String> pduInfo = new HashMap<String, String>();
    pduInfo.put(FlowgateConstant.PDU_ID_FROM_POWERIQ, "128");
    String pduInfoString = null;
    try {
        pduInfoString = mapper.writeValueAsString(pduInfo);
    } catch (JsonProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    HashMap<String, String> justficationfields = new HashMap<String, String>();
    justficationfields.put(FlowgateConstant.PDU, pduInfoString);
    asset.setJustificationfields(justficationfields);
    return asset;
}
Also used : HashMap(java.util.HashMap) Asset(com.vmware.flowgate.common.model.Asset) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 39 with Asset

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

the class SyncPduAssetJobTest method testSavePduAssetsToFlowgate.

@Test
public void testSavePduAssetsToFlowgate() {
    Map<String, Asset> existedPduAssets = new HashMap<>();
    Asset asset1 = createAsset();
    asset1.setId("126134615724572");
    Asset asset2 = createAsset();
    asset2.setId("BOQBNBHQOQJAOJQY");
    existedPduAssets.put(asset1.getId(), asset1);
    existedPduAssets.put(asset2.getId(), asset2);
    String assetSource = "UGVINQVNQIGQGQIDNKD";
    LocationInfo location = null;
    Pdu pdu1 = createPdu();
    pdu1.setId(126134615724572L);
    pdu1.setName("pek-wor-pdu-01");
    Pdu pdu2 = createPdu();
    pdu2.setId(226134615724572L);
    pdu2.setName("pek-wor-pdu-02");
    Mockito.doReturn(new ArrayList<>(Arrays.asList(pdu1, pdu2))).when(powerIQAPIClient).getPdus(100, 0);
    Mockito.doReturn(null).when(powerIQAPIClient).getPdus(100, 100);
    Mockito.doReturn(getOutlets()).when(powerIQAPIClient).getOutlets(Mockito.anyLong());
    Mockito.doReturn(getInlets()).when(powerIQAPIClient).getInlets(Mockito.anyLong());
    Mockito.doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(wormholeAPIClient).saveAssets(Mockito.any(Asset.class));
    Mockito.doReturn("23551d6dacf2432c8a3edbc6bbc922cd").when(powerIQService).getAssetIdByResponseEntity(Mockito.any(ResponseEntity.class));
    boolean triggerPDUAggregation = powerIQService.savePduAssetsToFlowgate(existedPduAssets, assetSource, powerIQAPIClient, location);
    TestCase.assertTrue(triggerPDUAggregation);
}
Also used : Pdu(com.vmware.flowgate.poweriqworker.model.Pdu) ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) Asset(com.vmware.flowgate.common.model.Asset) LocationInfo(com.vmware.flowgate.poweriqworker.model.LocationInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with Asset

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

the class SyncPduAssetJobTest method testUpdatePduMetricformular2.

@Test
public void testUpdatePduMetricformular2() throws JsonProcessingException {
    List<Asset> assets = new ArrayList<>();
    Asset asset = createAsset();
    asset.setCabinetUnitPosition(1);
    asset.setId("po09imkhdplbvf540fwusy67n");
    asset.setCategory(AssetCategory.Sensors);
    asset.setSubCategory(AssetSubCategory.Humidity);
    Map<String, String> sensorInfoMap = new HashMap<String, String>();
    sensorInfoMap.put(FlowgateConstant.POSITION, "INLET");
    ObjectMapper mapper = new ObjectMapper();
    HashMap<String, String> justfication = new HashMap<String, String>();
    try {
        justfication.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfoMap));
    } catch (JsonProcessingException e1) {
        TestCase.fail();
    }
    asset.setJustificationfields(justfication);
    Parent parent = new Parent();
    parent.setParentId("125");
    parent.setType("PDU");
    asset.setParent(parent);
    assets.add(asset);
    Map<String, Asset> pduIdAndAssetMap = new HashMap<String, Asset>();
    Asset pduAsset = createAsset();
    pduIdAndAssetMap.put("125", pduAsset);
    Set<Asset> pduNeedTosave = powerIQService.updatePduMetricformular(assets, pduIdAndAssetMap);
    TestCase.assertEquals(1, pduNeedTosave.size());
    Asset pdu = pduNeedTosave.iterator().next();
    TestCase.assertEquals(pduAsset.getAssetName(), pdu.getAssetName());
    try {
        Map<String, String> formulars = pdu.getMetricsformulars();
        Map<String, Map<String, String>> sensorFormulars = mapper.readValue(formulars.get(FlowgateConstant.SENSOR), new TypeReference<Map<String, Map<String, String>>>() {
        });
        Map<String, String> humidityLocationAndIdMap = sensorFormulars.get(MetricName.PDU_HUMIDITY);
        TestCase.assertEquals("po09imkhdplbvf540fwusy67n", humidityLocationAndIdMap.get(FlowgateConstant.RACK_UNIT_PREFIX + "1" + FlowgateConstant.SEPARATOR + sensorInfoMap.get(FlowgateConstant.POSITION)));
    } catch (Exception e) {
        TestCase.fail();
    }
}
Also used : HashMap(java.util.HashMap) Parent(com.vmware.flowgate.common.model.Parent) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Asset(com.vmware.flowgate.common.model.Asset) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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