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));
}
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);
}
}
}
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));
}
}
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;
}
}
}
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);
}
}
}
Aggregations