use of com.vmware.flowgate.openmanage.datamodel.ServerSpecificData 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.openmanage.datamodel.ServerSpecificData 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");
}
}
}
use of com.vmware.flowgate.openmanage.datamodel.ServerSpecificData in project flowgate by vmware.
the class OpenManageJobTest method getCommonResultServer.
private CommonResult<Server> getCommonResultServer() {
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);
return serversResult;
}
Aggregations