Search in sources :

Example 21 with CriteriaBuilder

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 22 with CriteriaBuilder

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 23 with CriteriaBuilder

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) PropertyNotFoundException(org.apache.cxf.jaxrs.ext.search.PropertyNotFoundException) GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) Criteria(org.opennms.core.criteria.Criteria) CriteriaBuilderSearchVisitor(org.opennms.web.rest.support.CriteriaBuilderSearchVisitor)

Example 24 with CriteriaBuilder

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));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Executor(org.apache.http.client.fluent.Executor) EventDao(org.opennms.netmgt.dao.api.EventDao) InetSocketAddress(java.net.InetSocketAddress) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) Criteria(org.opennms.core.criteria.Criteria) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) Date(java.util.Date) Test(org.junit.Test)

Example 25 with CriteriaBuilder

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());
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) MinionDao(org.opennms.netmgt.dao.api.MinionDao) Date(java.util.Date) Test(org.junit.Test)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)155 Test (org.junit.Test)60 Criteria (org.opennms.core.criteria.Criteria)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 Transactional (org.springframework.transaction.annotation.Transactional)23 Date (java.util.Date)20 GET (javax.ws.rs.GET)13 ArrayList (java.util.ArrayList)12 Produces (javax.ws.rs.Produces)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)11 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)11 InetSocketAddress (java.net.InetSocketAddress)9 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)7 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)4 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4