Search in sources :

Example 6 with Criteria

use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.

the class DefaultPollingContext method getNodeIpAddress.

/*
     * Return the IP address of the first interface on the node
     */
protected InetAddress getNodeIpAddress(OnmsNode node) {
    final Criteria criteria = new Criteria(OnmsIpInterface.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", node.getId()));
    List<OnmsIpInterface> matchingIfaces = getIpInterfaceDao().findMatching(criteria);
    return matchingIfaces.get(0).getIpAddress();
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria)

Example 7 with Criteria

use of org.opennms.core.criteria.Criteria 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 8 with Criteria

use of org.opennms.core.criteria.Criteria 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 9 with Criteria

use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.

the class SyslogIT method canReceiveSyslogMessages.

@Test
public void canReceiveSyslogMessages() throws Exception {
    final Date startOfTest = new Date();
    // Send a syslog packet to the Minion syslog listener
    sendMessage(ContainerAlias.MINION, "myhost", 1);
    // Parsing the message correctly relies on the customized syslogd-configuration.xml that is part of the OpenNMS image
    final EventDao eventDao = getDaoFactory().getDao(EventDaoHibernate.class);
    final Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).toCriteria();
    await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventDao(org.opennms.netmgt.dao.api.EventDao) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test)

Example 10 with Criteria

use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.

the class BusinessServiceSearchProvider method queryVertices.

@Override
public List<? extends VertexRef> queryVertices(SearchQuery searchQuery, GraphContainer container) {
    List<BusinessServiceVertex> results = Lists.newArrayList();
    String queryString = searchQuery.getQueryString();
    CriteriaBuilder bldr = new CriteriaBuilder(BusinessService.class);
    if (queryString != null && queryString.length() > 0) {
        bldr.ilike("name", String.format("%%%s%%", queryString));
    }
    bldr.orderBy("name", true);
    bldr.limit(10);
    Criteria dbQueryCriteria = bldr.toCriteria();
    for (BusinessService bs : businessServiceManager.findMatching(dbQueryCriteria)) {
        final BusinessServiceVertex businessServiceVertex = new BusinessServiceVertex(bs, 0);
        // Only consider results which are available in the Topology Provider, see BSM-191
        if (container.getTopologyServiceClient().getVertex(businessServiceVertex) != null) {
            results.add(businessServiceVertex);
        }
    }
    return results;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Criteria(org.opennms.core.criteria.Criteria)

Aggregations

Criteria (org.opennms.core.criteria.Criteria)62 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)31 Test (org.junit.Test)16 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)16 Date (java.util.Date)13 Alias (org.opennms.core.criteria.Alias)13 ArrayList (java.util.ArrayList)10 Order (org.opennms.core.criteria.Order)9 Transactional (org.springframework.transaction.annotation.Transactional)9 GET (javax.ws.rs.GET)8 PUT (javax.ws.rs.PUT)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 POST (javax.ws.rs.POST)6 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)5 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)5 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)5 Produces (javax.ws.rs.Produces)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 ScanReport (org.opennms.netmgt.model.ScanReport)4 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)4