Search in sources :

Example 1 with WiremapSaxHandler

use of com.vmware.flowgate.labsdb.util.WiremapSaxHandler 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)

Aggregations

Asset (com.vmware.flowgate.common.model.Asset)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 LabsdbClient (com.vmware.flowgate.labsdb.client.LabsdbClient)1 EndDevice (com.vmware.flowgate.labsdb.common.EndDevice)1 WiremapSaxHandler (com.vmware.flowgate.labsdb.util.WiremapSaxHandler)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1 SAXException (org.xml.sax.SAXException)1