use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class BusinessServiceDaoIT method verifyDistinctObjectLoading.
@Test
@Transactional
public void verifyDistinctObjectLoading() {
BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Parent Web Servers").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).addReductionKey("TestReductionKeyC", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
m_businessServiceDao.save(entity);
m_businessServiceDao.flush();
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(3, m_edgeDao.countAll());
Criteria criteria = new CriteriaBuilder(BusinessServiceEntity.class).toCriteria();
// verify that root entity is merged
assertEquals(1, m_businessServiceDao.findMatching(criteria).size());
// verify that countMatching also works
assertEquals(1, m_businessServiceDao.countMatching(criteria));
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class EventdIT method testPersistEvent.
@Test(timeout = 30000)
public void testPersistEvent() throws Exception {
CriteriaBuilder cb = new CriteriaBuilder(OnmsEvent.class);
cb.eq("eventUei", EventConstants.NODE_DOWN_EVENT_UEI);
assertEquals(0, m_eventDao.countMatching(cb.toCriteria()));
OnmsNode node = m_databasePopulator.getNode1();
assertNotNull(node);
sendNodeDownEvent(null, node);
while (m_eventDao.countMatching(cb.toCriteria()) < 1) {
Thread.sleep(SLEEP_TIME);
}
final List<OnmsEvent> matching = m_eventDao.findMatching(cb.toCriteria());
System.err.println("matching = " + matching);
assertEquals(1, m_eventDao.countMatching(cb.toCriteria()));
node = m_databasePopulator.getNode2();
assertNotNull(node);
Event generatedEvent = sendNodeDownEvent(null, node);
while (m_eventDao.countMatching(cb.toCriteria()) < 2) {
Thread.sleep(SLEEP_TIME);
}
assertEquals(2, m_eventDao.countMatching(cb.toCriteria()));
assertNull(generatedEvent.getInterfaceAddress());
cb.isNull("ipAddr");
assertEquals("failed, found: " + m_eventDao.findMatching(cb.toCriteria()), 2, m_eventDao.countMatching(cb.toCriteria()));
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class EventdIT method testPersistEventWithService.
/**
* Test that eventd's service ID lookup works properly.
*/
@Test(timeout = 30000)
public void testPersistEventWithService() throws Exception {
CriteriaBuilder cb = new CriteriaBuilder(OnmsEvent.class);
cb.eq("eventUei", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI);
assertEquals(0, m_eventDao.countMatching(cb.toCriteria()));
assertNotNull(m_serviceTypeDao.findByName("ICMP"));
OnmsNode node = m_databasePopulator.getNode1();
assertNotNull(node);
OnmsIpInterface intf = node.getIpInterfaceByIpAddress("192.168.1.1");
assertNotNull(intf);
System.err.println("services = " + intf.getMonitoredServices());
OnmsMonitoredService svc = intf.getMonitoredServiceByServiceType("ICMP");
assertNotNull(svc);
assertEquals("192.168.1.1", str(svc.getIpAddress()));
final Integer serviceId = svc.getServiceId();
sendServiceDownEvent(null, svc);
while (m_eventDao.countMatching(cb.toCriteria()) != 1) {
Thread.sleep(SLEEP_TIME);
}
assertEquals(1, m_eventDao.countMatching(cb.toCriteria()));
assertEquals("service ID for event", serviceId, m_eventDao.findMatching(cb.toCriteria()).get(0).getServiceType().getId());
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class IpLikeSearchProvider method query.
/**
* This method processes the <SearchQuery> that the user has typed and returns a <SearchResult> list
* of matching IP addresses as well as the query string itself, which is collapsible, to act
* as a subnet container.
*/
@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer graphContainer) {
LOG.info("SearchProvider->query: called with search query: '{}'", searchQuery);
List<SearchResult> results = new ArrayList<>();
String queryString = searchQuery.getQueryString();
if (!isIpLikeQuery(queryString)) {
LOG.debug("SearchProvider->query: query not IPLIKE compatible.");
return results;
}
CriteriaBuilder bldr = new CriteriaBuilder(OnmsIpInterface.class);
bldr.iplike("ipAddr", queryString).orderBy("ipAddress", true);
Criteria dbQueryCriteria = bldr.toCriteria();
List<OnmsIpInterface> ips;
// since it seems to do something very similar in its matches method.
try {
ips = ipInterfaceProvider.findMatching(dbQueryCriteria);
if (ips.size() == 0) {
return results;
} else {
if (isIpLikeQuery(queryString)) {
LOG.debug("SearchProvider->query: adding IPLIKE search spec '{}' to the search results.", queryString);
SearchResult searchResult = new SearchResult(getSearchProviderNamespace(), queryString, queryString, queryString, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
if (!results.contains(searchResult)) {
results.add(searchResult);
}
}
}
Set<String> ipAddrs = new HashSet<>();
LOG.info("SearchProvider->query: creating IP address set.");
for (OnmsIpInterface ip : ips) {
String hostAddress = ip.getIpAddress().getHostAddress();
LOG.debug("SearchProvider->query: adding '{}' to set of IPs.", hostAddress);
ipAddrs.add(hostAddress);
}
LOG.info("SearchProvider->query: building search result from set of IPs.");
IPLOOP: for (String ip : ipAddrs) {
if (findCriterion(ip, graphContainer) != null) {
continue IPLOOP;
} else {
SearchResult searchResult = createSearchResult(ip, queryString);
if (!results.contains(searchResult)) {
results.add(searchResult);
}
}
}
LOG.info("SearchProvider->query: found: '{}' IP interfaces.", ips.size());
} catch (Exception e) {
LOG.error("SearchProvider-query: caught exception during iplike query: {}", e);
}
LOG.info("SearchProvider->query: built search result with {} results.", results.size());
return results;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class IpLikeHopCriteria method getVertices.
@Override
public Set<VertexRef> getVertices() {
CriteriaBuilder bldr = new CriteriaBuilder(OnmsIpInterface.class);
bldr.iplike("ipAddr", m_ipQuery);
List<OnmsIpInterface> ips = ipInterfaceProvider.findMatching(bldr.toCriteria());
Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
for (OnmsIpInterface ip : ips) {
OnmsNode node = ip.getNode();
vertices.add(new DefaultVertexRef("nodes", String.valueOf(node.getId()), node.getLabel()));
}
return vertices;
}
Aggregations