Search in sources :

Example 1 with EventUser

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

the class EventMessageUtil method createEventMessage.

public static EventMessage createEventMessage(EventType type, String targetCommand, String message) {
    EventUser targetUser = new EventUserImpl(targetCommand);
    Set<EventUser> users = new HashSet<EventUser>();
    users.add(targetUser);
    EventTarget target = new EventTargetImpl(users);
    EventMessage newMessage = new EventMessageImpl(type, null, null, target, new Date().getTime(), message);
    return newMessage;
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) EventTarget(com.vmware.flowgate.common.model.redis.message.EventTarget) Date(java.util.Date) HashSet(java.util.HashSet)

Example 2 with EventUser

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

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

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

Example 5 with EventUser

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

the class AggregatorService method executeAsync.

@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage message) {
    if (message.getType() != EventType.Aggregator) {
        logger.warn("Drop none aggregator message " + message.getType());
        return;
    }
    logger.info(message.getContent());
    Set<EventUser> users = message.getTarget().getUsers();
    for (EventUser command : users) {
        logger.info(command.getId());
        switch(command.getId()) {
            case EventMessageUtil.FullMappingCommand:
                mergeServerMapping();
                logger.info("Finish full Mapping merge job.");
                break;
            case EventMessageUtil.HostNameIPMappingCommand:
                // the message in the format of:   hostname:ip
                String[] nameIP = message.getContent().split(":");
                syncHostMapping(nameIP[0], nameIP[1]);
                break;
            case EventMessageUtil.PDUServerMappingCommand:
                aggregateServerPDU();
                logger.info("Finish PDUServerMapping job.");
                break;
            case EventMessageUtil.FullSyncTemperatureAndHumiditySensors:
                syncHostTemperatureAndHumidySensor(true);
                break;
            case EventMessageUtil.SyncTemperatureAndHumiditySensors:
                syncHostTemperatureAndHumidySensor(false);
                break;
            case EventMessageUtil.CleanRealtimeData:
                cleanRealtimeData();
                break;
            case EventMessageUtil.AggregateAndCleanPowerIQPDU:
                aggregateAndCleanPDUFromPowerIQ();
                break;
            case EventMessageUtil.SUMMARY_DATA:
                syncSummaryData();
                break;
            default:
                break;
        }
    }
}
Also used : EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) Async(org.springframework.scheduling.annotation.Async)

Aggregations

EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)9 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)8 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)7 IOException (java.io.IOException)7 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)5 Async (org.springframework.scheduling.annotation.Async)4 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)2 EventTarget (com.vmware.flowgate.common.model.redis.message.EventTarget)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1