Search in sources :

Example 26 with IntegrationStatus

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

the class LabsdbService method syncWiremapData.

public void syncWiremapData(FacilitySoftwareConfig config, boolean isAll) {
    wormholeApiClient.setServiceKey(serviceKeyConfig.getServiceKey());
    List<Asset> servers = wormholeApiClient.getAllAssetsByType(AssetCategory.Server);
    if (!isAll) {
        servers = filterServers(servers);
    }
    Map<String, String> pduIDListMap = getAssetNameIDMap(AssetCategory.PDU);
    Map<String, String> networkIDListMap = getAssetNameIDMap(AssetCategory.Networks);
    LabsdbClient labsdbClient = createClient(config);
    try {
        if (!labsdbClient.checkConnection()) {
            return;
        }
    } catch (HttpClientErrorException e) {
        logger.error("Failed to query data from Labsdb", e);
        IntegrationStatus integrationStatus = config.getIntegrationStatus();
        if (integrationStatus == null) {
            integrationStatus = new IntegrationStatus();
        }
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(e.getMessage());
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        updateIntegrationStatus(config);
        return;
    } catch (ResourceAccessException e1) {
        if (e1.getCause().getCause() instanceof ConnectException) {
            checkAndUpdateIntegrationStatus(config, e1.getMessage());
            return;
        }
    }
    // generatorWiremapData(servers,pduIDListMap,networkIDListMap,labsdbClient);
    SAXParserFactory spf = SAXParserFactory.newInstance();
    WiremapSaxHandler handler = new WiremapSaxHandler(wirmMap_node);
    SAXParser parser = null;
    try {
        parser = spf.newSAXParser();
    } catch (ParserConfigurationException | SAXException e) {
        logger.error("Create new sax parser failed." + e.getMessage());
    }
    for (Asset asset : servers) {
        ResponseEntity<String> resultEntity = null;
        try {
            resultEntity = labsdbClient.getWireMap(asset.getAssetName());
        } catch (Exception e) {
            logger.error("An exception occurred while accessing the labsdb server." + e.getMessage());
        }
        if (resultEntity == null || resultEntity.getBody() == null) {
            continue;
        }
        try {
            parser.parse(new ByteArrayInputStream(resultEntity.getBody().getBytes()), handler);
        } catch (SAXException | IOException e) {
            logger.error("Error parsing XML input stream.This XML input stream is " + resultEntity.getBody());
        }
        // Get all the devices connected to the server
        List<EndDevice> devices = handler.getEndDevices();
        if (devices == null || devices.isEmpty()) {
            continue;
        }
        generatorWiremapData(asset, pduIDListMap, devices, networkIDListMap);
        wormholeApiClient.saveAssets(asset);
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) EndDevice(com.vmware.flowgate.labsdb.common.EndDevice) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) IOException(java.io.IOException) WiremapSaxHandler(com.vmware.flowgate.labsdb.util.WiremapSaxHandler) ResourceAccessException(org.springframework.web.client.ResourceAccessException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) Asset(com.vmware.flowgate.common.model.Asset) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LabsdbClient(com.vmware.flowgate.labsdb.client.LabsdbClient) ConnectException(java.net.ConnectException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 27 with IntegrationStatus

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

the class FacilitySoftwareController method createServer.

// create a new facilitySoftwareConfig
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void createServer(@RequestBody FacilitySoftwareConfig config, HttpServletRequest request) {
    HandleURL handleURL = new HandleURL();
    config.setServerURL(handleURL.formatURL(config.getServerURL()));
    if (repository.findOneByServerURL(config.getServerURL()) != null) {
        String message = String.format("The server %s is already exsit.", config.getServerURL());
        throw new WormholeRequestException(message);
    }
    serverValidationService.validateFacilityServer(config);
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
    integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
    config.setIntegrationStatus(integrationStatus);
    WormholeUserDetails user = accessTokenService.getCurrentUser(request);
    config.setUserId(user.getUserId());
    encryptServerPassword(config);
    BaseDocumentUtil.generateID(config);
    repository.save(config);
    decryptServerPassword(config);
    notifyFacilityWorker(config);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) HandleURL(com.vmware.flowgate.util.HandleURL) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with IntegrationStatus

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

the class VCDataService method checkAndUpdateIntegrationStatus.

public void checkAndUpdateIntegrationStatus(SDDCSoftwareConfig vc, String message) {
    IntegrationStatus integrationStatus = vc.getIntegrationStatus();
    if (integrationStatus == null) {
        integrationStatus = new IntegrationStatus();
    }
    int timesOftry = integrationStatus.getRetryCounter();
    timesOftry++;
    if (timesOftry < FlowgateConstant.MAXNUMBEROFRETRIES) {
        integrationStatus.setRetryCounter(timesOftry);
    } else {
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(message);
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        logger.error("Failed to sync data to VC");
    }
    vc.setIntegrationStatus(integrationStatus);
    updateIntegrationStatus(vc);
}
Also used : IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus)

Example 29 with IntegrationStatus

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

the class SDDCSoftwareControllerTest method createSDDCSoftwareConfig.

SDDCSoftwareConfig createSDDCSoftwareConfig(SoftwareType type) {
    SDDCSoftwareConfig example = new SDDCSoftwareConfig();
    example.setId(UUID.randomUUID().toString());
    example.setName("test server");
    example.setServerURL("10.160.30.134");
    example.setType(type);
    example.setUserName("administrator@vsphere.local");
    example.setPassword("Admin!23");
    example.setUserId("1001");
    example.setVerifyCert(false);
    example.setDescription("description");
    IntegrationStatus integrationStatus = new IntegrationStatus();
    example.setIntegrationStatus(integrationStatus);
    return example;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus)

Example 30 with IntegrationStatus

use of com.vmware.flowgate.common.model.IntegrationStatus 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)

Aggregations

IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)31 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)12 Asset (com.vmware.flowgate.common.model.Asset)10 ConnectException (java.net.ConnectException)10 IOException (java.io.IOException)8 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)7 HashMap (java.util.HashMap)7 ResourceAccessException (org.springframework.web.client.ResourceAccessException)7 ArrayList (java.util.ArrayList)5 AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)3 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)3 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)3 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)3 PowerIQAPIClient (com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AdvanceSettingType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)2 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)2 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)2 LocationGroup (com.vmware.flowgate.nlyteworker.model.LocationGroup)2 Manufacturer (com.vmware.flowgate.nlyteworker.model.Manufacturer)2