use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project cloudstack by apache.
the class ApiServer method handleAsyncJobPublishEvent.
@MessageHandler(topic = AsyncJob.Topics.JOB_EVENT_PUBLISH)
public 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) {
// no provider is configured to provide events bus, so just return
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) {
Type type = new TypeToken<Map<String, String>>() {
}.getType();
Map<String, String> cmdInfo = ApiGsonHelper.getBuilder().create().fromJson(info, type);
String eventTypeObj = cmdInfo.get("cmdEventType");
if (eventTypeObj != null) {
cmdEventType = eventTypeObj;
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.
String instanceType = job.getInstanceType() != null ? job.getInstanceType() : "unknown";
String instanceUuid = job.getInstanceId() != null ? ApiDBUtils.findJobInstanceUuid(job) : "";
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event("management-server", EventCategory.ASYNC_JOB_CHANGE_EVENT.getName(), jobEvent, instanceType, instanceUuid);
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", instanceUuid);
eventDescription.put("instanceType", instanceType);
eventDescription.put("commandEventType", cmdEventType);
eventDescription.put("jobId", job.getUuid());
eventDescription.put("jobResult", job.getResult());
eventDescription.put("cmdInfo", job.getCmdInfo());
eventDescription.put("status", "" + job.getStatus());
// 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());
eventDescription.put("accountname", jobOwner.getAccountName());
eventDescription.put("domainname", domain.getName());
}
event.setDescription(eventDescription);
try {
eventBus.publish(event);
} catch (EventBusException evx) {
String errMsg = "Failed to publish async job event on the the event bus.";
s_logger.warn(errMsg, evx);
}
}
use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project cloudstack by apache.
the class AlertGenerator method publishAlertOnEventBus.
public static void publishAlertOnEventBus(String alertType, long dataCenterId, Long podId, String subject, String body) {
String configKey = Config.PublishAlertEvent.key();
String value = s_configDao.getValue(configKey);
boolean configValue = Boolean.parseBoolean(value);
if (!configValue)
return;
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
} catch (NoSuchBeanDefinitionException nbe) {
// no provider is configured to provide events bus, so just return
return;
}
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, EventCategory.ALERT_EVENT.getName(), alertType, null, null);
Map<String, String> eventDescription = new HashMap<String, String>();
DataCenterVO dc = s_dcDao.findById(dataCenterId);
HostPodVO pod = s_podDao.findById(podId);
eventDescription.put("event", alertType);
if (dc != null) {
eventDescription.put("dataCenterId", dc.getUuid());
} else {
eventDescription.put("dataCenterId", null);
}
if (pod != null) {
eventDescription.put("podId", pod.getUuid());
} else {
eventDescription.put("podId", null);
}
eventDescription.put("subject", subject);
eventDescription.put("body", body);
String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
eventDescription.put("eventDateTime", eventDate);
event.setDescription(eventDescription);
try {
s_eventBus.publish(event);
} catch (EventBusException e) {
s_logger.warn("Failed to publish alert on the the event bus.");
}
}
use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project ignite by apache.
the class IgniteSpringHelperImpl method userVersion.
/** {@inheritDoc} */
@Override
public String userVersion(ClassLoader ldr, IgniteLogger log) {
assert ldr != null;
assert log != null;
// For system class loader return cached version.
if (ldr == U.gridClassLoader() && SYS_LDR_VER.get() != null)
return SYS_LDR_VER.get();
String usrVer = U.DFLT_USER_VERSION;
InputStream in = ldr.getResourceAsStream(IGNITE_XML_PATH);
if (in != null) {
// Note: use ByteArrayResource instead of InputStreamResource because
// InputStreamResource doesn't work.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
U.copy(in, out);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(new ByteArrayResource(out.toByteArray()));
usrVer = (String) factory.getBean("userVersion");
usrVer = usrVer == null ? U.DFLT_USER_VERSION : usrVer.trim();
} catch (NoSuchBeanDefinitionException ignored) {
if (log.isInfoEnabled())
log.info("User version is not explicitly defined (will use default version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']');
usrVer = U.DFLT_USER_VERSION;
} catch (BeansException e) {
U.error(log, "Failed to parse Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
usrVer = U.DFLT_USER_VERSION;
} catch (IOException e) {
U.error(log, "Failed to read Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
usrVer = U.DFLT_USER_VERSION;
} finally {
U.close(out, log);
}
}
// For system class loader return cached version.
if (ldr == U.gridClassLoader())
SYS_LDR_VER.compareAndSet(null, usrVer);
return usrVer;
}
use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project engine by craftercms.
the class AllHttpScopesAndAppContextHashModel method get.
@Override
public TemplateModel get(String key) throws TemplateModelException {
// Lookup in page scope
TemplateModel model = super.get(key);
if (model != null) {
return model;
}
// Lookup in request scope
Object obj = request.getAttribute(key);
if (obj != null) {
return wrap(obj);
}
// Lookup in session scope
HttpSession session = request.getSession(false);
if (session != null) {
obj = session.getAttribute(key);
if (obj != null) {
return wrap(obj);
}
}
// Lookup in application scope
obj = context.getAttribute(key);
if (obj != null) {
return wrap(obj);
}
// Lookup in application context
try {
return wrap(applicationContextAccessor.get(key));
} catch (NoSuchBeanDefinitionException e) {
}
// return wrapper's null object (probably null).
return wrap(null);
}
Aggregations