use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class NCSComponentServiceImpl method addOrUpdateComponents.
@Override
@Transactional
public NCSComponent addOrUpdateComponents(final NCSComponent component, final boolean deleteOrphans) {
final ComponentIdentifier componentId = getIdentifier(component);
LOG.debug("addOrUpdateComponents({}, {})", componentId, Boolean.valueOf(deleteOrphans));
final ComponentEventQueue ceq = new ComponentEventQueue();
final NCSComponent updatedComponent = addOrUpdateComponents(componentId, component, ceq, deleteOrphans);
try {
ceq.sendAll(m_eventProxy);
} catch (final EventProxyException e) {
LOG.warn("Component {} added, but an error occured while sending add/delete/update events.", componentId, e);
}
return updatedComponent;
}
use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class NCSComponentServiceImpl method handleOrphanedComponents.
private void handleOrphanedComponents(final NCSComponent parent, final ComponentIdentifier child, final ComponentEventQueue ceq, final boolean deleteOrphans) {
final ComponentIdentifier parentId = getIdentifier(parent);
final NCSComponent childComponent = getComponent(child);
final Set<ComponentIdentifier> childChildren = getIdentifiers(childComponent.getSubcomponents());
final Set<ComponentIdentifier> childParents = getIdentifiers(childComponent.getParentComponents());
LOG.trace("handleOrphanedComponents: parent: {}", parentId);
LOG.trace("handleOrphanedComponents: child: {}", child);
LOG.trace("handleOrphanedComponents: child's children: {}", childChildren);
LOG.trace("handleOrphanedComponents: child's parents: {}", childParents);
if (childParents.size() == 1) {
final ComponentIdentifier childParent = childParents.iterator().next();
if (childParent.equals(parentId)) {
LOG.trace("handleOrphanedComponents: child ({}) has only one parent ({}) and it's being deleted.", child, childParent);
deleteComponent(child, ceq, deleteOrphans);
} else {
LOG.trace("handleOrphanedComponents: child ({}) has only one parent ({}) but it's not the one we expected. This is weird.", child, childParent);
ceq.componentUpdated(childParent);
}
} else {
LOG.trace("handleOrphanedComponents: child ({}) has more than one parent, sending updates for remaining parents.", child);
for (final ComponentIdentifier childParent : childParents) {
ceq.componentUpdated(childParent);
}
}
}
use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class NCSRestService method getComponent.
/**
* <p>getNodes</p>
*
* @return a {@link org.opennms.netmgt.model.OnmsNodeList} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("{type}/{foreignSource}:{foreignId}")
public NCSComponent getComponent(@PathParam("type") final String type, @PathParam("foreignSource") final String foreignSource, @PathParam("foreignId") final String foreignId) {
afterPropertiesSet();
readLock();
try {
LOG.debug("getComponent: type = {}, foreignSource = {}, foreignId = {}", type, foreignSource, foreignId);
if (m_componentService == null) {
throw getException(Status.INTERNAL_SERVER_ERROR, "Component service is null");
}
if (foreignSource == null) {
throw getException(Status.BAD_REQUEST, "Foreign Source cannot be null");
}
if (foreignId == null) {
throw getException(Status.BAD_REQUEST, "Foreign ID cannot be null");
}
final NCSComponent component = m_componentService.getComponent(type, foreignSource, foreignId);
if (component == null)
throw getException(Status.NOT_FOUND, "Component of type {} not found for {}:{}", type, foreignSource, foreignId);
return component;
} finally {
readUnlock();
}
}
use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class NCSComponentDaoIT method setUp.
@Before
public void setUp() {
NetworkBuilder bldr = new NetworkBuilder();
// Make sure that the default OnmsMonitoringLocation is saved
m_locationDao.saveOrUpdate(bldr.getLocation());
bldr.addNode("PE1").setForeignSource("space").setForeignId("1111-PE1");
m_nodeDao.save(bldr.getCurrentNode());
m_pe1NodeId = bldr.getCurrentNode().getId();
bldr.addNode("PE2").setForeignSource("space").setForeignId("2222-PE2");
m_nodeDao.save(bldr.getCurrentNode());
m_pe2NodeId = bldr.getCurrentNode().getId();
NCSComponent svc = new NCSBuilder("Service", "NA-Service", "123").setName("CokeP2P").pushComponent("ServiceElement", "NA-ServiceElement", "8765").setName("PE1,SE1").setNodeIdentity("space", "1111-PE1").pushComponent("ServiceElementComponent", "NA-SvcElemComp", "8765,jnxVpnIf").setName("jnxVpnIf").setNodeIdentity("space", "1111-PE1").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfDown").setAttribute("jnxVpnIfVpnType", "5").setAttribute("jnxVpnIfVpnName", "ge-1/0/2.50").pushComponent("ServiceElementComponent", "NA-SvcElemComp", "8765,link").setName("link").setNodeIdentity("space", "1111-PE1").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/linkUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/linkDown").setAttribute("linkName", "ge-1/0/2").popComponent().popComponent().pushComponent("ServiceElementComponent", "NA-SvcElemComp", "8765,jnxVpnPw-vcid(50)").setName("jnxVpnPw-vcid(50)").setNodeIdentity("space", "1111-PE1").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnPwUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnPwDown").setAttribute("jnxVpnPwVpnType", "5").setAttribute("jnxVpnPwVpnName", "ge-1/0/2.50").setDependenciesRequired(DependencyRequirements.ANY).pushComponent("ServiceElementComponent", "NA-SvcElemComp", "8765,lspA-PE1-PE2").setName("lspA-PE1-PE2").setNodeIdentity("space", "1111-PE1").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathDown").setAttribute("mplsLspName", "lspA-PE1-PE2").popComponent().pushComponent("ServiceElementComponent", "NA-SvcElemComp", "8765,lspB-PE1-PE2").setName("lspB-PE1-PE2").setNodeIdentity("space", "1111-PE1").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathDown").setAttribute("mplsLspName", "lspB-PE1-PE2").popComponent().popComponent().popComponent().pushComponent("ServiceElement", "NA-ServiceElement", "9876").setName("PE2,SE1").setNodeIdentity("space", "2222-PE2").pushComponent("ServiceElementComponent", "NA-SvcElemComp", "9876,jnxVpnIf").setName("jnxVpnIf").setNodeIdentity("space", "2222-PE2").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfDown").setAttribute("jnxVpnIfVpnType", "5").setAttribute("jnxVpnIfVpnName", "ge-3/1/4.50").pushComponent("ServiceElementComponent", "NA-SvcElemComp", "9876,link").setName("link").setNodeIdentity("space", "2222-PE2").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/linkUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/linkDown").setAttribute("linkName", "ge-3/1/4").popComponent().popComponent().pushComponent("ServiceElementComponent", "NA-SvcElemComp", "9876,jnxVpnPw-vcid(50)").setName("jnxVpnPw-vcid(50)").setNodeIdentity("space", "2222-PE2").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnPwUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnPwDown").setAttribute("jnxVpnPwVpnType", "5").setAttribute("jnxVpnPwVpnName", "ge-3/1/4.50").setDependenciesRequired(DependencyRequirements.ANY).pushComponent("ServiceElementComponent", "NA-SvcElemComp", "9876,lspA-PE2-PE1").setName("lspA-PE2-PE1").setNodeIdentity("space", "2222-PE2").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathDown").setAttribute("mplsLspName", "lspA-PE2-PE1").popComponent().pushComponent("ServiceElementComponent", "NA-SvcElemComp", "9876,lspB-PE2-PE1").setName("lspB-PE2-PE1").setNodeIdentity("space", "2222-PE2").setUpEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathUp").setDownEventUei("uei.opennms.org/vendor/Juniper/traps/mplsLspPathDown").setAttribute("mplsLspName", "lspB-PE2-PE1").popComponent().popComponent().popComponent().get();
m_repository.save(svc);
}
use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class EventMappingRulesIT method findSubcomponentsOnNode.
private Set<String> findSubcomponentsOnNode(NCSComponent svc, String nodeForeignSource, String nodeForeignId) {
final Set<String> expectedIds = new HashSet<String>();
final NodeIdentification nodeIdent = new NodeIdentification(nodeForeignSource, nodeForeignId);
NCSComponentVisitor visitor = new AbstractNCSComponentVisitor() {
@Override
public void visitComponent(NCSComponent component) {
if (nodeIdent.equals(component.getNodeIdentification())) {
expectedIds.add(component.getForeignSource() + ":" + component.getForeignId());
}
}
};
svc.visit(visitor);
return expectedIds;
}
Aggregations