use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class OutageRestService method getCriteriaBuilder.
@Override
protected CriteriaBuilder getCriteriaBuilder() {
final CriteriaBuilder builder = new CriteriaBuilder(OnmsOutage.class);
builder.alias("monitoredService", "monitoredService", JoinType.LEFT_JOIN);
builder.alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN);
builder.alias("monitoredService.serviceType", "serviceType", JoinType.LEFT_JOIN);
builder.alias("ipInterface.node", "node", JoinType.LEFT_JOIN);
builder.alias("ipInterface.node.location", "location", JoinType.LEFT_JOIN);
builder.alias("serviceLostEvent", "serviceLostEvent", JoinType.LEFT_JOIN);
builder.alias("serviceRegainedEvent", "serviceRegainedEvent", JoinType.LEFT_JOIN);
// NOTE: Left joins on a toMany relationship need a join condition so that only one row is returned
// Order by ID by default
builder.orderBy("id").desc();
return builder;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class MinionRestService method getCriteriaBuilder.
protected CriteriaBuilder getCriteriaBuilder() {
final CriteriaBuilder builder = new CriteriaBuilder(OnmsMinion.class);
// Order by label by default
builder.orderBy("label").desc();
return builder;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class AbstractDaoRestService method getCriteria.
protected Criteria getCriteria(UriInfo uriInfo, SearchContext searchContext) {
final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
final CriteriaBuilder builder = getCriteriaBuilder();
if (searchContext != null) {
try {
SearchCondition<T> condition = searchContext.getCondition(getDaoClass());
if (condition != null) {
SearchConditionVisitor<T, CriteriaBuilder> visitor = new CriteriaBuilderSearchVisitor<T>(builder, getDaoClass());
condition.accept(visitor);
}
} catch (PropertyNotFoundException | ArrayIndexOutOfBoundsException e) {
LOG.warn(e.getClass().getSimpleName() + " while parsing FIQL search, ignoring: " + e.getMessage(), e);
}
}
// Apply limit, offset, orderBy, order params
applyLimitOffsetOrderBy(params, builder);
Criteria crit = builder.toCriteria();
return crit;
}
use of org.opennms.core.criteria.CriteriaBuilder 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.core.criteria.CriteriaBuilder 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());
}
Aggregations