Search in sources :

Example 1 with CommonResult

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;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) CommonResult(com.vmware.flowgate.openmanage.datamodel.CommonResult) ResolvableType(org.springframework.core.ResolvableType) URI(java.net.URI)

Example 2 with CommonResult

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;
}
Also used : ArrayList(java.util.ArrayList) CommonResult(com.vmware.flowgate.openmanage.datamodel.CommonResult) Plugin(com.vmware.flowgate.openmanage.datamodel.Plugin)

Example 3 with 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;
}
Also used : PowerSetting(com.vmware.flowgate.openmanage.datamodel.PowerSetting) ArrayList(java.util.ArrayList) CommonResult(com.vmware.flowgate.openmanage.datamodel.CommonResult)

Example 4 with CommonResult

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");
        }
    }
}
Also used : Server(com.vmware.flowgate.openmanage.datamodel.Server) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServerSpecificData(com.vmware.flowgate.openmanage.datamodel.ServerSpecificData) Asset(com.vmware.flowgate.common.model.Asset) CommonResult(com.vmware.flowgate.openmanage.datamodel.CommonResult) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Map(java.util.Map) HashMap(java.util.HashMap) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with CommonResult

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;
}
Also used : CommonResult(com.vmware.flowgate.openmanage.datamodel.CommonResult) ResolvableType(org.springframework.core.ResolvableType)

Aggregations

CommonResult (com.vmware.flowgate.openmanage.datamodel.CommonResult)7 ArrayList (java.util.ArrayList)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Asset (com.vmware.flowgate.common.model.Asset)2 Server (com.vmware.flowgate.openmanage.datamodel.Server)2 ServerSpecificData (com.vmware.flowgate.openmanage.datamodel.ServerSpecificData)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ResolvableType (org.springframework.core.ResolvableType)2 Chassis (com.vmware.flowgate.openmanage.datamodel.Chassis)1 Plugin (com.vmware.flowgate.openmanage.datamodel.Plugin)1 PowerSetting (com.vmware.flowgate.openmanage.datamodel.PowerSetting)1 URI (java.net.URI)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1