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);
}
}
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;
}
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;
}
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);
}
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));
}
Aggregations