Skip to content

Commit

Permalink
Fix missing vc-worker formula
Browse files Browse the repository at this point in the history
Signed-off-by: YangJiao <jiaoya@vmware.com>
  • Loading branch information
YangJiao committed May 11, 2021
1 parent 64f6302 commit 12b6e43
Showing 1 changed file with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,39 +386,43 @@ public void queryHostMetrics(SDDCSoftwareConfig vc) {
}

private void feedAssetMetricsFormulars(Asset asset) {

String assetId = asset.getId();
List<String> vcHostMetricsFormulaKeyList = new ArrayList<>(16);
// cpu
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_CPUUSAGE);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_CPUUSEDINMHZ);
// memory
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_ACTIVEMEMORY);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_BALLOONMEMORY);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_CONSUMEDMEMORY);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_SHAREDMEMORY);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_SWAPMEMORY);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_MEMORYUSAGE);
// storage
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_STORAGEIORATEUSAGE);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_STORAGEUSED);
// power
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_POWER);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_MINIMUM_USED_POWER);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_PEAK_USED_POWER);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_AVERAGE_USED_POWER);
vcHostMetricsFormulaKeyList.add(MetricName.SERVER_ENERGY_CONSUMPTION);

Map<String, String> metricsFormulas = asset.getMetricsformulars();
Map<String, String> metrics = null;
Map<String, String> hostMetricsFormula = new HashMap<>();
if (StringUtils.isNotBlank(metricsFormulas.get(FlowgateConstant.HOST_METRICS))) {
metrics = asset.metricsFormulaToMap(metricsFormulas.get(FlowgateConstant.HOST_METRICS), new TypeReference<Map<String, String>>() {});
hostMetricsFormula = asset.metricsFormulaToMap(metricsFormulas.get(FlowgateConstant.HOST_METRICS), new TypeReference<Map<String, String>>() {});
}
if (metrics == null || metrics.isEmpty()) {
metrics = new HashMap<>();
// cpu
metrics.put(MetricName.SERVER_CPUUSAGE, assetId);
metrics.put(MetricName.SERVER_CPUUSEDINMHZ, assetId);

// memory
metrics.put(MetricName.SERVER_ACTIVEMEMORY, assetId);
metrics.put(MetricName.SERVER_BALLOONMEMORY, assetId);
metrics.put(MetricName.SERVER_CONSUMEDMEMORY, assetId);
metrics.put(MetricName.SERVER_SHAREDMEMORY, assetId);
metrics.put(MetricName.SERVER_SWAPMEMORY, assetId);
metrics.put(MetricName.SERVER_MEMORYUSAGE, assetId);

// storage
metrics.put(MetricName.SERVER_STORAGEIORATEUSAGE, assetId);
metrics.put(MetricName.SERVER_STORAGEUSAGE, assetId);
metrics.put(MetricName.SERVER_STORAGEUSED, assetId);

// power
metrics.put(MetricName.SERVER_POWER, assetId);
metrics.put(MetricName.SERVER_MINIMUM_USED_POWER, assetId);
metrics.put(MetricName.SERVER_PEAK_USED_POWER, assetId);
metrics.put(MetricName.SERVER_AVERAGE_USED_POWER, assetId);
metrics.put(MetricName.SERVER_ENERGY_CONSUMPTION, assetId);
metricsFormulas.put(FlowgateConstant.HOST_METRICS, asset.metricsFormulaToString(metrics));
boolean isUpdated = false;
for (String vcHostMetricsFormulaKey : vcHostMetricsFormulaKeyList) {
if (!hostMetricsFormula.containsKey(vcHostMetricsFormulaKey)) {
hostMetricsFormula.put(vcHostMetricsFormulaKey, assetId);
isUpdated = true;
}
}
if (isUpdated) {
metricsFormulas.put(FlowgateConstant.HOST_METRICS, asset.metricsFormulaToString(hostMetricsFormula));
asset.setMetricsformulars(metricsFormulas);
restClient.saveAssets(asset);
}
}
Expand Down Expand Up @@ -1297,10 +1301,7 @@ private void feedData(Map<String, Asset> assetDictionary, List<ServerMapping> va
for (ServerMapping validServer : validMapping) {
HostSystem host = hostDictionary.get(validServer.getVcMobID());
Asset asset = assetDictionary.get(validServer.getAsset());
String hostMetricsMap = asset.getMetricsformulars().get(FlowgateConstant.HOST_METRICS);
if (hostMetricsMap == null || hostMetricsMap.isEmpty()) {
feedAssetMetricsFormulars(asset);
}
feedAssetMetricsFormulars(asset);
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(asset);
for (String key : VCConstants.hostCustomAttrMapping.keySet()) {
host.setCustomValue(VCConstants.hostCustomAttrMapping.get(key),
Expand Down

0 comments on commit 12b6e43

Please sign in to comment.