use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class OpenManageJobService method syncMetadataJob.
private void syncMetadataJob(FacilitySoftwareConfig integration) {
wormholeApiClient.setServiceKey(serviceKeyConfig.getServiceKey());
// check the status of integration
try (OpenManageAPIClient client = createClient(integration)) {
checkConnection(client, integration);
// sync server
List<Asset> oldServers = wormholeApiClient.getAllAssetsBySourceAndType(integration.getId(), AssetCategory.Server);
Map<Long, Asset> assetNumberMap = generateAssetNumberMap(oldServers);
int skip = defaultSkip;
while (true) {
CommonResult<Server> serversResult = client.getDevices(skip, defaultPageSize, Server.class);
int totalCount = serversResult.getCount();
if (totalCount == defaultSkip) {
logger.info("Not found server from : {}.", integration.getName());
break;
}
if (!serversResult.getValue().isEmpty()) {
List<Asset> serverAssetsToSave = handleServerAssets(serversResult, assetNumberMap, integration.getId());
if (!serverAssetsToSave.isEmpty()) {
List<Asset> openmanageServerToUpdate = new ArrayList<Asset>();
for (Asset asset : serverAssetsToSave) {
ResponseEntity<Void> res = wormholeApiClient.saveAssets(asset);
if (res.getStatusCode().is2xxSuccessful()) {
String uriPath = res.getHeaders().getLocation().getPath();
String id = uriPath.substring(uriPath.lastIndexOf("/") + 1);
asset.setId(id);
createMetricFormulas(asset);
openmanageServerToUpdate.add(asset);
}
}
// update asset about metricsFormula
wormholeApiClient.saveAssets(openmanageServerToUpdate);
}
}
skip += defaultPageSize;
if (skip > totalCount) {
break;
}
}
// sync chassis
List<Asset> oldChassis = wormholeApiClient.getAllAssetsBySourceAndType(integration.getId(), AssetCategory.Chassis);
Map<Long, Asset> chassisAssetNumberMap = generateAssetNumberMap(oldChassis);
int chassiItemSkip = defaultSkip;
while (true) {
CommonResult<Chassis> chassisResult = client.getDevices(chassiItemSkip, defaultPageSize, Chassis.class);
int totalCount = chassisResult.getCount();
if (totalCount == defaultSkip) {
logger.info("Not found chassis from : {}.", integration.getName());
break;
}
if (!chassisResult.getValue().isEmpty()) {
List<Asset> chassiAssetsToSave = handleChassisAssets(chassisResult, chassisAssetNumberMap, integration.getId());
if (!chassiAssetsToSave.isEmpty()) {
wormholeApiClient.saveAssets(chassiAssetsToSave);
}
}
chassiItemSkip += defaultPageSize;
if (chassiItemSkip > totalCount) {
break;
}
}
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class OpenManageJobService method generateAssetNumberMap.
private Map<Long, Asset> generateAssetNumberMap(List<Asset> assets) {
Map<Long, Asset> assetNumberMap = new HashMap<Long, Asset>();
for (Asset asset : assets) {
HashMap<String, String> justficationfileds = asset.getJustificationfields();
if (justficationfileds != null && justficationfileds.containsKey(FlowgateConstant.OPENMANAGE)) {
String openManageInfo = justficationfileds.get(FlowgateConstant.OPENMANAGE);
try {
Map<String, String> infoMap = getInfoMap(openManageInfo);
String openManageDeviceId = infoMap.get(FlowgateConstant.ASSETNUMBER);
assetNumberMap.put(Long.valueOf(openManageDeviceId), asset);
} catch (IOException ioException) {
logger.error("Deserializing device info error", ioException);
continue;
}
}
}
return assetNumberMap;
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class OpenManageJobService method handleServerAssets.
public List<Asset> handleServerAssets(CommonResult<Server> serversResult, Map<Long, Asset> assetNumberMap, String integrationId) {
List<Server> servers = serversResult.getValue();
List<Asset> serverAssetsToSave = new ArrayList<Asset>();
for (Server server : servers) {
// filter by device status
if (server.getStatus() == DeviceStatus.UNKNOWN.getValue() || server.getStatus() == DeviceStatus.NOSTATUS.getValue()) {
continue;
}
Asset needToSaveServerAsset = null;
if (assetNumberMap.containsKey(server.getId())) {
needToSaveServerAsset = assetNumberMap.get(server.getId());
if (deviceValueChanged(needToSaveServerAsset, server)) {
serverAssetsToSave.add(needToSaveServerAsset);
}
} else {
// new server asset
needToSaveServerAsset = translateToAsset(server);
needToSaveServerAsset.setCategory(AssetCategory.Server);
needToSaveServerAsset.setAssetSource(integrationId);
if (server.getDeviceSpecificData() != null) {
ServerSpecificData data = server.getDeviceSpecificData();
needToSaveServerAsset.setManufacturer(data.getManufacturer());
}
serverAssetsToSave.add(needToSaveServerAsset);
}
}
return serverAssetsToSave;
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class OpenManageJobTest method createAsset.
Asset createAsset() {
Asset asset = new Asset();
asset.setAssetName("pek-wor-server-02");
asset.setAssetNumber(12345);
asset.setAssetSource("l9i8728d55368540fcba1692");
asset.setCategory(AssetCategory.Server);
asset.setModel("Dell 750");
asset.setManufacturer("Dell");
return asset;
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class OpenManageJobTest method handleServerAssetsTest.
@Test
public void handleServerAssetsTest() {
CommonResult<Server> serversResult = new CommonResult<Server>();
List<Server> servers = new ArrayList<Server>();
Server server1 = new Server();
server1.setAssetTag("lkw456");
server1.setModel("los23");
server1.setId(258l);
server1.setDeviceName("myserver1");
server1.setPowerState(PowerState.ON.getValue());
server1.setStatus(DeviceStatus.NORMAL.getValue());
ServerSpecificData specificData = new ServerSpecificData();
specificData.setManufacturer("Dell");
server1.setDeviceSpecificData(specificData);
servers.add(server1);
Server server2 = new Server();
server2.setAssetTag("asdqw2");
server2.setModel("sr4d");
server2.setId(252l);
server2.setDeviceName("myserver2");
server2.setPowerState(PowerState.OFF.getValue());
server2.setStatus(DeviceStatus.NORMAL.getValue());
ServerSpecificData specificData2 = new ServerSpecificData();
specificData2.setManufacturer("Dell");
server2.setDeviceSpecificData(specificData2);
servers.add(server2);
serversResult.setValue(servers);
Asset asset = new Asset();
asset.setCategory(AssetCategory.Server);
asset.setAssetName("myserver2");
asset.setModel("sr4d");
asset.setManufacturer("Dell");
asset.setTag("0121");
Map<String, String> openManageMap = new HashMap<String, String>();
openManageMap.put(FlowgateConstant.ASSETNUMBER, String.valueOf(server2.getId()));
HashMap<String, String> justficationfileds = new HashMap<String, String>();
try {
String openManageInfo = mapper.writeValueAsString(openManageMap);
justficationfileds.put(FlowgateConstant.OPENMANAGE, openManageInfo);
asset.setJustificationfields(justficationfileds);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
Map<Long, Asset> assetNumberMap = new HashMap<Long, Asset>();
assetNumberMap.put(252l, asset);
String source = "integrationId";
List<Asset> assets = openmanageJobService.handleServerAssets(serversResult, assetNumberMap, source);
TestCase.assertEquals(servers.size(), assets.size());
for (Asset serverAsset : assets) {
HashMap<String, String> valueMap = serverAsset.getJustificationfields();
if (server1.getDeviceName().equals(serverAsset.getAssetName())) {
TestCase.assertEquals(server1.getAssetTag(), serverAsset.getTag());
TestCase.assertEquals(server1.getModel(), serverAsset.getModel());
TestCase.assertEquals(server1.getDeviceSpecificData().getManufacturer(), serverAsset.getManufacturer());
if (valueMap.isEmpty() || !valueMap.containsKey(FlowgateConstant.OPENMANAGE)) {
TestCase.fail("Asset number is required");
}
String openManageInfo = valueMap.get(FlowgateConstant.OPENMANAGE);
try {
Map<String, String> infoMap = mapper.readValue(openManageInfo, new TypeReference<Map<String, String>>() {
});
;
String openManageDeviceId = infoMap.get(FlowgateConstant.ASSETNUMBER);
TestCase.assertEquals(server1.getId(), Long.valueOf(openManageDeviceId).longValue());
} catch (IOException ioException) {
TestCase.fail(ioException.getMessage());
}
} else if (server2.getDeviceName().equals(serverAsset.getAssetName())) {
TestCase.assertEquals(server2.getAssetTag(), serverAsset.getTag());
TestCase.assertEquals(FlowgatePowerState.OFFHARD.name(), valueMap.get(FlowgateConstant.POWERSTATE));
} else {
TestCase.fail("Invalid asset");
}
}
}
Aggregations