use of org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource in project opennms by OpenNMS.
the class DataSourceConfigurationTest method data.
@Parameters
public static Collection<Object[]> data() throws Exception {
DataSourceConfiguration config = new DataSourceConfiguration();
ConnectionPool connectionPool = new ConnectionPool();
connectionPool.setFactory("org.opennms.core.db.HikariCPConnectionFactory");
connectionPool.setIdleTimeout(600);
connectionPool.setLoginTimeout(3);
connectionPool.setMinPool(50);
connectionPool.setMaxPool(50);
connectionPool.setMaxSize(50);
config.setConnectionPool(connectionPool);
JdbcDataSource opennmsDs = new JdbcDataSource();
opennmsDs.setName("opennms");
opennmsDs.setClassName("org.postgresql.Driver");
opennmsDs.setUrl("jdbc:postgresql://localhost:5432/template1");
opennmsDs.setUserName("opennms");
opennmsDs.setPassword("opennms");
config.addJdbcDataSource(opennmsDs);
JdbcDataSource opennmsDeuceDs = new JdbcDataSource();
opennmsDeuceDs.setName("opennms2");
opennmsDeuceDs.setClassName("org.postgresql.Driver");
opennmsDeuceDs.setUrl("jdbc:postgresql://localhost:5432/template1");
opennmsDeuceDs.addParam(new Param("user", "opennms"));
opennmsDeuceDs.addParam(new Param("password", "opennms"));
config.addJdbcDataSource(opennmsDeuceDs);
return Arrays.asList(new Object[][] { { config, new File("src/test/resources/org/opennms/core/db/opennms-datasources.xml") } });
}
use of org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource in project opennms by OpenNMS.
the class TemporaryDatabaseExecutionListener method prepareTestInstance.
@Override
public void prepareTestInstance(final TestContext testContext) throws Exception {
//System.err.println(String.format("TemporaryDatabaseExecutionListener.prepareTestInstance(%s); details: %s", testContext.hashCode(), testContext));
final JUnitTemporaryDatabase jtd = findAnnotation(testContext);
if (jtd == null) {
return;
}
m_database = m_databases.remove();
//
if (jtd.poolConnections()) {
JdbcDataSource ds = new JdbcDataSource();
ds.setDatabaseName(m_database.getTestDatabase());
ds.setUserName(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
ds.setPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
ds.setUrl(System.getProperty(TemporaryDatabase.URL_PROPERTY, TemporaryDatabase.DEFAULT_URL) + m_database.getTestDatabase());
ds.setClassName(System.getProperty(TemporaryDatabase.DRIVER_PROPERTY, TemporaryDatabase.DEFAULT_DRIVER));
HikariCPConnectionFactory pool = new HikariCPConnectionFactory(ds);
// NMS-8911: Reduce the max connection lifetime so that HikariCP recycles
// connections more aggressively during tests
pool.setMaxLifetime(500);
DataSourceFactory.setInstance(pool);
} else {
DataSourceFactory.setInstance(m_database);
}
XADataSourceFactory.setInstance(m_database);
//System.err.println(String.format("TemporaryDatabaseExecutionListener.prepareTestInstance(%s) prepared db %s; details: %s", testContext.hashCode(), m_database.toString(), testContext));
//System.err.println("Temporary Database Name: " + m_database.getTestDatabase());
}
use of org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource in project opennms by OpenNMS.
the class OnmsProperties method initialize.
/**
* Initialize.
*/
public static void initialize() {
try {
final Properties mainProperties = new Properties();
loadProperties(mainProperties, "opennms.properties");
registerProperties(mainProperties);
final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME);
final DataSourceConfiguration dsc = JaxbUtils.unmarshal(DataSourceConfiguration.class, cfgFile);
boolean found = false;
for (JdbcDataSource jds : dsc.getJdbcDataSourceCollection()) {
if (jds.getName().equals("opennms")) {
SimpleDataSource ds = new SimpleDataSource(jds);
DataSourceFactory.setInstance(ds);
found = true;
}
}
if (!found) {
throw NewtsConverterError.create("Can't find OpenNMS database configuration");
}
} catch (Exception e) {
throw NewtsConverterError.create(e, "Can't initialize OpenNMS database connection factory: {}", e.getMessage());
}
}
use of org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource in project opennms by OpenNMS.
the class ReportCompiler method initializeSingleInstanceDatabase.
/**
* Initializes a single instance DB connection factory.
* <p>From <code>org.opennms.netmgt.poller.MonitorTester</code></p>
*/
private static void initializeSingleInstanceDatabase() {
try {
final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME);
final DataSourceConfiguration dsc = JaxbUtils.unmarshal(DataSourceConfiguration.class, cfgFile);
boolean found = false;
for (JdbcDataSource jds : dsc.getJdbcDataSourceCollection()) {
if (jds.getName().equals("opennms")) {
System.out.printf("Initializing datatabase %s\n", jds.getUrl());
DataSourceFactory.setInstance(new SimpleDataSource(jds));
found = true;
}
}
if (!found) {
System.err.printf("Error: Can't find OpenNMS database configuration.\n");
System.exit(1);
}
} catch (Exception e) {
System.err.printf("Error: Can't initialize OpenNMS database connection factory. %s\n", e.getMessage());
System.exit(1);
}
}
use of org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource in project opennms by OpenNMS.
the class AbstractOnmsUpgrade method initializeDatasource.
/**
* Initializes the data source.
*
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
protected void initializeDatasource() throws OnmsUpgradeException {
if (dataSource != null) {
return;
}
try {
final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME);
final DataSourceConfiguration dsc = JaxbUtils.unmarshal(DataSourceConfiguration.class, cfgFile);
for (JdbcDataSource jds : dsc.getJdbcDataSourceCollection()) {
if (jds.getName().equals("opennms")) {
dataSource = new SimpleDataSource(jds);
DataSourceFactory.setInstance(dataSource);
}
}
if (dataSource == null) {
throw new OnmsUpgradeException("Can't find theOpenNMS Database settings.");
}
} catch (Exception e) {
throw new OnmsUpgradeException("Can't connect to OpenNMS Database because " + e.getMessage(), e);
}
}
Aggregations