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