use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class DiscoveryIT method canDiscoverRemoteNodes.
@Test
public void canDiscoverRemoteNodes() throws ClientProtocolException, IOException {
Date startOfTest = new Date();
final String tomcatIp = minionSystem.getContainerInfo(ContainerAlias.TOMCAT).networkSettings().ipAddress();
final InetSocketAddress opennmsHttp = minionSystem.getServiceAddress(ContainerAlias.OPENNMS, 8980);
final HttpHost opennmsHttpHost = new HttpHost(opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort());
HttpClient instance = HttpClientBuilder.create().setRedirectStrategy(// Ignore the 302 response to the POST
new LaxRedirectStrategy()).build();
Executor executor = Executor.newInstance(instance).auth(opennmsHttpHost, "admin", "admin").authPreemptive(opennmsHttpHost);
// Configure Discovery with the specific address of our Tomcat server
// No REST endpoint is currently available to configure the Discovery daemon
// so we resort to POSTin nasty form data
executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=AddSpecific", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("specificipaddress", tomcatIp).add("specifictimeout", "2000").add("specificretries", "1").add("initialsleeptime", "30000").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=SaveAndRestart", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("initialsleeptime", "1").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).toCriteria();
await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
}
use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class MinionHeartBeatIT method minionHeartBeatTestForLastUpdated.
@Test
public void minionHeartBeatTestForLastUpdated() {
Date startOfTest = new Date();
InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
MinionDao minionDao = daoFactory.getDao(MinionDaoHibernate.class);
NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
// The heartbeat runs every minute so if we miss the first one, poll long enough
// to catch the next one
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(minionDao, new CriteriaBuilder(OnmsMinion.class).ge("lastUpdated", startOfTest).toCriteria()), greaterThan(0));
await().atMost(180, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).eq("foreignSource", "Minions").eq("foreignId", "00000000-0000-0000-0000-000000ddba11").toCriteria()), equalTo(1));
Assert.assertEquals("MINION", nodeDao.get("Minions:00000000-0000-0000-0000-000000ddba11").getLocation().getLocationName());
}
use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class AbstractSyslogTestCase method getDaoFactory.
protected HibernateDaoFactory getDaoFactory() {
if (m_daoFactory == null) {
// Connect to the postgresql container
final InetSocketAddress pgsql = testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
m_daoFactory = new HibernateDaoFactory(pgsql);
}
return m_daoFactory;
}
use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class TrapIT method canReceiveTraps.
@Test
public void canReceiveTraps() throws Exception {
Date startOfTest = new Date();
final InetSocketAddress trapAddr = minionSystem.getServiceAddress(ContainerAlias.MINION, 1162, "udp");
// Connect to the postgresql container
InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
// Parsing the message correctly relies on the customized syslogd-configuration.xml that is part of the OpenNMS image
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/generic/traps/SNMP_Warm_Start").ge("eventTime", startOfTest).toCriteria();
// Send traps to the Minion listener until one makes it through
await().atMost(5, MINUTES).pollInterval(30, SECONDS).pollDelay(0, SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
sendTrap(trapAddr);
try {
await().atMost(30, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThanOrEqualTo(1));
} catch (final Exception e) {
return false;
}
return true;
}
});
}
use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class StatisticsReportsIT method hasReportLinkThatMatchDescription.
@Test
public void hasReportLinkThatMatchDescription() throws Exception {
Date startOfTest = new Date();
HibernateDaoFactory daoFactory = new HibernateDaoFactory(getPostgresService());
ResourceReferenceDao resourceReferenceDao = daoFactory.getDao(ResourceReferenceDaoHibernate.class);
StatisticsReportDao statisticsReportDao = daoFactory.getDao(StatisticsReportDaoHibernate.class);
StatisticsReport report = new StatisticsReport();
report.setName("Top10_Response_Hourly");
report.setDescription("Hourly Top 10 responses across all nodes");
report.setStartDate(new Date());
report.setEndDate(new Date());
report.setJobStartedDate(new Date());
report.setJobCompletedDate(new Date());
report.setPurgeDate(new Date());
ResourceReference resource = new ResourceReference();
resource.setResourceId("node1");
resourceReferenceDao.save(resource);
StatisticsReportData data = new StatisticsReportData();
data.setReport(report);
data.setResource(resource);
data.setValue(4.0);
report.addData(data);
statisticsReportDao.save(report);
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(statisticsReportDao, new CriteriaBuilder(StatisticsReport.class).ge("startDate", startOfTest).toCriteria()), notNullValue());
m_driver.navigate().refresh();
assertNotNull(findElementByLink("Hourly Top 10 responses across all nodes"));
}
Aggregations