use of com.vmware.flowgate.openmanage.datamodel.CommonResult in project flowgate by vmware.
the class OpenManageAPIClient method getDevices.
public <T> CommonResult<T> getDevices(int skip, int limit, Class<T> type) {
String url = getServiceEndPoint() + String.format(GetDeviceUri, deviceTypeMap.get(type), skip, limit);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
URI uri = builder.build().encode().toUri();
ResolvableType resolvableType = ResolvableType.forClassWithGenerics(CommonResult.class, type);
ParameterizedTypeReference<CommonResult<T>> typeRef = ParameterizedTypeReference.forType(resolvableType.getType());
ResponseEntity<CommonResult<T>> entity = this.restTemplate.exchange(uri, HttpMethod.GET, getDefaultEntity(), typeRef);
CommonResult<T> result = null;
if (entity.hasBody()) {
result = entity.getBody();
}
return result;
}
use of com.vmware.flowgate.openmanage.datamodel.CommonResult in project flowgate by vmware.
the class OpenManageJobTest method getCommonResult.
private CommonResult<Plugin> getCommonResult() {
Plugin plugin1 = new Plugin();
plugin1.setEnabled(true);
plugin1.setInstalled(true);
plugin1.setName(OpenManageJobService.PowerManager);
plugin1.setId("powerManagerplugin");
List<Plugin> plugins = new ArrayList<Plugin>();
plugins.add(plugin1);
CommonResult<Plugin> commonResult = new CommonResult<Plugin>();
commonResult.setValue(plugins);
return commonResult;
}
use of com.vmware.flowgate.openmanage.datamodel.CommonResult in project flowgate by vmware.
the class OpenManageJobTest method getPowerSettings.
private CommonResult<PowerSetting> getPowerSettings() {
CommonResult<PowerSetting> powerSettings = new CommonResult<PowerSetting>();
List<PowerSetting> values = new ArrayList<PowerSetting>();
PowerSetting power = new PowerSetting();
power.setId(PowerSettingType.PowerUnit.getValue());
power.setValue(PowerDisplayUnit.Watt.getValue());
values.add(power);
PowerSetting temperature = new PowerSetting();
temperature.setId(PowerSettingType.TemperatureUnit.getValue());
temperature.setValue(TemperatureDisplayUnit.Celsius.getValue());
values.add(temperature);
powerSettings.setValue(values);
return powerSettings;
}
use of com.vmware.flowgate.openmanage.datamodel.CommonResult 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.CommonResult in project flowgate by vmware.
the class OpenManageAPIClient method getCommonResult.
public <T> CommonResult<T> getCommonResult(Class<T> type) {
ResolvableType resolvableType = ResolvableType.forClassWithGenerics(CommonResult.class, type);
ParameterizedTypeReference<CommonResult<T>> typeRef = ParameterizedTypeReference.forType(resolvableType.getType());
ResponseEntity<CommonResult<T>> entity = this.restTemplate.exchange(getServiceEndPoint() + resourceUriMap.get(type), HttpMethod.GET, getDefaultEntity(), typeRef);
CommonResult<T> result = null;
if (entity.hasBody()) {
result = entity.getBody();
}
return result;
}
Aggregations