Search in sources :

Example 16 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class AggregatorJobDispatcher method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    String execountString = template.opsForValue().get(EventMessageUtil.AGGREGATOR_EXECOUNT);
    if (execountString == null || "".equals(execountString)) {
        execountString = "0";
    }
    long execount = Long.valueOf(execountString);
    // will execute weekly?
    if (execount++ % 168 == 0) {
        try {
            EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.FullMappingCommand, "");
            String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.AggregatorTopic, message);
            logger.info("Send full mapping sync command");
        } catch (IOException e) {
            logger.error("Failed to send full mapping sync command", e);
        }
    } else if (execount % 87 == 0) {
        try {
            EventMessage eventMessageForCleanJob = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.CleanRealtimeData, "");
            String cleanJobMessage = EventMessageUtil.convertEventMessageAsString(eventMessageForCleanJob);
            publisher.publish(EventMessageUtil.AggregatorTopic, cleanJobMessage);
            logger.info("Send clean realtime data command");
        } catch (IOException e) {
            logger.error("Failed to Send clean realtime data command", e);
        }
        try {
            EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.AggregateAndCleanPowerIQPDU, "");
            String jobmessage = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.AggregatorTopic, jobmessage);
            logger.info("Send aggregate Pdu data command");
        } catch (IOException e) {
            logger.error("Failed to Send aggregate pdu data command", e);
        }
    } else if (execount % 24 == 0) {
        try {
            EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.SUMMARY_DATA, "");
            String jobmessage = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.AggregatorTopic, jobmessage);
            logger.info("Send sync summary data command");
        } catch (IOException e) {
            logger.error("Failed to Send sync summary data command", e);
        }
    } else {
        // will execute hourly?
        try {
            EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.PDUServerMappingCommand, "");
            String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.AggregatorTopic, message);
            logger.info("Send pdu servermapping command");
        } catch (IOException e) {
            logger.error("Failed to send pdu server mapping command.", e);
        }
        try {
            EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.SyncTemperatureAndHumiditySensors, "");
            String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.AggregatorTopic, message);
            logger.info("Send sensor host mapping sync command.");
        } catch (IOException e) {
            logger.error("Failed to send sensor sync command", e);
        }
    }
    template.opsForValue().set(EventMessageUtil.AGGREGATOR_EXECOUNT, String.valueOf(execount));
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException)

Example 17 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class PowerIQService method syncPowerIQAssetsMetaData.

public void syncPowerIQAssetsMetaData(FacilitySoftwareConfig powerIQ) {
    PowerIQAPIClient client = createClient(powerIQ);
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    try {
        client.testConnection();
    } catch (ResourceAccessException e1) {
        if (e1.getCause().getCause() instanceof ConnectException) {
            checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
            return;
        }
    } catch (HttpClientErrorException e) {
        logger.error("Failed to query data from PowerIQ", e);
        IntegrationStatus integrationStatus = powerIQ.getIntegrationStatus();
        if (integrationStatus == null) {
            integrationStatus = new IntegrationStatus();
        }
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(e.getMessage());
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        updateIntegrationStatus(powerIQ);
        return;
    }
    LocationInfo location = getLocationInfo(client);
    List<Asset> pdusFromFlowgate = restClient.getAllAssetsBySourceAndType(powerIQ.getId(), AssetCategory.PDU);
    Map<String, Asset> pduIDAndAssetMap = getPDUIDAndAssetMap(pdusFromFlowgate);
    boolean hasNewPduToSave = savePduAssetsToFlowgate(pduIDAndAssetMap, powerIQ.getId(), client, location);
    logger.info("Finish sync PDU metadata for " + powerIQ.getName());
    Map<String, Asset> exsitingSensorAssets = getAssetsFromWormhole(powerIQ.getId());
    saveSensorAssetsToFlowgate(exsitingSensorAssets, client, powerIQ.getId(), location);
    logger.info("Finish sync Sensor metadata for: " + powerIQ.getName());
    if (hasNewPduToSave) {
        try {
            EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.AggregateAndCleanPowerIQPDU, "");
            String jobmessage = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.AggregatorTopic, jobmessage);
            logger.info("Send aggregate Pdu data command");
        } catch (IOException e) {
            logger.error("Failed to Send aggregate pdu data command", e);
        }
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) LocationInfo(com.vmware.flowgate.poweriqworker.model.LocationInfo) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) PowerIQAPIClient(com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient) Asset(com.vmware.flowgate.common.model.Asset) ConnectException(java.net.ConnectException)

Example 18 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class RedisMessageReceiver method receiveMessage.

@Override
public void receiveMessage(String message) {
    try {
        EventMessage eventMessage = mapper.readValue(message, EventMessageImpl.class);
        asyncService.executeAsync(eventMessage);
    } catch (IOException e) {
        logger.info(String.format("Failed prase message %s", message));
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException)

Example 19 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage 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 20 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage 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)

Aggregations

EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)33 IOException (java.io.IOException)24 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)8 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)8 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)7 Test (org.junit.Test)6 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Asset (com.vmware.flowgate.common.model.Asset)4 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 ArrayList (java.util.ArrayList)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Async (org.springframework.scheduling.annotation.Async)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)2 Date (java.util.Date)2 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1