Search in sources :

Example 76 with Asset

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

the class AssetService method getLatestAssetMetricsDataById.

public List<MetricData> getLatestAssetMetricsDataById(String assetID, Long starttime, Integer duration) {
    Asset asset = getAssetById(assetID);
    Map<String, List<ValueUnit>> assetAndValueUnitsMap;
    if (asset.getCategory() == AssetCategory.PDU) {
        // 1. Get all metric Data
        assetAndValueUnitsMap = getPDURawMetrics(asset, starttime, duration);
        if (assetAndValueUnitsMap.isEmpty()) {
            return new ArrayList<>();
        }
        // 2. Remove or filter
        assetAndValueUnitsMap = findLatestMetricDataByAssetValueUnitMap(assetAndValueUnitsMap);
        // 3. Translate
        return translateToMetricDataForPDU(assetAndValueUnitsMap, asset);
    } else if (asset.getCategory() == AssetCategory.Server) {
        // 1. Get all metric Data
        assetAndValueUnitsMap = getServerRawMetrics(asset, starttime, duration);
        if (assetAndValueUnitsMap.isEmpty()) {
            return new ArrayList<>();
        }
        // 2. Remove or filter
        assetAndValueUnitsMap = findLatestMetricDataByAssetValueUnitMap(assetAndValueUnitsMap);
        // 3. Translate
        return translateToMetricDataForServer(assetAndValueUnitsMap, asset);
    } else {
        assetAndValueUnitsMap = getRawMetrics(asset, starttime, duration);
        if (assetAndValueUnitsMap.isEmpty()) {
            return new ArrayList<>();
        }
        assetAndValueUnitsMap = findLatestMetricDataByAssetValueUnitMap(assetAndValueUnitsMap);
        return translateToMetricDataForOtherAsset(assetAndValueUnitsMap, asset);
    }
}
Also used : ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) List(java.util.List) ArrayList(java.util.ArrayList)

Example 77 with Asset

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

the class AssetController method findServersWithPDUInfo.

/**
 * @return Server list that have PDU information. It only Include the servers that create mapping
 *         between SDDC system and Wormhole.
 */
@RequestMapping(value = "/pdusisnotnull", method = RequestMethod.GET)
public List<Asset> findServersWithPDUInfo() {
    List<ServerMapping> serverMappings = serverMappingRepository.findByAssetNotNull();
    List<String> assetIDs = serverMappings.stream().map(ServerMapping::getAsset).collect(Collectors.toList());
    JsonArray array = JsonArray.from(assetIDs);
    Iterable<Asset> assets = assetRepository.findAll(array);
    List<Asset> result = new ArrayList<Asset>();
    for (Asset asset : assets) {
        if (asset.getPdus() != null && !asset.getPdus().isEmpty()) {
            result.add(asset);
        }
    }
    return result;
}
Also used : JsonArray(com.couchbase.client.java.document.json.JsonArray) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with Asset

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

the class AssetController method replaceAssetIDwithAssetName.

private Page<ServerMapping> replaceAssetIDwithAssetName(Page<ServerMapping> mappings) {
    HashMap<String, String> assetIdAndName = new HashMap<String, String>();
    for (ServerMapping mapping : mappings.getContent()) {
        String assetID = mapping.getAsset();
        if (assetID == null) {
            continue;
        }
        if (assetIdAndName.containsKey(assetID)) {
            String assetName = assetIdAndName.get(assetID);
            mapping.setAsset(assetName);
        } else {
            Optional<Asset> assetOptional = assetRepository.findById(assetID);
            if (assetOptional.isPresent()) {
                String assetName = assetOptional.get().getAssetName();
                mapping.setAsset(assetName);
                assetIdAndName.put(assetID, assetName);
            }
        }
    }
    return mappings;
}
Also used : HashMap(java.util.HashMap) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) Asset(com.vmware.flowgate.common.model.Asset)

Example 79 with Asset

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

the class AssetController method getMappedAsset.

// Read mapped Asset
@RequestMapping(value = "/mappedasset/category/{category}", method = RequestMethod.GET)
public List<Asset> getMappedAsset(@PathVariable AssetCategory category) {
    List<ServerMapping> serverMappings = serverMappingRepository.findByAssetNotNull();
    List<String> assetIDs = serverMappings.stream().map(ServerMapping::getAsset).collect(Collectors.toList());
    JsonArray assetIdarray = JsonArray.from(assetIDs);
    Iterable<Asset> assets = assetRepository.findAll(assetIdarray);
    Set<String> assetids = new HashSet<String>();
    if (category.equals(AssetCategory.Server)) {
        return Lists.newArrayList(assets);
    } else {
        if (category.equals(AssetCategory.PDU)) {
            for (Asset asset : assets) {
                if (asset.getPdus() != null) {
                    assetids.addAll(asset.getPdus());
                }
            }
        } else if (category.equals(AssetCategory.Networks)) {
            for (Asset asset : assets) {
                if (asset.getSwitches() != null) {
                    assetids.addAll(asset.getSwitches());
                }
            }
        }
        if (!assetids.isEmpty()) {
            JsonArray array = JsonArray.from(new ArrayList<String>(assetids));
            assets = assetRepository.findAll(array);
        } else {
            assets = new ArrayList<Asset>();
        }
    }
    return Lists.newArrayList(assets);
}
Also used : JsonArray(com.couchbase.client.java.document.json.JsonArray) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) Asset(com.vmware.flowgate.common.model.Asset) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 80 with Asset

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

the class AggregatorServiceTest method getPdus.

private List<Asset> getPdus() {
    Asset asset1 = new Asset();
    asset1.setId("ASDFASDFASDFASDF");
    asset1.setAssetName("PDU-1");
    asset1.setAssetNumber(12345);
    asset1.setAssetSource("QWENBADJWRTUIJWJAYQY");
    asset1.setCategory(AssetCategory.PDU);
    setPowerIQPduFormulas(asset1);
    Asset asset2 = new Asset();
    asset2.setId("QOBNQHJGOQAJVJQO");
    asset2.setAssetName("PDU-2");
    asset2.setAssetNumber(54321);
    asset2.setAssetSource("QWENBADJWRTUIJWJAYQY");
    asset2.setCategory(AssetCategory.PDU);
    setPowerIQPduFormulas(asset2);
    Asset asset3 = new Asset();
    asset3.setId("ASDFASDFASDFASDF");
    asset3.setAssetName("PDU-1");
    asset3.setAssetNumber(12345);
    asset3.setAssetSource("GIBNQOPVBNJQJVPQGJQJK");
    asset3.setCategory(AssetCategory.PDU);
    setPduFormulas(asset3);
    Asset asset4 = new Asset();
    asset4.setId("QOBNQHJGOQAJVJQO");
    asset4.setAssetName("PDU-2");
    asset4.setAssetNumber(54321);
    asset4.setAssetSource("GIBNQOPVBNJQJVPQGJQJK");
    asset4.setCategory(AssetCategory.PDU);
    setPduFormulas(asset4);
    return new ArrayList<>(Arrays.asList(asset1, asset2, asset3, asset4));
}
Also used : ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset)

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