Search in sources :

Example 1 with LocationInfo

use of com.vmware.flowgate.poweriqworker.model.LocationInfo 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 2 with LocationInfo

use of com.vmware.flowgate.poweriqworker.model.LocationInfo in project flowgate by vmware.

the class PowerIQService method getLocationInfo.

public LocationInfo getLocationInfo(PowerIQAPIClient client) {
    LocationInfo location = new LocationInfo();
    location.setAislesMap(getAislesMap(client));
    location.setRacksMap(getRacksMap(client));
    location.setRowsMap(getRowsMap(client));
    location.setRoomsMap(getRoomsMap(client));
    location.setFloorsMap(getFloorsMap(client));
    location.setDataCentersMap(getDataCentersMap(client));
    return location;
}
Also used : LocationInfo(com.vmware.flowgate.poweriqworker.model.LocationInfo)

Example 3 with LocationInfo

use of com.vmware.flowgate.poweriqworker.model.LocationInfo in project flowgate by vmware.

the class PowerIQService method syncPowerIQAssetsMetaData.

public void syncPowerIQAssetsMetaData(FacilitySoftwareConfig powerIQ) {
    PowerIQAPIClient client = createClient(powerIQ);
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    try {
        client.testConnection();
    } catch (ResourceAccessException e1) {
        if (e1.getCause().getCause() instanceof ConnectException) {
            checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
            return;
        }
    } catch (HttpClientErrorException e) {
        logger.error("Failed to query data from PowerIQ", e);
        IntegrationStatus integrationStatus = powerIQ.getIntegrationStatus();
        if (integrationStatus == null) {
            integrationStatus = new IntegrationStatus();
        }
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(e.getMessage());
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        updateIntegrationStatus(powerIQ);
        return;
    }
    LocationInfo location = getLocationInfo(client);
    List<Asset> pdusFromFlowgate = restClient.getAllAssetsBySourceAndType(powerIQ.getId(), AssetCategory.PDU);
    Map<String, Asset> pduIDAndAssetMap = getPDUIDAndAssetMap(pdusFromFlowgate);
    boolean hasNewPduToSave = savePduAssetsToFlowgate(pduIDAndAssetMap, powerIQ.getId(), client, location);
    logger.info("Finish sync PDU metadata for " + powerIQ.getName());
    Map<String, Asset> exsitingSensorAssets = getAssetsFromWormhole(powerIQ.getId());
    saveSensorAssetsToFlowgate(exsitingSensorAssets, client, powerIQ.getId(), location);
    logger.info("Finish sync Sensor metadata for: " + powerIQ.getName());
    if (hasNewPduToSave) {
        try {
            EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.AggregateAndCleanPowerIQPDU, "");
            String jobmessage = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.AggregatorTopic, jobmessage);
            logger.info("Send aggregate Pdu data command");
        } catch (IOException e) {
            logger.error("Failed to Send aggregate pdu data command", e);
        }
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) LocationInfo(com.vmware.flowgate.poweriqworker.model.LocationInfo) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) PowerIQAPIClient(com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient) Asset(com.vmware.flowgate.common.model.Asset) ConnectException(java.net.ConnectException)

Example 4 with LocationInfo

use of com.vmware.flowgate.poweriqworker.model.LocationInfo in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method testSaveSensorAssetsToFlowgate.

@Test
public void testSaveSensorAssetsToFlowgate() {
    Map<String, Asset> exsitingSensorAssets = new HashMap<>();
    Asset asset1 = createAsset();
    asset1.setId("18672301765107L");
    Asset asset2 = createAsset();
    asset2.setId("BOQBNBHQOQJAOJQY");
    exsitingSensorAssets.put(asset1.getId(), asset1);
    exsitingSensorAssets.put(asset2.getId(), asset2);
    String assetSource = "UGVINQVNQIGQGQIDNKD";
    LocationInfo location = new LocationInfo();
    Sensor sensor1 = createSensor();
    sensor1.setId(18672301765107L);
    sensor1.setName("sensor-1");
    sensor1.setType("TemperatureSensor");
    Sensor sensor2 = createSensor();
    sensor2.setId(81675117203607L);
    sensor2.setName("sensor-2");
    sensor2.setType("HumiditySensor");
    Sensor sensor3 = createSensor();
    sensor3.setId(61675386203607L);
    sensor3.setName("sensor-3");
    sensor3.setType("TemperatureSensor");
    Sensor sensor4 = createSensor();
    sensor4.setId(38661675203607L);
    sensor4.setName("sensor-4");
    sensor4.setType("AirFlowSensor");
    Mockito.doReturn(new ArrayList<>()).when(wormholeAPIClient).getAllAssetsBySourceAndType(Mockito.anyString(), Mockito.any());
    Mockito.doReturn(new ArrayList<>(Arrays.asList(sensor1, sensor2, sensor3, sensor4))).when(powerIQAPIClient).getSensors(100, 0);
    Mockito.doReturn(null).when(powerIQAPIClient).getSensors(100, 1);
    Mockito.doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(wormholeAPIClient).saveAssets(Mockito.any(Asset.class));
    Mockito.doReturn("32c1d6dacf248a23553edbc6bbc922cd").when(powerIQService).getAssetIdByResponseEntity(Mockito.any(ResponseEntity.class));
    powerIQService.saveSensorAssetsToFlowgate(exsitingSensorAssets, powerIQAPIClient, assetSource, location);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) Asset(com.vmware.flowgate.common.model.Asset) LocationInfo(com.vmware.flowgate.poweriqworker.model.LocationInfo) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

LocationInfo (com.vmware.flowgate.poweriqworker.model.LocationInfo)4 Asset (com.vmware.flowgate.common.model.Asset)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ResponseEntity (org.springframework.http.ResponseEntity)2 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)1 PowerIQAPIClient (com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient)1 Pdu (com.vmware.flowgate.poweriqworker.model.Pdu)1 Sensor (com.vmware.flowgate.poweriqworker.model.Sensor)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1