Search in sources :

Example 26 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class PowerIQService method syncAllSensorMetricFormula.

public void syncAllSensorMetricFormula() {
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    FacilitySoftwareConfig[] powerIQs = restClient.getFacilitySoftwareInternalByType(SoftwareType.PowerIQ).getBody();
    for (FacilitySoftwareConfig powerIQ : powerIQs) {
        logger.info("Start sync sensor metrics formula for " + powerIQ.getName());
        List<Asset> pdusFromFlowgate = restClient.getAllAssetsBySourceAndType(powerIQ.getId(), AssetCategory.PDU);
        Map<String, Asset> pduIDAndAssetMap = getPDUIDAndAssetMap(pdusFromFlowgate);
        int pageSize = 200;
        int pageNumber = 0;
        List<Asset> sensors = null;
        ResponseEntity<PageModelImp<Asset>> res = restClient.getAssetsBySourceAndType(powerIQ.getId(), AssetCategory.Sensors, pageNumber, pageSize);
        while (!res.getBody().getContent().isEmpty()) {
            sensors = res.getBody().getContent();
            Set<Asset> pduAssetNeedToUpdate = updatePduMetricformular(sensors, pduIDAndAssetMap);
            restClient.saveAssets(new ArrayList<Asset>(pduAssetNeedToUpdate));
            pageNumber++;
            res = restClient.getAssetsBySourceAndType(powerIQ.getId(), AssetCategory.Sensors, pageNumber, pageSize);
        }
        logger.info("Finished sync sensor metrics formula for " + powerIQ.getName());
    }
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) Asset(com.vmware.flowgate.common.model.Asset) PageModelImp(com.vmware.flowgate.common.model.PageModelImp)

Example 27 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class NlyteDataService method executeAsync.

@Override
public void executeAsync(EventMessage message) {
    if (message.getType() != EventType.Nlyte) {
        logger.warn("Drop none Nlyte message " + message.getType());
        return;
    }
    logger.info("message received");
    Set<EventUser> users = message.getTarget().getUsers();
    for (EventUser command : users) {
        logger.info(command.getId());
        switch(command.getId()) {
            case EventMessageUtil.NLYTE_SyncData:
                // it will sync all the data depend on the type in the nlyteJobList.
                String messageString = null;
                while ((messageString = template.opsForList().rightPop(EventMessageUtil.nlyteJobList)) != null) {
                    EventMessage payloadMessage = null;
                    try {
                        payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (payloadMessage == null) {
                        continue;
                    }
                    FacilitySoftwareConfig nlyte = null;
                    try {
                        nlyte = mapper.readValue(payloadMessage.getContent(), FacilitySoftwareConfig.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (null == nlyte) {
                        continue;
                    }
                    if (!nlyte.checkIsActive()) {
                        continue;
                    }
                    for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
                        executeJob(payloadCommand.getId(), nlyte);
                    }
                }
                break;
            default:
                FacilitySoftwareConfig nlyteInfo = null;
                try {
                    nlyteInfo = mapper.readValue(message.getContent(), FacilitySoftwareConfig.class);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    logger.info("Failed to convert message", e);
                }
                if (nlyteInfo != null) {
                    executeJob(EventMessageUtil.NLYTE_SyncMappedAssetData, nlyteInfo);
                }
                break;
        }
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 28 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class OpenManageJobService method executeAsync.

@Override
public void executeAsync(EventMessage message) {
    if (message.getType() != EventType.OpenManage) {
        logger.warn("Drop non-OpenManage message " + message.getType());
        return;
    }
    logger.info("message received");
    String messageString = null;
    while ((messageString = template.opsForList().rightPop(EventMessageUtil.OpenManageJobList)) != null) {
        EventMessage payloadMessage = null;
        try {
            payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
        } catch (IOException e) {
            logger.error("Cannot process message", e);
        }
        if (payloadMessage == null) {
            continue;
        }
        FacilitySoftwareConfig integration = null;
        try {
            integration = mapper.readValue(payloadMessage.getContent(), FacilitySoftwareConfig.class);
        } catch (IOException e) {
            logger.error("Cannot process message", e);
        }
        if (null == integration) {
            continue;
        }
        if (!integration.checkIsActive()) {
            continue;
        }
        for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
            executeJob(payloadCommand.getId(), integration);
        }
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 29 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class OpenManageJobTest method getMetricDatas.

@Test
public void getMetricDatas() {
    Mockito.when(this.openManageAPIClient.getCommonResult(Plugin.class)).thenReturn(getCommonResult());
    Mockito.when(this.openManageAPIClient.getDevicePowerMetrics("10074")).thenReturn(getPowerMetricsData());
    Mockito.when(this.openManageAPIClient.getDeviceTemperatureMetrics("10074")).thenReturn(getDeviceTemperature());
    Mockito.when(this.openManageAPIClient.getMetricsFromPowerManage(any(PowerManageMetricsRequestBody.class))).thenReturn(getDeviceMetricsResult());
    Mockito.when(this.openManageAPIClient.getCommonResult(PowerSetting.class)).thenReturn(getPowerSettings());
    FacilitySoftwareConfig config = new FacilitySoftwareConfig();
    config.setId(createAsset().getAssetSource());
    List<RealTimeData> metricDatas = openmanageJobService.getMetricDatas(config, openManageAPIClient);
    for (RealTimeData data : metricDatas) {
        if ("assetid1611766210404".equals(data.getId())) {
            // power metrics
            List<ValueUnit> values = data.getValues();
            for (ValueUnit value : values) {
                switch(value.getKey()) {
                    case MetricName.SERVER_AVERAGE_USED_POWER:
                        TestCase.assertEquals(0.074, value.getValueNum());
                        break;
                    // use powerManager value to override it
                    case MetricName.SERVER_POWER:
                        TestCase.assertEquals(0.072, value.getValueNum());
                        break;
                    case MetricName.SERVER_MINIMUM_USED_POWER:
                        TestCase.assertEquals(0.07, value.getValueNum());
                        break;
                    case MetricName.SERVER_PEAK_USED_POWER:
                        TestCase.assertEquals(0.08, value.getValueNum());
                        break;
                    case MetricName.SERVER_ENERGY_CONSUMPTION:
                        TestCase.assertEquals(800.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_AVERAGE_TEMPERATURE:
                        TestCase.assertEquals(22.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_TEMPERATURE:
                        TestCase.assertEquals(24.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_PEAK_TEMPERATURE:
                        TestCase.assertEquals(30.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_FRONT_TEMPERATURE:
                        TestCase.assertEquals(24.0, value.getValueNum());
                        break;
                    default:
                        TestCase.fail();
                        break;
                }
            }
        } else {
            TestCase.fail();
        }
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) PowerManageMetricsRequestBody(com.vmware.flowgate.openmanage.datamodel.PowerManageMetricsRequestBody) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 30 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class OpenManageJobTest method getMetricDatasTestNA.

@Test
public void getMetricDatasTestNA() {
    Mockito.when(this.openManageAPIClient.getCommonResult(Plugin.class)).thenReturn(getCommonResult());
    DevicePower powerMetrics = getPowerMetricsData();
    powerMetrics.setMinimumPower("N/A");
    Mockito.when(this.openManageAPIClient.getDevicePowerMetrics("10074")).thenReturn(powerMetrics);
    Mockito.when(this.openManageAPIClient.getDeviceTemperatureMetrics("10074")).thenReturn(getDeviceTemperature());
    Mockito.when(this.openManageAPIClient.getMetricsFromPowerManage(any(PowerManageMetricsRequestBody.class))).thenReturn(getDeviceMetricsResult());
    Mockito.when(this.openManageAPIClient.getCommonResult(PowerSetting.class)).thenReturn(getPowerSettings());
    FacilitySoftwareConfig config = new FacilitySoftwareConfig();
    config.setId(createAsset().getAssetSource());
    List<RealTimeData> metricDatas = openmanageJobService.getMetricDatas(config, openManageAPIClient);
    for (RealTimeData data : metricDatas) {
        if ("assetid1611766210404".equals(data.getId())) {
            // power metrics
            List<ValueUnit> values = data.getValues();
            for (ValueUnit value : values) {
                switch(value.getKey()) {
                    case MetricName.SERVER_AVERAGE_USED_POWER:
                        TestCase.assertEquals(0.074, value.getValueNum());
                        break;
                    // use powerManager value to override it
                    case MetricName.SERVER_POWER:
                        TestCase.assertEquals(0.072, value.getValueNum());
                        break;
                    case MetricName.SERVER_MINIMUM_USED_POWER:
                        TestCase.fail("Should not contain the " + MetricName.SERVER_MINIMUM_USED_POWER);
                        break;
                    case MetricName.SERVER_PEAK_USED_POWER:
                        TestCase.assertEquals(0.08, value.getValueNum());
                        break;
                    case MetricName.SERVER_ENERGY_CONSUMPTION:
                        TestCase.assertEquals(800.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_AVERAGE_TEMPERATURE:
                        TestCase.assertEquals(22.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_TEMPERATURE:
                        TestCase.assertEquals(24.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_PEAK_TEMPERATURE:
                        TestCase.assertEquals(30.0, value.getValueNum());
                        break;
                    case MetricName.SERVER_FRONT_TEMPERATURE:
                        TestCase.assertEquals(24.0, value.getValueNum());
                        break;
                    default:
                        TestCase.fail();
                        break;
                }
            }
        } else {
            TestCase.fail();
        }
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) DevicePower(com.vmware.flowgate.openmanage.datamodel.DevicePower) PowerManageMetricsRequestBody(com.vmware.flowgate.openmanage.datamodel.PowerManageMetricsRequestBody) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)60 Test (org.junit.Test)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)29 ArrayList (java.util.ArrayList)13 Asset (com.vmware.flowgate.common.model.Asset)8 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)7 IOException (java.io.IOException)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)6 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)5 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)5 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)5 HashMap (java.util.HashMap)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)4 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)4 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)4