Search in sources :

Example 6 with EventMessage

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

the class VCDataService method executeAsync.

@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage message) {
    // update the value.
    if (message.getType() != EventType.VCenter) {
        logger.warn("Drop none vcenter message " + message.getType());
        return;
    }
    // TO, this should be comment out since it may contain vc password.
    logger.info("message received");
    Set<EventUser> users = message.getTarget().getUsers();
    for (EventUser command : users) {
        logger.info(command.getId());
        switch(command.getId()) {
            case EventMessageUtil.VCENTER_SyncData:
                // it will sync all the data depend on the type in the vcjoblist.
                String messageString = null;
                while ((messageString = template.opsForList().rightPop(EventMessageUtil.vcJobList)) != null) {
                    EventMessage payloadMessage = null;
                    try {
                        payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
                    } catch (IOException ioException) {
                        logger.error("Cannot process message", ioException);
                    }
                    if (payloadMessage == null) {
                        continue;
                    }
                    SDDCSoftwareConfig vcInfo = null;
                    try {
                        vcInfo = mapper.readValue(payloadMessage.getContent(), SDDCSoftwareConfig.class);
                    } catch (IOException ioException) {
                        logger.error("Cannot process message", ioException);
                    }
                    if (null == vcInfo) {
                        continue;
                    }
                    for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
                        switch(payloadCommand.getId()) {
                            case EventMessageUtil.VCENTER_SyncCustomerAttrs:
                                syncCustomAttributes(vcInfo);
                                logger.info("Finish sync customer attributes for " + vcInfo.getName());
                                break;
                            case EventMessageUtil.VCENTER_SyncCustomerAttrsData:
                                syncCustomerAttrsData(vcInfo);
                                logger.info("Finish sync data for " + vcInfo.getName());
                                break;
                            case EventMessageUtil.VCENTER_QueryHostMetaData:
                                queryHostMetaData(vcInfo);
                                logger.info("Finish query host metadata for " + vcInfo.getName());
                                break;
                            case EventMessageUtil.VCENTER_QueryHostUsageData:
                                queryHostMetrics(vcInfo);
                                logger.info("Finish query host usage for " + vcInfo.getName());
                                break;
                            default:
                                break;
                        }
                    }
                }
                break;
            case EventMessageUtil.VCENTER_SyncCustomerAttrs:
                logger.warn("VCENTER_SyncCustomerAttrs command is depreacted. use VCENTER_SyncData instead");
                break;
            case EventMessageUtil.VCENTER_SyncCustomerAttrsData:
                logger.warn("VCENTER_SyncCustomerAttrsData command is depreacted. use VCENTER_SyncData instead");
                break;
            default:
                logger.warn("Not supported command");
                break;
        }
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) 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) IOException(java.io.IOException) Async(org.springframework.scheduling.annotation.Async)

Example 7 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 8 with EventMessage

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

the class VROAsyncJob method executeAsync.

@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage message) {
    if (message.getType() != EventType.VROps) {
        logger.warn("Drop none VROps message " + message.getType());
        return;
    }
    // TO, this should be comment out since it may contain vc password.
    logger.info("message received");
    Set<EventUser> users = message.getTarget().getUsers();
    for (EventUser command : users) {
        logger.info(command.getId());
        switch(command.getId()) {
            case EventMessageUtil.VRO_SyncData:
                String messageString = null;
                while ((messageString = template.opsForList().rightPop(EventMessageUtil.vroJobList)) != null) {
                    EventMessage payloadMessage = null;
                    try {
                        payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (payloadMessage == null) {
                        continue;
                    }
                    SDDCSoftwareConfig vroInfo = null;
                    try {
                        vroInfo = mapper.readValue(payloadMessage.getContent(), SDDCSoftwareConfig.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (null == vroInfo) {
                        continue;
                    }
                    for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
                        switch(payloadCommand.getId()) {
                            case EventMessageUtil.VRO_SyncMetricData:
                                syncVROMetricData(vroInfo);
                                logger.info("Finish Sync Metric data for " + vroInfo.getName());
                                break;
                            case EventMessageUtil.VRO_SyncMetricPropertyAndAlert:
                                syncVROMetricPropertyAlertDefinition(vroInfo);
                                logger.info("Finish Sync customer attributes and alerts for " + vroInfo.getName());
                                break;
                            default:
                                break;
                        }
                    }
                }
                break;
            case EventMessageUtil.VRO_SyncMetricData:
                logger.warn("VRO_SyncMetricData command is deprecated, please use VRO_SyncData");
                break;
            case EventMessageUtil.VRO_SyncMetricPropertyAndAlert:
                logger.warn("VRO_SyncMetricPropertyAndAlert command is deprecated, please use VRO_SyncData");
                break;
            default:
                logger.warn("Unknown command, ignore it: " + command.getId());
                break;
        }
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) 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) IOException(java.io.IOException) Async(org.springframework.scheduling.annotation.Async)

Example 9 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 10 with EventMessage

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

the class PowerIQService method executeAsync.

@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage message) {
    // update the value.
    if (message.getType() != EventType.PowerIQ) {
        logger.warn("Drop none PowerIQ 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.POWERIQ_SyncData:
                // it will sync all the data depend on the type in the powerIQJobList.
                String messageString = null;
                while ((messageString = template.opsForList().rightPop(EventMessageUtil.powerIQJobList)) != 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 powerIQinfo = null;
                    try {
                        powerIQinfo = mapper.readValue(payloadMessage.getContent(), FacilitySoftwareConfig.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (null == powerIQinfo) {
                        continue;
                    }
                    if (!powerIQinfo.checkIsActive()) {
                        continue;
                    }
                    for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
                        executeJob(payloadCommand.getId(), powerIQinfo);
                    }
                }
                break;
            default:
                FacilitySoftwareConfig powerIQ = null;
                try {
                    powerIQ = mapper.readValue(message.getContent(), FacilitySoftwareConfig.class);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    logger.error("Failed to convert message", e1);
                }
                if (powerIQ != null) {
                    executeJob(command.getId(), powerIQ);
                }
                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) Async(org.springframework.scheduling.annotation.Async)

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