use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class DefaultEventProcessor method process.
@Override
public void process(final Exchange exchange) throws Exception {
final Event event = exchange.getIn().getBody(Event.class);
// are added as message headers
if (event.getNodeid() > 0) {
OnmsNode node = nodeDao.get(event.getNodeid().intValue());
if (node != null) {
String foreignSource = node.getForeignSource();
String foreignId = node.getForeignId();
if (foreignSource != null && foreignId != null) {
exchange.getIn().setHeader(EVENT_HEADER_FOREIGNSOURCE, node.getForeignSource());
exchange.getIn().setHeader(EVENT_HEADER_FOREIGNID, node.getForeignId());
}
} else {
LOG.warn("Could not find node {} in the database, cannot add requisition headers", event.getNodeid());
}
}
// Marshall the Event to XML
exchange.getIn().setBody(JaxbUtils.marshal(event), String.class);
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class IPServiceEdgeDaoIT method ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade.
@Test
public void ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade() throws InterruptedException {
// Create a business service
BusinessServiceEntity bs = new BusinessServiceEntity();
bs.setName("Mont Cascades");
bs.setAttribute("dc", "RDU");
bs.setReductionFunction(m_highestSeverity);
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// Initially there should be no edges
assertEquals(0, m_businessServiceEdgeDao.countAll());
// Create an edge
IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
edge.setMapFunction(m_identity);
edge.setBusinessService(bs);
// Grab the first monitored service from node 1
OnmsNode node = m_databasePopulator.getNode1();
OnmsMonitoredService ipService = node.getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
edge.setIpService(ipService);
m_businessServiceEdgeDao.save(edge);
m_businessServiceEdgeDao.flush();
bs.addEdge(edge);
m_businessServiceDao.update(bs);
m_businessServiceDao.flush();
// We should have a single business service with a single IP service associated
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(1, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
// Now delete the node
m_nodeDao.delete(node);
m_nodeDao.flush();
// The business service should still be present, but the IP service should have been deleted
// by the foreign key constraint
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(0, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method getNodeEntity.
private OnmsNode getNodeEntity(Integer nodeId) {
Objects.requireNonNull(nodeId);
final OnmsNode entity = nodeDao.get(nodeId);
if (entity == null) {
throw new NoSuchElementException("OnmsNode with id " + nodeId);
}
return entity;
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class CollectorComplianceTest method canCollectUsingMinionWorkflow.
@Test
public void canCollectUsingMinionWorkflow() throws CollectionInitializationException, CollectionException {
Assume.assumeTrue(runsOnMinion);
// create the agent
OnmsNode node = mock(OnmsNode.class);
when(node.getId()).thenReturn(1);
OnmsIpInterface iface = mock(OnmsIpInterface.class);
when(iface.getNode()).thenReturn(node);
when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
when(ifaceDao.load(1)).thenReturn(iface);
PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
final SnmpCollectionAgent agent = DefaultCollectionAgent.create(1, ifaceDao, transMgr);
// init() should execute without any exceptions
final ServiceCollector opennmsCollector = getCollector();
initialize(opennmsCollector);
// getEffectiveLocation() should return the original location
final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
assertEquals("Location cannot be altered.", targetLocation, opennmsCollector.getEffectiveLocation(targetLocation));
// getRuntimeAttributes() should return a valid map
final Map<String, Object> requiredParams = getRequiredParameters();
final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams));
// marshalParameters() should marshal all parameters to strings
final Map<String, Object> allParms = new HashMap<>();
allParms.putAll(requiredParams);
allParms.putAll(runtimeAttrs);
final Map<String, String> marshaledParms = opennmsCollector.marshalParameters(Collections.unmodifiableMap(allParms));
beforeMinion();
// create a separate instance of the collector
final ServiceCollector minionCollector = getNewCollector();
// unmarshalParameters() should unmarshal all parameters from strings
final Map<String, Object> unmarshaledParms = minionCollector.unmarshalParameters(Collections.unmodifiableMap(marshaledParms));
// collect() should return a valid collection set
final CollectionAgentDTO agentDTO = new CollectionAgentDTO(agent);
final CollectionSet collectionSet = minionCollector.collect(agentDTO, Collections.unmodifiableMap(unmarshaledParms));
assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
afterMinion();
// the collection set should be marshalable
JaxbUtils.marshal(collectionSet);
// getRrdRepository() should return a valid repository
assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class CollectorComplianceTest method canCollectUsingOpenNMSWorkflow.
@Test
public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException {
// create the agent
OnmsNode node = mock(OnmsNode.class);
OnmsIpInterface iface = mock(OnmsIpInterface.class);
when(iface.getNode()).thenReturn(node);
when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
when(ifaceDao.load(1)).thenReturn(iface);
PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
final SnmpCollectionAgent agent = DefaultCollectionAgent.create(1, ifaceDao, transMgr);
// init() should execute without any exceptions
final ServiceCollector opennmsCollector = getCollector();
initialize(opennmsCollector);
// getEffectiveLocation() should execute without any exceptions
// in this context there are no requirements on its return value
final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
opennmsCollector.getEffectiveLocation(targetLocation);
// getRuntimeAttributes() should return a valid map
final Map<String, Object> requiredParams = getRequiredParameters();
final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams));
// collect() should return a valid collection set
final Map<String, Object> allParms = new HashMap<>();
allParms.putAll(requiredParams);
allParms.putAll(runtimeAttrs);
final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms));
assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
// getRrdRepository() should return a valid repository
assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
}
Aggregations