+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+
+package org.opennms.core.db;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.ValidationException;
+import org.opennms.core.xml.CastorUtils;
+import org.opennms.netmgt.config.opennmsDataSources.ConnectionPool;
+import org.opennms.netmgt.config.opennmsDataSources.DataSourceConfiguration;
+import org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * This is the class used to load the OpenNMS database configuration
+ * from the opennms-datasources.xml.
+ *
+ * @author Brian Weaver
+ */
+public final class DataSourceConfigurationFactory {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DataSourceConfigurationFactory.class);
+
+ private final DataSourceConfiguration m_dsc;
+
+ public DataSourceConfigurationFactory(File fileName) {
+ InputStream is = null;
+ try {
+ is = new FileInputStream(fileName);
+ m_dsc = CastorUtils.unmarshal(DataSourceConfiguration.class, is);
+ } catch (MarshalException e) {
+ throw new IllegalArgumentException("Could not unmarshal " + DataSourceConfiguration.class.getName(), e);
+ } catch (ValidationException e) {
+ throw new IllegalArgumentException("Could not unmarshal " + DataSourceConfiguration.class.getName(), e);
+ } catch (FileNotFoundException e) {
+ throw new IllegalArgumentException("Could not unmarshal " + DataSourceConfiguration.class.getName(), e);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ public DataSourceConfigurationFactory(String fileName) {
+ this(new File(fileName));
+ }
+
+ public DataSourceConfigurationFactory(InputStream fileInputStream) {
+ try {
+ m_dsc = CastorUtils.unmarshal(DataSourceConfiguration.class, fileInputStream);
+ } catch (MarshalException e) {
+ throw new IllegalArgumentException("Could not unmarshal " + DataSourceConfiguration.class.getName(), e);
+ } catch (ValidationException e) {
+ throw new IllegalArgumentException("Could not unmarshal " + DataSourceConfiguration.class.getName(), e);
+ }
+ }
+
+ public ConnectionPool getConnectionPool() {
+ return m_dsc.getConnectionPool();
+ }
+
+ public JdbcDataSource getJdbcDataSource(String name) {
+ for (JdbcDataSource ds : m_dsc.getJdbcDataSource()) {
+ if (ds.getName().equals(name)) {
+ return ds;
+ }
+ }
+ return null;
+ }
+}
diff --git a/core/db/src/main/java/org/opennms/core/db/DataSourceFactory.java b/core/db/src/main/java/org/opennms/core/db/DataSourceFactory.java
index ac34857b4a53..76d485251084 100644
--- a/core/db/src/main/java/org/opennms/core/db/DataSourceFactory.java
+++ b/core/db/src/main/java/org/opennms/core/db/DataSourceFactory.java
@@ -29,14 +29,9 @@
package org.opennms.core.db;
import java.beans.PropertyVetoException;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.PrintWriter;
import java.lang.reflect.Constructor;
-import java.sql.Connection;
import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -44,16 +39,13 @@
import javax.sql.DataSource;
-import org.apache.commons.io.IOUtils;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
import org.opennms.core.utils.ConfigFileConstants;
-import org.opennms.core.xml.CastorUtils;
import org.opennms.netmgt.config.opennmsDataSources.ConnectionPool;
-import org.opennms.netmgt.config.opennmsDataSources.DataSourceConfiguration;
+import org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;
/**
*
@@ -70,123 +62,107 @@
*
* @author Brian Weaver
*/
-public final class DataSourceFactory implements DataSource {
-
+public abstract class DataSourceFactory {
+
private static final Logger LOG = LoggerFactory.getLogger(DataSourceFactory.class);
-
- private static final Class> DEFAULT_FACTORY_CLASS = C3P0ConnectionFactory.class;
- /**
- * The singleton instance of this factory
- */
- private static DataSource m_singleton = null;
+ private static final Class> DEFAULT_FACTORY_CLASS = AtomikosDataSourceFactory.class;
+ private static DataSourceConfigurationFactory m_dataSourceConfigFactory;
+
private static final Map m_dataSources = new ConcurrentHashMap();
private static final List m_closers = new LinkedList();
+ private static ClosableDataSource parseDataSource(final String dsName) {
+ String factoryClass = null;
+
+ ConnectionPool connectionPool = m_dataSourceConfigFactory.getConnectionPool();
+ factoryClass = connectionPool.getFactory();
+
+ ClosableDataSource dataSource = null;
+ final String defaultClassName = DEFAULT_FACTORY_CLASS.getName();
+ try {
+ final Class> clazz = Class.forName(factoryClass);
+ final Constructor> constructor = clazz.getConstructor(new Class>[] { JdbcDataSource.class });
+ dataSource = (ClosableDataSource)constructor.newInstance(new Object[] { m_dataSourceConfigFactory.getJdbcDataSource(dsName) });
+ } catch (final Throwable t) {
+ LOG.debug("Unable to load {}, falling back to the default dataSource ({})", factoryClass, defaultClassName, t);
+ try {
+ final Constructor> constructor = ((Class>) DEFAULT_FACTORY_CLASS).getConstructor(new Class>[] { JdbcDataSource.class });
+ dataSource = (ClosableDataSource)constructor.newInstance(new Object[] { m_dataSourceConfigFactory.getJdbcDataSource(dsName) });
+ } catch (final Throwable cause) {
+ LOG.error("Unable to load {}.", DEFAULT_FACTORY_CLASS.getName(), cause);
+ throw new IllegalArgumentException("Unable to load " + defaultClassName + ".", cause);
+ }
+ }
+
+ if (connectionPool != null) {
+ dataSource.setIdleTimeout(connectionPool.getIdleTimeout());
+ try {
+ dataSource.setLoginTimeout(connectionPool.getLoginTimeout());
+ } catch (SQLException e) {
+ LOG.warn("Exception thrown while trying to set login timeout on datasource", e);
+ }
+ dataSource.setMinPool(connectionPool.getMinPool());
+ dataSource.setMaxPool(connectionPool.getMaxPool());
+ dataSource.setMaxSize(connectionPool.getMaxSize());
+ }
+
+ return dataSource;
+ }
+
/**
- * Load the config from the default config file and create the singleton
- * instance of this factory.
- *
- * @exception java.io.IOException
- * Thrown if the specified config file cannot be read
- * @exception org.exolab.castor.xml.MarshalException
- * Thrown if the file does not conform to the schema.
- * @exception org.exolab.castor.xml.ValidationException
- * Thrown if the contents do not match the required schema.
- * @throws java.sql.SQLException if any.
- * @throws java.beans.PropertyVetoException if any.
- * @throws java.io.IOException if any.
- * @throws org.exolab.castor.xml.MarshalException if any.
- * @throws org.exolab.castor.xml.ValidationException if any.
- * @throws java.lang.ClassNotFoundException if any.
+ * @deprecated This function is no longer necessary for DataSourceFactory initialization
+ *
+ * @throws IOException
+ * @throws MarshalException
+ * @throws ValidationException
+ * @throws ClassNotFoundException
+ * @throws PropertyVetoException
+ * @throws SQLException
*/
public static synchronized void init() throws IOException, MarshalException, ValidationException, ClassNotFoundException, PropertyVetoException, SQLException {
- if (!isLoaded("opennms")) {
- init("opennms");
- }
}
/**
* init
*
* @param dsName a {@link java.lang.String} object.
- * @throws java.io.IOException if any.
- * @throws org.exolab.castor.xml.MarshalException if any.
- * @throws org.exolab.castor.xml.ValidationException if any.
- * @throws java.lang.ClassNotFoundException if any.
- * @throws java.beans.PropertyVetoException if any.
- * @throws java.sql.SQLException if any.
*/
- public static synchronized void init(final String dsName) throws IOException, MarshalException, ValidationException, ClassNotFoundException, PropertyVetoException, SQLException {
+ public static synchronized void init(final String dsName) {
if (isLoaded(dsName)) {
- // init already called - return
- // to reload, reload() will need to be called
+ // init already called, return
return;
}
- String factoryClass = null;
- final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME);
- DataSourceConfiguration dsc = null;
- ConnectionPool connectionPool = null;
- FileInputStream fileInputStream = null;
- try {
- fileInputStream = new FileInputStream(cfgFile);
- dsc = CastorUtils.unmarshal(DataSourceConfiguration.class, fileInputStream);
- connectionPool = dsc.getConnectionPool();
- if (connectionPool != null) {
- factoryClass = connectionPool.getFactory();
- }
- } finally {
- IOUtils.closeQuietly(fileInputStream);
- }
+ // If a data source configuration factory wasn't set, try to load the default settings
+ if (m_dataSourceConfigFactory == null) {
+ try {
+ m_dataSourceConfigFactory = new DataSourceConfigurationFactory(ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME));
+ } catch (IOException e) {
+ LOG.warn("Could not parse default data source configuration", e);
+ m_dataSourceConfigFactory = null;
+ }
+ }
- final String configPath = cfgFile.getPath();
- ClosableDataSource dataSource = null;
- final String defaultClassName = DEFAULT_FACTORY_CLASS.getName();
- try {
- final Class> clazz = Class.forName(factoryClass);
- final Constructor> constructor = clazz.getConstructor(new Class>[] { String.class, String.class });
- dataSource = (ClosableDataSource)constructor.newInstance(new Object[] { configPath, dsName });
- } catch (final Throwable t) {
- LOG.debug("Unable to load {}, falling back to the default dataSource ({})", factoryClass, defaultClassName, t);
- try {
- final Constructor> constructor = ((Class>) DEFAULT_FACTORY_CLASS).getConstructor(new Class>[] { String.class, String.class });
- dataSource = (ClosableDataSource)constructor.newInstance(new Object[] { configPath, dsName });
- } catch (final Throwable cause) {
- LOG.error("Unable to load {}.", DEFAULT_FACTORY_CLASS.getName(), cause);
- throw new SQLException("Unable to load " + defaultClassName + ".", cause);
- }
- }
+ final ClosableDataSource dataSource = parseDataSource(dsName);
- final ClosableDataSource runnableDs = dataSource;
m_closers.add(new Runnable() {
@Override
public void run() {
try {
- runnableDs.close();
+ dataSource.close();
} catch (final Throwable cause) {
LOG.info("Unable to close datasource {}.", dsName, cause);
}
}
});
-
- if (connectionPool != null) {
- dataSource.setIdleTimeout(connectionPool.getIdleTimeout());
- dataSource.setLoginTimeout(connectionPool.getLoginTimeout());
- dataSource.setMinPool(connectionPool.getMinPool());
- dataSource.setMaxPool(connectionPool.getMaxPool());
- dataSource.setMaxSize(connectionPool.getMaxSize());
- }
- // Springframework provided proxies that make working with transactions much easier
- final LazyConnectionDataSourceProxy lazyProxy = new LazyConnectionDataSourceProxy(dataSource);
-
- setInstance(dsName, lazyProxy);
+ setInstance(dsName, dataSource);
}
- private static synchronized boolean isLoaded(final String dsName) {
+ private static boolean isLoaded(final String dsName) {
return m_dataSources.containsKey(dsName);
}
@@ -214,60 +190,27 @@ public static DataSource getInstance() {
* @return a {@link javax.sql.DataSource} object.
*/
public static DataSource getInstance(final String name) {
- final DataSource dataSource = getDataSource(name);
- if (dataSource == null) {
- throw new IllegalArgumentException("Unable to locate data source named " + name + ". Does this need to be init'd?");
- } else {
- return dataSource;
- }
- }
-
- /**
- * Return a new database connection to the database configured in the
- * opennms-database.xml. The database connection is not managed
- * by the factory and must be release by the caller by using the
- * close
method.
- *
- * @return a new database connection to the database configured in the
- * opennms-database.xml
- * @throws java.sql.SQLException
- * Thrown if there is an error opening the connection to the
- * database.
- */
- @Override
- public Connection getConnection() throws SQLException {
- return getConnection("opennms");
- }
-
- /**
- * getConnection
- *
- * @param dsName a {@link java.lang.String} object.
- * @return a {@link java.sql.Connection} object.
- * @throws java.sql.SQLException if any.
- */
- public Connection getConnection(final String dsName) throws SQLException {
- return getDataSource(dsName).getConnection();
+ init(name);
+ return getDataSource(name);
}
/**
* setInstance
*
- * @param singleton a {@link javax.sql.DataSource} object.
+ * @param ds a {@link javax.sql.DataSource} object.
*/
- public static void setInstance(final DataSource singleton) {
- m_singleton=singleton;
- setInstance("opennms", singleton);
+ public static void setInstance(final DataSource ds) {
+ setInstance("opennms", ds);
}
/**
* setInstance
*
* @param dsName a {@link java.lang.String} object.
- * @param singleton a {@link javax.sql.DataSource} object.
+ * @param ds a {@link javax.sql.DataSource} object.
*/
- public static synchronized void setInstance(final String dsName, final DataSource singleton) {
- m_dataSources.put(dsName,singleton);
+ public static synchronized void setInstance(final String dsName, final DataSource ds) {
+ m_dataSources.put(dsName, ds);
}
/**
@@ -289,93 +232,12 @@ public static synchronized DataSource getDataSource(final String dsName) {
return m_dataSources.get(dsName);
}
- /** {@inheritDoc} */
- @Override
- public Connection getConnection(final String username, final String password) throws SQLException {
- return getConnection();
- }
-
- /**
- * getLogWriter
- *
- * @return a {@link java.io.PrintWriter} object.
- * @throws java.sql.SQLException if any.
- */
- @Override
- public PrintWriter getLogWriter() throws SQLException {
- return m_singleton.getLogWriter();
- }
-
- /**
- * getLogWriter
- *
- * @param dsName a {@link java.lang.String} object.
- * @return a {@link java.io.PrintWriter} object.
- * @throws java.sql.SQLException if any.
- */
- public PrintWriter getLogWriter(final String dsName) throws SQLException {
- return getDataSource(dsName).getLogWriter();
- }
-
- /** {@inheritDoc} */
- @Override
- public void setLogWriter(final PrintWriter out) throws SQLException {
- setLogWriter("opennms", out);
- }
-
- /**
- * setLogWriter
- *
- * @param dsName a {@link java.lang.String} object.
- * @param out a {@link java.io.PrintWriter} object.
- * @throws java.sql.SQLException if any.
- */
- public void setLogWriter(final String dsName, final PrintWriter out) throws SQLException {
- getDataSource(dsName).setLogWriter(out);
- }
-
- /** {@inheritDoc} */
- @Override
- public void setLoginTimeout(final int seconds) throws SQLException {
- setLoginTimeout("opennms", seconds);
- }
-
- /**
- * setLoginTimeout
- *
- * @param dsName a {@link java.lang.String} object.
- * @param seconds a int.
- * @throws java.sql.SQLException if any.
- */
- public void setLoginTimeout(final String dsName, final int seconds) throws SQLException {
- getDataSource(dsName).setLoginTimeout(seconds);
- }
-
/**
- * getLoginTimeout
- *
- * @return a int.
- * @throws java.sql.SQLException if any.
- */
- @Override
- public int getLoginTimeout() throws SQLException {
- return getLoginTimeout("opennms");
- }
-
- /**
- * getLoginTimeout
- *
- * @param dsName a {@link java.lang.String} object.
- * @return a int.
- * @throws java.sql.SQLException if any.
*/
- public int getLoginTimeout(final String dsName) throws SQLException {
- return getDataSource(dsName).getLoginTimeout();
- }
-
- /** {@inheritDoc} */
- public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
- throw new SQLFeatureNotSupportedException("getParentLogger not supported");
+ public static synchronized void setDataSourceConfigurationFactory(final DataSourceConfigurationFactory factory) {
+ // Close any existing datasources
+ close();
+ m_dataSourceConfigFactory = factory;
}
/**
@@ -383,7 +245,7 @@ public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedE
*
* @throws java.sql.SQLException if any.
*/
- public static synchronized void close() throws SQLException {
+ public static synchronized void close() {
for(Runnable closer : m_closers) {
closer.run();
@@ -391,31 +253,5 @@ public static synchronized void close() throws SQLException {
m_closers.clear();
m_dataSources.clear();
-
- }
-
- /**
- * unwrap
- *
- * @param iface a {@link java.lang.Class} object.
- * @param a T object.
- * @return a T object.
- * @throws java.sql.SQLException if any.
- */
- @Override
- public T unwrap(final Class iface) throws SQLException {
- return null; //TODO
- }
-
- /**
- * isWrapperFor
- *
- * @param iface a {@link java.lang.Class} object.
- * @return a boolean.
- * @throws java.sql.SQLException if any.
- */
- @Override
- public boolean isWrapperFor(final Class> iface) throws SQLException {
- return false; //TODO
}
}
diff --git a/core/db/src/main/java/org/opennms/core/db/DataSourceFactoryBean.java b/core/db/src/main/java/org/opennms/core/db/DataSourceFactoryBean.java
index 81f761790938..b7e93139b879 100644
--- a/core/db/src/main/java/org/opennms/core/db/DataSourceFactoryBean.java
+++ b/core/db/src/main/java/org/opennms/core/db/DataSourceFactoryBean.java
@@ -83,7 +83,6 @@ public boolean isSingleton() {
*/
@Override
public void afterPropertiesSet() throws Exception {
- DataSourceFactory.init();
Vault.setDataSource(DataSourceFactory.getInstance()); // Fix for Bug 4117
}
@@ -94,7 +93,7 @@ public void afterPropertiesSet() throws Exception {
*/
@Override
public void destroy() throws Exception {
- LOG.info("Closing DataSourceFactory!!!");
+ LOG.info("Closing {}!!!", getClass().getSimpleName());
DataSourceFactory.close();
}
diff --git a/core/db/src/main/java/org/opennms/core/db/XADataSourceFactory.java b/core/db/src/main/java/org/opennms/core/db/XADataSourceFactory.java
index 664257b6aca0..f9c8c3d1d4af 100644
--- a/core/db/src/main/java/org/opennms/core/db/XADataSourceFactory.java
+++ b/core/db/src/main/java/org/opennms/core/db/XADataSourceFactory.java
@@ -28,23 +28,13 @@
package org.opennms.core.db;
-import java.beans.PropertyVetoException;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.URL;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
+import java.net.URI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import javax.sql.XAConnection;
import javax.sql.XADataSource;
-import org.apache.commons.io.IOUtils;
-import org.exolab.castor.xml.MarshalException;
-import org.exolab.castor.xml.ValidationException;
import org.opennms.core.utils.ConfigFileConstants;
import org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource;
import org.postgresql.xa.PGXADataSource;
@@ -66,73 +56,52 @@
*
* @author Brian Weaver
*/
-public final class XADataSourceFactory implements XADataSource {
+public abstract class XADataSourceFactory {
private static final Logger LOG = LoggerFactory.getLogger(DataSourceFactory.class);
- /**
- * The singleton instance of this factory
- */
- private static XADataSource m_singleton = null;
-
- private static final Map m_dataSources = new ConcurrentHashMap();
-
- /**
- * Load the config from the default config file and create the singleton
- * instance of this factory.
- *
- * @exception java.io.IOException
- * Thrown if the specified config file cannot be read
- * @exception org.exolab.castor.xml.MarshalException
- * Thrown if the file does not conform to the schema.
- * @exception org.exolab.castor.xml.ValidationException
- * Thrown if the contents do not match the required schema.
- * @throws java.sql.SQLException if any.
- * @throws java.beans.PropertyVetoException if any.
- * @throws java.io.IOException if any.
- * @throws org.exolab.castor.xml.MarshalException if any.
- * @throws org.exolab.castor.xml.ValidationException if any.
- * @throws java.lang.ClassNotFoundException if any.
- */
- public static synchronized void init() throws IOException, MarshalException, ValidationException, ClassNotFoundException, PropertyVetoException, SQLException {
- if (!isLoaded("opennms")) {
- init("opennms");
+ private static DataSourceConfigurationFactory m_dataSourceConfigFactory;
+
+ static {
+ // Try to create a DataSourceConfigurationFactory from the default opennms-datasources.xml
+ try {
+ m_dataSourceConfigFactory = new DataSourceConfigurationFactory(ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME));
+ } catch (IOException e) {
+ LOG.warn("Could not parse default data source configuration", e);
+ m_dataSourceConfigFactory = null;
}
}
+ private static final Map m_dataSources = new ConcurrentHashMap();
+
/**
* init
*
* @param dsName a {@link java.lang.String} object.
- * @throws java.io.IOException if any.
- * @throws org.exolab.castor.xml.MarshalException if any.
- * @throws org.exolab.castor.xml.ValidationException if any.
- * @throws java.lang.ClassNotFoundException if any.
- * @throws java.beans.PropertyVetoException if any.
- * @throws java.sql.SQLException if any.
*/
- public static synchronized void init(final String dsName) throws IOException, MarshalException, ValidationException, ClassNotFoundException, PropertyVetoException, SQLException {
+ public static synchronized void init(final String dsName) {
if (isLoaded(dsName)) {
- // init already called - return
- // to reload, reload() will need to be called
+ // init already called, return
return;
}
- final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME);
- FileInputStream fileInputStream = null;
- try {
- fileInputStream = new FileInputStream(cfgFile);
- final JdbcDataSource ds = ConnectionFactoryUtil.marshalDataSourceFromConfig(fileInputStream, dsName);
+ final JdbcDataSource ds = m_dataSourceConfigFactory.getJdbcDataSource(dsName);
+ String urlString = ds.getUrl();
+ if (urlString.startsWith("jdbc:")) {
+ urlString = urlString.substring("jdbc:".length());
+ }
+ URI url = URI.create(urlString);
+ // TODO: Add support for more XADataSources (hsqldb, derby)
+ if ("postgresql".equalsIgnoreCase(url.getScheme())) {
PGXADataSource xaDataSource = new PGXADataSource();
- URL url = new URL(ds.getUrl());
xaDataSource.setServerName(url.getHost());
xaDataSource.setPortNumber(url.getPort());
xaDataSource.setDatabaseName(ds.getDatabaseName());
xaDataSource.setUser(ds.getUserName());
xaDataSource.setPassword(ds.getPassword());
- setInstance(xaDataSource);
- } finally {
- IOUtils.closeQuietly(fileInputStream);
+ setInstance(dsName, xaDataSource);
+ } else {
+ throw new UnsupportedOperationException("Data source scheme not supported: " + url.getScheme());
}
}
@@ -172,42 +141,13 @@ public static XADataSource getInstance(final String name) {
}
}
- /**
- * Return a new database connection to the database configured in the
- * opennms-database.xml. The database connection is not managed
- * by the factory and must be release by the caller by using the
- * close
method.
- *
- * @return a new database connection to the database configured in the
- * opennms-database.xml
- * @throws java.sql.SQLException
- * Thrown if there is an error opening the connection to the
- * database.
- */
- @Override
- public XAConnection getXAConnection() throws SQLException {
- return getXAConnection("opennms");
- }
-
- /**
- * getConnection
- *
- * @param dsName a {@link java.lang.String} object.
- * @return a {@link java.sql.Connection} object.
- * @throws java.sql.SQLException if any.
- */
- public XAConnection getXAConnection(final String dsName) throws SQLException {
- return getXADataSource(dsName).getXAConnection();
- }
-
/**
* setInstance
*
- * @param singleton a {@link javax.sql.DataSource} object.
+ * @param ds a {@link javax.sql.DataSource} object.
*/
- public static void setInstance(final XADataSource singleton) {
- m_singleton=singleton;
- setInstance("opennms", singleton);
+ public static void setInstance(final XADataSource ds) {
+ setInstance("opennms", ds);
}
/**
@@ -217,7 +157,7 @@ public static void setInstance(final XADataSource singleton) {
* @param singleton a {@link javax.sql.DataSource} object.
*/
public static synchronized void setInstance(final String dsName, final XADataSource singleton) {
- m_dataSources.put(dsName,singleton);
+ m_dataSources.put(dsName, singleton);
}
/**
@@ -236,103 +176,23 @@ public static XADataSource getXADataSource() {
* @return a {@link javax.sql.DataSource} object.
*/
public static synchronized XADataSource getXADataSource(final String dsName) {
+ init(dsName);
return m_dataSources.get(dsName);
}
- /** {@inheritDoc} */
- @Override
- public XAConnection getXAConnection(final String username, final String password) throws SQLException {
- return getXAConnection();
- }
-
- /**
- * getLogWriter
- *
- * @return a {@link java.io.PrintWriter} object.
- * @throws java.sql.SQLException if any.
- */
- @Override
- public PrintWriter getLogWriter() throws SQLException {
- return m_singleton.getLogWriter();
- }
-
- /**
- * getLogWriter
- *
- * @param dsName a {@link java.lang.String} object.
- * @return a {@link java.io.PrintWriter} object.
- * @throws java.sql.SQLException if any.
- */
- public PrintWriter getLogWriter(final String dsName) throws SQLException {
- return getXADataSource(dsName).getLogWriter();
- }
-
- /** {@inheritDoc} */
- @Override
- public void setLogWriter(final PrintWriter out) throws SQLException {
- setLogWriter("opennms", out);
- }
-
- /**
- * setLogWriter
- *
- * @param dsName a {@link java.lang.String} object.
- * @param out a {@link java.io.PrintWriter} object.
- * @throws java.sql.SQLException if any.
- */
- public void setLogWriter(final String dsName, final PrintWriter out) throws SQLException {
- getXADataSource(dsName).setLogWriter(out);
- }
-
- /** {@inheritDoc} */
- @Override
- public void setLoginTimeout(final int seconds) throws SQLException {
- setLoginTimeout("opennms", seconds);
- }
-
- /**
- * setLoginTimeout
- *
- * @param dsName a {@link java.lang.String} object.
- * @param seconds a int.
- * @throws java.sql.SQLException if any.
- */
- public void setLoginTimeout(final String dsName, final int seconds) throws SQLException {
- getXADataSource(dsName).setLoginTimeout(seconds);
- }
-
- /**
- * getLoginTimeout
- *
- * @return a int.
- * @throws java.sql.SQLException if any.
- */
- @Override
- public int getLoginTimeout() throws SQLException {
- return getLoginTimeout("opennms");
- }
-
- /**
- * getLoginTimeout
- *
- * @param dsName a {@link java.lang.String} object.
- * @return a int.
- * @throws java.sql.SQLException if any.
- */
- public int getLoginTimeout(final String dsName) throws SQLException {
- return getXADataSource(dsName).getLoginTimeout();
- }
-
- /** {@inheritDoc} */
- public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
- throw new SQLFeatureNotSupportedException("getParentLogger not supported");
- }
+ /**
+ */
+ public static synchronized void setDataSourceConfigurationFactory(final DataSourceConfigurationFactory factory) {
+ // Close any existing datasources
+ close();
+ m_dataSourceConfigFactory = factory;
+ }
/**
* close
*
* @throws java.sql.SQLException if any.
*/
- public static synchronized void close() throws SQLException {
+ public static synchronized void close() {
}
}
diff --git a/core/db/src/main/java/org/opennms/core/db/XADataSourceFactoryBean.java b/core/db/src/main/java/org/opennms/core/db/XADataSourceFactoryBean.java
index fe378e2c8b26..04ccc04f944d 100644
--- a/core/db/src/main/java/org/opennms/core/db/XADataSourceFactoryBean.java
+++ b/core/db/src/main/java/org/opennms/core/db/XADataSourceFactoryBean.java
@@ -40,7 +40,7 @@
/**
* XADataSourceFactoryBean class.
*/
-public class XADataSourceFactoryBean implements FactoryBean, InitializingBean, DisposableBean {
+public class XADataSourceFactoryBean implements FactoryBean, DisposableBean {
private static final Logger LOG = LoggerFactory.getLogger(XADataSourceFactoryBean.class);
@@ -75,16 +75,6 @@ public boolean isSingleton() {
return true;
}
- /**
- * afterPropertiesSet
- *
- * @throws java.lang.Exception if any.
- */
- @Override
- public void afterPropertiesSet() throws Exception {
- XADataSourceFactory.init();
- }
-
/**
* destroy
*
@@ -92,7 +82,7 @@ public void afterPropertiesSet() throws Exception {
*/
@Override
public void destroy() throws Exception {
- LOG.info("Closing DataSourceFactory!!!");
+ LOG.info("Closing {}!!!", getClass().getSimpleName());
XADataSourceFactory.close();
}
diff --git a/core/db/src/test/java/org/opennms/core/db/C3P0ConnectionFactoryTest.java b/core/db/src/test/java/org/opennms/core/db/ConnectionFactoryTest.java
similarity index 71%
rename from core/db/src/test/java/org/opennms/core/db/C3P0ConnectionFactoryTest.java
rename to core/db/src/test/java/org/opennms/core/db/ConnectionFactoryTest.java
index d202040bae47..2cab7ec1ce29 100644
--- a/core/db/src/test/java/org/opennms/core/db/C3P0ConnectionFactoryTest.java
+++ b/core/db/src/test/java/org/opennms/core/db/ConnectionFactoryTest.java
@@ -29,6 +29,7 @@
package org.opennms.core.db;
import java.beans.PropertyVetoException;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
@@ -40,16 +41,21 @@
import org.apache.commons.io.IOUtils;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
+import org.opennms.core.test.ConfigurationTestUtils;
import org.opennms.core.utils.ConfigFileConstants;
+import org.opennms.test.DaoTestConfigBean;
/**
*
* @author David Hustace
*/
-public class C3P0ConnectionFactoryTest extends TestCase {
+public class ConnectionFactoryTest extends TestCase {
public void testMarshalDataSourceFromConfig() throws Exception {
- C3P0ConnectionFactory factory1 = null;
- C3P0ConnectionFactory factory2 = null;
+ DaoTestConfigBean bean = new DaoTestConfigBean();
+ bean.afterPropertiesSet();
+
+ AtomikosDataSourceFactory factory1 = null;
+ AtomikosDataSourceFactory factory2 = null;
try {
factory1 = makeFactory("opennms");
@@ -114,12 +120,16 @@ public void testMarshalDataSourceFromConfig() throws Exception {
}
}
- private C3P0ConnectionFactory makeFactory(String database) throws MarshalException, ValidationException, PropertyVetoException, SQLException, IOException {
- InputStream stream = this.getClass().getResourceAsStream(ConfigFileConstants.getFileName(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME));
+ private AtomikosDataSourceFactory makeFactory(String database) throws MarshalException, ValidationException, PropertyVetoException, SQLException, IOException, ClassNotFoundException {
+ InputStream stream1 = new ByteArrayInputStream(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, ConfigFileConstants.getFileName(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME)).getBytes());
+ DataSourceFactory.setDataSourceConfigurationFactory(new DataSourceConfigurationFactory(stream1));
+ InputStream stream2 = new ByteArrayInputStream(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, ConfigFileConstants.getFileName(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME)).getBytes());
+ XADataSourceFactory.setDataSourceConfigurationFactory(new DataSourceConfigurationFactory(stream2));
try {
- return new C3P0ConnectionFactory(stream, database);
+ return new AtomikosDataSourceFactory();
} finally {
- IOUtils.closeQuietly(stream);
+ IOUtils.closeQuietly(stream1);
+ IOUtils.closeQuietly(stream2);
}
}
}
diff --git a/core/lib/pom.xml b/core/lib/pom.xml
index 83f60049eda8..61df39733e59 100644
--- a/core/lib/pom.xml
+++ b/core/lib/pom.xml
@@ -28,10 +28,6 @@
-
- commons-io
- commons-io
-
org.opennms.dependencies
spring-dependencies
diff --git a/core/lib/src/main/java/org/opennms/core/utils/ExecRunner.java b/core/lib/src/main/java/org/opennms/core/utils/ExecRunner.java
index 4b199a8b52e1..c91db3227fa5 100644
--- a/core/lib/src/main/java/org/opennms/core/utils/ExecRunner.java
+++ b/core/lib/src/main/java/org/opennms/core/utils/ExecRunner.java
@@ -30,6 +30,7 @@
*******************************************************************************/
package org.opennms.core.utils;
+import java.io.Closeable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -39,7 +40,8 @@
import java.util.Date;
import java.util.StringTokenizer;
-import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
@@ -57,6 +59,7 @@
* @author Scott McCrory .
*/
public class ExecRunner {
+ private static final Logger LOG = LoggerFactory.getLogger(ExecRunner.class);
/** Win NT/2K/MEPro require cmd.exe to run programs * */
private static final String WINDOWS_NT_2000_COMMAND_1 = "cmd.exe";
@@ -184,10 +187,10 @@ public int exec(final String command) throws IOException, InterruptedException {
return rc;
} finally {
- IOUtils.closeQuietly(pwErr);
- IOUtils.closeQuietly(swErr);
- IOUtils.closeQuietly(pwOut);
- IOUtils.closeQuietly(swOut);
+ closeQuietly(pwErr);
+ closeQuietly(swErr);
+ closeQuietly(pwOut);
+ closeQuietly(swOut);
}
}
@@ -217,8 +220,8 @@ public int exec(final String command, final OutputStream stdoutStream, final Out
return exec(command, pwOut, pwErr);
} finally {
- IOUtils.closeQuietly(pwErr);
- IOUtils.closeQuietly(pwOut);
+ closeQuietly(pwErr);
+ closeQuietly(pwOut);
}
}
@@ -459,4 +462,14 @@ private final void writeObject(final ObjectOutputStream out) throws IOException
}
+ private void closeQuietly(final Closeable c) {
+ if (c != null) {
+ try {
+ c.close();
+ } catch (final IOException closeE) {
+ LOG.debug("failed to close", closeE);
+ }
+ }
+ }
+
}
diff --git a/core/lib/src/main/java/org/opennms/core/utils/StreamGobbler.java b/core/lib/src/main/java/org/opennms/core/utils/StreamGobbler.java
index 3490b1ffd63b..eaeeafe91293 100644
--- a/core/lib/src/main/java/org/opennms/core/utils/StreamGobbler.java
+++ b/core/lib/src/main/java/org/opennms/core/utils/StreamGobbler.java
@@ -31,6 +31,7 @@
package org.opennms.core.utils;
import java.io.BufferedReader;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -39,7 +40,6 @@
import java.io.OutputStream;
import java.io.PrintWriter;
-import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -186,8 +186,8 @@ public void run() {
} catch (final Throwable e) {
LOG.debug("Unable to read lines.", e);
} finally {
- IOUtils.closeQuietly(br);
- IOUtils.closeQuietly(isr);
+ closeQuietly(br);
+ closeQuietly(isr);
}
}
@@ -205,4 +205,14 @@ private final void writeObject(final ObjectOutputStream out) throws IOException
throw new IOException("Object cannot be serialized");
}
+ private void closeQuietly(final Closeable c) {
+ if (c != null) {
+ try {
+ c.close();
+ } catch (final IOException closeE) {
+ LOG.debug("failed to close", closeE);
+ }
+ }
+ }
+
}
diff --git a/core/pom.xml b/core/pom.xml
index 3c88f4973f82..7fe6c3eca2b0 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -38,6 +38,7 @@
soa
tasks
test-api
+ upgrade
xml
diff --git a/core/test-api/db/pom.xml b/core/test-api/db/pom.xml
index 40d838854dbf..6a56d1dbf6b6 100644
--- a/core/test-api/db/pom.xml
+++ b/core/test-api/db/pom.xml
@@ -62,6 +62,11 @@
org.opennms.tests.mock-elements
compile
+
+ org.opennms.dependencies
+ atomikos-dependencies
+ pom
+
org.opennms.dependencies
spring-test-dependencies
@@ -76,7 +81,7 @@
org.hsqldb
hsqldb
- 2.2.9
+ 2.3.1
-->
diff --git a/core/test-api/db/src/main/java/org/opennms/core/test/db/TemporaryDatabaseExecutionListener.java b/core/test-api/db/src/main/java/org/opennms/core/test/db/TemporaryDatabaseExecutionListener.java
index 4799d7e3bf35..237af37ae9d9 100644
--- a/core/test-api/db/src/main/java/org/opennms/core/test/db/TemporaryDatabaseExecutionListener.java
+++ b/core/test-api/db/src/main/java/org/opennms/core/test/db/TemporaryDatabaseExecutionListener.java
@@ -47,16 +47,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.DelegatingDataSource;
-import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.util.Assert;
-import com.mchange.v2.c3p0.DataSources;
-import com.mchange.v2.c3p0.PooledDataSource;
-
/**
* This {@link TestExecutionListener} creates a temporary database and then
* registers it as the default datasource inside {@link DataSourceFactory} by
@@ -81,8 +77,9 @@ public void afterTestMethod(final TestContext testContext) throws Exception {
final JUnitTemporaryDatabase jtd = findAnnotation(testContext);
if (jtd == null) return;
- final PooledDataSource pds = (PooledDataSource)testContext.getAttribute("org.opennms.netmgt.dao.db.TemporaryDatabaseExecutionListener.pooledDataSource");
- if (pds != null) pds.hardReset();
+ // Close down the data sources that are referenced by the static DataSourceFactory helper classes
+ DataSourceFactory.close();
+ XADataSourceFactory.close();
try {
// DON'T REMOVE THE DATABASE, just rely on the ShutdownHook to remove them instead
@@ -219,21 +216,10 @@ public void prepareTestInstance(final TestContext testContext) throws Exception
}
m_database = m_databases.remove();
- final PooledDataSource pooledDataSource = (PooledDataSource)DataSources.pooledDataSource(m_database);
-
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- try { pooledDataSource.close(); }
- catch (final Throwable t) { LOG.debug("failed to close pooled data source", t); }
- }
- });
- final LazyConnectionDataSourceProxy proxy = new LazyConnectionDataSourceProxy(pooledDataSource);
- DataSourceFactory.setInstance(proxy);
+ DataSourceFactory.setInstance(m_database);
XADataSourceFactory.setInstance(m_database);
- testContext.setAttribute("org.opennms.netmgt.dao.db.TemporaryDatabaseExecutionListener.pooledDataSource", pooledDataSource);
System.err.println(String.format("TemporaryDatabaseExecutionListener.prepareTestInstance(%s) prepared db %s", testContext, m_database.toString()));
System.err.println("Temporary Database Name: " + m_database.getTestDatabase());
}
diff --git a/core/test-api/db/src/main/resources/META-INF/opennms/applicationContext-testDao.xml b/core/test-api/db/src/main/resources/META-INF/opennms/applicationContext-testDao.xml
index 1b6f509ff1b6..52af19efaee7 100644
--- a/core/test-api/db/src/main/resources/META-INF/opennms/applicationContext-testDao.xml
+++ b/core/test-api/db/src/main/resources/META-INF/opennms/applicationContext-testDao.xml
@@ -24,24 +24,48 @@
+
+
+
+
+
+
+
+
+
+
+
- org.opennms.netmgt.dao
+ org.opennms.netmgt.dao.hibernate
+ org.opennms.netmgt.model
+
+
+
+
+
+ org.opennms.netmgt.dao.hibernate
org.opennms.netmgt.model
+
+
hibernate.dialect=org.hibernate.dialect.HSQLDialect
- hibernate.cache.use_second_level_cache=false
- hibernate.cache=false
+
hibernate.cache.use_query_cache=false
- hibernate.jdbc.batch_size=0
- hibernate.format_sql=false
- hibernate.show_sql=false
+ hibernate.cache.use_second_level_cache=false
+
hibernate.hbm2ddl.auto=create
+ hibernate.jdbc.batch_size=0
+
diff --git a/core/upgrade/pom.xml b/core/upgrade/pom.xml
new file mode 100644
index 000000000000..2ef382d8ae8b
--- /dev/null
+++ b/core/upgrade/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+ org.opennms
+ org.opennms.core
+ 1.13.0-SNAPSHOT
+
+ 4.0.0
+ org.opennms.core
+ org.opennms.core.upgrade
+ OpenNMS Core Upgrade Library
+ jar
+
+
+
+ org.opennms.dependencies
+ spring-dependencies
+ pom
+
+
+ org.opennms.core
+ org.opennms.core.daemon
+
+
+ org.opennms
+ opennms-rrd-model
+
+
+
+ commons-io
+ commons-io
+
+
+ org.opennms
+ opennms-config
+
+
+ org.opennms
+ opennms-provision-persistence
+
+
+ org.opennms.dependencies
+ jrobin-dependencies
+ pom
+
+
+ org.opennms
+ opennms-rrd-jrobin
+
+
+
+ junit
+ junit
+ test
+
+
+
diff --git a/core/upgrade/src/main/java/org/opennms/netmgt/vmmgr/ControllerUtils.java b/core/upgrade/src/main/java/org/opennms/netmgt/vmmgr/ControllerUtils.java
new file mode 100644
index 000000000000..aeceeecb5847
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/netmgt/vmmgr/ControllerUtils.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.netmgt.vmmgr;
+
+/**
+ * The Class ControllerUtils.
+ *
+ * @author Alejandro Galue
+ */
+public class ControllerUtils {
+
+ /** The controller. */
+ private static Controller controller;
+
+ /**
+ * Gets the controller.
+ *
+ * @return the controller
+ */
+ public static Controller getController() {
+ if (controller == null) {
+ controller = new Controller();
+ controller.setInvokeUrl("http://127.0.0.1:8181/invoke?objectname=OpenNMS:Name=Manager");
+ controller.setAuthenticator(controller.createAuthenticatorUsingConfigCredentials());
+ }
+ return controller;
+ }
+
+}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/api/AbstractOnmsUpgrade.java b/core/upgrade/src/main/java/org/opennms/upgrade/api/AbstractOnmsUpgrade.java
new file mode 100644
index 000000000000..ef735fba0d4b
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/api/AbstractOnmsUpgrade.java
@@ -0,0 +1,468 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.api;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.opennms.core.utils.ConfigFileConstants;
+import org.opennms.core.xml.CastorUtils;
+import org.opennms.netmgt.config.opennmsDataSources.DataSourceConfiguration;
+import org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource;
+import org.opennms.netmgt.rrd.RrdUtils;
+
+/**
+ * The Abstract class for OpenNMS Upgrade Implementations.
+ * This contains the basic methods that may be required for several implementations.
+ *
+ * @author Alejandro Galue
+ */
+public abstract class AbstractOnmsUpgrade implements OnmsUpgrade {
+
+ /** The Constant ZIP_EXT. */
+ public static final String ZIP_EXT = ".zip";
+
+ /** The main properties. */
+ private Properties mainProperties;
+
+ /** The RRD properties. */
+ private Properties rrdProperties;
+
+ /** The OpenNMS version. */
+ private String onmsVersion;
+
+ /**
+ * Instantiates a new abstract OpenNMS upgrade.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public AbstractOnmsUpgrade() throws OnmsUpgradeException {
+ registerProperties(getMainProperties());
+ registerProperties(getRrdProperties());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getSimpleName();
+ }
+
+ /**
+ * Gets the home directory.
+ *
+ * @return the home directory
+ */
+ protected String getHomeDirectory() {
+ return ConfigFileConstants.getHome();
+ }
+
+ /**
+ * Gets the files.
+ *
+ * @param resourceDir the resource directory
+ * @param ext the file extension
+ * @return the files
+ */
+ protected File[] getFiles(final File resourceDir, final String ext) {
+ return resourceDir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.toLowerCase().endsWith(ext);
+ }
+ });
+ }
+
+ /**
+ * Register properties.
+ *
+ * @param properties the properties
+ */
+ protected void registerProperties(Properties properties) {
+ if (properties == null) {
+ return;
+ }
+ for (Object o : properties.keySet()) {
+ String key = (String) o;
+ System.setProperty(key, properties.getProperty(key));
+ }
+ }
+
+ /**
+ * Load properties.
+ *
+ * @param properties the properties
+ * @param fileName the file name
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void loadProperties(Properties properties, String fileName) throws OnmsUpgradeException {
+ try {
+ File propertiesFile = ConfigFileConstants.getConfigFileByName(fileName);
+ properties.load(new FileInputStream(propertiesFile));
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't load " + fileName);
+ }
+ }
+
+ /**
+ * Gets the main properties.
+ *
+ * @return the main properties
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected Properties getMainProperties() throws OnmsUpgradeException {
+ if (mainProperties == null) {
+ mainProperties = new Properties();
+ loadProperties(mainProperties, "opennms.properties");
+ }
+ return mainProperties;
+ }
+
+ /**
+ * Gets the RRD properties.
+ *
+ * @return the RRD properties
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected Properties getRrdProperties() throws OnmsUpgradeException {
+ if (rrdProperties == null) {
+ rrdProperties = new Properties();
+ loadProperties(rrdProperties, "rrd-configuration.properties");
+ }
+ return rrdProperties;
+ }
+
+ /**
+ * Checks if storeByGroup is enabled.
+ *
+ * @return true, if storeByGroup is enabled
+ */
+ protected boolean isStoreByGroupEnabled() {
+ try {
+ return Boolean.parseBoolean(getMainProperties().getProperty("org.opennms.rrd.storeByGroup", "false"));
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * Checks if storeByForeignSource is enabled.
+ *
+ * @return true, if storeByForeignSource is enabled
+ */
+ protected boolean isStoreByForeignSourceEnabled() {
+ try {
+ return Boolean.parseBoolean(getMainProperties().getProperty("org.opennms.rrd.storeByForeignSource", "false"));
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * Checks if is RRDtool enabled.
+ *
+ * @return true, if is RRDtool enabled
+ */
+ protected boolean isRrdToolEnabled() {
+ try {
+ RrdUtils.getStrategy().getClass().getSimpleName().equals("JniRrdStrategy");
+ String strategy = getRrdProperties().getProperty("org.opennms.rrd.strategyClass", "org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy");
+ return !strategy.endsWith(".JRobinRrdStrategy");
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * Gets the RRD extension.
+ *
+ * @return the RRD extension
+ */
+ protected String getRrdExtension() {
+ try {
+ return RrdUtils.getExtension();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Gets the DB connection.
+ *
+ * @return the DB connection
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected Connection getDbConnection() throws OnmsUpgradeException {
+ try {
+ final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME);
+ DataSourceConfiguration dsc = null;
+ FileInputStream fileInputStream = null;
+ try {
+ fileInputStream = new FileInputStream(cfgFile);
+ dsc = CastorUtils.unmarshal(DataSourceConfiguration.class, fileInputStream);
+ } finally {
+ IOUtils.closeQuietly(fileInputStream);
+ }
+ for (JdbcDataSource ds : dsc.getJdbcDataSourceCollection()) {
+ if (ds.getName().equals("opennms")) {
+ return DriverManager.getConnection(ds.getUrl(), ds.getUserName(), ds.getPassword());
+ }
+ }
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't connect to OpenNMS Database");
+ }
+ throw new OnmsUpgradeException("Databaseconnection cannot be null");
+ }
+
+ /**
+ * Populate files list.
+ *
+ * @param dir the source directory
+ * @param filesListInDir the list of files to populate
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ private void populateFilesList(File dir, List filesListInDir) throws IOException {
+ File[] files = dir.listFiles();
+ for (File file : files) {
+ if (file.isFile()) filesListInDir.add(file);
+ else populateFilesList(file, filesListInDir);
+ }
+ }
+
+ /**
+ * ZIP a list of files.
+ *
+ * @param zipFile the output ZIP file
+ * @param sourceFolder the source folder
+ * @param filesToCompress the list of files to compress
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ private void zipFiles(File zipFile, File sourceFolder, List filesToCompress) throws OnmsUpgradeException {
+ try {
+ FileOutputStream fos = new FileOutputStream(zipFile);
+ ZipOutputStream zos = new ZipOutputStream(fos);
+ for(File file : filesToCompress){
+ String filePath = file.getAbsolutePath();
+ log(" Zipping %s\n", filePath);
+ ZipEntry ze = new ZipEntry(filePath.substring(sourceFolder.getAbsolutePath().length() + 1, filePath.length()));
+ zos.putNextEntry(ze);
+ FileInputStream fis = new FileInputStream(file);
+ byte[] buffer = new byte[1024];
+ int len;
+ while ((len = fis.read(buffer)) > 0) {
+ zos.write(buffer, 0, len);
+ }
+ zos.closeEntry();
+ fis.close();
+ }
+ zos.flush();
+ zos.close();
+ fos.close();
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Cannot ZIP files because " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * ZIP a directory.
+ *
+ * @param zipFile the output ZIP file
+ * @param sourceFolder the source folder
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void zipDir(File zipFile, File sourceFolder) throws OnmsUpgradeException {
+ List filesToCompress = new ArrayList();
+ try {
+ populateFilesList(sourceFolder, filesToCompress);
+ } catch (IOException e) {
+ throw new OnmsUpgradeException("Cannot ZIP files because " + e.getMessage(), e);
+ }
+ zipFiles(zipFile, sourceFolder, filesToCompress);
+ }
+
+ /**
+ * ZIP a file.
+ *
+ * The name of the ZIP file will be the name of the source file plus ".zip"
+ * @param sourceFile the source file
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void zipFile(File sourceFile) throws OnmsUpgradeException {
+ zipFiles(new File(sourceFile.getAbsolutePath() + ZIP_EXT), sourceFile.getParentFile(), Collections.singletonList(sourceFile));
+ }
+
+ /**
+ * UNZIP a file.
+ *
+ * @param zipFile the input ZIP file
+ * @param outputFolder the output folder
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void unzipFile(File zipFile, File outputFolder) throws OnmsUpgradeException {
+ try {
+ if (!outputFolder.exists()) outputFolder.mkdirs();
+ FileInputStream fis;
+ byte[] buffer = new byte[1024];
+ fis = new FileInputStream(zipFile);
+ ZipInputStream zis = new ZipInputStream(fis);
+ ZipEntry ze = zis.getNextEntry();
+ while(ze != null){
+ String fileName = ze.getName();
+ File newFile = new File(outputFolder, fileName);
+ log(" Unzipping to %s\n", newFile.getAbsolutePath());
+ new File(newFile.getParent()).mkdirs();
+ FileOutputStream fos = new FileOutputStream(newFile);
+ int len;
+ while ((len = zis.read(buffer)) > 0) {
+ fos.write(buffer, 0, len);
+ }
+ fos.close();
+ zis.closeEntry();
+ ze = zis.getNextEntry();
+ }
+ zis.closeEntry();
+ zis.close();
+ fis.close();
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Cannot UNZIP file because " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Gets the currently installed OpenNMS version.
+ *
+ * @return the OpenNMS version
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected String getOpennmsVersion() throws OnmsUpgradeException {
+ if (onmsVersion == null) {
+ File versionFile = new File(getHomeDirectory(), "jetty-webapps/opennms/WEB-INF/version.properties");
+ Properties properties = new Properties();
+ try {
+ properties.load(new FileInputStream(versionFile));
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't load " + versionFile);
+ }
+ final String version = properties.getProperty("version.display");
+ if (version == null) {
+ throw new OnmsUpgradeException("Can't retrive OpenNMS version");
+ }
+ onmsVersion = version;
+ }
+ return onmsVersion;
+ }
+
+ /**
+ * Checks if the installed version of OpenNMS is greater or equals than the supplied version.
+ *
+ * @param mayor the mayor
+ * @param minor the minor
+ * @param release the release
+ * @return true, if the current installed version is greater or equals than $major.$minor.$release
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected boolean isInstalledVersionGreaterOrEqual(int mayor, int minor, int release) throws OnmsUpgradeException {
+ String version = getOpennmsVersion();
+ String[] a = version.split("\\.");
+ try {
+ int supplied = mayor * 100 + minor * 10 + release;
+ int installed = Integer.parseInt(a[0]) * 100 + Integer.parseInt(a[1]) * 10 + Integer.parseInt(a[2].replaceFirst("[^\\d].+", ""));
+ return installed >= supplied;
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't process the OpenNMS version");
+ }
+ }
+
+ /**
+ * Prints the settings.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void printMainSettings() throws OnmsUpgradeException {
+ log("OpenNMS Home: %s\n", getHomeDirectory());
+ log("OpenNMS Version: %s\n", getOpennmsVersion());
+ log("Is RRDtool enabled? %s\n", isRrdToolEnabled());
+ log("Is storeByGroup enabled? %s\n", isStoreByGroupEnabled());
+ log("RRD Extension: %s\n", getRrdExtension());
+ log("RRD Strategy: %s\n", RrdUtils.getStrategy().getClass().getName());
+ }
+
+ /**
+ * Prints the full settings.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void printFullSettings() throws OnmsUpgradeException {
+ printMainSettings();
+ printProperties("Main Properties", getMainProperties());
+ printProperties("RRD Properties", getRrdProperties());
+ }
+
+ /**
+ * Prints the properties.
+ *
+ * @param title the title
+ * @param properties the properties
+ */
+ private void printProperties(String title, Properties properties) {
+ List keys = new ArrayList();
+ for (Object k : properties.keySet()) {
+ keys.add((String) k);
+ }
+ Collections.sort(keys);
+ log("%s\n", title);
+ for (String key : keys) {
+ log(" %s = %s\n", key, properties.getProperty(key));
+ }
+ }
+
+ /**
+ * Log.
+ *
+ * @param msgFormat the message format
+ * @param args the message's arguments
+ */
+ protected void log(String msgFormat, Object... args) {
+ System.out.printf(" " + msgFormat, args);
+ }
+
+}
diff --git a/opennms-import/src/main/java/org/opennms/netmgt/importer/operations/AbstractImportOperation.java b/core/upgrade/src/main/java/org/opennms/upgrade/api/Ignore.java
similarity index 76%
rename from opennms-import/src/main/java/org/opennms/netmgt/importer/operations/AbstractImportOperation.java
rename to core/upgrade/src/main/java/org/opennms/upgrade/api/Ignore.java
index b37d2a0bd2b1..f5914262b61f 100644
--- a/opennms-import/src/main/java/org/opennms/netmgt/importer/operations/AbstractImportOperation.java
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/api/Ignore.java
@@ -25,17 +25,18 @@
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/
+package org.opennms.upgrade.api;
-package org.opennms.netmgt.importer.operations;
-
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
/**
- * Abstract AbstractImportOperation class.
- *
- * @author ranger
- * @version $Id: $
+ * The Interface Ignore.
+ * Add this annotation to any OnmsUpgrade implementation that is not supposed to be executed (or ignored).
+ *
+ * @author Alejandro Galue
*/
-public abstract class AbstractImportOperation implements ImportOperation {
-
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Ignore {
}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgrade.java b/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgrade.java
new file mode 100644
index 000000000000..9042adbd848a
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgrade.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+
+package org.opennms.upgrade.api;
+
+/**
+ * The Interface OnmsUpgrade.
+ * All the post-processing scripts must implement this class.
+ *
+ * @author Alejandro Galue
+ */
+public interface OnmsUpgrade {
+
+ /**
+ * Gets the order.
+ * In order to execute all the implementations of this interface on a specify order,
+ * each implementation must return an integer for this purpose.
+ *
+ * @return the order
+ */
+ int getOrder();
+
+ /**
+ * Gets the id.
+ * This is for informational purposes, and will be used to store the execution status.
+ * It is recommended to use the class-name, but any other text can be used.
+ *
+ * @return the id
+ */
+ String getId();
+
+ /**
+ * Gets the description.
+ * This is for informational purposes, and should contain a brief description about
+ * what is the purpose of this upgrade class.
+ *
+ * @return the description
+ */
+ String getDescription();
+
+ /**
+ * Pre-execute
+ * Runs some checks to ensure that what it would execute() would work.
+ * If something is missing, an exception will be thrown
+ *
Execute backups of the JRBs/RRDs if they are going to be modified.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ void preExecute() throws OnmsUpgradeException;
+
+ /**
+ * Post execute.
+ * Runs some clean up tasks after executing the execute() method.
+ * If something is wrong, an exception will be thrown
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ void postExecute() throws OnmsUpgradeException;
+
+ /**
+ * Rollback.
+ *
Restore the initial state of the OpenNMS files if something went wrong while running the execute() method.
+ * Must restore the backups of the files if necessary.
+ */
+ void rollback() throws OnmsUpgradeException;
+
+ /**
+ * Execute.
+ * This is the main method, and this is the one where all the upgrade code
+ * must be placed.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ void execute() throws OnmsUpgradeException;
+
+ /**
+ * Requires OpenNMS running.
+ *
+ * @return true, if OpenNMS must be running to execute this upgrade or false
+ * if OpenNMS must be stopped.
+ */
+ boolean requiresOnmsRunning();
+}
+
+
diff --git a/opennms-import/src/main/java/org/opennms/netmgt/importer/operations/ImportOperation.java b/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgradeComparator.java
similarity index 69%
rename from opennms-import/src/main/java/org/opennms/netmgt/importer/operations/ImportOperation.java
rename to core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgradeComparator.java
index b456fd32e2fa..8b6cb1cbbcc0 100644
--- a/opennms-import/src/main/java/org/opennms/netmgt/importer/operations/ImportOperation.java
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgradeComparator.java
@@ -25,31 +25,24 @@
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/
+package org.opennms.upgrade.api;
-package org.opennms.netmgt.importer.operations;
-
-import java.util.List;
-
-import org.opennms.netmgt.xml.event.Event;
+import java.util.Comparator;
/**
- * ImportOperation interface.
- *
- * @author ranger
- * @version $Id: $
+ * The Class OnmsUpgradeComparator.
+ * By default, the implementations are going to be ordered according with the order integer.
+ *
+ * @author Alejandro Galue
*/
-public interface ImportOperation {
+public class OnmsUpgradeComparator implements Comparator {
- /**
- * gatherAdditionalData
- */
- void gatherAdditionalData();
-
- /**
- * persist
- *
- * @return a {@link java.util.List} object.
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
- List persist();
+ @Override
+ public int compare(OnmsUpgrade a, OnmsUpgrade b) {
+ return a.getOrder() - b.getOrder();
+ }
}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgradeException.java b/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgradeException.java
new file mode 100644
index 000000000000..5bab0ec8e1a9
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/api/OnmsUpgradeException.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+
+package org.opennms.upgrade.api;
+
+/**
+ * The Class OnmsUpgradeException.
+ *
+ * @author Alejandro Galue
+ */
+@SuppressWarnings("serial")
+public class OnmsUpgradeException extends Exception {
+
+ /**
+ * Instantiates a new OpenNMS upgrade exception.
+ */
+ public OnmsUpgradeException() {
+ super();
+ }
+
+ /**
+ * Instantiates a new OpenNMS upgrade exception.
+ *
+ * @param msg the message
+ * @param t the exception causing the problem.
+ */
+ public OnmsUpgradeException(String msg, Throwable t) {
+ super(msg, t);
+ }
+
+ /**
+ * Instantiates a new OpenNMS upgrade exception.
+ *
+ * @param msg the message
+ */
+ public OnmsUpgradeException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Instantiates a new OpenNMS upgrade exception.
+ *
+ * @param t the exception causing the problem.
+ */
+ public OnmsUpgradeException(Throwable t) {
+ super(t);
+ }
+
+}
\ No newline at end of file
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/implementations/JmxRrdMigratorOffline.java b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/JmxRrdMigratorOffline.java
new file mode 100644
index 000000000000..64791ef4f2e9
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/JmxRrdMigratorOffline.java
@@ -0,0 +1,640 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.implementations;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.LineIterator;
+import org.jrobin.core.RrdDb;
+import org.opennms.core.utils.AlphaNumeric;
+import org.opennms.core.utils.ConfigFileConstants;
+import org.opennms.netmgt.config.CollectdConfigFactory;
+import org.opennms.netmgt.config.JMXDataCollectionConfigFactory;
+import org.opennms.netmgt.config.collectd.CollectdConfiguration;
+import org.opennms.netmgt.config.collectd.Collector;
+import org.opennms.netmgt.config.collectd.Package;
+import org.opennms.netmgt.config.collectd.Service;
+import org.opennms.upgrade.api.AbstractOnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+
+/**
+ * The Class RRD/JRB Migrator for JMX Collector.
+ *
+ * The fix for the following issues is going to break existing collected data specially for JRBs.
+ * For this reason, these files must be updated too.
+ *
+ * Issues fixed:
+ *
+ * - NMS-1539
+ * - NMS-3485
+ * - NMS-4592
+ * - NMS-4612
+ * - NMS-5247
+ * - NMS-5279
+ * - NMS-5824
+ *
+ *
+ * @author Alejandro Galue
+ */
+public class JmxRrdMigratorOffline extends AbstractOnmsUpgrade {
+
+ /** The JMX resource directories. */
+ private List jmxResourceDirectories;
+
+ /** The list of bad metrics. */
+ protected List badMetrics = new ArrayList();
+
+ /** Backup files. */
+ protected List backupFiles = new ArrayList();
+
+ /**
+ * Instantiates a new JMX RRD migrator offline.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public JmxRrdMigratorOffline() throws OnmsUpgradeException {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 4;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Fix the JRB names for the new JMX Collector: NMS-1539, NMS-3485, NMS-4592, NMS-4612, NMS-5247, NMS-5279, NMS-5824";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ printMainSettings();
+ if (isInstalledVersionGreaterOrEqual(1, 12, 2)) {
+ try {
+ CollectdConfigFactory.init();
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't initialize collectd-configuration.xml because " + e.getMessage());
+ }
+ try {
+ JMXDataCollectionConfigFactory.init();
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't initialize jmx-datacollection-config.xml because " + e.getMessage());
+ }
+ for (File jmxResourceDir : getJmxResourceDirectories()) {
+ log("Backing up %s\n", jmxResourceDir);
+ zipDir(new File(jmxResourceDir.getAbsolutePath() + ZIP_EXT), jmxResourceDir);
+ }
+ } else {
+ throw new OnmsUpgradeException("This upgrade procedure requires at least OpenNMS 1.12.2, the current version is " + getOpennmsVersion());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ for (File jmxResourceDir : getJmxResourceDirectories()) {
+ File zip = new File(jmxResourceDir.getAbsolutePath() + ZIP_EXT);
+ if (zip.exists()) {
+ log("Removing backup %s\n", zip);
+ FileUtils.deleteQuietly(zip);
+ }
+ }
+ for (File backupFile : backupFiles) {
+ log("Removing backup %s\n", backupFile);
+ FileUtils.deleteQuietly(backupFile);
+ FileUtils.deleteQuietly(new File(backupFile.getAbsolutePath().replaceFirst(ZIP_EXT, ".temp")));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ try {
+ for (File jmxResourceDir : getJmxResourceDirectories()) {
+ File zip = new File(jmxResourceDir.getAbsolutePath() + ZIP_EXT);
+ FileUtils.deleteDirectory(jmxResourceDir);
+ jmxResourceDir.mkdirs();
+ unzipFile(zip, jmxResourceDir);
+ zip.delete();
+ }
+ File configDir = new File(ConfigFileConstants.getFilePathString());
+ for (File backupFile : backupFiles) {
+ unzipFile(backupFile, configDir);
+ }
+ } catch (IOException e) {
+ throw new OnmsUpgradeException("Can't restore the backup files because " + e.getMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ try {
+ // Fixing JRB/RRD files
+ final boolean isRrdtool = isRrdToolEnabled();
+ final boolean storeByGroup = isStoreByGroupEnabled();
+ for (File jmxResourceDir : getJmxResourceDirectories()) {
+ if (storeByGroup) {
+ processGroupFiles(jmxResourceDir, isRrdtool);
+ } else {
+ processSingleFiles(jmxResourceDir, isRrdtool);
+ }
+ }
+ // Fixing JMX Configuration File
+ File jmxConfigFile = null;
+ try {
+ jmxConfigFile = ConfigFileConstants.getFile(ConfigFileConstants.JMX_DATA_COLLECTION_CONF_FILE_NAME);
+ } catch (IOException e) {
+ throw new OnmsUpgradeException("Can't find JMX Configuration file (ignoring processing)");
+ }
+ fixJmxConfigurationFile(jmxConfigFile);
+ // List Bad Metrics:
+ log("Found %s Bad Metrics: %s\n", badMetrics.size(), badMetrics);
+ // Fixing Graph Templates
+ File jmxGraphsFile = new File(ConfigFileConstants.getFilePathString(), "snmp-graph.properties");
+ fixJmxGraphTemplateFile(jmxGraphsFile);
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't upgrade the JRBs because " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Fixes a JMX configuration file.
+ *
+ * @param jmxConfigFile the JMX configuration file
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ private void fixJmxConfigurationFile(File jmxConfigFile) throws OnmsUpgradeException {
+ try {
+ log("Updating JMX metric definitions on %s\n", jmxConfigFile);
+ zipFile(jmxConfigFile);
+ backupFiles.add(new File(jmxConfigFile.getAbsolutePath() + ZIP_EXT));
+ File outputFile = new File(jmxConfigFile.getCanonicalFile() + ".temp");
+ FileWriter w = new FileWriter(outputFile);
+ Pattern extRegex = Pattern.compile("import-mbeans[>](.+)[<]");
+ Pattern aliasRegex = Pattern.compile("alias=\"([^\"]+\\.[^\"]+)\"");
+ List externalFiles = new ArrayList();
+ for (LineIterator it = FileUtils.lineIterator(jmxConfigFile); it.hasNext();) {
+ String line = it.next();
+ Matcher m = extRegex.matcher(line);
+ if (m.find()) {
+ externalFiles.add(new File(jmxConfigFile.getParentFile(), m.group(1)));
+ }
+ m = aliasRegex.matcher(line);
+ if (m.find()) {
+ String badDs = m.group(1);
+ String fixedDs = getFixedDsName(badDs);
+ log(" Replacing bad alias %s with %s on %s\n", badDs, fixedDs, line.trim());
+ line = line.replaceAll(badDs, fixedDs);
+ if (badMetrics.contains(badDs) == false) {
+ badMetrics.add(badDs);
+ }
+ }
+ w.write(line + "\n");
+ }
+ w.close();
+ FileUtils.deleteQuietly(jmxConfigFile);
+ FileUtils.moveFile(outputFile, jmxConfigFile);
+ if (!externalFiles.isEmpty()) {
+ for (File configFile : externalFiles) {
+ fixJmxConfigurationFile(configFile);
+ }
+ }
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't fix " + jmxConfigFile + " because " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Fixes a JMX graph template file.
+ *
+ * @param jmxTemplateFile the JMX template file
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ private void fixJmxGraphTemplateFile(File jmxTemplateFile) throws OnmsUpgradeException {
+ try {
+ log("Updating JMX graph templates on %s\n", jmxTemplateFile);
+ zipFile(jmxTemplateFile);
+ backupFiles.add(new File(jmxTemplateFile.getAbsolutePath() + ZIP_EXT));
+ File outputFile = new File(jmxTemplateFile.getCanonicalFile() + ".temp");
+ FileWriter w = new FileWriter(outputFile);
+ Pattern defRegex = Pattern.compile("DEF:.+:(.+\\..+):");
+ Pattern colRegex = Pattern.compile("\\.columns=(.+)$");
+ Pattern incRegex = Pattern.compile("^include.directory=(.+)$");
+ List externalFiles = new ArrayList();
+ boolean override = false;
+ for (LineIterator it = FileUtils.lineIterator(jmxTemplateFile); it.hasNext();) {
+ String line = it.next();
+ Matcher m = incRegex.matcher(line);
+ if (m.find()) {
+ File includeDirectory = new File(jmxTemplateFile.getParentFile(), m.group(1));
+ if (includeDirectory.isDirectory()) {
+ FilenameFilter propertyFilesFilter = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return (name.endsWith(".properties"));
+ }
+ };
+ for (File file : includeDirectory.listFiles(propertyFilesFilter)) {
+ externalFiles.add(file);
+ }
+ }
+ }
+ m = colRegex.matcher(line);
+ if (m.find()) {
+ String[] badColumns = m.group(1).split(",(\\s)?");
+ for (String badDs : badColumns) {
+ String fixedDs = getFixedDsName(badDs);
+ if (fixedDs.equals(badDs)) {
+ continue;
+ }
+ if (badMetrics.contains(badDs)) {
+ override = true;
+ log(" Replacing bad data source %s with %s on %s\n", badDs, fixedDs, line);
+ line = line.replaceAll(badDs, fixedDs);
+ } else {
+ log(" Warning: a bad data source not related with JMX has been found: %s (this won't be updated)\n", badDs);
+ }
+ }
+ }
+ m = defRegex.matcher(line);
+ if (m.find()) {
+ String badDs = m.group(1);
+ if (badMetrics.contains(badDs)) {
+ override = true;
+ String fixedDs = getFixedDsName(badDs);
+ log(" Replacing bad data source %s with %s on %s\n", badDs, fixedDs, line);
+ line = line.replaceAll(badDs, fixedDs);
+ } else {
+ log(" Warning: a bad data source not related with JMX has been found: %s (this won't be updated)\n", badDs);
+ }
+ }
+ w.write(line + "\n");
+ }
+ w.close();
+ if (override) {
+ FileUtils.deleteQuietly(jmxTemplateFile);
+ FileUtils.moveFile(outputFile, jmxTemplateFile);
+ } else {
+ FileUtils.deleteQuietly(outputFile);
+ }
+ if (!externalFiles.isEmpty()) {
+ for (File configFile : externalFiles) {
+ fixJmxGraphTemplateFile(configFile);
+ }
+ }
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't fix " + jmxTemplateFile + " because " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Gets the JMX resource directories.
+ *
+ * @return the JMX resource directories
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ private List getJmxResourceDirectories() throws OnmsUpgradeException {
+ if (jmxResourceDirectories == null) {
+ jmxResourceDirectories = new ArrayList();
+ CollectdConfiguration config;
+ try {
+ config = CollectdConfigFactory.getInstance().getCollectdConfig().getConfig();
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't upgrade the JRBs because " + e.getMessage(), e);
+ }
+ List services = getJmxServices(config);
+ log("JMX services found: %s\n", services);
+ List jmxFriendlyNames = new ArrayList();
+ for (String service : services) {
+ Service svc = getServiceObject(config, service);
+ String friendlyName = getSvcPropertyValue(svc, "friendly-name");
+ jmxFriendlyNames.add(friendlyName);
+ }
+ log("JMX friendly names found: %s\n", jmxFriendlyNames);
+ File rrdDir = new File(JMXDataCollectionConfigFactory.getInstance().getRrdPath());
+ findJmxDirectories(rrdDir, jmxFriendlyNames, jmxResourceDirectories);
+ if (jmxResourceDirectories.isEmpty()) {
+ log("Warning: no JMX directories found on %s\n", rrdDir);
+ }
+ }
+ return jmxResourceDirectories;
+ }
+
+ /**
+ * Find JMX directories.
+ *
+ * @param rrdDir the RRD directory
+ * @param jmxfriendlyNames the JMX friendly names
+ * @param jmxDirectories the target list for JMX directories
+ */
+ private void findJmxDirectories(final File rrdDir, final List jmxfriendlyNames, final List jmxDirectories) {
+ File[] files = rrdDir.listFiles();
+ if (files == null) {
+ return;
+ }
+ for (File file : files) {
+ if (file.isDirectory()) {
+ boolean valid = false;
+ for (String friendlyName : jmxfriendlyNames) {
+ if (file.getAbsolutePath().endsWith(friendlyName)) {
+ valid = true;
+ }
+ }
+ if (valid) {
+ jmxDirectories.add(file);
+ }
+ findJmxDirectories(file, jmxfriendlyNames, jmxDirectories);
+ }
+ }
+ }
+
+ /**
+ * Process single files.
+ *
+ * @param resourceDir the resource directory
+ * @param isRrdtool the is RRDtool enabled
+ * @throws Exception the exception
+ */
+ private void processSingleFiles(File resourceDir, boolean isRrdtool) throws Exception {
+ // META
+ final String metaExt = ".meta";
+ File[] metaFiles = getFiles(resourceDir, metaExt);
+ if (metaFiles == null) {
+ log("Warning: there are no %s files on %s\n", metaExt, resourceDir);
+ } else {
+ for (final File metaFile : metaFiles) {
+ log("Processing META %s\n", metaFile);
+ String dsName = metaFile.getName().replaceFirst(metaExt, "");
+ String newName = getFixedDsName(dsName);
+ if (!dsName.equals(newName)) {
+ Properties meta = new Properties();
+ Properties newMeta = new Properties();
+ meta.load(new FileInputStream(metaFile));
+ for (Object k : meta.keySet()) {
+ String key = (String) k;
+ String newKey = key.replaceAll(dsName, newName);
+ newMeta.put(newKey, newName);
+ }
+ File newFile = new File(metaFile.getParentFile(), newName + metaExt);
+ log("Re-creating META into %s\n", newFile);
+ newMeta.store(new FileWriter(newFile), null);
+ if (!metaFile.equals(newFile))
+ metaFile.delete();
+ }
+ }
+ }
+ // JRBs
+ final String rrdExt = getRrdExtension();
+ File[] jrbFiles = getFiles(resourceDir, rrdExt);
+ if (jrbFiles == null) {
+ log("Warning: there are no %s files on %s\n", rrdExt, resourceDir);
+ } else {
+ for (final File jrbFile : jrbFiles) {
+ log("Processing %s %s\n", rrdExt.toUpperCase(), jrbFile);
+ String dsName = jrbFile.getName().replaceFirst(rrdExt, "");
+ String newName = getFixedDsName(dsName);
+ File newFile = new File(jrbFile.getParentFile(), newName + rrdExt);
+ if (!dsName.equals(newName)) {
+ try {
+ log("Renaming %s to %s\n", rrdExt.toUpperCase(), newFile);
+ FileUtils.moveFile(jrbFile, newFile);
+ } catch (Exception e) {
+ log("Warning: Can't move file because: %s", e.getMessage());
+ continue;
+ }
+ }
+ if (!isRrdtool) { // Only the JRBs may contain invalid DS inside
+ updateJrb(newFile);
+ }
+ }
+ }
+ }
+
+ /**
+ * Process group files.
+ *
+ * @param resourceDir the resource directory
+ * @param isRrdtool the is RRDtool enabled
+ * @throws Exception the exception
+ */
+ private void processGroupFiles(File resourceDir, boolean isRrdtool) throws Exception {
+ // DS
+ File dsFile = new File(resourceDir, "ds.properties");
+ log("Processing DS %s\n", dsFile);
+ if (dsFile.exists()) {
+ Properties dsProperties = new Properties();
+ Properties newDsProperties = new Properties();
+ dsProperties.load(new FileInputStream(dsFile));
+ for (Object key : dsProperties.keySet()) {
+ String oldName = (String) key;
+ String newName = getFixedDsName(oldName);
+ String oldFile = dsProperties.getProperty(oldName);
+ String newFile = getFixedFileName(oldFile);
+ newDsProperties.put(newName, newFile);
+ }
+ newDsProperties.store(new FileWriter(dsFile), null);
+ }
+ // META
+ final String metaExt = ".meta";
+ File[] metaFiles = getFiles(resourceDir, metaExt);
+ if (metaFiles == null) {
+ log("Warning: there are no %s files on %s\n", metaExt, resourceDir);
+ } else {
+ for (final File metaFile : metaFiles) {
+ log("Processing META %s\n", metaFile);
+ Properties meta = new Properties();
+ Properties newMeta = new Properties();
+ meta.load(new FileInputStream(metaFile));
+ for (Object k : meta.keySet()) {
+ String key = (String) k;
+ String dsName = meta.getProperty(key);
+ String newName = getFixedDsName(dsName);
+ String newKey = key.replaceAll(dsName, newName);
+ newMeta.put(newKey, newName);
+ }
+ File newFile = new File(metaFile.getParentFile(), getFixedFileName(metaFile.getName().replaceFirst(metaExt, "")) + metaExt);
+ log("Recreating META into %s\n", newFile);
+ newMeta.store(new FileWriter(newFile), null);
+ if (!metaFile.equals(newFile))
+ metaFile.delete();
+ }
+ }
+ // JRBs
+ final String rrdExt = getRrdExtension();
+ File[] jrbFiles = getFiles(resourceDir, rrdExt);
+ if (jrbFiles == null) {
+ log("Warning: there are no %s files on %s\n", rrdExt, resourceDir);
+ } else {
+ for (final File jrbFile : jrbFiles) {
+ log("Processing %s %s\n", rrdExt.toUpperCase(), jrbFile);
+ File newFile = new File(jrbFile.getParentFile(), getFixedFileName(jrbFile.getName().replaceFirst(rrdExt, "")) + rrdExt);
+ if (!jrbFile.equals(newFile)) {
+ try {
+ log("Renaming %s to %s\n", rrdExt.toUpperCase(), newFile);
+ FileUtils.moveFile(jrbFile, newFile);
+ } catch (Exception e) {
+ log("Warning: Can't move file because: %s", e.getMessage());
+ continue;
+ }
+ }
+ if (!isRrdtool) { // Only the JRBs may contain invalid DS inside
+ updateJrb(newFile);
+ }
+ }
+ }
+ }
+
+ /**
+ * Update JRB.
+ *
+ * @param jrbFile the JRB file
+ * @throws Exception the exception
+ */
+ private void updateJrb(File jrbFile) throws Exception {
+ RrdDb rrdDb = new RrdDb(jrbFile);
+ for (String ds : rrdDb.getDsNames()) {
+ String newDs = getFixedDsName(ds);
+ if (!ds.equals(newDs)) {
+ log("Updating internal DS name from %s to %s\n", ds, newDs);
+ rrdDb.getDatasource(ds).setDsName(newDs);
+ }
+ }
+ rrdDb.close();
+ }
+
+ /**
+ * Gets the JMX services.
+ *
+ * @param config the Collectd's configuration
+ * @return the list of JMX services
+ */
+ private List getJmxServices(CollectdConfiguration config) {
+ List services = new ArrayList();
+ for (Collector c : config.getCollectorCollection()) {
+ // The following code has been made that way to avoid a dependency with opennms-services
+ // TODO Depends on opennms-services is not that bad, considering that some customers could have different implementations.
+ if (c.getClassName().matches(".*(JBoss|JMXSecure|Jsr160|MX4J)Collector$")) {
+ services.add(c.getService());
+ }
+ }
+ return services;
+ }
+
+ /**
+ * Gets the service object.
+ *
+ * @param config the Collectd's configuration
+ * @param service the service's name
+ * @return the service object
+ */
+ private Service getServiceObject(CollectdConfiguration config, String service) {
+ for (Package pkg : config.getPackageCollection()) {
+ for (Service svc : pkg.getServiceCollection()) {
+ if (svc.getName().equals(service)) {
+ return svc;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets the value of a service property.
+ *
+ * @param svc the service's name
+ * @param propertyName the property name
+ * @return the service property value
+ */
+ private String getSvcPropertyValue(Service svc, String propertyName) {
+ for (org.opennms.netmgt.config.collectd.Parameter p : svc.getParameterCollection()) {
+ if (p.getKey().equals(propertyName)) {
+ return p.getValue();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets the fixed DS name.
+ *
+ * @param dsName the DS name
+ * @return the fixed DS name
+ */
+ protected String getFixedDsName(String dsName) {
+ if (dsName.contains(".")) {
+ String parts[] = dsName.split("\\.");
+ return parts[0] + parts[1].substring(0, 1).toUpperCase() + parts[1].substring(1);
+ }
+ return dsName;
+ }
+
+ /**
+ * Gets the fixed file name.
+ *
+ * @param oldFile the old file
+ * @return the fixed file name
+ */
+ protected String getFixedFileName(String oldFile) {
+ return AlphaNumeric.parseAndReplace(oldFile, '_');
+ }
+
+}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/implementations/RequisitionsMigratorOffline.java b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/RequisitionsMigratorOffline.java
new file mode 100644
index 000000000000..d12d28a99a3d
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/RequisitionsMigratorOffline.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.implementations;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.opennms.core.utils.ConfigFileConstants;
+import org.opennms.core.xml.JaxbUtils;
+import org.opennms.netmgt.provision.persist.requisition.Requisition;
+import org.opennms.upgrade.api.AbstractOnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+
+/**
+ * The Class Requisitions Migrator.
+ *
+ * The attributes non-ip-snmp-primary
and non-ip-interfaces
which are valid in 1.10 have been removed in 1.12.
+ * This tool will parse the raw requisitions XML and remove those tags.
+ *
+ * Issues fixed:
+ *
+ * - NMS-5630
+ * - NMS-5571
+ *
+ *
+ * @author Alejandro Galue
+ */
+public class RequisitionsMigratorOffline extends AbstractOnmsUpgrade {
+
+ /** The requisition directory. */
+ private File requisitionDir;
+
+ /**
+ * Instantiates a new requisitions migrator offline.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public RequisitionsMigratorOffline() throws OnmsUpgradeException {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Remove non-ip-snmp-primary and non-ip-interfaces from requisitions: NMS-5630, NMS-5571";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ log("Backing up: %s\n", getRequisitionDir());
+ zipDir(getBackupFile(), getRequisitionDir());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ File zip = getBackupFile();
+ if (zip.exists()) {
+ log("Removing backup %s\n", zip);
+ zip.delete();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ File zip = getBackupFile();
+ unzipFile(zip, getRequisitionDir());
+ zip.delete();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ try {
+ for (File req : FileUtils.listFiles(getRequisitionDir(), new String[]{"xml"}, true)) {
+ log("Processing %s\n", req);
+ String content = IOUtils.toString(new FileInputStream(req), "UTF-8");
+ String output = content.replaceAll(" non-ip-(snmp-primary|interfaces)=\"[^\"]+\"", "");
+ if (content.length() != output.length()) {
+ log(" Updating and parsing the requisition\n", req);
+ IOUtils.write(output, new FileOutputStream(req), "UTF-8");
+ Requisition requisition = JaxbUtils.unmarshal(Requisition.class, req, true);
+ if (requisition == null) {
+ throw new OnmsUpgradeException("Can't parse requisition " + req);
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't upgrade requisitions because " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Gets the requisition directory.
+ *
+ * @return the requisition directory
+ */
+ private File getRequisitionDir() {
+ if (requisitionDir == null) {
+ requisitionDir = new File(ConfigFileConstants.getFilePathString() + "imports");
+ }
+ return requisitionDir;
+ }
+
+ /**
+ * Gets the backup file.
+ *
+ * @return the backup file
+ */
+ private File getBackupFile() {
+ return new File(getRequisitionDir().getAbsoluteFile() + ZIP_EXT);
+ }
+}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/implementations/SnmpInterfaceRrdMigratorOnline.java b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/SnmpInterfaceRrdMigratorOnline.java
new file mode 100644
index 000000000000..ff5caf9ba3f0
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/SnmpInterfaceRrdMigratorOnline.java
@@ -0,0 +1,354 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.implementations;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.opennms.core.utils.DBUtils;
+import org.opennms.netmgt.config.DataCollectionConfigFactory;
+import org.opennms.netmgt.config.KSC_PerformanceReportFactory;
+import org.opennms.netmgt.config.kscReports.Graph;
+import org.opennms.netmgt.config.kscReports.Report;
+import org.opennms.netmgt.rrd.model.RrdConvertUtils;
+import org.opennms.netmgt.rrd.model.v1.RRDv1;
+import org.opennms.netmgt.rrd.model.v3.RRDv3;
+import org.opennms.upgrade.api.AbstractOnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+
+/**
+ * The Class RRD/JRB Migrator for SNMP Interfaces Data (Online Version)
+ *
+ * 1.12 always add the MAC Address to the snmpinterface table if exist, which
+ * is different from the 1.10 behavior. For this reason, some interfaces are going
+ * to appear twice, and the data must be merged.
+ *
+ * This tool requires that OpenNMS 1.12 is running for a while to be sure that
+ * all the MAC addresses have been updated, and the directories already exist.
+ *
+ * Issues fixed:
+ *
+ *
+ * @author Alejandro Galue
+ */
+public class SnmpInterfaceRrdMigratorOnline extends AbstractOnmsUpgrade {
+
+ /** The interfaces to merge. */
+ private List interfacesToMerge;
+
+ /**
+ * Instantiates a new SNMP interface RRD migrator online.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public SnmpInterfaceRrdMigratorOnline() throws OnmsUpgradeException {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ public int getOrder() {
+ return 2;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ public String getDescription() {
+ return "Merge SNMP Interface directories (Online Version): NMS-6056";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ public boolean requiresOnmsRunning() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ public void preExecute() throws OnmsUpgradeException {
+ printMainSettings();
+ if (getRrdExtension() == null) {
+ throw new OnmsUpgradeException("Can't find the configured extension for JRB/RRD.");
+ }
+ try {
+ DataCollectionConfigFactory.init();
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't initialize datacollection-config.xml because " + e.getMessage());
+ }
+ try {
+ KSC_PerformanceReportFactory.init();
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't initialize ksc-performance-reports.xml because " + e.getMessage());
+ }
+ interfacesToMerge = getInterfacesToMerge();
+ for (SnmpInterfaceUpgrade intf : interfacesToMerge) {
+ File[] targets = { intf.getOldInterfaceDir(), intf.getNewInterfaceDir() };
+ for (File target : targets) {
+ if (target.exists()) {
+ log("Backing up: %s\n", target);
+ zipDir(new File(target.getAbsolutePath() + ZIP_EXT), target);
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ public void postExecute() throws OnmsUpgradeException {
+ for (SnmpInterfaceUpgrade intf : interfacesToMerge) {
+ File[] targets = { intf.getOldInterfaceDir(), intf.getNewInterfaceDir() };
+ for (File target : targets) {
+ File zip = new File(target.getAbsolutePath() + ZIP_EXT);
+ if (zip.exists()) {
+ log("Removing backup: %s\n", zip);
+ zip.delete();
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ // The idea is to roll back only the interfaces that weren't updated. A global roll back is not necessary.
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ for (SnmpInterfaceUpgrade intf : interfacesToMerge) {
+ try {
+ merge(intf.getOldInterfaceDir(), intf.getNewInterfaceDir());
+ } catch (Exception e) {
+ StringWriter w = new StringWriter();
+ PrintWriter p = new PrintWriter(w);
+ e.printStackTrace(p);
+ log("Error: Can't upgrade %s because %s: %s. Rolling back changes\n", intf, e.getMessage(), w.toString());
+ File[] targets = { intf.getOldInterfaceDir(), intf.getNewInterfaceDir() };
+ for (File target : targets) {
+ File zip = new File(target.getAbsolutePath() + ZIP_EXT);
+ try {
+ FileUtils.deleteDirectory(target);
+ } catch (IOException e1) {
+ log("Warning: can't delete directory %s\n", target);
+ }
+ target.mkdirs();
+ unzipFile(zip, target);
+ zip.delete();
+ }
+ }
+ }
+ fixKscReports();
+ }
+
+ /**
+ * Fix KSC reports.
+ */
+ protected void fixKscReports() throws OnmsUpgradeException {
+ log("Fixing KSC Reports.\n");
+ boolean changed = false;
+ for (Integer reportId : KSC_PerformanceReportFactory.getInstance().getReportList().keySet()) {
+ Report report = KSC_PerformanceReportFactory.getInstance().getReportByIndex(reportId);
+ log(" Checking report %s\n", report.getTitle());
+ for (Graph graph : report.getGraphCollection()) {
+ for (SnmpInterfaceUpgrade intf : interfacesToMerge) {
+ if (intf.shouldUpdate(graph.getResourceId())) {
+ changed = true;
+ graph.setResourceId(intf.getNewResourceId());
+ }
+ }
+ }
+ }
+ if (changed) {
+ log("Updating KSC reports.");
+ try {
+ KSC_PerformanceReportFactory.getInstance().saveCurrent();
+ } catch (Exception e) {
+ log("Warning: can't save KSC Reports because %s\n", e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Gets the interfaces to merge.
+ *
+ * @return the list of interfaces to merge
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected List getInterfacesToMerge() throws OnmsUpgradeException {
+ List interfacesToMerge = new ArrayList();
+ Connection conn = getDbConnection();
+ final DBUtils db = new DBUtils(getClass());
+ db.watch(conn);
+ try {
+ Statement st = conn.createStatement();
+ db.watch(st);
+ String query = "SELECT n.nodeid, n.foreignsource, n.foreignid, i.snmpifdescr, i.snmpifname, i.snmpphysaddr from node n, snmpinterface i where n.nodeid = i.nodeid and i.snmpcollect in ('C','UC') and i.snmpphysaddr is not null";
+ ResultSet rs = st.executeQuery(query);
+ db.watch(rs);
+ while (rs.next()) {
+ SnmpInterfaceUpgrade intf = new SnmpInterfaceUpgrade(rs, isStoreByForeignSourceEnabled());
+ if (intf.shouldMerge()) {
+ interfacesToMerge.add(intf);
+ }
+ }
+ } catch (Exception e) {
+ log("Error: can't retrieve data from the OpenNMS Database because " + e.getMessage());
+ } finally {
+ db.cleanUp();
+ }
+ return interfacesToMerge;
+ }
+
+ /**
+ * Merge.
+ *
+ * @param oldDir the old directory
+ * @param newDir the new directory
+ * @throws Exception the exception
+ */
+ protected void merge(File oldDir, File newDir) throws Exception {
+ log("Merging data from %s to %s\n", oldDir, newDir);
+ if (newDir.exists()) {
+ File[] rrdFiles = getFiles(oldDir, getRrdExtension());
+ if (rrdFiles == null) {
+ log("Warning: there are no %s files on %s\n", getRrdExtension(), oldDir);
+ } else {
+ for (File source : rrdFiles) {
+ File dest = new File(newDir, source.getName());
+ if (dest.exists()) {
+ if (isRrdToolEnabled()) {
+ mergeRrd(source, dest);
+ } else {
+ mergeJrb(source, dest);
+ }
+ } else {
+ log(" Warning: %s doesn't exist\n", dest);
+ }
+ }
+ }
+ try {
+ log(" removing old directory %s\n", oldDir.getName());
+ FileUtils.deleteDirectory(oldDir);
+ } catch (Exception e) {
+ log(" Warning: can't delete old directory because %s", e.getMessage());
+ }
+ } else {
+ try {
+ log(" moving %s to %s\n", oldDir.getName(), newDir.getName());
+ FileUtils.moveDirectory(oldDir, newDir);
+ } catch (Exception e) {
+ log(" Warning: can't rename directory because %s", e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Merge RRDs.
+ *
+ * @param source the source RRD
+ * @param dest the destination RRD
+ * @throws Exception the exception
+ */
+ protected void mergeRrd(File source, File dest) throws Exception {
+ log(" merging RRD %s into %s\n", source, dest);
+ RRDv3 rrdSrc = RrdConvertUtils.dumpRrd(source);
+ RRDv3 rrdDst = RrdConvertUtils.dumpRrd(dest);
+ if (rrdSrc == null || rrdDst == null) {
+ log(" Warning: can't load RRDs (ingoring merge).\n");
+ return;
+ }
+ rrdDst.merge(rrdSrc);
+ final File outputFile = new File(dest.getCanonicalPath() + ".merged");
+ RrdConvertUtils.restoreRrd(rrdDst, outputFile);
+ if (dest.exists()) {
+ FileUtils.deleteQuietly(dest);
+ }
+ FileUtils.moveFile(outputFile, dest);
+ }
+
+ /**
+ * Merge JRBs.
+ *
+ * @param source the source JRB
+ * @param dest the destination JRB
+ */
+ protected void mergeJrb(File source, File dest) throws Exception {
+ log(" merging JRB %s into %s\n", source, dest);
+ RRDv1 rrdSrc = RrdConvertUtils.dumpJrb(source);
+ RRDv1 rrdDst = RrdConvertUtils.dumpJrb(dest);
+ if (rrdSrc == null || rrdDst == null) {
+ log(" Warning: can't load JRBs (ingoring merge).\n");
+ return;
+ }
+ rrdDst.merge(rrdSrc);
+ final File outputFile = new File(dest.getCanonicalPath() + ".merged");
+ RrdConvertUtils.restoreJrb(rrdDst, outputFile);
+ if (dest.exists()) {
+ FileUtils.deleteQuietly(dest);
+ }
+ FileUtils.moveFile(outputFile, dest);
+ }
+
+ /**
+ * Gets the node directory.
+ *
+ * @param nodeId the node id
+ * @param foreignSource the foreign source
+ * @param foreignId the foreign id
+ * @return the node directory
+ */
+ protected File getNodeDirectory(int nodeId, String foreignSource, String foreignId) {
+ File dir = new File(DataCollectionConfigFactory.getInstance().getRrdPath(), String.valueOf(nodeId));
+ if (Boolean.getBoolean("org.opennms.rrd.storeByForeignSource") && !(foreignSource == null) && !(foreignId == null)) {
+ File fsDir = new File(DataCollectionConfigFactory.getInstance().getRrdPath(), "fs" + File.separatorChar + foreignSource);
+ dir = new File(fsDir, foreignId);
+ }
+ return dir;
+ }
+
+}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/implementations/SnmpInterfaceUpgrade.java b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/SnmpInterfaceUpgrade.java
new file mode 100644
index 000000000000..5ab36b56bf52
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/implementations/SnmpInterfaceUpgrade.java
@@ -0,0 +1,302 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.implementations;
+
+import java.io.File;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.opennms.core.utils.RrdLabelUtils;
+import org.opennms.netmgt.config.DataCollectionConfigFactory;
+import org.opennms.netmgt.model.OnmsResource;
+
+/**
+ * The Class SnmpInterfaceUpgrade.
+ *
+ * @author Alejandro Galue
+ */
+public class SnmpInterfaceUpgrade {
+
+ /** The node's directory. */
+ private File nodeDir;
+
+ /** The node's id. */
+ private int nodeId;
+
+ /** The node's foreign id. */
+ private String foreignId;
+
+ /** The node's foreign source. */
+ private String foreignSource;
+
+ /** The SNMP interface name. */
+ private String ifName;
+
+ /** The SNMP interface description. */
+ private String ifDescr;
+
+ /** The SNMP physical address. */
+ private String physAddr;
+
+ /** The old RRD label. */
+ private String oldRrdLabel;
+
+ /** The new RRD label. */
+ private String newRrdLabel;
+
+ /** The store by foreign source. */
+ private boolean storeByForeignSource;
+
+ /**
+ * Instantiates a new SNMP interface upgrade.
+ *
+ * @param rs the ResultSet
+ * @param storeByForeignSource true, if the store by foreign source is enabled
+ * @throws SQLException the sQL exception
+ */
+ public SnmpInterfaceUpgrade(ResultSet rs, boolean storeByForeignSource) throws SQLException {
+ nodeId = rs.getInt("nodeid");
+ foreignSource = rs.getString("foreignsource");
+ foreignId = rs.getString("foreignid");
+ ifDescr = rs.getString("snmpifdescr");
+ ifName = rs.getString("snmpifname");
+ physAddr = rs.getString("snmpphysaddr");
+ this.storeByForeignSource = storeByForeignSource;
+ initialize();
+ }
+
+ /**
+ * Instantiates a new SNMP interface upgrade.
+ *
+ * @param nodeId the node id
+ * @param foreignSource the foreign source
+ * @param foreignId the foreign id
+ * @param ifDescr the SNMP interface description
+ * @param ifName the SNMP interface name
+ * @param physAddr the SNMP physical address
+ * @param storeByForeignSource true, if store by foreign source is enabled
+ */
+ public SnmpInterfaceUpgrade(int nodeId, String foreignSource,
+ String foreignId, String ifDescr, String ifName,
+ String physAddr, boolean storeByForeignSource) {
+ this.nodeId = nodeId;
+ this.foreignSource = foreignSource;
+ this.foreignId = foreignId;
+ this.ifDescr = ifDescr;
+ this.ifName = ifName;
+ this.physAddr = physAddr;
+ this.storeByForeignSource = storeByForeignSource;
+ initialize();
+ }
+
+ /**
+ * Initialize.
+ */
+ private void initialize() {
+ oldRrdLabel = RrdLabelUtils.computeLabelForRRD(ifName, ifDescr, null);
+ newRrdLabel = RrdLabelUtils.computeLabelForRRD(ifName, ifDescr, physAddr);
+ nodeDir = getNodeDirectory(nodeId, foreignSource, foreignId);
+ }
+
+ /**
+ * Gets the node directory.
+ *
+ * @return the node directory
+ */
+ public File getNodeDir() {
+ return nodeDir;
+ }
+
+ /**
+ * Gets the old interface directory.
+ *
+ * @return the old interface directory
+ */
+ public File getOldInterfaceDir() {
+ return new File(getNodeDir(), getOldRrdLabel());
+ }
+
+ /**
+ * Gets the new interface directory.
+ *
+ * @return the new interface directory
+ */
+ public File getNewInterfaceDir() {
+ return new File(getNodeDir(), getNewRrdLabel());
+ }
+
+ /**
+ * Gets the node id.
+ *
+ * @return the node id
+ */
+ public int getNodeId() {
+ return nodeId;
+ }
+
+ /**
+ * Gets the foreign id.
+ *
+ * @return the foreign id
+ */
+ public String getForeignId() {
+ return foreignId;
+ }
+
+ /**
+ * Gets the foreign source.
+ *
+ * @return the foreign source
+ */
+ public String getForeignSource() {
+ return foreignSource;
+ }
+
+ /**
+ * Gets the interface name.
+ *
+ * @return the interface name
+ */
+ public String getIfName() {
+ return ifName;
+ }
+
+ /**
+ * Gets the interface description.
+ *
+ * @return the interface description
+ */
+ public String getIfDescr() {
+ return ifDescr;
+ }
+
+ /**
+ * Gets the physical address.
+ *
+ * @return the physical address
+ */
+ public String getPhysAddr() {
+ return physAddr;
+ }
+
+ /**
+ * Gets the old RRD label.
+ *
+ * @return the old RRD label
+ */
+ public String getOldRrdLabel() {
+ return oldRrdLabel;
+ }
+
+ /**
+ * Gets the new RRD label.
+ *
+ * @return the new RRD label
+ */
+ public String getNewRrdLabel() {
+ return newRrdLabel;
+ }
+
+ /**
+ * Checks if the interface directories should be merged
+ *
+ * @return true, if the interface directory should be merged
+ */
+ public boolean shouldMerge() {
+ // An SnmpInterfaceUpgrade entry only exist for SNMP interfaces with MAC Address.
+ // For this reason, if the old directory exist, that means, the interface statistics must be merged.
+ return getOldInterfaceDir().exists();
+ }
+
+ /**
+ * Gets the old resource id.
+ *
+ * @return the old resource id
+ */
+ public String getOldResourceId() {
+ return getResourceId(oldRrdLabel);
+ }
+
+ /**
+ * Gets the new resource id.
+ *
+ * @return the new resource id
+ */
+ public String getNewResourceId() {
+ return getResourceId(newRrdLabel);
+ }
+
+ /**
+ * Gets the resource id.
+ *
+ * @param label the label
+ * @return the resource id
+ */
+ private String getResourceId(String label) {
+ String parentType = storeByForeignSource ? "nodeSource" : "node";
+ String parentId = storeByForeignSource ? foreignSource + ':' + foreignId : Integer.toString(nodeId);
+ return OnmsResource.createResourceId(parentType, parentId, "interfaceSnmp", label);
+ }
+
+ /**
+ * Checks if the resourceId should be updated.
+ *
+ * @param resourceId the resource id to check
+ * @return true, if the resource should be updated
+ */
+ public boolean shouldUpdate(String resourceId) {
+ return resourceId.endsWith("interfaceSnmp[" + oldRrdLabel + "]");
+ }
+
+ /**
+ * Gets the node directory.
+ *
+ * @param nodeId the node id
+ * @param foreignSource the foreign source
+ * @param foreignId the foreign id
+ * @return the node directory
+ */
+ protected File getNodeDirectory(int nodeId, String foreignSource, String foreignId) {
+ String rrdPath = DataCollectionConfigFactory.getInstance().getRrdPath();
+ File dir = new File(rrdPath, String.valueOf(nodeId));
+ if (Boolean.getBoolean("org.opennms.rrd.storeByForeignSource") && !(foreignSource == null) && !(foreignId == null)) {
+ File fsDir = new File(rrdPath, "fs" + File.separatorChar + foreignSource);
+ dir = new File(fsDir, foreignId);
+ }
+ return dir;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "Interface[ifName=" + getIfName() + ", nodeId=" + getNodeId() + ", foreignSource=" + getForeignSource() + ", foreignId=" + getForeignId() + "]";
+ }
+
+}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/support/Upgrade.java b/core/upgrade/src/main/java/org/opennms/upgrade/support/Upgrade.java
new file mode 100644
index 000000000000..c0f1ffc8c174
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/support/Upgrade.java
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.support;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import org.opennms.core.utils.FuzzyDateFormatter;
+import org.opennms.netmgt.vmmgr.ControllerUtils;
+import org.opennms.upgrade.api.Ignore;
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeComparator;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.core.type.filter.AssignableTypeFilter;
+
+/**
+ * The Class Upgrade.
+ * This is the helper class that is going to be instantiated from outside OpenNMS to perform the upgrade operations.
+ *
+ * @author Alejandro Galue
+ */
+public class Upgrade {
+
+ /** The class scope. */
+ private String classScope = "org/opennms/upgrade"; // To avoid issues with OSGi and other classes.
+
+ /** The upgrade status object. */
+ private UpgradeStatus upgradeStatus;
+
+ /**
+ * Gets the upgrade status.
+ *
+ * @return the upgrade status
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public UpgradeStatus getUpgradeStatus() throws OnmsUpgradeException {
+ if (upgradeStatus == null) {
+ upgradeStatus = new UpgradeStatus();
+ }
+ return upgradeStatus;
+ }
+
+ /**
+ * Sets the upgrade status.
+ *
+ * @param upgradeStatus the new upgrade status
+ */
+ public void setUpgradeStatus(UpgradeStatus upgradeStatus) {
+ this.upgradeStatus = upgradeStatus;
+ }
+
+ /**
+ * Gets the class scope.
+ *
+ * @return the class scope
+ */
+ public String getClassScope() {
+ return classScope;
+ }
+
+ /**
+ * Sets the class scope.
+ *
+ * @param classScope the new class scope
+ */
+ public void setClassScope(String classScope) {
+ this.classScope = classScope;
+ }
+
+ /**
+ * Checks if is OpenNMS running.
+ *
+ * @return true, if is OpenNMS running
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected boolean isOpennmsRunning() {
+ try {
+ return ControllerUtils.getController().status() == 0;
+ } catch (Exception e) {
+ log("Warning: can't retrieve OpeNNMS status (assuming it is not running).\n");
+ return false;
+ }
+ }
+
+ /**
+ * Was executed.
+ *
+ * @param upg the upgrade implementation class
+ * @return true, if successful
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected boolean wasExecuted(OnmsUpgrade upg) throws OnmsUpgradeException {
+ return getUpgradeStatus().wasExecuted(upg);
+ }
+
+ /**
+ * Execute upgrade.
+ *
+ * @param upg the upgrade implementation class
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void executeUpgrade(OnmsUpgrade upg) {
+ Date start = new Date();
+ try {
+ if (wasExecuted(upg)) {
+ log(" Task %s has been executed at %s\n", upg.getId(), getUpgradeStatus().getLastExecutionTime(upg));
+ return;
+ }
+ log("- Running pre-execution phase\n");
+ upg.preExecute();
+ } catch (OnmsUpgradeException e) {
+ log(" Ignoring: %s\n", e.getMessage());
+ return;
+ }
+ try {
+ log("- Running execution phase\n");
+ upg.execute();
+ log("- Saving the execution state\n");
+ markAsExecuted(upg);
+ } catch (OnmsUpgradeException executeException) {
+ log(" Warning: can't perform the upgrade operation because: %s\n", executeException.getMessage());
+ try {
+ log("- Executing rollback phase\n");
+ upg.rollback();
+ } catch (OnmsUpgradeException rollbackException) {
+ log(" Warning: can't rollback the upgrade because: %s\n", rollbackException.getMessage());
+ rollbackException.printStackTrace();
+ }
+ }
+ try {
+ log("- Running post-execution phase\n");
+ upg.postExecute();
+ } catch (OnmsUpgradeException e) {
+ log(" Warning: can't run the post-execute phase because: %s\n", e.getMessage());
+ }
+ log("\nFinished in %s\n\n", FuzzyDateFormatter.calculateDifference(start, new Date()));
+ }
+
+ /**
+ * Mark as executed.
+ *
+ * @param upg the upgrade implementation class
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected void markAsExecuted(OnmsUpgrade upg) throws OnmsUpgradeException {
+ getUpgradeStatus().markAsExecuted(upg);
+ }
+
+ /**
+ * Log.
+ *
+ * @param msgFormat the message format
+ * @param args the message's arguments
+ */
+ protected void log(String msgFormat, Object... args) {
+ System.out.printf(msgFormat, args);
+ }
+
+ /**
+ * Gets the upgrade objects.
+ *
+ * @return the upgrade objects
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ protected List getUpgradeObjects() throws OnmsUpgradeException {
+ List upgrades = new ArrayList();
+ try {
+ ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
+ provider.addIncludeFilter(new AssignableTypeFilter(OnmsUpgrade.class));
+ Set components = provider.findCandidateComponents(getClassScope());
+ for (BeanDefinition component : components) {
+ if (component.isAbstract()) {
+ continue;
+ }
+ Class> cls = Class.forName(component.getBeanClassName());
+ if (cls.getAnnotation(Ignore.class) != null) {
+ continue;
+ }
+ OnmsUpgrade upgrade = (OnmsUpgrade) cls.newInstance();
+ upgrades.add(upgrade);
+ log("Found upgrade task %s\n", upgrade.getId());
+ }
+ Collections.sort(upgrades, new OnmsUpgradeComparator());
+ } catch (Exception e) {
+ throw new OnmsUpgradeException(" Can't find the upgrade classes because: " + e.getMessage(), e);
+ }
+ return upgrades;
+ }
+
+ /**
+ * Execute.
+ * Perform the upgrade operations.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public void execute() throws OnmsUpgradeException {
+ log("\n==============================================================================\n");
+ log("OpenNMS Upgrader");
+ log("\n==============================================================================\n\n");
+ log("OpenNMS is currently %s\n", (isOpennmsRunning() ? "running" : "stopped"));
+ List upgradeObjects = getUpgradeObjects();
+ for (OnmsUpgrade upg : upgradeObjects) {
+ log("Processing %s: %s\n", upg.getId(), upg.getDescription());
+ if (isOpennmsRunning()) {
+ if (upg.requiresOnmsRunning()) {
+ executeUpgrade(upg);
+ } else {
+ log(" Task %s requires that OpenNMS is stopped but it is running (ignoring)\n", upg.getId());
+ }
+ } else {
+ if (upg.requiresOnmsRunning()) {
+ log(" Task %s requires OpenNMS is running but it is stopped (ignoring)\n", upg.getId());
+ } else {
+ executeUpgrade(upg);
+ }
+ }
+ }
+ log("\nUpgrade completed successfully!\n");
+ }
+
+ /**
+ * The main method.
+ * This is the class that must be called externally to perform the upgrade.
+ *
+ * TODO: be able to pass the class scope (package filter)
+ * TODO: be able to pass the execution status file
+ *
+ * @param args the arguments
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public static void main(String args[]) throws OnmsUpgradeException {
+ new Upgrade().execute();
+ }
+}
diff --git a/core/upgrade/src/main/java/org/opennms/upgrade/support/UpgradeStatus.java b/core/upgrade/src/main/java/org/opennms/upgrade/support/UpgradeStatus.java
new file mode 100644
index 000000000000..f9755949a859
--- /dev/null
+++ b/core/upgrade/src/main/java/org/opennms/upgrade/support/UpgradeStatus.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.support;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.util.Date;
+import java.util.Properties;
+
+import org.opennms.core.utils.ConfigFileConstants;
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+
+/**
+ * The Class UpgradeStatus.
+ *
+ * @author Alejandro Galue
+ */
+public class UpgradeStatus {
+
+ /** The Constant STATUS_FILE. */
+ public static final String STATUS_FILE = "opennms-upgrade-status.properties";
+
+ /** The status properties. */
+ private Properties status;
+
+ /** The status file. */
+ private File statusFile;
+
+ /**
+ * Instantiates a new upgrade status.
+ *
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public UpgradeStatus() throws OnmsUpgradeException {
+ this(new File(ConfigFileConstants.getFilePathString() + STATUS_FILE));
+ }
+
+ /**
+ * Instantiates a new upgrade status.
+ *
+ * @param statusFile the status file
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public UpgradeStatus(File statusFile) throws OnmsUpgradeException {
+ this.statusFile = statusFile;
+ status = new Properties();
+ try {
+ if (statusFile.exists()) {
+ status.load(new FileReader(statusFile));
+ }
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't load upgrade status data.", e);
+ }
+ }
+
+ /**
+ * Was executed.
+ *
+ * @param upg the upgrade implementation class
+ * @return true, if successful
+ */
+ public boolean wasExecuted(OnmsUpgrade upg) {
+ for (Object obj : status.keySet()) {
+ String cls = (String) obj;
+ if (cls.equals(upg.getId())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Gets the last execution time.
+ *
+ * @param upg the upgrade implementation class
+ * @return the last execution time
+ */
+ public String getLastExecutionTime(OnmsUpgrade upg) {
+ for (Object obj : status.keySet()) {
+ String cls = (String) obj;
+ if (cls.equals(upg.getId())) {
+ return status.getProperty(cls);
+ }
+ }
+ return "Never";
+ }
+
+ /**
+ * Mark as executed.
+ *
+ * @param upg the upgrade implementation class
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ public void markAsExecuted(OnmsUpgrade upg) throws OnmsUpgradeException {
+ status.put(upg.getId(), new Date().toString());
+ try {
+ status.store(new FileWriter(statusFile), null);
+ } catch (Exception e) {
+ throw new OnmsUpgradeException("Can't save upgrade status.", e);
+ }
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/api/AbstractOnmsUpgradeTest.java b/core/upgrade/src/test/java/org/opennms/upgrade/api/AbstractOnmsUpgradeTest.java
new file mode 100644
index 000000000000..6f7282780671
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/api/AbstractOnmsUpgradeTest.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.api;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The Test Class for AbstractOnmsUpgrade.
+ *
+ * @author Alejandro Galue
+ */
+public class AbstractOnmsUpgradeTest {
+
+ /** The task. */
+ private MockOnmsUpgrade task;
+
+ /**
+ * Sets up the test.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ System.setProperty("opennms.home", "src/test/resources");
+ task = new MockOnmsUpgrade();
+ }
+
+ /**
+ * Test properties.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testProperties() throws Exception {
+ Assert.assertEquals(task.getClass().getSimpleName(), task.getId());
+ Assert.assertEquals("src/test/resources", task.getHomeDirectory());
+ Assert.assertEquals("1.12.2", task.getOpennmsVersion());
+ Assert.assertEquals(".jrb", task.getRrdExtension());
+ Assert.assertTrue(task.isInstalledVersionGreaterOrEqual(1, 8, 17));
+ Assert.assertTrue(task.isInstalledVersionGreaterOrEqual(1, 10, 13));
+ Assert.assertTrue(task.isInstalledVersionGreaterOrEqual(1, 12, 1));
+ Assert.assertFalse(task.isInstalledVersionGreaterOrEqual(1, 12, 3));
+ Assert.assertFalse(task.isInstalledVersionGreaterOrEqual(1, 13, 0));
+ Assert.assertFalse(task.isRrdToolEnabled());
+ Assert.assertFalse(task.isStoreByGroupEnabled());
+ }
+
+ /**
+ * Test ZIP and UNZIP directory.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testZipAndUnzipDirectory() throws Exception {
+ task.testZipAndUnzipDirectory();
+ }
+
+ /**
+ * Test ZIP and UNZIP file.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testZipAndUnzipFile() throws Exception {
+ task.testZipAndUnzipFile();
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/api/MockOnmsUpgrade.java b/core/upgrade/src/test/java/org/opennms/upgrade/api/MockOnmsUpgrade.java
new file mode 100644
index 000000000000..dacb52e3d47d
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/api/MockOnmsUpgrade.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.api;
+
+import java.io.File;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+
+/**
+ * The test implementation of AbstractOnmsUpgrade.
+ *
+ * @author Alejandro Galue
+ */
+public class MockOnmsUpgrade extends AbstractOnmsUpgrade {
+
+ /** The Constant TEST_ZIP. */
+ public final static File TEST_ZIP = new File("target/zip-test.zip");
+
+ /**
+ * Instantiates a new mock onms upgrade.
+ *
+ * @throws OnmsUpgradeException the onms upgrade exception
+ */
+ public MockOnmsUpgrade() throws OnmsUpgradeException {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Mock Upgrade";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+ /**
+ * Test Zip and Unzip directory.
+ *
+ * @throws Exception the exception
+ */
+ public void testZipAndUnzipDirectory() throws Exception {
+ zipDir(TEST_ZIP, new File("src/main/java"));
+ File output = new File("target/zip-test");
+ unzipFile(TEST_ZIP, output);
+ Assert.assertTrue(new File(output, "org/opennms/upgrade/api/OnmsUpgrade.java").exists());
+ FileUtils.deleteDirectory(output);
+ }
+
+ /**
+ * Test Zip and Unzip file.
+ *
+ * @throws Exception the exception
+ */
+ public void testZipAndUnzipFile() throws Exception {
+ File output = new File("target/zip-test");
+ File srcFile = new File("src/main/java/org/opennms/upgrade/api/OnmsUpgrade.java");
+ File dstFile = new File(output, "/org/opennms/upgrade/api/OnmsUpgrade.java");
+ FileUtils.copyFile(srcFile, dstFile);
+ zipFile(dstFile);
+ File zip = new File(dstFile.getAbsoluteFile() + ".zip");
+ Assert.assertTrue(zip.exists());
+ FileUtils.deleteQuietly(dstFile);
+ unzipFile(zip, output);
+ Assert.assertTrue(new File(output, "OnmsUpgrade.java").exists());
+ FileUtils.deleteDirectory(output);;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/implementations/JmxRrdMigratorOfflineTest.java b/core/upgrade/src/test/java/org/opennms/upgrade/implementations/JmxRrdMigratorOfflineTest.java
new file mode 100644
index 000000000000..8ebac66e611a
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/implementations/JmxRrdMigratorOfflineTest.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.implementations;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.util.Arrays;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.LineIterator;
+import org.jrobin.core.RrdDb;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The Test Class for JmxRrdMigratorOffline.
+ *
+ * @author Alejandro Galue
+ */
+public class JmxRrdMigratorOfflineTest {
+
+ /**
+ * Sets up the test.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ FileUtils.copyDirectory(new File("src/test/resources/etc"), new File("target/home/etc"));
+ FileUtils.copyDirectory(new File("src/test/resources/jetty-webapps/opennms/WEB-INF"), new File("target/home/jetty-webapps/opennms/WEB-INF/"));
+ System.setProperty("opennms.home", "target/home");
+ }
+
+ /**
+ * Tear down the test.
+ *
+ * @throws Exception the exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ FileUtils.deleteDirectory(new File("target/home"));
+ }
+
+ /**
+ * Test upgrade (single-metric JRBs, i.e. storeByGroup=false).
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testUpgradeSingleMetric() throws Exception {
+ FileUtils.copyDirectory(new File("src/test/resources/rrd"), new File("target/home/rrd"));
+
+ JmxRrdMigratorOffline jmxMigrator = executeMigrator();
+
+ File rrdDir = new File("target/home/rrd/1/opennms-jvm/");
+ for (File file : getFiles(rrdDir, ".jrb")) {
+ RrdDb jrb = new RrdDb(file, true);
+ String ds = jrb.getDsNames()[0];
+ jrb.close();
+ Assert.assertFalse(ds.contains("."));
+ Assert.assertEquals(file.getName(), ds + ".jrb");
+ Assert.assertEquals(ds, jmxMigrator.getFixedDsName(ds));
+ }
+ for (File file : getFiles(rrdDir, ".meta")) {
+ String ds = file.getName().replaceFirst("\\.meta", "");
+ Properties p = new Properties();
+ p.load(new FileReader(file));
+ for (Object o : p.keySet()) {
+ String key = (String) o;
+ Assert.assertTrue(key.endsWith(ds));
+ Assert.assertEquals(ds, p.getProperty(key));
+ }
+ }
+ }
+
+ /**
+ * Test upgrade (multi-metric JRBs, i.e. storeByGroup=true).
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testUpgradeMultiMetric() throws Exception {
+ FileUtils.copyDirectory(new File("src/test/resources/rrd2"), new File("target/home/rrd"));
+
+ File config = new File("target/home/etc/opennms.properties");
+ Properties p = new Properties();
+ p.load(new FileReader(config));
+ p.setProperty("org.opennms.rrd.storeByGroup", "true");
+ p.store(new FileWriter(config), null);
+
+ executeMigrator();
+
+ File jrbFile = new File("target/home/rrd/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor_Space.jrb");
+ Assert.assertTrue(jrbFile.exists());
+ RrdDb jrb = new RrdDb(jrbFile, true);
+ String[] dataSources = jrb.getDsNames();
+ jrb.close();
+
+ Properties dsProp = new Properties();
+ dsProp.load(new FileReader("target/home/rrd/1/opennms-jvm/ds.properties"));
+
+ Properties meta = new Properties();
+ meta.load(new FileReader("target/home/rrd/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor_Space.meta"));
+
+ for (String ds : dataSources) {
+ Assert.assertFalse(ds.contains("."));
+ Assert.assertEquals("java_lang_type_MemoryPool_name_Survivor_Space", dsProp.getProperty(ds));
+ Assert.assertEquals(ds, meta.getProperty("JMX_java.lang:type=MemoryPool.name.Survivor Space." + ds));
+ }
+ }
+
+ /**
+ * Executes the JMX Migrator.
+ *
+ * @return the JMX Migrator object
+ * @throws Exception the exception
+ */
+ private JmxRrdMigratorOffline executeMigrator() throws Exception {
+ JmxRrdMigratorOffline jmxMigrator = new JmxRrdMigratorOffline();
+ jmxMigrator.preExecute();
+ jmxMigrator.execute();
+ jmxMigrator.postExecute();
+ Assert.assertEquals(60, jmxMigrator.badMetrics.size());
+
+ // Verify graph templates
+ File templates = new File("target/home/etc/snmp-graph.properties.d/jvm-graph.properties");
+ Pattern defRegex = Pattern.compile("DEF:.+:(.+\\..+):");
+ Pattern colRegex = Pattern.compile("\\.columns=(.+)$");
+ for (LineIterator it = FileUtils.lineIterator(templates); it.hasNext();) {
+ String line = it.next();
+ Matcher m = defRegex.matcher(line);
+ if (m.find()) {
+ String ds = m.group(1);
+ if (jmxMigrator.badMetrics.contains(ds)) {
+ Assert.fail("Bad metric found");
+ }
+ }
+ m = colRegex.matcher(line);
+ if (m.find()) {
+ String[] badColumns = m.group(1).split(",(\\s)?");
+ if (jmxMigrator.badMetrics.containsAll(Arrays.asList(badColumns))) {
+ Assert.fail("Bad metric found");
+ }
+ }
+ }
+
+ // Verify metric definitions
+ File metrics = new File("target/home/etc/jmx-datacollection-config.xml");
+ Pattern aliasRegex = Pattern.compile("alias=\"([^\"]+\\.[^\"]+)\"");
+ for (LineIterator it = FileUtils.lineIterator(metrics); it.hasNext();) {
+ String line = it.next();
+ Matcher m = aliasRegex.matcher(line);
+ if (m.find()) {
+ String ds = m.group(1);
+ if (jmxMigrator.badMetrics.contains(ds)) {
+ Assert.fail("Bad metric found");
+ }
+ }
+ }
+
+ return jmxMigrator;
+ }
+
+ /**
+ * Gets the files.
+ *
+ * @param resourceDir the resource directory
+ * @param ext the extension
+ * @return the files
+ */
+ private File[] getFiles(final File resourceDir, final String ext) {
+ return resourceDir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.toLowerCase().endsWith(ext);
+ }
+ });
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/implementations/SnmpInterfaceRrdMigratorOnlineTest.java b/core/upgrade/src/test/java/org/opennms/upgrade/implementations/SnmpInterfaceRrdMigratorOnlineTest.java
new file mode 100644
index 000000000000..8672c3e1be4e
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/implementations/SnmpInterfaceRrdMigratorOnlineTest.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.implementations;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opennms.netmgt.config.DataCollectionConfigFactory;
+import org.opennms.netmgt.config.DefaultDataCollectionConfigDao;
+import org.opennms.netmgt.rrd.model.Row;
+import org.opennms.netmgt.rrd.model.RrdConvertUtils;
+import org.opennms.netmgt.rrd.model.v1.RRDv1;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.springframework.core.io.FileSystemResource;
+
+/**
+ * The Test Class for SnmpInterfaceRrdMigratorOnline.
+ *
+ * @author Alejandro Galue
+ */
+public class SnmpInterfaceRrdMigratorOnlineTest {
+
+ /**
+ * Sets up the test.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ FileUtils.copyDirectory(new File("src/test/resources/etc"), new File("target/home/etc"));
+ FileUtils.copyDirectory(new File("src/test/resources/rrd"), new File("target/home/rrd"));
+ FileUtils.copyDirectory(new File("src/test/resources/jetty-webapps/opennms/WEB-INF"), new File("target/home/jetty-webapps/opennms/WEB-INF/"));
+ System.setProperty("opennms.home", "target/home");
+ DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
+ dao.setConfigResource(new FileSystemResource(new File("target/home/etc/datacollection-config.xml")));
+ dao.afterPropertiesSet();
+ DataCollectionConfigFactory.setInstance(dao);
+ }
+
+ /**
+ * Tear down the test.
+ *
+ * @throws Exception the exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ FileUtils.deleteDirectory(new File("target/home"));
+ }
+
+ /**
+ * Test upgrade.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testUpgrade() throws Exception {
+ // Check Current JRBs
+ RRDv1 rrd = RrdConvertUtils.dumpJrb(new File("target/home/rrd/1/eth0/ifInOctets.jrb"));
+ Row r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381500900l);
+ Assert.assertNotNull(r);
+ Assert.assertEquals(new Double(-6.0), r.getValues().get(0));
+ r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381512300l);
+ Assert.assertNull(r);
+
+ rrd = RrdConvertUtils.dumpJrb(new File("target/home/rrd/1/eth0-005056c00008/ifInOctets.jrb"));
+ r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381500900l);
+ Assert.assertNotNull(r);
+ Assert.assertTrue(r.getValues().get(0).isNaN());
+ r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381512300l);
+ Assert.assertNotNull(r);
+ Assert.assertEquals(new Double(12.0), r.getValues().get(0));
+
+ // Perform Migration
+ SnmpInterfaceRrdMigratorOnline obj = new SnmpInterfaceRrdMigratorOnline() {
+ protected List getInterfacesToMerge() throws OnmsUpgradeException {
+ List interfaces = new ArrayList();
+ interfaces.add(new SnmpInterfaceUpgrade(1, null, null, "eth0", "eth0", "005056c00008", false));
+ return interfaces;
+ }
+ };
+ obj.preExecute();
+ obj.execute();
+ obj.postExecute();
+
+ // Check Merged JRB
+ rrd = RrdConvertUtils.dumpJrb(new File("target/home/rrd/1/eth0-005056c00008/ifInOctets.jrb"));
+ r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381500900l);
+ Assert.assertNotNull(r);
+ Assert.assertEquals(new Double(-6.0), r.getValues().get(0));
+ r = rrd.findRowByTimestamp(rrd.getRras().get(0), 1381512300l);
+ Assert.assertNotNull(r);
+ Assert.assertEquals(new Double(12.0), r.getValues().get(0));
+ }
+
+}
diff --git a/opennms-import/src/main/java/org/opennms/netmgt/importer/operations/SaveOrUpdateOperation.java b/core/upgrade/src/test/java/org/opennms/upgrade/support/UpgradeHelper.java
similarity index 53%
rename from opennms-import/src/main/java/org/opennms/netmgt/importer/operations/SaveOrUpdateOperation.java
rename to core/upgrade/src/test/java/org/opennms/upgrade/support/UpgradeHelper.java
index 85432581746a..0ee9b7157b15 100644
--- a/opennms-import/src/main/java/org/opennms/netmgt/importer/operations/SaveOrUpdateOperation.java
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/support/UpgradeHelper.java
@@ -25,50 +25,58 @@
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/
+package org.opennms.upgrade.support;
-package org.opennms.netmgt.importer.operations;
-
-import org.opennms.netmgt.importer.config.types.InterfaceSnmpPrimaryType;
-
+import java.util.ArrayList;
+import java.util.List;
/**
- * SaveOrUpdateOperation interface.
- *
- * @author ranger
- * @version $Id: $
+ * The Class UpgradeHelper.
+ *
+ * @author Alejandro Galue
*/
-public interface SaveOrUpdateOperation extends ImportOperation{
+public class UpgradeHelper {
+
+ /** The executed list. */
+ public static List executed = new ArrayList();
+
+ /** The rolled-back list. */
+ public static List rolledback = new ArrayList();
/**
- * foundInterface
+ * Gets the executed List.
*
- * @param ipAddr a {@link java.lang.String} object.
- * @param descr a {@link java.lang.Object} object.
- * @param interfaceSnmpPrimaryType a {@link InterfaceSnmpPrimaryType} object.
- * @param managed a boolean.
- * @param status a int.
+ * @return the upgrade order
*/
- void foundInterface(String ipAddr, Object descr, InterfaceSnmpPrimaryType interfaceSnmpPrimaryType, boolean managed, int status);
+ public static List getExecutedList() {
+ return executed;
+ }
/**
- * foundMonitoredService
+ * Adds an executed class.
*
- * @param serviceName a {@link java.lang.String} object.
+ * @param upgradeId the upgrade id
*/
- void foundMonitoredService(String serviceName);
+ public static void addExecuted(String upgradeId) {
+ executed.add(upgradeId);
+ }
/**
- * foundCategory
+ * Gets the rolled-back List.
*
- * @param name a {@link java.lang.String} object.
+ * @return the upgrade order
*/
- void foundCategory(String name);
+ public static List getRolledBackList() {
+ return rolledback;
+ }
/**
- * foundAsset
+ * Adds an rolled-back class.
*
- * @param name a {@link java.lang.String} object.
- * @param value a {@link java.lang.String} object.
+ * @param upgradeId the upgrade id
*/
- void foundAsset(String name, String value);
+ public static void addRolledBack(String upgradeId) {
+ rolledback.add(upgradeId);
+ }
+
}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/support/UpgradeTest.java b/core/upgrade/src/test/java/org/opennms/upgrade/support/UpgradeTest.java
new file mode 100644
index 000000000000..abfe7f67edc6
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/support/UpgradeTest.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.support;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.Date;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.opennms.upgrade.tests.TestUpgradeA;
+import org.opennms.upgrade.tests.TestUpgradeB;
+import org.opennms.upgrade.tests.TestUpgradeExecuted;
+import org.opennms.upgrade.tests.TestUpgradeNothing;
+import org.opennms.upgrade.tests.bad.TestUpgradeWIthException;
+
+/**
+ * The Class UpgradeTest.
+ *
+ * @author Alejandro Galue
+ */
+public class UpgradeTest {
+
+ /** The status file. */
+ private File statusFile;
+
+ /** The upgrade status. */
+ private UpgradeStatus upgradeStatus;
+
+ /**
+ * Sets up the test.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ statusFile = new File("target/status.properties");
+ Properties p = new Properties();
+ p.put(new TestUpgradeExecuted().getId(), new Date().toString());
+ p.store(new FileWriter(statusFile), null);
+ upgradeStatus = new UpgradeStatus(statusFile);
+ }
+
+ /**
+ * Tear down the test.
+ *
+ * @throws Exception the exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ statusFile.delete();
+ }
+
+ /**
+ * Test upgrade.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testUpgrade() throws Exception {
+ Assert.assertFalse(upgradeStatus.wasExecuted(new TestUpgradeNothing()));
+ performUpgrade("org/opennms/upgrade/tests");
+ Assert.assertTrue(upgradeStatus.wasExecuted(new TestUpgradeNothing()));
+ Assert.assertEquals(3, UpgradeHelper.getExecutedList().size());
+ Assert.assertEquals(TestUpgradeNothing.class.getName(), UpgradeHelper.getExecutedList().get(0));
+ Assert.assertEquals(TestUpgradeA.class.getName(), UpgradeHelper.getExecutedList().get(1));
+ Assert.assertEquals(TestUpgradeB.class.getName(), UpgradeHelper.getExecutedList().get(2));
+ Assert.assertEquals(1, UpgradeHelper.getRolledBackList().size());
+ Assert.assertEquals(TestUpgradeWIthException.class.getName(), UpgradeHelper.getRolledBackList().get(0));
+ }
+
+ /**
+ * Perform upgrade.
+ *
+ * @param scope the scope
+ * @throws OnmsUpgradeException the OpenNMS upgrade exception
+ */
+ private void performUpgrade(String scope) throws OnmsUpgradeException {
+ Upgrade upgrade = new Upgrade();
+ upgrade.setClassScope(scope);
+ upgrade.setUpgradeStatus(upgradeStatus);
+ upgrade.execute();
+ }
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeA.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeA.java
new file mode 100644
index 000000000000..4f00e715d361
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeA.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests;
+
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.opennms.upgrade.support.UpgradeHelper;
+
+/**
+ * The Class TestUpgradeA.
+ * This is an example implementation for the JUnit tests.
+ *
+ * @author Alejandro Galue
+ */
+public class TestUpgradeA implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 200;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing class A";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ UpgradeHelper.addRolledBack(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ UpgradeHelper.addExecuted(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeB.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeB.java
new file mode 100644
index 000000000000..dbd864b888a1
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeB.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests;
+
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.opennms.upgrade.support.UpgradeHelper;
+
+/**
+ * The Class TestUpgradeB.
+ * This is an example implementation for the JUnit tests.
+ *
+ * @author Alejandro Galue
+ */
+public class TestUpgradeB implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 300;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing class B";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ UpgradeHelper.addRolledBack(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ UpgradeHelper.addExecuted(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeC.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeC.java
new file mode 100644
index 000000000000..969b346deb6b
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeC.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests;
+
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.opennms.upgrade.support.UpgradeHelper;
+
+/**
+ * The Class TestUpgradeC.
+ * This is an example implementation for the JUnit tests.
+ * This class should not be executed because it requires OpenNMS to be running.
+ *
+ * @author Alejandro Galue
+ */
+public class TestUpgradeC implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 400;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing class C";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ UpgradeHelper.addRolledBack(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ UpgradeHelper.addExecuted(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return true;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeExecuted.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeExecuted.java
new file mode 100644
index 000000000000..45d1c2c5f5c4
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeExecuted.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests;
+
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.opennms.upgrade.support.UpgradeHelper;
+
+/**
+ * The Class TestUpgradeExecuted.
+ * This is an example implementation for the JUnit tests.
+ *
+ * @author Alejandro Galue
+ */
+public class TestUpgradeExecuted implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing class executed";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ UpgradeHelper.addRolledBack(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ UpgradeHelper.addExecuted(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeNothing.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeNothing.java
new file mode 100644
index 000000000000..8c710b7e3f1e
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/TestUpgradeNothing.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests;
+
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.opennms.upgrade.support.UpgradeHelper;
+
+/**
+ * The Class TestUpgradeNothing.
+ * This is an example implementation for the JUnit tests.
+ *
+ * @author Alejandro Galue
+ */
+public class TestUpgradeNothing implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 100;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing class - do nothing";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ UpgradeHelper.addRolledBack(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ UpgradeHelper.addExecuted(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestAbstract.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestAbstract.java
new file mode 100644
index 000000000000..51029bcbdc76
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestAbstract.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests.bad;
+
+import org.opennms.upgrade.api.Ignore;
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+
+/**
+ * The Class TestAbstract.
+ * This is an example implementation for the JUnit tests.
+ *
+ * @author Alejandro Galue
+ */
+@Ignore
+public abstract class TestAbstract implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 25;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing Ignore";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestIgnore.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestIgnore.java
new file mode 100644
index 000000000000..b3be3b09700f
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestIgnore.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests.bad;
+
+import org.opennms.upgrade.api.Ignore;
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+
+/**
+ * The Class TestIgnore.
+ * This is an example implementation for the JUnit tests.
+ *
+ * @author Alejandro Galue
+ */
+@Ignore
+public class TestIgnore implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 50;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing Ignore";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ throw new RuntimeException("This should not be called");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+}
diff --git a/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestUpgradeWIthException.java b/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestUpgradeWIthException.java
new file mode 100644
index 000000000000..8df7cb88ca74
--- /dev/null
+++ b/core/upgrade/src/test/java/org/opennms/upgrade/tests/bad/TestUpgradeWIthException.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * This file is part of OpenNMS(R).
+ *
+ * Copyright (C) 2006-2012 The OpenNMS Group, Inc.
+ * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * OpenNMS(R) is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * OpenNMS(R) is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenNMS(R). If not, see:
+ * http://www.gnu.org/licenses/
+ *
+ * For more information contact:
+ * OpenNMS(R) Licensing
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *******************************************************************************/
+package org.opennms.upgrade.tests.bad;
+
+import org.opennms.upgrade.api.OnmsUpgrade;
+import org.opennms.upgrade.api.OnmsUpgradeException;
+import org.opennms.upgrade.support.UpgradeHelper;
+
+/**
+ * The Class TestUpgradeWIthException.
+ * This is an example implementation for the JUnit tests.
+ *
+ * @author Alejandro Galue
+ */
+public class TestUpgradeWIthException implements OnmsUpgrade {
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getOrder()
+ */
+ @Override
+ public int getOrder() {
+ return 100;
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getId()
+ */
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#getDescription()
+ */
+ @Override
+ public String getDescription() {
+ return "Testing class - do nothing";
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#preExecute()
+ */
+ @Override
+ public void preExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#postExecute()
+ */
+ @Override
+ public void postExecute() throws OnmsUpgradeException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#rollback()
+ */
+ @Override
+ public void rollback() throws OnmsUpgradeException {
+ UpgradeHelper.addRolledBack(getId());
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#execute()
+ */
+ @Override
+ public void execute() throws OnmsUpgradeException {
+ throw new OnmsUpgradeException("Something bad happen");
+ }
+
+ /* (non-Javadoc)
+ * @see org.opennms.upgrade.api.OnmsUpgrade#requiresOnmsRunning()
+ */
+ @Override
+ public boolean requiresOnmsRunning() {
+ return false;
+ }
+
+}
diff --git a/core/upgrade/src/test/resources/etc/collectd-configuration.xml b/core/upgrade/src/test/resources/etc/collectd-configuration.xml
new file mode 100644
index 000000000000..45d6f923bb57
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/collectd-configuration.xml
@@ -0,0 +1,29 @@
+
+
+
+
+ IPADDR != '0.0.0.0'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/upgrade/src/test/resources/etc/datacollection-config.xml b/core/upgrade/src/test/resources/etc/datacollection-config.xml
new file mode 100644
index 000000000000..847b90137bf3
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/datacollection-config.xml
@@ -0,0 +1,26 @@
+
+
+
+
+ RRA:AVERAGE:0.5:1:2016
+ RRA:AVERAGE:0.5:12:1488
+ RRA:AVERAGE:0.5:288:366
+ RRA:MAX:0.5:288:366
+ RRA:MIN:0.5:288:366
+
+
+
+
+
+
+
+
+
+ .1.3.6.1.4.1.
+
+ mib2-interfaces
+
+
+
+
+
diff --git a/core/upgrade/src/test/resources/etc/jmx-datacollection-config.xml b/core/upgrade/src/test/resources/etc/jmx-datacollection-config.xml
new file mode 100644
index 000000000000..bcf259fc0af2
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/jmx-datacollection-config.xml
@@ -0,0 +1,151 @@
+
+
+
+
+ RRA:AVERAGE:0.5:1:2016
+ RRA:AVERAGE:0.5:12:1488
+ RRA:AVERAGE:0.5:288:366
+ RRA:MAX:0.5:288:366
+ RRA:MIN:0.5:288:366
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/upgrade/src/test/resources/etc/ksc-performance-reports.xml b/core/upgrade/src/test/resources/etc/ksc-performance-reports.xml
new file mode 100644
index 000000000000..aefbd5059cea
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/ksc-performance-reports.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/core/upgrade/src/test/resources/etc/opennms-server.xml b/core/upgrade/src/test/resources/etc/opennms-server.xml
new file mode 100644
index 000000000000..e969c2b42d76
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/opennms-server.xml
@@ -0,0 +1,2 @@
+
+
diff --git a/core/upgrade/src/test/resources/etc/opennms.properties b/core/upgrade/src/test/resources/etc/opennms.properties
new file mode 100644
index 000000000000..9684671b1b33
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/opennms.properties
@@ -0,0 +1,3 @@
+org.opennms.rrd.storeByGroup=false
+rrd.base.dir=target/home/rrd
+rrd.binary=/opt/local/bin/rrdtool
\ No newline at end of file
diff --git a/core/upgrade/src/test/resources/etc/rrd-configuration.properties b/core/upgrade/src/test/resources/etc/rrd-configuration.properties
new file mode 100644
index 000000000000..282039add02a
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/rrd-configuration.properties
@@ -0,0 +1,4 @@
+org.opennms.rrd.strategyClass=org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy
+org.opennms.rrd.fileExtension=.jrb
+org.opennms.rrd.usequeue=false
+org.opennms.rrd.usetcp=false
diff --git a/core/upgrade/src/test/resources/etc/snmp-graph.properties b/core/upgrade/src/test/resources/etc/snmp-graph.properties
new file mode 100644
index 000000000000..44c0b1aa18b7
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/snmp-graph.properties
@@ -0,0 +1,17 @@
+command.prefix=/opt/local/bin/rrdtool graph - --imgformat PNG --font DEFAULT:7 --font TITLE:10 --start {startTime} --end {endTime}
+info.command=/opt/local/bin/rrdtool info
+default.report=mib2.HCbits
+output.mime=image/png
+include.directory=snmp-graph.properties.d
+
+reports=dummy
+
+report.dummy.name=Dummy Template
+report.dummy.columns=dummy.updates
+report.dummy.type=nodeSnmp
+report.dummy.command=--title="Dummy Updates" \
+ DEF:updates={rrd1}:dummy.updates:AVERAGE \
+ LINE1:updates#0000ff:"Dummy Updates" \
+ GPRINT:updates:AVERAGE:" Avg \\: %8.2lf %s" \
+ GPRINT:updates:MIN:"Min \\: %8.2lf %s" \
+ GPRINT:updates:MAX:"Max \\: %8.2lf %s\\n"
diff --git a/core/upgrade/src/test/resources/etc/snmp-graph.properties.d/jvm-graph.properties b/core/upgrade/src/test/resources/etc/snmp-graph.properties.d/jvm-graph.properties
new file mode 100644
index 000000000000..acd5df4abb14
--- /dev/null
+++ b/core/upgrade/src/test/resources/etc/snmp-graph.properties.d/jvm-graph.properties
@@ -0,0 +1,275 @@
+##############################################################################
+##
+## Please add report definition in a new line to make it easier
+## for script based sanity checks
+##
+##################################################
+
+reports=free.memory, \
+jvm.thread.count, \
+jvm.thread.daemon, \
+jvm.thread.peak, \
+jvm.mempool.eden, \
+jvm.mempool.perm, \
+jvm.mempool.oldgen, \
+jvm.mempool.survivor, \
+jvm.gc.copy, \
+jvm.gc.msc, \
+jvm.gc.parnew, \
+jvm.gc.cms, \
+jvm.gc.psms, \
+jvm.gc.pss
+
+###
+## JVM
+###
+report.free.memory.name=Free Memory
+report.free.memory.columns=FreeMemory, TotalMemory
+report.free.memory.type=interfaceSnmp
+report.free.memory.command=--title="Memory Usage" \
+ DEF:freemem={rrd1}:FreeMemory:AVERAGE \
+ DEF:minFreemem={rrd1}:FreeMemory:MIN \
+ DEF:maxFreemem={rrd1}:FreeMemory:MAX \
+ DEF:totalmem={rrd2}:TotalMemory:AVERAGE \
+ DEF:minTotalmem={rrd2}:TotalMemory:MIN \
+ DEF:maxTotalmem={rrd2}:TotalMemory:MAX \
+ CDEF:percentfree=freemem,totalmem,/,100,* \
+ CDEF:minPercentfree=minFreemem,minTotalmem,/,100,* \
+ CDEF:maxPercentfree=maxFreemem,maxTotalmem,/,100,* \
+ LINE2:percentfree#0000ff:"%FreeMemory" \
+ GPRINT:percentfree:AVERAGE:" Avg \\: %5.2lf %s" \
+ GPRINT:percentfree:MIN:"Min \\: %5.2lf %s" \
+ GPRINT:percentfree:MAX:"Max \\: %5.2lf %s\\n"
+
+report.jvm.thread.count.name=JVM Threading
+report.jvm.thread.count.columns=ThreadCount
+report.jvm.thread.count.type=interfaceSnmp
+report.jvm.thread.count.command=--title="JVM Thread Count" \
+ DEF:threads={rrd1}:ThreadCount:AVERAGE \
+ LINE2:threads#0000ff:"Threads" \
+ GPRINT:threads:AVERAGE:" Avg \\: %8.2lf %s\\n"
+
+report.jvm.thread.daemon.name=JVM Daemon Threads
+report.jvm.thread.daemon.columns=DaemonThreadCount
+report.jvm.thread.daemon.type=interfaceSnmp
+report.jvm.thread.daemon.command=--title="JVM Daemon Thread Count" \
+ DEF:dthreads={rrd1}:DaemonThreadCount:AVERAGE \
+ LINE2:dthreads#0000ff:"Daemon Threads" \
+ GPRINT:dthreads:AVERAGE:" Avg \\: %5.2lf %s\\n"
+
+report.jvm.thread.peak.name=JVM Peak Thread Count
+report.jvm.thread.peak.columns=PeakThreadCount
+report.jvm.thread.peak.type=interfaceSnmp
+report.jvm.thread.peak.command=--title="JVM Peak Thread Count" \
+ DEF:threads={rrd1}:PeakThreadCount:AVERAGE \
+ LINE2:threads#0000ff:"Threads" \
+ GPRINT:threads:AVERAGE:" Avg \\: %5.2lf %s\\n"
+
+report.jvm.mempool.eden.name=JVM Memory Pool: Eden Space
+report.jvm.mempool.eden.columns=EdenUsage.used, EdenUsage.max
+report.jvm.mempool.eden.type=interfaceSnmp
+report.jvm.mempool.eden.command=--title="JVM Memory Pool: Eden Space" \
+ DEF:used={rrd1}:EdenUsage.used:AVERAGE \
+ DEF:max={rrd2}:EdenUsage.max:AVERAGE \
+ LINE2:used#0000ff:"Bytes Used" \
+ GPRINT:used:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:used:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:used:MAX:" Max \\: %5.2lf %s " \
+ LINE2:max#ff0000:"Bytes Allocated" \
+ GPRINT:max:AVERAGE:"Avg \\: %5.2lf %s " \
+ GPRINT:max:MIN:"Min \\: %5.2lf %s " \
+ GPRINT:max:MAX:"Max \\: %5.2lf %s\\n"
+
+report.jvm.mempool.perm.name=JVM Memory Pool: Perm Space
+report.jvm.mempool.perm.columns=PermUsage.used, PermUsage.max
+report.jvm.mempool.perm.type=interfaceSnmp
+report.jvm.mempool.perm.command=--title="JVM Memory Pool: Perm Space" \
+ DEF:used={rrd1}:PermUsage.used:AVERAGE \
+ DEF:max={rrd2}:PermUsage.max:AVERAGE \
+ LINE2:used#0000ff:"Bytes Used" \
+ GPRINT:used:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:used:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:used:MAX:" Max \\: %5.2lf %s " \
+ LINE2:max#ff0000:"Bytes Allocated" \
+ GPRINT:max:AVERAGE:"Avg \\: %5.2lf %s " \
+ GPRINT:max:MIN:"Min \\: %5.2lf %s " \
+ GPRINT:max:MAX:"Max \\: %5.2lf %s\\n"
+
+report.jvm.mempool.survivor.name=JVM Memory Pool: Survivor Space
+report.jvm.mempool.survivor.columns=SurvUsage.used, SurvUsage.max
+report.jvm.mempool.survivor.type=interfaceSnmp
+report.jvm.mempool.survivor.command=--title="JVM Memory Pool: Survivor Space" \
+ DEF:used={rrd1}:SurvUsage.used:AVERAGE \
+ DEF:max={rrd2}:SurvUsage.max:AVERAGE \
+ LINE2:used#0000ff:"Bytes Used" \
+ GPRINT:used:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:used:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:used:MAX:" Max \\: %5.2lf %s " \
+ LINE2:max#ff0000:"Bytes Allocated" \
+ GPRINT:max:AVERAGE:"Avg \\: %5.2lf %s " \
+ GPRINT:max:MIN:"Min \\: %5.2lf %s " \
+ GPRINT:max:MAX:"Max \\: %5.2lf %s\\n"
+
+report.jvm.mempool.oldgen.name=JVM Memory Pool: OldGen Space
+report.jvm.mempool.oldgen.columns=OGenUsage.used, OGenUsage.max
+report.jvm.mempool.oldgen.type=interfaceSnmp
+report.jvm.mempool.oldgen.command=--title="JVM Memory Pool: Old Gen Space" \
+ DEF:used={rrd1}:OGenUsage.used:AVERAGE \
+ DEF:max={rrd2}:OGenUsage.max:AVERAGE \
+ LINE2:used#0000ff:"Bytes Used" \
+ GPRINT:used:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:used:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:used:MAX:" Max \\: %5.2lf %s " \
+ LINE2:max#ff0000:"Bytes Allocated" \
+ GPRINT:max:AVERAGE:"Avg \\: %5.2lf %s " \
+ GPRINT:max:MIN:"Min \\: %5.2lf %s " \
+ GPRINT:max:MAX:"Max \\: %5.2lf %s\\n"
+
+#report.jvm.gc.copy
+report.jvm.gc.copy.name=JVM GarbageCollector: Copy
+report.jvm.gc.copy.columns=Copy.CollCnt, Copy.CollTime, Copy.Duration
+report.jvm.gc.copy.type=interfaceSnmp
+report.jvm.gc.copy.command=--title="JVM GarbageCollector: Copy" \
+ DEF:collCnt={rrd1}:Copy.CollCnt:AVERAGE \
+ DEF:collTime={rrd2}:Copy.CollTime:AVERAGE \
+ DEF:duration={rrd3}:Copy.Duration:AVERAGE \
+ CDEF:collPerMin=collCnt,5,/ \
+ CDEF:avgCollTime=collTime,collCnt,/,1000,/ \
+ CDEF:collTimePerMin=avgCollTime,collPerMin,* \
+ LINE2:collCnt#ff0000:"CollectionCount" \
+ GPRINT:collCnt:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTime#00ff00:"CollectionTime" \
+ GPRINT:collTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:duration#0000ff:"CollectionDuration" \
+ GPRINT:duration:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:duration:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:duration:MAX:" Max \\: %5.2lf %s " \
+ LINE2:avgCollTime#0000aa:"AvgCollTime" \
+ GPRINT:avgCollTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collPerMin#0000aa:"CollPerMin" \
+ GPRINT:collPerMin:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTimePerMin#aa0000:"CollTimePerMin" \
+ GPRINT:collTimePerMin:AVERAGE:" Avg \\: %5.2lf %s\\n"
+
+report.jvm.gc.msc.name=JVM GarbageCollector: MarkSweepCompact
+report.jvm.gc.msc.columns=MSC.CollCnt, MSC.CollTime, MSC.Duration
+report.jvm.gc.msc.type=interfaceSnmp
+report.jvm.gc.msc.command=--title="JVM GarbageCollector: MarkSweepCompact" \
+ DEF:collCnt={rrd1}:MSC.CollCnt:AVERAGE \
+ DEF:collTime={rrd2}:MSC.CollTime:AVERAGE \
+ DEF:duration={rrd3}:MSC.Duration:AVERAGE \
+ CDEF:collPerMin=collCnt,5,/ \
+ CDEF:avgCollTime=collTime,collCnt,/,1000,/ \
+ CDEF:collTimePerMin=avgCollTime,collPerMin,* \
+ LINE2:collCnt#ff0000:"CollectionCount" \
+ GPRINT:collCnt:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTime#00ff00:"CollectionTime" \
+ GPRINT:collTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:duration#0000ff:"CollectionDuration" \
+ GPRINT:duration:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:duration:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:duration:MAX:" Max \\: %5.2lf %s " \
+ LINE2:collPerMin#0000aa:"CollPerMin" \
+ GPRINT:collPerMin:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTimePerMin#aa0000:"CollTimePerMin" \
+ GPRINT:collTimePerMin:AVERAGE:" Avg \\: %5.2lf %s\\n"
+
+report.jvm.gc.parnew.name=JVM GarbageCollector: ParNew
+report.jvm.gc.parnew.columns=ParNew.CollCnt, ParNew.CollTime, ParNew.Duration
+report.jvm.gc.parnew.type=interfaceSnmp
+report.jvm.gc.parnew.command=--title="JVM GarbageCollector: ParNew" \
+ DEF:collCnt={rrd1}:ParNew.CollCnt:AVERAGE \
+ DEF:collTime={rrd2}:ParNew.CollTime:AVERAGE \
+ DEF:duration={rrd3}:ParNew.Duration:AVERAGE \
+ CDEF:collPerMin=collCnt,5,/ \
+ CDEF:avgCollTime=collTime,collCnt,/,1000,/ \
+ CDEF:collTimePerMin=avgCollTime,collPerMin,* \
+ LINE2:collCnt#ff0000:"CollectionCount" \
+ GPRINT:collCnt:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTime#00ff00:"CollectionTime" \
+ GPRINT:collTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:duration#0000ff:"CollectionDuration" \
+ GPRINT:duration:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:duration:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:duration:MAX:" Max \\: %5.2lf %s " \
+ LINE2:avgCollTime#0000aa:"AvgCollTime" \
+ GPRINT:avgCollTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collPerMin#0000aa:"CollPerMin" \
+ GPRINT:collPerMin:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTimePerMin#aa0000:"CollTimePerMin" \
+ GPRINT:collTimePerMin:AVERAGE:" Avg \\: %5.2lf %s\\n"
+
+report.jvm.gc.cms.name=JVM GarbageCollector: ConcurrentMarkSweep
+report.jvm.gc.cms.columns=CMS.CollCnt, CMS.CollTime, CMS.Duration
+report.jvm.gc.cms.type=interfaceSnmp
+report.jvm.gc.cms.command=--title="JVM GarbageCollector: ConcurrentMarkSweep" \
+ DEF:collCnt={rrd1}:CMS.CollCnt:AVERAGE \
+ DEF:collTime={rrd2}:CMS.CollTime:AVERAGE \
+ DEF:duration={rrd3}:CMS.Duration:AVERAGE \
+ CDEF:collPerMin=collCnt,5,/ \
+ CDEF:avgCollTime=collTime,collCnt,/,1000,/ \
+ CDEF:collTimePerMin=avgCollTime,collPerMin,* \
+ LINE2:collCnt#ff0000:"CollectionCount" \
+ GPRINT:collCnt:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTime#00ff00:"CollectionTime" \
+ GPRINT:collTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:duration#0000ff:"CollectionDuration" \
+ GPRINT:duration:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:duration:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:duration:MAX:" Max \\: %5.2lf %s " \
+ LINE2:avgCollTime#0000aa:"AvgCollTime" \
+ GPRINT:avgCollTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collPerMin#0000aa:"CollPerMin" \
+ GPRINT:collPerMin:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTimePerMin#aa0000:"CollTimePerMin" \
+ GPRINT:collTimePerMin:AVERAGE:" Avg \\: %5.2lf %s\\n"
+
+report.jvm.gc.psms.name=JVM GarbageCollector: PS MarkSweep
+report.jvm.gc.psms.columns=PSMS.CollCnt, PSMS.CollTime, PSMS.Duration
+report.jvm.gc.psms.type=interfaceSnmp
+report.jvm.gc.psms.command=--title="JVM GarbageCollector: PS MarkSweep" \
+ DEF:collCnt={rrd1}:PSMS.CollCnt:AVERAGE \
+ DEF:collTime={rrd2}:PSMS.CollTime:AVERAGE \
+ DEF:duration={rrd3}:PSMS.Duration:AVERAGE \
+ CDEF:collPerMin=collCnt,5,/ \
+ CDEF:avgCollTime=collTime,collCnt,/,1000,/ \
+ CDEF:collTimePerMin=avgCollTime,collPerMin,* \
+ LINE2:collCnt#ff0000:"CollectionCount" \
+ GPRINT:collCnt:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTime#00ff00:"CollectionTime" \
+ GPRINT:collTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:duration#0000ff:"CollectionDuration" \
+ GPRINT:duration:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:duration:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:duration:MAX:" Max \\: %5.2lf %s " \
+ LINE2:avgCollTime#0000aa:"AvgCollTime" \
+ GPRINT:avgCollTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collPerMin#0000aa:"CollPerMin" \
+ GPRINT:collPerMin:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTimePerMin#aa0000:"CollTimePerMin" \
+ GPRINT:collTimePerMin:AVERAGE:" Avg \\: %5.2lf %s\\n"
+
+report.jvm.gc.pss.name=JVM GarbageCollector: PS Scavenge
+report.jvm.gc.pss.columns=PSS.CollCnt, PSS.CollTime, PSS.Duration
+report.jvm.gc.pss.type=interfaceSnmp
+report.jvm.gc.pss.command=--title="JVM GarbageCollector: PS Scavenge" \
+ DEF:collCnt={rrd1}:PSS.CollCnt:AVERAGE \
+ DEF:collTime={rrd2}:PSS.CollTime:AVERAGE \
+ DEF:duration={rrd3}:PSS.Duration:AVERAGE \
+ CDEF:collPerMin=collCnt,5,/ \
+ CDEF:avgCollTime=collTime,collCnt,/,1000,/ \
+ CDEF:collTimePerMin=avgCollTime,collPerMin,* \
+ LINE2:collCnt#ff0000:"CollectionCount" \
+ GPRINT:collCnt:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTime#00ff00:"CollectionTime" \
+ GPRINT:collTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:duration#0000ff:"CollectionDuration" \
+ GPRINT:duration:AVERAGE:" Avg \\: %5.2lf %s " \
+ GPRINT:duration:MIN:" Min \\: %5.2lf %s " \
+ GPRINT:duration:MAX:" Max \\: %5.2lf %s " \
+ LINE2:avgCollTime#0000aa:"AvgCollTime" \
+ GPRINT:avgCollTime:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collPerMin#0000aa:"CollPerMin" \
+ GPRINT:collPerMin:AVERAGE:" Avg \\: %5.2lf %s " \
+ LINE2:collTimePerMin#aa0000:"CollTimePerMin" \
+ GPRINT:collTimePerMin:AVERAGE:" Avg \\: %5.2lf %s\\n"
diff --git a/core/upgrade/src/test/resources/jetty-webapps/opennms/WEB-INF/version.properties b/core/upgrade/src/test/resources/jetty-webapps/opennms/WEB-INF/version.properties
new file mode 100644
index 000000000000..cab32a30f108
--- /dev/null
+++ b/core/upgrade/src/test/resources/jetty-webapps/opennms/WEB-INF/version.properties
@@ -0,0 +1 @@
+version.display=1.12.2
diff --git a/core/upgrade/src/test/resources/rrd/1/eth0-005056c00008/ifInOctets.jrb b/core/upgrade/src/test/resources/rrd/1/eth0-005056c00008/ifInOctets.jrb
new file mode 100644
index 000000000000..a1c7011913ca
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd/1/eth0-005056c00008/ifInOctets.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd/1/eth0/ifInOctets.jrb b/core/upgrade/src/test/resources/rrd/1/eth0/ifInOctets.jrb
new file mode 100644
index 000000000000..23ed21d83a15
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd/1/eth0/ifInOctets.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollCnt.jrb b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollCnt.jrb
new file mode 100644
index 000000000000..2c5aa8b90973
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollCnt.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollCnt.meta b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollCnt.meta
new file mode 100644
index 000000000000..66848a6c6939
--- /dev/null
+++ b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollCnt.meta
@@ -0,0 +1,2 @@
+#Tue Jul 30 12:29:26 EDT 2013
+JMX_java.lang\:type\=GarbageCollector.name.PS\ Scavenge.PSS.CollCnt=PSS.CollCnt
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollTime.jrb b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollTime.jrb
new file mode 100644
index 000000000000..982b2a5e8869
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollTime.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollTime.meta b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollTime.meta
new file mode 100644
index 000000000000..d8b9bea982ad
--- /dev/null
+++ b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.CollTime.meta
@@ -0,0 +1,2 @@
+#Tue Jul 30 12:29:26 EDT 2013
+JMX_java.lang\:type\=GarbageCollector.name.PS\ Scavenge.PSS.CollTime=PSS.CollTime
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.Duration.jrb b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.Duration.jrb
new file mode 100644
index 000000000000..4e7ecc7b0e3e
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.Duration.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.Duration.meta b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.Duration.meta
new file mode 100644
index 000000000000..9dd017317698
--- /dev/null
+++ b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.Duration.meta
@@ -0,0 +1,2 @@
+#Tue Jul 30 12:29:26 EDT 2013
+JMX_java.lang\:type\=GarbageCollector.name.PS\ Scavenge.PSS.Duration=PSS.Duration
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.EndTime.jrb b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.EndTime.jrb
new file mode 100644
index 000000000000..1cf3c2bd1e0a
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.EndTime.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.EndTime.meta b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.EndTime.meta
new file mode 100644
index 000000000000..e15c02070c49
--- /dev/null
+++ b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.EndTime.meta
@@ -0,0 +1,2 @@
+#Tue Jul 30 12:29:26 EDT 2013
+JMX_java.lang\:type\=GarbageCollector.name.PS\ Scavenge.PSS.EndTime=PSS.EndTime
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.GcThreadCnt.jrb b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.GcThreadCnt.jrb
new file mode 100644
index 000000000000..3339d15d5fde
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.GcThreadCnt.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.GcThreadCnt.meta b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.GcThreadCnt.meta
new file mode 100644
index 000000000000..09876f9e4027
--- /dev/null
+++ b/core/upgrade/src/test/resources/rrd/1/opennms-jvm/PSS.GcThreadCnt.meta
@@ -0,0 +1,2 @@
+#Tue Jul 30 12:29:26 EDT 2013
+JMX_java.lang\:type\=GarbageCollector.name.PS\ Scavenge.PSS.GcThreadCnt=PSS.GcThreadCnt
diff --git a/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/ds.properties b/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/ds.properties
new file mode 100644
index 000000000000..a72839a4a808
--- /dev/null
+++ b/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/ds.properties
@@ -0,0 +1,11 @@
+#Wed Oct 30 09:57:14 EDT 2013
+SurvPeakUsage.max=java_lang_type_MemoryPool_name_Survivor Space
+SurvPeakUsage.used=java_lang_type_MemoryPool_name_Survivor Space
+SurvUsage.used=java_lang_type_MemoryPool_name_Survivor Space
+SurvCollUseThrshCnt=java_lang_type_MemoryPool_name_Survivor Space
+SurvPeakUsage.init=java_lang_type_MemoryPool_name_Survivor Space
+SurvUsage.init=java_lang_type_MemoryPool_name_Survivor Space
+SurvUsage.max=java_lang_type_MemoryPool_name_Survivor Space
+SurvCollUseThresh=java_lang_type_MemoryPool_name_Survivor Space
+SurvPeakUsg.cmmttd=java_lang_type_MemoryPool_name_Survivor Space
+SurvUsg.cmmttd=java_lang_type_MemoryPool_name_Survivor Space
diff --git a/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor Space.jrb b/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor Space.jrb
new file mode 100644
index 000000000000..fd81044ab673
Binary files /dev/null and b/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor Space.jrb differ
diff --git a/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor Space.meta b/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor Space.meta
new file mode 100644
index 000000000000..8b3cb95fd011
--- /dev/null
+++ b/core/upgrade/src/test/resources/rrd2/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor Space.meta
@@ -0,0 +1,11 @@
+#Wed Oct 30 09:57:14 EDT 2013
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvPeakUsage.used=SurvPeakUsage.used
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvUsg.cmmttd=SurvUsg.cmmttd
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvUsage.init=SurvUsage.init
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvUsage.used=SurvUsage.used
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvPeakUsage.max=SurvPeakUsage.max
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvUsage.max=SurvUsage.max
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvCollUseThrshCnt=SurvCollUseThrshCnt
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvCollUseThresh=SurvCollUseThresh
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvPeakUsg.cmmttd=SurvPeakUsg.cmmttd
+JMX_java.lang\:type\=MemoryPool.name.Survivor\ Space.SurvPeakUsage.init=SurvPeakUsage.init
diff --git a/dependencies/atomikos/pom.xml b/dependencies/atomikos/pom.xml
new file mode 100644
index 000000000000..d6059adc234e
--- /dev/null
+++ b/dependencies/atomikos/pom.xml
@@ -0,0 +1,71 @@
+
+
+
+ org.opennms
+ dependencies
+ 1.13.0-SNAPSHOT
+
+ 4.0.0
+ org.opennms.dependencies
+ atomikos-dependencies
+ pom
+ OpenNMS Dependencies JOTM
+
+ This module is used to provide a single artifact that the opennms project
+ can depend on to use JOTM.
+
+
+
+ com.atomikos
+ transactions-jta
+ 3.8.0
+
+
+ com.atomikos
+ transactions-jdbc
+ 3.8.0
+
+
+ javax.transaction
+ jta
+ 1.1
+
+
+
+
diff --git a/dependencies/jasper/pom.xml b/dependencies/jasper/pom.xml
index 231608bf676a..96ba6d5cb1fa 100644
--- a/dependencies/jasper/pom.xml
+++ b/dependencies/jasper/pom.xml
@@ -43,6 +43,10 @@
eclipse
jdtcore
+
+ commons-logging
+ commons-logging
+