Search in sources :

Example 1 with Asset

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

the class SystemSummaryTest method createAsset.

Asset createAsset() {
    Asset asset = new Asset();
    asset.setId(UUID.randomUUID().toString());
    return asset;
}
Also used : Asset(com.vmware.flowgate.common.model.Asset)

Example 2 with Asset

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

the class NlyteDataService method savePduAssetAndUpdatePduUsageFormula.

public void savePduAssetAndUpdatePduUsageFormula(List<Asset> pduList) {
    for (Asset pdu : pduList) {
        // save asset
        ResponseEntity<Void> responseEntity = restClient.saveAssets(pdu);
        if (responseEntity.getStatusCode().is2xxSuccessful()) {
            String pduId = getAssetIdByResponseEntity(responseEntity);
            pdu.setId(pduId);
            if (pdu.getMetricsformulars().get(FlowgateConstant.PDU) == null) {
                Map<String, String> pduMetricsFormulas = new HashMap<>(1);
                Map<String, String> pduUsageMetricsFormulas = new HashMap<>(3);
                pduUsageMetricsFormulas.put(MetricName.PDU_CURRENT, pduId);
                pduUsageMetricsFormulas.put(MetricName.PDU_TOTAL_POWER, pduId);
                pduUsageMetricsFormulas.put(MetricName.PDU_VOLTAGE, pduId);
                pduMetricsFormulas.put(FlowgateConstant.PDU, pdu.metricsFormulaToString(pduUsageMetricsFormulas));
                pdu.setMetricsformulars(pduMetricsFormulas);
                // save asset formula
                restClient.saveAssets(pdu);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset)

Example 3 with Asset

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

the class NlyteDataService method generateMountedAssetNumberAndChassisAssetIdMap.

public HashMap<Long, String> generateMountedAssetNumberAndChassisAssetIdMap(List<Asset> chassisFromFlowgate) {
    HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap = new HashMap<Long, String>();
    for (Asset asset : chassisFromFlowgate) {
        HashMap<String, String> justficationMap = asset.getJustificationfields();
        String chassisInfo = justficationMap.get(FlowgateConstant.CHASSIS);
        Map<String, String> chassisInfoMap = null;
        List<FlowgateChassisSlot> flowgateChassisSlots = null;
        if (chassisInfo != null) {
            try {
                chassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
                });
                String chassisSlots = chassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
                flowgateChassisSlots = mapper.readValue(chassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
                });
            } catch (Exception e) {
                logger.error("Failed to read the data of chassis slots, error: " + e.getMessage());
                continue;
            }
            if (flowgateChassisSlots != null && !flowgateChassisSlots.isEmpty()) {
                for (FlowgateChassisSlot slot : flowgateChassisSlots) {
                    if (slot.getMountedAssetNumber() != null) {
                        chassisMountedAssetNumberAndChassisIdMap.put(slot.getMountedAssetNumber().longValue(), asset.getId());
                    }
                }
            }
        } else {
            continue;
        }
    }
    return chassisMountedAssetNumberAndChassisIdMap;
}
Also used : FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) HashMap(java.util.HashMap) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) TypeReference(com.fasterxml.jackson.core.type.TypeReference) WormholeException(com.vmware.flowgate.common.exception.WormholeException) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Example 4 with Asset

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

the class NlyteDataService method removeInActiveData.

private void removeInActiveData(FacilitySoftwareConfig nlyte) {
    NlyteAPIClient nlyteAPIclient = createClient(nlyte);
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    List<Asset> servers = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Server);
    List<Asset> pdus = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.PDU);
    List<Asset> networks = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Networks);
    List<Asset> cabinets = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Cabinet);
    long currentTime = System.currentTimeMillis();
    // remove inactive pdus information from server and remove inactive pdus
    long expiredTimeRange = FlowgateConstant.DEFAULTEXPIREDTIMERANGE;
    String expiredTimeValue = template.opsForValue().get(EventMessageUtil.EXPIREDTIMERANGE);
    if (expiredTimeValue != null) {
        expiredTimeRange = Long.valueOf(expiredTimeValue);
    }
    for (Asset pdu : pdus) {
        if (!pdu.isExpired(currentTime, expiredTimeRange)) {
            continue;
        }
        NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.PDU, pdu.getAssetNumber());
        if (asset == null || !assetIsActived(asset, AssetCategory.PDU)) {
            servers = removePduFromServer(servers, pdu.getId());
            restClient.saveAssets(servers);
            restClient.removeAssetByID(pdu.getId());
        } else if (asset != null && assetIsActived(asset, AssetCategory.PDU)) {
            pdu.setLastupdate(currentTime);
            restClient.saveAssets(pdu);
        }
    }
    // remove inactive network information from servers and remove inactive networks
    for (Asset network : networks) {
        if (!network.isExpired(currentTime, expiredTimeRange)) {
            continue;
        }
        NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.Networks, network.getAssetNumber());
        if (asset == null || !assetIsActived(asset, AssetCategory.Networks)) {
            servers = removeNetworkFromServer(servers, network.getId());
            restClient.saveAssets(servers);
            restClient.removeAssetByID(network.getId());
        } else if (asset != null && assetIsActived(asset, AssetCategory.Networks)) {
            network.setLastupdate(currentTime);
            restClient.saveAssets(network);
        }
    }
    // remove cabinets
    for (Asset cabinet : cabinets) {
        if (!cabinet.isExpired(currentTime, expiredTimeRange)) {
            continue;
        }
        NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.Cabinet, cabinet.getAssetNumber());
        if (asset == null || !assetIsActived(asset, AssetCategory.Cabinet)) {
            restClient.removeAssetByID(cabinet.getId());
        } else if (asset != null && assetIsActived(asset, AssetCategory.Cabinet)) {
            cabinet.setLastupdate(currentTime);
            restClient.saveAssets(cabinet);
        }
    }
    // get all serverMapping
    SDDCSoftwareConfig[] vcs = restClient.getInternalSDDCSoftwareConfigByType(SDDCSoftwareConfig.SoftwareType.VCENTER).getBody();
    SDDCSoftwareConfig[] vros = restClient.getInternalSDDCSoftwareConfigByType(SDDCSoftwareConfig.SoftwareType.VRO).getBody();
    List<ServerMapping> mappings = new ArrayList<ServerMapping>();
    for (SDDCSoftwareConfig vc : vcs) {
        mappings.addAll(new ArrayList<>(Arrays.asList(restClient.getServerMappingsByVC(vc.getId()).getBody())));
    }
    for (SDDCSoftwareConfig vro : vros) {
        mappings.addAll(new ArrayList<>(Arrays.asList(restClient.getServerMappingsByVRO(vro.getId()).getBody())));
    }
    // remove inactive asset from serverMapping and remove inactive servers
    for (Asset server : servers) {
        if (!server.isExpired(currentTime, expiredTimeRange)) {
            continue;
        }
        NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.Server, server.getAssetNumber());
        if (asset == null || !assetIsActived(asset, AssetCategory.Server)) {
            for (ServerMapping mapping : mappings) {
                if (mapping.getAsset() == null) {
                    continue;
                }
                if (server.getId().equals(mapping.getAsset())) {
                    mapping.setAsset(null);
                    restClient.saveServerMapping(mapping);
                }
            }
            restClient.removeAssetByID(server.getId());
        } else if (asset != null && assetIsActived(asset, AssetCategory.Server)) {
            server.setLastupdate(currentTime);
            restClient.saveAssets(server);
        }
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) NlyteAPIClient(com.vmware.flowgate.nlyteworker.restclient.NlyteAPIClient) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset)

Example 5 with Asset

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

the class NlyteDataService method getRealTimeDatas.

public List<RealTimeData> getRealTimeDatas(NlyteAPIClient nlyteAPIclient, FacilitySoftwareConfig facilitySoftwareConfig, Set<String> assetIds) {
    List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
    for (String assetId : assetIds) {
        Asset asset = restClient.getAssetByID(assetId).getBody();
        if (asset == null || !facilitySoftwareConfig.getId().equals(asset.getAssetSource())) {
            continue;
        }
        RealTimeData realTimeData = null;
        try {
            realTimeData = generateRealTimeData(asset, nlyteAPIclient, getAdvanceSetting(facilitySoftwareConfig));
        } catch (HttpClientErrorException e) {
            logger.error("Failed to query data from Nlyte", e);
            IntegrationStatus integrationStatus = facilitySoftwareConfig.getIntegrationStatus();
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail(e.getMessage());
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(facilitySoftwareConfig);
            break;
        } catch (ResourceAccessException e1) {
            if (e1.getCause().getCause() instanceof ConnectException) {
                checkAndUpdateIntegrationStatus(facilitySoftwareConfig, e1.getMessage());
                break;
            }
        }
        if (realTimeData == null) {
            continue;
        }
        realTimeDatas.add(realTimeData);
    }
    return realTimeDatas;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) ResourceAccessException(org.springframework.web.client.ResourceAccessException) ConnectException(java.net.ConnectException)

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