private void handleAsyncJobPublishEvent(String subject, String senderAddress, Object args) {
assert (args != null);
@SuppressWarnings("unchecked")
Pair<AsyncJob, String> eventInfo = (Pair<AsyncJob, String>)args;
AsyncJob job = eventInfo.first();
String jobEvent = eventInfo.second();
if (s_logger.isTraceEnabled())
s_logger.trace("Handle asyjob publish event " + jobEvent);
EventBus eventBus = null;
try {
eventBus = ComponentContext.getComponent(EventBus.class);
} catch (NoSuchBeanDefinitionException nbe) {
return; // no provider is configured to provide events bus, so just return
}
if (!job.getDispatcher().equalsIgnoreCase("ApiAsyncJobDispatcher")) {
return;
}
User userJobOwner = _accountMgr.getUserIncludingRemoved(job.getUserId());
Account jobOwner = _accountMgr.getAccount(userJobOwner.getAccountId());
// Get the event type from the cmdInfo json string
String info = job.getCmdInfo();
String cmdEventType = "unknown";
if (info != null) {
String marker = "\"cmdEventType\"";
int begin = info.indexOf(marker);
if (begin >= 0) {
cmdEventType = info.substring(begin + marker.length() + 2, info.indexOf(",", begin) - 1);
if (s_logger.isDebugEnabled())
s_logger.debug("Retrieved cmdEventType from job info: " + cmdEventType);
} else {
if (s_logger.isDebugEnabled())
s_logger.debug("Unable to locate cmdEventType marker in job info. publish as unknown event");
}
}
// For some reason, the instanceType / instanceId are not abstract, which means we may get null values.
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(
"management-server",
EventCategory.ASYNC_JOB_CHANGE_EVENT.getName(),
jobEvent,
(job.getInstanceType() != null ? job.getInstanceType().toString() : "unknown"), null);
Map<String, String> eventDescription = new HashMap<String, String>();
eventDescription.put("command", job.getCmd());
eventDescription.put("user", userJobOwner.getUuid());
eventDescription.put("account", jobOwner.getUuid());
eventDescription.put("processStatus", "" + job.getProcessStatus());
eventDescription.put("resultCode", "" + job.getResultCode());
eventDescription.put("instanceUuid", ApiDBUtils.findJobInstanceUuid(job));
eventDescription.put("instanceType", (job.getInstanceType() != null ? job.getInstanceType().toString() : "unknown"));
eventDescription.put("commandEventType", cmdEventType);
eventDescription.put("jobId", job.getUuid());
// If the event.accountinfo boolean value is set, get the human readable value for the username / domainname
Map<String, String> configs = _configDao.getConfiguration("management-server", new HashMap<String, String>());
if (Boolean.valueOf(configs.get("event.accountinfo"))) {
DomainVO domain = _domainDao.findById(jobOwner.getDomainId());
eventDescription.put("username", userJobOwner.getUsername());