Search in sources :

Example 81 with Asset

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

the class MessageProcessingTest method testRemovePduFromServer.

@Test
public void testRemovePduFromServer() {
    Asset[] servers = new Asset[2];
    Asset server = new Asset();
    List<String> pduids = new ArrayList<String>();
    pduids.add("qwiounasdyi2avewrasdf");
    pduids.add("mienoas2389asddsfqzda");
    server.setPdus(pduids);
    HashMap<String, String> justficationfields = new HashMap<String, String>();
    String pduPorts = "01" + FlowgateConstant.SEPARATOR + "pdu1" + FlowgateConstant.SEPARATOR + "01" + FlowgateConstant.SEPARATOR + "qwepouasdnlksaydasmnd" + FlowgateConstant.SPILIT_FLAG + "02" + FlowgateConstant.SEPARATOR + "pdu2" + FlowgateConstant.SEPARATOR + "02" + FlowgateConstant.SEPARATOR + "mienoas2389asddsfqzda";
    justficationfields.put(FlowgateConstant.PDU_PORT_FOR_SERVER, pduPorts);
    server.setJustificationfields(justficationfields);
    Map<String, String> metricsFormular = new HashMap<String, String>();
    Map<String, Map<String, String>> pduMetricsFormula = new HashMap<String, Map<String, String>>();
    Map<String, String> pduinfo1 = new HashMap<String, String>();
    pduinfo1.put(MetricName.PDU_ACTIVE_POWER, "mienoas2389asddsfqzda");
    pduMetricsFormula.put("mienoas2389asddsfqzda", pduinfo1);
    Map<String, String> pduinfo2 = new HashMap<String, String>();
    pduinfo2.put(MetricName.PDU_ACTIVE_POWER, "asdasdw2213dsdfaewwqe");
    pduMetricsFormula.put("asdasdw2213dsdfaewwqe", pduinfo2);
    ObjectMapper mapper = new ObjectMapper();
    String pduMetricFormulasInfo = null;
    try {
        pduMetricFormulasInfo = mapper.writeValueAsString(pduMetricsFormula);
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
    metricsFormular.put(FlowgateConstant.PDU, pduMetricFormulasInfo);
    server.setMetricsformulars(metricsFormular);
    servers[0] = server;
    Asset server1 = new Asset();
    List<String> pduids1 = new ArrayList<String>();
    pduids1.add("asdasdasd");
    pduids1.add("qweertwtc");
    server1.setPdus(pduids1);
    servers[1] = server1;
    HashSet<String> pduAssetIDs = new HashSet<String>();
    pduAssetIDs.add("mienoas2389asddsfqzda");
    pduAssetIDs.add("asdw2cvxcjchftyhretyv");
    List<Asset> needToUpdateServer = aggregatorService.removePduFromServer(servers, pduAssetIDs);
    TestCase.assertEquals(1, needToUpdateServer.size());
    Asset needupdateServer = needToUpdateServer.get(0);
    TestCase.assertEquals("01" + FlowgateConstant.SEPARATOR + "pdu1" + FlowgateConstant.SEPARATOR + "01" + FlowgateConstant.SEPARATOR + "qwepouasdnlksaydasmnd", needupdateServer.getJustificationfields().get(FlowgateConstant.PDU_PORT_FOR_SERVER));
    TestCase.assertEquals(1, needupdateServer.getPdus().size());
    TestCase.assertEquals("qwiounasdyi2avewrasdf", needupdateServer.getPdus().get(0));
    Map<String, String> metricsFormulars = needupdateServer.getMetricsformulars();
    TestCase.assertEquals(1, metricsFormulars.size());
    Map<String, Map<String, String>> pduMetricsFormulaMap = null;
    try {
        pduMetricsFormulaMap = mapper.readValue(metricsFormulars.get(FlowgateConstant.PDU), new TypeReference<Map<String, Map<String, String>>>() {
        });
    } catch (IOException e) {
        TestCase.fail(e.getMessage());
    }
    TestCase.assertEquals("asdasdw2213dsdfaewwqe", pduMetricsFormulaMap.keySet().iterator().next());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) Asset(com.vmware.flowgate.common.model.Asset) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 82 with Asset

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

the class MessageProcessingTest method testGetPositionInfo.

@Test
public void testGetPositionInfo() {
    Asset asset1 = new Asset();
    TestCase.assertEquals(FlowgateConstant.DEFAULT_CABINET_UNIT_POSITION, aggregatorService.getPositionInfo(asset1));
    Asset asset2 = new Asset();
    asset2.setCabinetUnitPosition(2);
    TestCase.assertEquals(FlowgateConstant.RACK_UNIT_PREFIX + asset2.getCabinetUnitPosition(), aggregatorService.getPositionInfo(asset2));
    Asset asset3 = new Asset();
    asset3.setCabinetUnitPosition(3);
    HashMap<String, String> sensorAssetJustfication = new HashMap<String, String>();
    Map<String, String> sensorInfo = new HashMap<String, String>();
    sensorInfo.put(FlowgateConstant.POSITION, "INLET");
    ObjectMapper mapper = new ObjectMapper();
    try {
        sensorAssetJustfication.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfo));
        asset3.setJustificationfields(sensorAssetJustfication);
    } catch (JsonProcessingException e) {
        TestCase.fail();
    }
    TestCase.assertEquals(FlowgateConstant.RACK_UNIT_PREFIX + asset3.getCabinetUnitPosition() + FlowgateConstant.SEPARATOR + "INLET", aggregatorService.getPositionInfo(asset3));
    Asset asset4 = new Asset();
    HashMap<String, String> justfication = new HashMap<String, String>();
    Map<String, String> sensorInfo1 = new HashMap<String, String>();
    sensorInfo1.put(FlowgateConstant.POSITION, "INLET");
    try {
        justfication.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfo1));
        asset4.setJustificationfields(justfication);
    } catch (JsonProcessingException e) {
        TestCase.fail();
    }
    TestCase.assertEquals("INLET", aggregatorService.getPositionInfo(asset4));
    Asset asset5 = new Asset();
    asset5.setCabinetUnitPosition(3);
    HashMap<String, String> justfication5 = new HashMap<String, String>();
    Map<String, String> sensorInfo5 = new HashMap<String, String>();
    try {
        justfication5.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfo5));
        asset5.setJustificationfields(justfication5);
    } catch (JsonProcessingException e) {
        TestCase.fail();
    }
    TestCase.assertEquals(FlowgateConstant.RACK_UNIT_PREFIX + asset5.getCabinetUnitPosition(), aggregatorService.getPositionInfo(asset5));
    Asset asset6 = new Asset();
    HashMap<String, String> justfication6 = new HashMap<String, String>();
    Map<String, String> sensorInfo6 = new HashMap<String, String>();
    try {
        justfication6.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfo6));
        asset5.setJustificationfields(justfication6);
    } catch (JsonProcessingException e) {
        TestCase.fail();
    }
    TestCase.assertEquals(FlowgateConstant.DEFAULT_CABINET_UNIT_POSITION, aggregatorService.getPositionInfo(asset6));
}
Also used : HashMap(java.util.HashMap) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 83 with Asset

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

the class AggregatorService method syncHostTemperatureAndHumidySensor.

/**
 * This task now focus on the Sensors from PowerIQ 1> First it get all the servers that has pdu.
 * 2> then it get all the sensors that attached with the pdu. 3> it update the server's sensor
 * information with the sensors get from step2
 */
private void syncHostTemperatureAndHumidySensor(boolean fullSync) {
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    Asset[] allServers = restClient.getServersWithPDUInfo().getBody();
    List<Asset> candidateServer = new ArrayList<Asset>();
    if (fullSync) {
        candidateServer = Arrays.asList(allServers);
    } else {
        for (Asset asset : allServers) {
            Map<String, String> metricsFormulas = asset.getMetricsformulars();
            if (metricsFormulas == null) {
                metricsFormulas = new HashMap<String, String>();
                asset.setMetricsformulars(metricsFormulas);
                candidateServer.add(asset);
            } else {
                String sensorFormulasInfo = metricsFormulas.get(FlowgateConstant.SENSOR);
                if (sensorFormulasInfo == null) {
                    candidateServer.add(asset);
                } else {
                    Map<String, Map<String, String>> metricFormulaMap = asset.metricsFormulaToMap(sensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
                    });
                    if (metricFormulaMap == null) {
                        continue;
                    }
                    if (!metricFormulaMap.containsKey(MetricName.SERVER_BACK_TEMPREATURE) || !metricFormulaMap.containsKey(MetricName.SERVER_FRONT_TEMPERATURE) || !metricFormulaMap.containsKey(MetricName.SERVER_BACK_HUMIDITY) || !metricFormulaMap.containsKey(MetricName.SERVER_FRONT_HUMIDITY)) {
                        candidateServer.add(asset);
                    }
                }
            }
        }
    }
    if (candidateServer.isEmpty()) {
        return;
    }
    List<Asset> sensors = restClient.getAllAssetsByType(AssetCategory.Sensors);
    if (sensors.isEmpty()) {
        return;
    }
    Map<String, List<Asset>> pduAndSensorsMap = new HashMap<String, List<Asset>>();
    for (Asset sensor : sensors) {
        if (sensor.getJustificationfields() == null) {
            continue;
        }
        String sensorInfo = sensor.getJustificationfields().get(FlowgateConstant.SENSOR);
        if (sensorInfo == null) {
            continue;
        }
        Map<String, String> sensorInfoMap = null;
        try {
            sensorInfoMap = mapper.readValue(sensorInfo, new TypeReference<Map<String, String>>() {
            });
        } catch (IOException e) {
            logger.error("Format sensor info map error ", e.getMessage());
            continue;
        }
        String pduAssetID = sensorInfoMap.get(FlowgateConstant.PDU_ASSET_ID);
        if (pduAssetID == null) {
            continue;
        }
        if (!pduAndSensorsMap.containsKey(pduAssetID)) {
            pduAndSensorsMap.put(pduAssetID, new ArrayList<Asset>());
        }
        pduAndSensorsMap.get(pduAssetID).add(sensor);
    }
    List<Asset> needUpdateServers = new ArrayList<Asset>();
    for (Asset server : candidateServer) {
        List<String> pduIds = server.getPdus();
        List<String> temperatureSensorAssetIds = new ArrayList<String>();
        List<String> humiditySensorAssetIds = new ArrayList<String>();
        boolean needUpdate = false;
        Map<String, String> metricsFormulas = server.getMetricsformulars();
        String sensorMetricFormulasInfo = null;
        Map<String, Map<String, String>> sensorMetricsFormulasMap = null;
        if (metricsFormulas != null) {
            sensorMetricFormulasInfo = metricsFormulas.get(FlowgateConstant.SENSOR);
        }
        if (sensorMetricFormulasInfo == null) {
            sensorMetricsFormulasMap = new HashMap<String, Map<String, String>>();
        } else {
            sensorMetricsFormulasMap = server.metricsFormulaToMap(sensorMetricFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
            });
            // If there is a problem with deserialization, the map will be null
            if (sensorMetricsFormulasMap == null) {
                continue;
            }
        }
        List<Asset> allSensorAssetsForServer = new ArrayList<Asset>();
        for (String pduID : pduIds) {
            List<Asset> sensorAssets = pduAndSensorsMap.get(pduID);
            if (sensorAssets == null) {
                continue;
            }
            allSensorAssetsForServer.addAll(sensorAssets);
        }
        if (allSensorAssetsForServer.isEmpty()) {
            continue;
        }
        generateMetricsFormular(sensorMetricsFormulasMap, allSensorAssetsForServer, temperatureSensorAssetIds, humiditySensorAssetIds);
        if (sensorMetricsFormulasMap.isEmpty()) {
            if (!temperatureSensorAssetIds.isEmpty()) {
                Map<String, String> frontTemp = new HashMap<String, String>();
                frontTemp.put(FlowgateConstant.DEFAULT_CABINET_UNIT_POSITION, temperatureSensorAssetIds.get(0));
                sensorMetricsFormulasMap.put(MetricName.SERVER_FRONT_TEMPERATURE, frontTemp);
                Map<String, String> backTemp = new HashMap<String, String>();
                String backTemperatureId = temperatureSensorAssetIds.get(0);
                if (temperatureSensorAssetIds.size() > 1) {
                    backTemperatureId = temperatureSensorAssetIds.get(1);
                }
                backTemp.put(FlowgateConstant.DEFAULT_CABINET_UNIT_POSITION, backTemperatureId);
                sensorMetricsFormulasMap.put(MetricName.SERVER_BACK_TEMPREATURE, backTemp);
                needUpdate = true;
            }
            if (!humiditySensorAssetIds.isEmpty()) {
                Map<String, String> humidity = new HashMap<String, String>();
                humidity.put(FlowgateConstant.DEFAULT_CABINET_UNIT_POSITION, humiditySensorAssetIds.get(0));
                sensorMetricsFormulasMap.put(MetricName.SERVER_FRONT_HUMIDITY, humidity);
                Map<String, String> backHumidity = new HashMap<String, String>();
                String backHumidityId = humiditySensorAssetIds.get(0);
                if (humiditySensorAssetIds.size() > 1) {
                    backHumidityId = humiditySensorAssetIds.get(1);
                }
                backHumidity.put(FlowgateConstant.DEFAULT_CABINET_UNIT_POSITION, backHumidityId);
                sensorMetricsFormulasMap.put(MetricName.SERVER_BACK_HUMIDITY, backHumidity);
                needUpdate = true;
            }
        } else {
            needUpdate = true;
        }
        if (needUpdate) {
            String sensorMetricsFormulaInfo = server.metricsFormulaToString(sensorMetricsFormulasMap);
            metricsFormulas.put(FlowgateConstant.SENSOR, sensorMetricsFormulaInfo);
            needUpdateServers.add(server);
        }
    }
    if (!needUpdateServers.isEmpty()) {
        logger.info("update asset item number: " + needUpdateServers.size());
        restClient.saveAssets(needUpdateServers);
    }
    logger.info("No server need to update sensor metric formula.");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Asset(com.vmware.flowgate.common.model.Asset) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with Asset

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

the class AggregatorService method aggregateAndCleanPDUFromPowerIQ.

public void aggregateAndCleanPDUFromPowerIQ() {
    logger.info("Start aggregate pdu from PowerIQ to other systems");
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    FacilitySoftwareConfig[] powerIQs = restClient.getFacilitySoftwareInternalByType(SoftwareType.PowerIQ).getBody();
    if (powerIQs == null || powerIQs.length == 0) {
        logger.info("No PowerIQ server find");
        return;
    }
    Map<String, Asset> pdusOnlyFromPowerIQ = new HashMap<String, Asset>();
    Map<String, String> powerIQIDs = new HashMap<String, String>();
    for (FacilitySoftwareConfig powerIQ : powerIQs) {
        powerIQIDs.put(powerIQ.getId(), powerIQ.getName());
    }
    if (powerIQIDs.isEmpty()) {
        logger.info("No Pdu from PowerIQ server find");
        return;
    }
    List<Asset> pdus = restClient.getAllAssetsByType(AssetCategory.PDU);
    Iterator<Asset> pduIte = pdus.iterator();
    while (pduIte.hasNext()) {
        Asset pdu = pduIte.next();
        // pdu only from powerIQ
        if (pdu.getAssetSource().split(FlowgateConstant.SPILIT_FLAG).length == 1 && powerIQIDs.get(pdu.getAssetSource()) != null) {
            if (pdu.getAssetName() == null || pdu.getAssetName().isEmpty()) {
                continue;
            }
            pdusOnlyFromPowerIQ.put(pdu.getAssetName().toLowerCase(), pdu);
            pduIte.remove();
        }
    }
    if (pdus.isEmpty()) {
        logger.info("All pdus are from powerIQ");
        return;
    }
    HashSet<String> pduAssetIds = new HashSet<String>(pdusOnlyFromPowerIQ.size());
    /**
     * Part of these pdus comes from other DCIMs,
     * and the other part comes from PowerIQ and other DCIMs(integrated pdus)
     * We need NON-PowerIQ's pdus(Not integrated pdus)
     */
    for (Asset targetPdu : pdus) {
        if (targetPdu.getAssetName() == null || targetPdu.getAssetName().isEmpty()) {
            continue;
        }
        String targetPduName = targetPdu.getAssetName().toLowerCase();
        String targetSource = targetPdu.getAssetSource();
        boolean isSkip = false;
        // pdus from multiple DCIM system
        if (targetSource.indexOf(FlowgateConstant.SPILIT_FLAG) > -1) {
            String[] sources = targetSource.split(FlowgateConstant.SPILIT_FLAG);
            for (String assetSource : sources) {
                if (powerIQIDs.containsKey(assetSource)) {
                    // Remove integrated pdu
                    pdusOnlyFromPowerIQ.remove(targetPduName);
                    isSkip = true;
                    break;
                }
            }
        }
        /**
         * When the pdu is integrated, skip.
         */
        if (isSkip) {
            continue;
        }
        // We need to integrate the PowerIQ PDU and Other DCIM PDU
        Asset sourcePdu = pdusOnlyFromPowerIQ.get(targetPduName);
        if (sourcePdu != null) {
            HashMap<String, String> sourcePduExtraInfo = sourcePdu.getJustificationfields();
            HashMap<String, String> targetPduExtraInfo = targetPdu.getJustificationfields();
            if (targetSource.indexOf(sourcePdu.getAssetSource()) == -1) {
                targetPdu.setAssetSource(targetSource + FlowgateConstant.SPILIT_FLAG + sourcePdu.getAssetSource());
            }
            Map<String, String> sourcePduMetricsFormulas = sourcePdu.getMetricsformulars();
            Map<String, String> targetPduMetricsFormulas = targetPdu.getMetricsformulars();
            Map<String, String> sourcePduUsageFormulasMap = new HashMap<>();
            Map<String, String> targetPduUsageFormulasMap = new HashMap<>();
            if (sourcePduMetricsFormulas.get(FlowgateConstant.PDU) != null) {
                Map<String, String> tempSourcePduUsageMetricsFormulaMap = targetPdu.metricsFormulaToMap(sourcePduMetricsFormulas.get(FlowgateConstant.PDU), new TypeReference<Map<String, String>>() {
                });
                if (tempSourcePduUsageMetricsFormulaMap != null) {
                    sourcePduUsageFormulasMap = tempSourcePduUsageMetricsFormulaMap;
                }
            }
            if (targetPduMetricsFormulas.get(FlowgateConstant.PDU) != null) {
                Map<String, String> tempTargetPduUsageMetricsFormulaMap = targetPdu.metricsFormulaToMap(targetPduMetricsFormulas.get(FlowgateConstant.PDU), new TypeReference<Map<String, String>>() {
                });
                if (tempTargetPduUsageMetricsFormulaMap != null) {
                    targetPduUsageFormulasMap = tempTargetPduUsageMetricsFormulaMap;
                }
            }
            for (String metricName : sourcePduUsageFormulasMap.keySet()) {
                if (!targetPduUsageFormulasMap.containsKey(metricName)) {
                    targetPduUsageFormulasMap.put(metricName, targetPdu.getId());
                }
            }
            targetPduMetricsFormulas.put(FlowgateConstant.PDU, targetPdu.metricsFormulaToString(targetPduUsageFormulasMap));
            Map<String, Map<String, String>> sourceSensorFormulasMap = new HashMap<>();
            Map<String, Map<String, String>> targetSensorFormulasMap = new HashMap<>();
            if (sourcePduMetricsFormulas.get(FlowgateConstant.SENSOR) != null) {
                Map<String, Map<String, String>> tempSourcePduSensorMetricsFormulaMap = targetPdu.metricsFormulaToMap(sourcePduMetricsFormulas.get(FlowgateConstant.SENSOR), new TypeReference<Map<String, Map<String, String>>>() {
                });
                if (tempSourcePduSensorMetricsFormulaMap != null) {
                    sourceSensorFormulasMap = tempSourcePduSensorMetricsFormulaMap;
                }
            }
            if (targetPduMetricsFormulas.get(FlowgateConstant.SENSOR) != null) {
                Map<String, Map<String, String>> tempTargetPduSensorMetricsFormulaMap = targetPdu.metricsFormulaToMap(targetPduMetricsFormulas.get(FlowgateConstant.SENSOR), new TypeReference<Map<String, Map<String, String>>>() {
                });
                if (tempTargetPduSensorMetricsFormulaMap != null) {
                    targetSensorFormulasMap = tempTargetPduSensorMetricsFormulaMap;
                }
            }
            for (Map.Entry<String, Map<String, String>> sourceMetricEntry : sourceSensorFormulasMap.entrySet()) {
                String metricName = sourceMetricEntry.getKey();
                Map<String, String> sourceSensorLocationFormulas = sourceMetricEntry.getValue();
                Map<String, String> targetSensorLocationFormulas = targetSensorFormulasMap.get(metricName);
                if (targetSensorLocationFormulas == null || targetSensorLocationFormulas.isEmpty()) {
                    targetSensorFormulasMap.put(metricName, sourceSensorLocationFormulas);
                } else {
                    for (Map.Entry<String, String> sourceLocationEntry : sourceSensorLocationFormulas.entrySet()) {
                        if (!targetSensorLocationFormulas.containsKey(sourceLocationEntry.getKey())) {
                            targetSensorLocationFormulas.put(sourceLocationEntry.getKey(), sourceLocationEntry.getValue());
                        }
                    }
                    targetSensorFormulasMap.put(metricName, targetSensorLocationFormulas);
                }
            }
            targetPduMetricsFormulas.put(FlowgateConstant.SENSOR, targetPdu.metricsFormulaToString(targetSensorFormulasMap));
            targetPdu.setMetricsformulars(targetPduMetricsFormulas);
            if (targetPduExtraInfo == null || targetPduExtraInfo.isEmpty()) {
                targetPdu.setJustificationfields(sourcePduExtraInfo);
                restClient.saveAssets(targetPdu);
                pduAssetIds.add(sourcePdu.getId());
                // If there are more than one pdus with the same name from Nlyte system,only one from these pdus can be merged.
                pdusOnlyFromPowerIQ.remove(targetPduName);
                restClient.removeAssetByID(sourcePdu.getId());
                continue;
            }
            String sourcePduInfo = sourcePduExtraInfo.get(FlowgateConstant.PDU);
            if (sourcePduInfo == null) {
                continue;
            }
            String targetPduInfo = targetPduExtraInfo.get(FlowgateConstant.PDU);
            if (targetPduInfo == null) {
                targetPduExtraInfo.put(FlowgateConstant.PDU, sourcePduInfo);
                restClient.saveAssets(targetPdu);
                pduAssetIds.add(sourcePdu.getId());
                pdusOnlyFromPowerIQ.remove(targetPduName);
                restClient.removeAssetByID(sourcePdu.getId());
                continue;
            }
            Map<String, String> sourcePduInfoMap = null;
            Map<String, String> targetPduInfoMap = null;
            try {
                sourcePduInfoMap = mapper.readValue(sourcePduInfo, new TypeReference<Map<String, String>>() {
                });
                targetPduInfoMap = mapper.readValue(targetPduInfo, new TypeReference<Map<String, String>>() {
                });
            } catch (IOException e) {
                logger.error("Format pdu justficationfields error");
                continue;
            }
            targetPduInfoMap.put(FlowgateConstant.PDU_RATE_AMPS, sourcePduInfoMap.get(FlowgateConstant.PDU_RATE_AMPS));
            targetPduInfoMap.put(FlowgateConstant.PDU_MIN_RATE_POWER, sourcePduInfoMap.get(FlowgateConstant.PDU_MIN_RATE_POWER));
            targetPduInfoMap.put(FlowgateConstant.PDU_MAX_RATE_POWER, sourcePduInfoMap.get(FlowgateConstant.PDU_MAX_RATE_POWER));
            targetPduInfoMap.put(FlowgateConstant.PDU_MIN_RATE_VOLTS, sourcePduInfoMap.get(FlowgateConstant.PDU_MIN_RATE_VOLTS));
            targetPduInfoMap.put(FlowgateConstant.PDU_MAX_RATE_VOLTS, sourcePduInfoMap.get(FlowgateConstant.PDU_MAX_RATE_VOLTS));
            targetPduInfoMap.put(FlowgateConstant.PDU_OUTLETS_FROM_POWERIQ, sourcePduInfoMap.get(FlowgateConstant.PDU_OUTLETS_FROM_POWERIQ));
            targetPduInfoMap.put(FlowgateConstant.PDU_INLETS_FROM_POWERIQ, sourcePduInfoMap.get(FlowgateConstant.PDU_INLETS_FROM_POWERIQ));
            targetPduInfoMap.put(FlowgateConstant.PDU_ID_FROM_POWERIQ, sourcePduInfoMap.get(FlowgateConstant.PDU_ID_FROM_POWERIQ));
            try {
                String newPduInfo = mapper.writeValueAsString(targetPduInfoMap);
                targetPduExtraInfo.put(FlowgateConstant.PDU, newPduInfo);
                targetPdu.setJustificationfields(targetPduExtraInfo);
            } catch (JsonProcessingException e) {
                logger.error("Format pdu extra info error", e.getCause());
            }
            restClient.saveAssets(targetPdu);
            pduAssetIds.add(sourcePdu.getId());
            pdusOnlyFromPowerIQ.remove(targetPduName);
            restClient.removeAssetByID(sourcePdu.getId());
        }
    }
    logger.info("Finished aggregate pdu from PowerIQ to other systems");
    if (!pduAssetIds.isEmpty()) {
        Asset[] serversWithPduInfo = restClient.getServersWithPDUInfo().getBody();
        if (serversWithPduInfo == null || serversWithPduInfo.length == 0) {
            logger.info("No mapped server");
            return;
        }
        List<Asset> needToUpdateServer = removePduFromServer(serversWithPduInfo, pduAssetIds);
        restClient.saveAssets(needToUpdateServer);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) Asset(com.vmware.flowgate.common.model.Asset) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HashMap(java.util.HashMap) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HashSet(java.util.HashSet)

Example 85 with Asset

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

the class NlyteDataService method getAssetIdfromformular.

public Set<String> getAssetIdfromformular(List<Asset> mappedServers) {
    Set<String> assetIds = new HashSet<String>();
    for (Asset asset : mappedServers) {
        Map<String, String> formulars = asset.getMetricsformulars();
        if (formulars == null || formulars.isEmpty()) {
            continue;
        }
        // {"pduAssetID",{"type_1","pduAssetID"}}
        Map<String, Map<String, String>> pduFormulas = asset.metricsFormulaToMap(formulars.get(FlowgateConstant.PDU), new TypeReference<Map<String, Map<String, String>>>() {
        });
        if (pduFormulas == null || pduFormulas.isEmpty()) {
            continue;
        }
        for (Map.Entry<String, Map<String, String>> pduFormularMap : pduFormulas.entrySet()) {
            assetIds.add(pduFormularMap.getKey());
        }
    }
    return assetIds;
}
Also used : NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

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