Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.12'
Browse files Browse the repository at this point in the history
Conflicts:
	core/test-api/snmp/src/main/java/org/opennms/core/test/snmp/ProxySnmpAgentConfigFactory.java
	opennms-base-assembly/src/main/filtered/etc/snmp-graph.properties
	opennms-config/src/main/java/org/opennms/netmgt/config/SnmpPeerFactory.java
	opennms-import/src/test/java/org/opennms/netmgt/importer/operations/UpdateOperationTest.java
	opennms-services/src/main/java/org/opennms/netmgt/collectd/Collectd.java
	opennms-webapp/src/main/java/org/opennms/gwt/web/ui/CoreWeb.gwt.xml
	opennms-webapp/src/main/resources/org/opennms/web/svclayer/applicationContext-svclayer.xml
  • Loading branch information
Benjamin Reed committed Aug 26, 2014
2 parents 484011e + b50c8cd commit e19a99f
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 159 deletions.
Expand Up @@ -42,13 +42,14 @@
import org.opennms.netmgt.snmp.SnmpAgentConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.InputStreamResource;

public class ProxySnmpAgentConfigFactory extends SnmpPeerFactory {

private static final Logger LOG = LoggerFactory.getLogger(ProxySnmpAgentConfigFactory.class);

public ProxySnmpAgentConfigFactory(InputStream config) throws MarshalException, ValidationException, FileNotFoundException, IOException {
super(config);
public ProxySnmpAgentConfigFactory(final InputStream config) throws MarshalException, ValidationException, FileNotFoundException, IOException {
super(new InputStreamResource(config));
}

@Override
Expand Down
Expand Up @@ -105,6 +105,7 @@
<attrib name="PeakPoolThreads" alias="ONMSCollectPoolPeak" type="gauge"/>
<attrib name="TasksTotal" alias="ONMSCollectTasksTot" type="counter"/>
<attrib name="TasksCompleted" alias="ONMSCollectTasksCpt" type="counter"/>
<attrib name="CollectableServiceCount" alias="ONMSCollectSvcCount" type="gauge"/>
</mbean>
<mbean name="OpenNMS.Capsd" objectname="OpenNMS:Name=Capsd">
<attrib name="ActiveSuspectThreads" alias="ActiveSuspecThreads" type="gauge"/>
Expand Down
Expand Up @@ -66,7 +66,8 @@ include.directory=snmp-graph.properties.d
# files
reports=onms.queued.updates, onms.queued.pending, \
onms.pollerd.activeThreads, onms.pollerd.completedRatio, onms.pollerd.polls, \
onms.collectd.activeThreads, onms.collectd.completedRatio, onms.collectd.threadpool, \
onms.collectd.activeThreads, onms.collectd.threadpool, \
onms.collectd.completedRatio, onms.collectd.collectableServiceCount, \
OpenNMS.Capsd.ActiveSuspecThreads.AttributeReport, \
OpenNMS.Capsd.ActiveRescanThreads.AttributeReport, \
OpenNMS.Capsd.SuspectCompletTasks.AttributeReport, \
Expand Down Expand Up @@ -228,6 +229,18 @@ report.onms.collectd.completedRatio.command=--title="OpenNMS Collectd Task Compl
GPRINT:percent:MIN:"Min \\: %8.2lf %s" \
GPRINT:percent:MAX:"Max \\: %8.2lf %s\\n"

report.onms.collectd.collectableServiceCount.name=OpenNMS Collectd Collectable Services
report.onms.collectd.collectableServiceCount.columns=ONMSCollectSvcCount
report.onms.collectd.collectableServiceCount.type=interfaceSnmp
report.onms.collectd.collectableServiceCount.command=--title="OpenNMS Collectd Collectable Services" \
--vertical-label="Services" \
DEF:total={rrd1}:ONMSCollectSvcCount:AVERAGE \
AREA:total#F5CD9A \
LINE2:total#F19A2A:"Collectable" \
GPRINT:total:AVERAGE:" Avg \\: %8.2lf %s" \
GPRINT:total:MIN:"Min \\: %8.2lf %s" \
GPRINT:total:MAX:"Max \\: %8.2lf %s\\n"

###
## OpenNMS Vacuumd
###
Expand Down
Expand Up @@ -32,9 +32,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
Expand All @@ -46,6 +44,8 @@
import org.apache.commons.io.IOUtils;
import org.opennms.core.utils.ConfigFileConstants;
import org.opennms.core.utils.InetAddressUtils;
import org.opennms.core.spring.FileReloadCallback;
import org.opennms.core.spring.FileReloadContainer;
import org.opennms.core.xml.JaxbUtils;
import org.opennms.netmgt.config.api.SnmpAgentConfigFactory;
import org.opennms.netmgt.config.snmp.AddressSnmpConfigVisitor;
Expand All @@ -57,7 +57,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.xml.sax.InputSource;

/**
* This class is the main repository for SNMP configuration information used by
Expand Down Expand Up @@ -92,20 +91,19 @@ public class SnmpPeerFactory implements SnmpAgentConfigFactory {
public static SnmpConfig m_config;

private static File m_configFile;

private static FileReloadContainer<SnmpConfig> m_container;
private static FileReloadCallback<SnmpConfig> m_callback;

/**
* This member is set to true if the configuration file has been loaded.
*/
private static boolean m_loaded = false;

/**
* Private constructor
*
* @exception java.io.IOException
* Thrown if the specified config file cannot be read
*/
private SnmpPeerFactory(final File configFile) throws IOException {
this(new FileSystemResource(configFile));
private static final int VERSION_UNSPECIFIED = -1;

protected SnmpConfig loadConfig(final Resource resource) {
return JaxbUtils.unmarshal(SnmpConfig.class, resource);
}

/**
Expand All @@ -116,54 +114,33 @@ private SnmpPeerFactory(final File configFile) throws IOException {
public SnmpPeerFactory(final Resource resource) {
SnmpPeerFactory.getWriteLock().lock();
try {
m_config = JaxbUtils.unmarshal(SnmpConfig.class, resource);
} finally {
SnmpPeerFactory.getWriteLock().unlock();
}
}
final SnmpConfig config = loadConfig(resource);

/**
* <p>Constructor for SnmpPeerFactory.</p>
*
* @param rdr a {@link java.io.Reader} object.
* @throws java.io.IOException if any.
* @deprecated Use code for InputStream instead to avoid character set issues
*/
public SnmpPeerFactory(final Reader rdr) throws IOException {
SnmpPeerFactory.getWriteLock().lock();
try {
m_config = JaxbUtils.unmarshal(SnmpConfig.class, rdr);
} finally {
SnmpPeerFactory.getWriteLock().unlock();
}
}

/**
* A constructor that takes a config string for use mostly in tests
*/
public SnmpPeerFactory(final String configString) throws IOException {
SnmpPeerFactory.getWriteLock().lock();
try {
m_config = JaxbUtils.unmarshal(SnmpConfig.class, configString);
} finally {
SnmpPeerFactory.getWriteLock().unlock();
}
}

/**
* <p>Constructor for SnmpPeerFactory.</p>
*
* @param stream a {@link java.io.InputStream} object.
*/
public SnmpPeerFactory(final InputStream stream) {
SnmpPeerFactory.getWriteLock().lock();
try {
m_config = JaxbUtils.unmarshal(SnmpConfig.class, new InputSource(stream), null);
try {
final File file = resource.getFile();
if (file != null) {
m_callback = new FileReloadCallback<SnmpConfig>() {
@Override
public SnmpConfig reload(final SnmpConfig object, final Resource resource) throws IOException {
return loadConfig(resource);
}

};
m_container = new FileReloadContainer<SnmpConfig>(config, resource, m_callback);
return;
}
} catch (final IOException e) {
LOG.debug("No file associated with resource {}, skipping reload container initialization.", resource);
}

// if we fall through to here, then the file was null, or something else went wrong
// store the config directly
m_config = config;
} finally {
SnmpPeerFactory.getWriteLock().unlock();
}
}

protected static Lock getReadLock() {
return m_readLock;
}
Expand Down Expand Up @@ -192,7 +169,9 @@ public static void init() throws IOException {

final File cfgFile = getFile();
LOG.debug("init: config file path: {}", cfgFile.getPath());
m_singleton = new SnmpPeerFactory(cfgFile);
final FileSystemResource resource = new FileSystemResource(cfgFile);

m_singleton = new SnmpPeerFactory(resource);
m_loaded = true;
} finally {
SnmpPeerFactory.getWriteLock().unlock();
Expand All @@ -212,8 +191,7 @@ public static void saveToFile(final File file)
throws UnsupportedEncodingException, FileNotFoundException,
IOException {
// Marshal to a string first, then write the string to the file. This
// way the original config
// isn't lost if the XML from the marshal is hosed.
// way the original config isn't lost if the XML from the marshal is hosed.
final String marshalledConfig = marshallConfig();

FileOutputStream out = null;
Expand All @@ -226,6 +204,9 @@ public static void saveToFile(final File file)
fileWriter.write(marshalledConfig);
fileWriter.flush();
fileWriter.close();
if (m_container != null) {
m_container.reload();
}
}
} finally {
IOUtils.closeQuietly(fileWriter);
Expand Down Expand Up @@ -318,7 +299,7 @@ public SnmpAgentConfig getAgentConfig(final InetAddress agentAddress) {
private SnmpAgentConfig getAgentConfig(final InetAddress agentInetAddress, final int requestedSnmpVersion) {
SnmpPeerFactory.getReadLock().lock();
try {
if (m_config == null) {
if (getSnmpConfig() == null) {
final SnmpAgentConfig agentConfig = new SnmpAgentConfig(agentInetAddress);
if (requestedSnmpVersion == SnmpAgentConfig.VERSION_UNSPECIFIED) {
agentConfig.setVersion(SnmpAgentConfig.DEFAULT_VERSION);
Expand All @@ -331,11 +312,11 @@ private SnmpAgentConfig getAgentConfig(final InetAddress agentInetAddress, final

final SnmpAgentConfig agentConfig = new SnmpAgentConfig(agentInetAddress);

// Now set the defaults from the m_config
// Now set the defaults from the getSnmpConfig()
setSnmpAgentConfig(agentConfig, new Definition(), requestedSnmpVersion);

final AddressSnmpConfigVisitor visitor = new AddressSnmpConfigVisitor(agentInetAddress);
m_config.visit(visitor);
getSnmpConfig().visit(visitor);
final Definition matchingDef = visitor.getDefinition();
if (matchingDef != null) {
setSnmpAgentConfig(agentConfig, matchingDef, requestedSnmpVersion);
Expand All @@ -347,7 +328,7 @@ private SnmpAgentConfig getAgentConfig(final InetAddress agentInetAddress, final
}

private void setSnmpAgentConfig(final SnmpAgentConfig agentConfig, final Definition def, final int requestedSnmpVersion) {
int version = getVersionCode(def, m_config, requestedSnmpVersion);
int version = getVersionCode(def, getSnmpConfig(), requestedSnmpVersion);

setCommonAttributes(agentConfig, def, version);
agentConfig.setSecurityLevel(def.getSecurityLevel());
Expand Down Expand Up @@ -411,7 +392,11 @@ public int getVersionCode(final Definition def, final SnmpConfig config, final i
public static SnmpConfig getSnmpConfig() {
SnmpPeerFactory.getReadLock().lock();
try {
return m_config;
if (m_container == null) {
return m_config;
} else {
return m_container.getObject();
}
} finally {
SnmpPeerFactory.getReadLock().unlock();
}
Expand All @@ -430,7 +415,7 @@ public static SnmpConfig getSnmpConfig() {
public void define(final SnmpEventInfo info) {
getWriteLock().lock();
try {
final SnmpConfigManager mgr = new SnmpConfigManager(m_config);
final SnmpConfigManager mgr = new SnmpConfigManager(getSnmpConfig());
mgr.mergeIntoConfig(info.createDef());
} finally {
getWriteLock().unlock();
Expand All @@ -450,7 +435,7 @@ public static String marshallConfig() {
StringWriter writer = null;
try {
writer = new StringWriter();
JaxbUtils.marshal(m_config, writer);
JaxbUtils.marshal(getSnmpConfig(), writer);
marshalledConfig = writer.toString();
} finally {
IOUtils.closeQuietly(writer);
Expand Down

0 comments on commit e19a99f

Please sign in to comment.