Search in sources :

Example 56 with FacilitySoftwareConfig

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

the class SystemSummaryTest method testSummaryRepo.

@Test
public void testSummaryRepo() throws IOException {
    ValueOperations<String, String> valueOperations = Mockito.mock(ValueOperations.class);
    Mockito.doReturn(valueOperations).when(template).opsForValue();
    FacilitySoftwareConfig nlyte1 = createFacility();
    nlyte1.setType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.Nlyte);
    nlyte1 = facilityrepo.save(nlyte1);
    FacilitySoftwareConfig powerIQ1 = createFacility();
    powerIQ1.setType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.PowerIQ);
    powerIQ1 = facilityrepo.save(powerIQ1);
    Asset nlyteServer1 = createAsset();
    nlyteServer1.setCategory(AssetCategory.Server);
    nlyteServer1.setAssetSource(nlyte1.getId());
    nlyteServer1 = assetrepo.save(nlyteServer1);
    Asset nlyteServer2 = createAsset();
    nlyteServer2.setCategory(AssetCategory.Server);
    nlyteServer2.setAssetSource(nlyte1.getId());
    nlyteServer2 = assetrepo.save(nlyteServer2);
    Asset nlytePDU1 = createAsset();
    nlytePDU1.setCategory(AssetCategory.PDU);
    nlytePDU1.setAssetSource(nlyte1.getId());
    nlytePDU1 = assetrepo.save(nlytePDU1);
    Asset nlytePDU2 = createAsset();
    nlytePDU2.setCategory(AssetCategory.PDU);
    nlytePDU2.setAssetSource(nlyte1.getId());
    nlytePDU2 = assetrepo.save(nlytePDU2);
    Asset powerIQSensor1 = createAsset();
    powerIQSensor1.setCategory(AssetCategory.Sensors);
    powerIQSensor1.setSubCategory(AssetSubCategory.Humidity);
    powerIQSensor1.setAssetSource(powerIQ1.getId());
    powerIQSensor1 = assetrepo.save(powerIQSensor1);
    Asset powerIQSensor2 = createAsset();
    powerIQSensor2.setCategory(AssetCategory.Sensors);
    powerIQSensor2.setSubCategory(AssetSubCategory.Humidity);
    powerIQSensor2.setAssetSource(powerIQ1.getId());
    powerIQSensor2 = assetrepo.save(powerIQSensor2);
    Asset powerIQSensor3 = createAsset();
    powerIQSensor3.setCategory(AssetCategory.Sensors);
    powerIQSensor3.setSubCategory(AssetSubCategory.Temperature);
    powerIQSensor3.setAssetSource(powerIQ1.getId());
    powerIQSensor3 = assetrepo.save(powerIQSensor3);
    Asset powerIQSensor4 = createAsset();
    powerIQSensor4.setCategory(AssetCategory.Sensors);
    powerIQSensor4.setSubCategory(AssetSubCategory.Temperature);
    powerIQSensor4.setAssetSource(powerIQ1.getId());
    powerIQSensor4 = assetrepo.save(powerIQSensor4);
    SDDCSoftwareConfig vro1 = createSDDC();
    vro1.setType(SoftwareType.VRO);
    vro1 = sddcrepo.save(vro1);
    SDDCSoftwareConfig vro2 = createSDDC();
    vro2.setType(SoftwareType.VRO);
    vro2 = sddcrepo.save(vro2);
    SDDCSoftwareConfig vc1 = createSDDC();
    vc1.setType(SoftwareType.VCENTER);
    vc1 = sddcrepo.save(vc1);
    SDDCSoftwareConfig vc2 = createSDDC();
    vc2.setType(SoftwareType.VCENTER);
    vc2 = sddcrepo.save(vc2);
    ServerMapping server1 = createServerMapping();
    server1.setVroID(vro1.getId());
    server1 = mappingrepo.save(server1);
    ServerMapping server2 = createServerMapping();
    server2.setVroID(vro1.getId());
    server2 = mappingrepo.save(server2);
    ServerMapping server3 = createServerMapping();
    server3.setVcID(vc1.getId());
    server3 = mappingrepo.save(server3);
    ServerMapping server4 = createServerMapping();
    server4.setVcID(vc2.getId());
    server4 = mappingrepo.save(server4);
    ServerMapping server5 = createServerMapping();
    server5.setVroID(vro2.getId());
    server5 = mappingrepo.save(server5);
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        SystemSummary data = summaryService.getSystemResult(false);
        TestCase.assertEquals(8, data.getAssetsNum());
        TestCase.assertEquals(2, data.getFacilitySystemNum());
        TestCase.assertEquals(4, data.getSddcIntegrationNum());
        TestCase.assertEquals(2, data.getHumiditySensorNum());
        TestCase.assertEquals(2, data.getTemperatureSensorNum());
        TestCase.assertEquals(4, data.getSensorNum());
        TestCase.assertEquals(2, data.getPduNum());
        TestCase.assertEquals(2, data.getServerNum());
        TestCase.assertEquals(5, data.getSddcServerNum());
        TestCase.assertEquals(2, data.getVroNum());
        TestCase.assertEquals(2, data.getVcNum());
    } finally {
        facilityrepo.deleteById(nlyte1.getId());
        facilityrepo.deleteById(powerIQ1.getId());
        assetrepo.deleteById(nlyteServer1.getId());
        assetrepo.deleteById(nlyteServer2.getId());
        assetrepo.deleteById(nlytePDU1.getId());
        assetrepo.deleteById(nlytePDU2.getId());
        assetrepo.deleteById(powerIQSensor1.getId());
        assetrepo.deleteById(powerIQSensor2.getId());
        assetrepo.deleteById(powerIQSensor3.getId());
        assetrepo.deleteById(powerIQSensor4.getId());
        sddcrepo.deleteById(vc1.getId());
        sddcrepo.deleteById(vc2.getId());
        sddcrepo.deleteById(vro1.getId());
        sddcrepo.deleteById(vro2.getId());
        mappingrepo.deleteById(server1.getId());
        mappingrepo.deleteById(server2.getId());
        mappingrepo.deleteById(server3.getId());
        mappingrepo.deleteById(server4.getId());
        mappingrepo.deleteById(server5.getId());
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) SystemSummary(com.vmware.flowgate.common.model.SystemSummary) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) Asset(com.vmware.flowgate.common.model.Asset) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 57 with FacilitySoftwareConfig

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

the class SummaryService method getNlyteSummaryList.

public List<NlyteSummary> getNlyteSummaryList() {
    List<NlyteSummary> nlyteSummarys = new ArrayList<>();
    List<FacilitySoftwareConfig> facility = facilityRepo.findAllByType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.Nlyte.name());
    for (FacilitySoftwareConfig nlyte : facility) {
        NlyteSummary nlyteSummary = getNlyteSummary(nlyte);
        nlyteSummarys.add(nlyteSummary);
    }
    return nlyteSummarys;
}
Also used : NlyteSummary(com.vmware.flowgate.common.model.NlyteSummary) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig)

Example 58 with FacilitySoftwareConfig

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

the class SummaryService method getPowerIQSummaryList.

public List<PowerIqSummary> getPowerIQSummaryList() {
    List<PowerIqSummary> powerIqSummarys = new ArrayList<PowerIqSummary>();
    List<FacilitySoftwareConfig> facility = facilityRepo.findAllByType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.PowerIQ.name());
    for (FacilitySoftwareConfig powerIq : facility) {
        PowerIqSummary powerIQSummary = getPowerIQSummary(powerIq);
        powerIqSummarys.add(powerIQSummary);
    }
    return powerIqSummarys;
}
Also used : PowerIqSummary(com.vmware.flowgate.common.model.PowerIqSummary) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig)

Example 59 with FacilitySoftwareConfig

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

the class InfoBloxService method executeAsync.

@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage eventMessage) {
    // The data format of the message. should be an ip address.
    // Do the business here.
    String message = eventMessage.getContent();
    logger.info(String.format("Try to find hostname for ip: %s", message));
    // check message , make sure it is an valid ip address;
    wormholeAPIClient.setServiceKey(serviceKeyConfig.getServiceKey());
    FacilitySoftwareConfig[] infoBloxes = wormholeAPIClient.getFacilitySoftwareInternalByType(SoftwareType.InfoBlox).getBody();
    List<InfoBloxIPInfoResult> infoBloxIPInfoResults = new ArrayList<>();
    List<InfoBloxIPInfoResult> hostRecordResults = null;
    List<InfoBloxIPInfoResult> ipv4addressResults = null;
    for (FacilitySoftwareConfig infoblox : infoBloxes) {
        if (!infoblox.checkIsActive()) {
            continue;
        }
        InfobloxClient client = buildInfobloxClient(infoblox);
        IntegrationStatus integrationStatus = infoblox.getIntegrationStatus();
        IntegrationStatus.Status status = integrationStatus == null ? null : integrationStatus.getStatus();
        try {
            if (status == null || IntegrationStatus.Status.ACTIVE.equals(status)) {
                hostRecordResults = client.queryHostRecordByIP(message);
                logger.debug("queryHostRecordByIP: {}", hostRecordResults);
                if (hostRecordResults != null && !hostRecordResults.isEmpty()) {
                    infoBloxIPInfoResults.addAll(hostRecordResults);
                }
            }
            if (hostRecordResults == null || hostRecordResults.isEmpty()) {
                ipv4addressResults = client.queryIpv4addressByIP(message);
                logger.debug("queryHostNamesByIP: {}", ipv4addressResults);
                if (ipv4addressResults != null && !ipv4addressResults.isEmpty()) {
                    infoBloxIPInfoResults.addAll(ipv4addressResults);
                }
                if (!IntegrationStatus.Status.WARNING.equals(status) && ipv4addressResults != null) {
                    updateIntegrationStatusToWarning(infoblox, message);
                }
            }
        } catch (ResourceAccessException e) {
            if (e.getCause().getCause() instanceof ConnectException) {
                checkAndUpdateIntegrationStatus(infoblox, e.getCause().getCause().getMessage());
                continue;
            }
        } catch (HttpClientErrorException e1) {
            logger.error("Failed to query data from Infoblox", e1);
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail(e1.getMessage());
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            infoblox.setIntegrationStatus(integrationStatus);
            updateIntegrationStatus(infoblox);
            continue;
        }
        if (integrationStatus != null && integrationStatus.getRetryCounter() > 0) {
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(infoblox);
        }
        if (!infoBloxIPInfoResults.isEmpty()) {
            for (InfoBloxIPInfoResult infoBloxIPInfoResult : infoBloxIPInfoResults) {
                try {
                    Asset asset = wormholeAPIClient.getAssetByName(infoBloxIPInfoResult.getHostName()).getBody();
                    if (asset == null) {
                        logger.info(String.format("hostname (%s) no found!", infoBloxIPInfoResult.getHostName()));
                        continue;
                    }
                } catch (HttpClientErrorException e) {
                    logger.error(String.format("Error when searching %s", infoBloxIPInfoResult.getHostName()), e);
                    continue;
                }
                AssetIPMapping tempMapping = new AssetIPMapping();
                tempMapping.setAssetname(infoBloxIPInfoResult.getHostName());
                tempMapping.setMacAddress(infoBloxIPInfoResult.getMacAddress());
                tempMapping.setIp(message);
                AssetIPMapping[] mappings = wormholeAPIClient.getHostnameIPMappingByIP(message).getBody();
                boolean isNewMapping = true;
                if (null != mappings && mappings.length > 0) {
                    for (AssetIPMapping mapping : mappings) {
                        if (tempMapping.getAssetname().equals(mapping.getAssetname())) {
                            if (!StringUtils.equals(mapping.getMacAddress(), tempMapping.getMacAddress())) {
                                mapping.setMacAddress(tempMapping.getMacAddress());
                                wormholeAPIClient.updateHostnameIPMapping(mapping);
                            }
                            isNewMapping = false;
                            break;
                        }
                    }
                }
                if (isNewMapping) {
                    wormholeAPIClient.createHostnameIPMapping(tempMapping);
                }
                logger.info(String.format("Find hostname %s for ip %s", infoBloxIPInfoResult.getHostName(), message));
                return;
            }
        }
    }
    logger.info(String.format("Cannot find the hostname for IP: %s", message));
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ArrayList(java.util.ArrayList) ResourceAccessException(org.springframework.web.client.ResourceAccessException) InfoBloxIPInfoResult(com.vmware.flowgate.infobloxworker.model.InfoBloxIPInfoResult) InfobloxClient(com.vmware.flowgate.infobloxworker.service.InfobloxClient) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) Asset(com.vmware.flowgate.common.model.Asset) ConnectException(java.net.ConnectException) Async(org.springframework.scheduling.annotation.Async)

Example 60 with FacilitySoftwareConfig

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

the class EventMessageUtil method generateFacilityMessageListByType.

public static List<String> generateFacilityMessageListByType(EventType type, String targetCommand, FacilitySoftwareConfig[] facilites) throws JsonProcessingException {
    List<String> result = new ArrayList<String>();
    for (FacilitySoftwareConfig facility : facilites) {
        String payload = mapper.writeValueAsString(facility);
        EventMessage message = EventMessageUtil.createEventMessage(type, targetCommand, payload);
        result.add(mapper.writeValueAsString(message));
    }
    return result;
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig)

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