Skip to content

Commit

Permalink
Fix for NMS-7546.
Browse files Browse the repository at this point in the history
Notifd was converted to a Srping-based daemon, and is no longer a singleton.

Conflicts:
	opennms-services/src/main/java/org/opennms/netmgt/notifd/BSFNotificationStrategy.java
  • Loading branch information
Jesse White committed Apr 13, 2015
1 parent 095ae9a commit 39f55bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@

import java.util.List;

import org.opennms.core.spring.BeanUtils;
import org.opennms.netmgt.asterisk.agi.scripts.BaseOnmsAgiScript;
import org.opennms.netmgt.asterisk.utils.AsteriskOriginator;
import org.opennms.netmgt.asterisk.utils.AsteriskOriginatorException;
import org.opennms.netmgt.config.NotificationManager;
import org.opennms.netmgt.dao.api.NodeDao;
import org.opennms.netmgt.model.notifd.Argument;
import org.opennms.netmgt.model.notifd.NotificationStrategy;
import org.opennms.netmgt.notifd.Notifd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -105,7 +106,8 @@ private AsteriskOriginator buildOriginator(final List<Argument> arguments) throw
LOG.debug("Found: PARAM_NODE => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODEID, argValue);
try {
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODELABEL, Notifd.getInstance().getNodeDao().get(argValue).getLabel());
final NodeDao nodeDao = BeanUtils.getFactory("notifdContext", NodeDao.class);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODELABEL, nodeDao.get(argValue).getLabel());
} catch (final Throwable t) {
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODELABEL, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.bsf.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opennms.core.spring.BeanUtils;
import org.opennms.netmgt.config.NotificationManager;
import org.opennms.netmgt.dao.api.NodeDao;
import org.opennms.netmgt.model.OnmsAssetRecord;
Expand Down Expand Up @@ -161,7 +162,7 @@ public int send(List<Argument> arguments) {
}

private static void declareBeans(BSFNotificationStrategy obj) throws BSFException {
NodeDao nodeDao = Notifd.getInstance().getNodeDao();
NodeDao nodeDao = BeanUtils.getFactory("notifdContext", NodeDao.class);
Integer nodeId;
try {
nodeId = Integer.valueOf(obj.m_notifParams.get(NotificationManager.PARAM_NODE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public final class Notifd extends AbstractServiceDaemon {

private static final String LOG4J_CATEGORY = "notifd";

/**
* The singleton instance.
*/
private static final Notifd m_singleton = new Notifd();

/**
* The map for holding different notice queues
*/
Expand Down Expand Up @@ -221,16 +216,6 @@ protected void onResume() {
}
}

/**
* Returns the singular instance of the Notifd daemon. There can be only
* one instance of this service per virtual machine.
*
* @return a {@link org.opennms.netmgt.notifd.Notifd} object.
*/
public static Notifd getInstance() {
return m_singleton;
}

public static String getLoggingCategory() {
return LOG4J_CATEGORY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,70 +54,63 @@ protected String getSpringContext() {
return "notifdContext";
}

/**
* @return Notifd instance
*/
private org.opennms.netmgt.notifd.Notifd getNotifd() {
return org.opennms.netmgt.notifd.Notifd.getInstance();
}

@Override
/** {@inheritDoc} */
public long getNotificationTasksQueued() {
return getNotifd().getNotificationManager().getNotificationTasksQueued();
return getDaemon().getNotificationManager().getNotificationTasksQueued();
}

@Override
/** {@inheritDoc} */
public long getBinaryNoticesAttempted() {
return getNotifd().getNotificationManager().getBinaryNoticesAttempted();
return getDaemon().getNotificationManager().getBinaryNoticesAttempted();
}

@Override
/** {@inheritDoc} */
public long getJavaNoticesAttempted() {
return getNotifd().getNotificationManager().getJavaNoticesAttempted();
return getDaemon().getNotificationManager().getJavaNoticesAttempted();
}

@Override
/** {@inheritDoc} */
public long getBinaryNoticesSucceeded() {
return getNotifd().getNotificationManager().getBinaryNoticesSucceeded();
return getDaemon().getNotificationManager().getBinaryNoticesSucceeded();
}

@Override
/** {@inheritDoc} */
public long getJavaNoticesSucceeded() {
return getNotifd().getNotificationManager().getJavaNoticesSucceeded();
return getDaemon().getNotificationManager().getJavaNoticesSucceeded();
}

@Override
/** {@inheritDoc} */
public long getBinaryNoticesFailed() {
return getNotifd().getNotificationManager().getBinaryNoticesFailed();
return getDaemon().getNotificationManager().getBinaryNoticesFailed();
}

@Override
/** {@inheritDoc} */
public long getJavaNoticesFailed() {
return getNotifd().getNotificationManager().getJavaNoticesFailed();
return getDaemon().getNotificationManager().getJavaNoticesFailed();
}

@Override
/** {@inheritDoc} */
public long getBinaryNoticesInterrupted() {
return getNotifd().getNotificationManager().getBinaryNoticesInterrupted();
return getDaemon().getNotificationManager().getBinaryNoticesInterrupted();
}

@Override
/** {@inheritDoc} */
public long getJavaNoticesInterrupted() {
return getNotifd().getNotificationManager().getJavaNoticesInterrupted();
return getDaemon().getNotificationManager().getJavaNoticesInterrupted();
}

@Override
/** {@inheritDoc} */
public long getUnknownNoticesInterrupted() {
return getNotifd().getNotificationManager().getUnknownNoticesInterrupted();
return getDaemon().getNotificationManager().getUnknownNoticesInterrupted();
}
}

3 comments on commit 39f55bb

@dschlenk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j-white I'm getting a ClassCastException (can't convert ClassPathXmlApplicationContext to NodeDao) in BSFNotificationStrategy at this point:

NodeDao nodeDao = BeanUtils.getFactory("notifdContext", NodeDao.class);

Changing it to

BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);

resolves it. However, this is on a fork of 15.0.2 with a couple BSF patches applied, so maybe the former would actually work in develop? Not a Spring expert, so thought I'd ask before submitting a PR with the change.

@j-white
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dschlenk Thanks for the heads up - looks like it doesn't work in develop either.

I'll fix it and some tests to verify those code paths.

For reference http://issues.opennms.org/browse/NMS-7634

@dschlenk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @j-white!

Please sign in to comment.