Search in sources :

Example 21 with FacilitySoftwareConfig

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

the class MessageProcessingTest method createFacilitySoftware.

FacilitySoftwareConfig createFacilitySoftware() {
    FacilitySoftwareConfig example = new FacilitySoftwareConfig();
    example.setId(UUID.randomUUID().toString());
    example.setName("OtherDcimSample");
    example.setUserName("administrator@vsphere.local");
    example.setPassword("Admin!23");
    example.setServerURL("https://10.160.30.134");
    example.setType(FacilitySoftwareConfig.SoftwareType.OtherDCIM);
    example.setUserId("1");
    example.setVerifyCert(false);
    example.setDescription("description");
    HashMap<AdvanceSettingType, String> advanceSetting = new HashMap<AdvanceSettingType, String>();
    example.setAdvanceSetting(advanceSetting);
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setDetail("");
    integrationStatus.setRetryCounter(0);
    integrationStatus.setStatus(Status.ACTIVE);
    example.setIntegrationStatus(integrationStatus);
    return example;
}
Also used : HashMap(java.util.HashMap) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AdvanceSettingType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)

Example 22 with FacilitySoftwareConfig

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

the class MessageProcessingTest method testExecuteCustomerSendMessageJob.

@Test
public void testExecuteCustomerSendMessageJob() throws JobExecutionException {
    ListOperations<String, String> listOp = Mockito.mock(ListOperations.class);
    ValueOperations<String, String> valueOp = Mockito.mock(ValueOperations.class);
    when(template.opsForList()).thenReturn(listOp);
    when(listOp.leftPushAll(anyString(), anyString())).thenReturn(1L);
    when(template.hasKey(anyString())).thenReturn(true);
    when(template.opsForValue()).thenReturn(valueOp);
    FacilitySoftwareConfig fac1 = createFacilitySoftware();
    String unique_value1 = UUID.randomUUID().toString();
    fac1.setSubCategory("OtherDCIM_" + unique_value1);
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherDCIM)).thenReturn(getFacilitySoftwareByType(fac1));
    FacilitySoftwareConfig fac2 = createFacilitySoftware();
    fac2.setType(FacilitySoftwareConfig.SoftwareType.OtherCMDB);
    String unique_value2 = UUID.randomUUID().toString();
    fac2.setSubCategory("OtherCMDB_" + unique_value2);
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherCMDB)).thenReturn(getFacilitySoftwareByType(fac2));
    FacilityAdapter adapter = new FacilityAdapter();
    adapter.setSubCategory("OtherDCIM_" + unique_value1);
    AdapterJobCommand command1 = new AdapterJobCommand();
    command1.setCommand("syncmetadata");
    command1.setTriggerCycle(20);
    List<AdapterJobCommand> commands = new ArrayList<AdapterJobCommand>();
    commands.add(command1);
    adapter.setCommands(commands);
    adapter.setTopic(unique_value1);
    adapter.setQueueName(unique_value1 + ":joblist");
    FacilityAdapter adapter2 = new FacilityAdapter();
    adapter2.setSubCategory("OtherCMDB_" + unique_value2);
    AdapterJobCommand command2 = new AdapterJobCommand();
    command2.setCommand("syncmetadata");
    command2.setTriggerCycle(20);
    List<AdapterJobCommand> commands2 = new ArrayList<AdapterJobCommand>();
    commands2.add(command2);
    adapter2.setCommands(commands2);
    adapter2.setTopic(unique_value2);
    adapter2.setQueueName(unique_value2 + ":joblist");
    FacilityAdapter[] adapters = new FacilityAdapter[2];
    adapters[0] = adapter;
    adapters[1] = adapter2;
    when(restClient.getAllCustomerFacilityAdapters()).thenReturn(new ResponseEntity<FacilityAdapter[]>(adapters, HttpStatus.OK));
    customerAdapter.execute(null);
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig 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 24 with FacilitySoftwareConfig

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

the class SycnRealTimeDataJobTest method getFacilitySoftwareByType.

public ResponseEntity<FacilitySoftwareConfig[]> getFacilitySoftwareByType() {
    HashMap<AdvanceSettingType, String> advanceSettingMap = new HashMap<AdvanceSettingType, String>();
    advanceSettingMap.put(AdvanceSettingType.DateFormat, NlyteDataService.DateFormat);
    advanceSettingMap.put(AdvanceSettingType.TimeZone, "GMT");
    FacilitySoftwareConfig[] configs = new FacilitySoftwareConfig[1];
    configs[0] = new FacilitySoftwareConfig();
    configs[0].setId("l9i8728d55368540fcba1692");
    configs[0].setType(SoftwareType.Nlyte);
    configs[0].setAdvanceSetting(advanceSettingMap);
    return new ResponseEntity<FacilitySoftwareConfig[]>(configs, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) AdvanceSettingType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)

Example 25 with FacilitySoftwareConfig

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

the class SycnRealTimeDataJobTest method testGetRealTimeDatas.

@Test
public void testGetRealTimeDatas() {
    Set<String> assetIds = new HashSet<String>();
    assetIds.add("5x4ff46982db22e1b040e0f2");
    FacilitySoftwareConfig config = getFacilitySoftwareByType().getBody()[0];
    List<RealTimeData> realTimeDatas = nlyteDataService.getRealTimeDatas(nlyteAPIClient, config, assetIds);
    TestCase.assertEquals(1, realTimeDatas.size());
    TestCase.assertEquals("5x4ff46982db22e1b040e0f2", realTimeDatas.get(0).getAssetID());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) HashSet(java.util.HashSet) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)60 Test (org.junit.Test)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)29 ArrayList (java.util.ArrayList)13 Asset (com.vmware.flowgate.common.model.Asset)8 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)7 IOException (java.io.IOException)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)6 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)5 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)5 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)5 HashMap (java.util.HashMap)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)4 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)4 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)4