use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class MonolithicDependencyRulesIT 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 NCSComponentDaoIT method testFindComponentsByNodeId.
@Test
public void testFindComponentsByNodeId() {
assertNotNull(m_repository);
assertFalse(0 == m_pe1NodeId);
assertFalse(0 == m_pe2NodeId);
List<NCSComponent> pe1Components = m_repository.findComponentsByNodeId(m_pe1NodeId);
assertFalse(pe1Components.isEmpty());
NCSComponent pe1SvcElem = m_repository.findByTypeAndForeignIdentity("ServiceElement", "NA-ServiceElement", "8765");
assertNotNull(pe1SvcElem);
assertTrue(pe1Components.contains(pe1SvcElem));
assertEquals(6, pe1Components.size());
List<NCSComponent> pe2Components = m_repository.findComponentsByNodeId(m_pe2NodeId);
assertFalse(pe2Components.isEmpty());
assertEquals(6, pe2Components.size());
}
use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class NCSRestServiceIT method testPostAService.
@Test
public void testPostAService() throws Exception {
setupLogging("DEBUG");
anticipateEvents(EventConstants.COMPONENT_ADDED_UEI);
sendPost("/NCS", m_serviceXML, 200, null);
final NCSComponentRepository repo = m_webApplicationContext.getBean("ncsComponentRepository", NCSComponentRepository.class);
for (final NCSComponent component : repo.findAll()) {
LOG.debug("Found Component: {}/{}/{}", component.getType(), component.getForeignSource(), component.getForeignId());
}
String url = "/NCS/ServiceElementComponent/NA-SvcElemComp:9876%2Cvcid(50)";
// Testing GET Collection
System.err.println("GET!!!");
String xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("jnxVpnPwVpnName"));
}
use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class NCSComponentServiceImpl method addOrUpdateComponents.
private NCSComponent addOrUpdateComponents(final ComponentIdentifier id, final NCSComponent component, final ComponentEventQueue ceq, final boolean deleteOrphans) {
final Set<NCSComponent> subcomponents = new LinkedHashSet<NCSComponent>();
final NCSComponent existing = new UpsertTemplate<NCSComponent, NCSComponentDao>(m_transactionManager, m_componentDao) {
@Override
protected NCSComponent query() {
return getComponent(id);
}
@Override
protected NCSComponent doInsert() {
for (final NCSComponent subcomponent : component.getSubcomponents()) {
final NCSComponent updatedComponent = addOrUpdateComponents(getIdentifier(subcomponent), subcomponent, ceq, deleteOrphans);
subcomponents.add(updatedComponent);
}
component.setSubcomponents(subcomponents);
m_componentDao.save(component);
ceq.componentAdded(getIdentifier(component));
return component;
}
@Override
protected NCSComponent doUpdate(final NCSComponent dbObj) {
for (final NCSComponent subcomponent : component.getSubcomponents()) {
final NCSComponent updatedComponent = addOrUpdateComponents(getIdentifier(subcomponent), subcomponent, ceq, deleteOrphans);
subcomponents.add(updatedComponent);
}
if (deleteOrphans)
deleteOrphanedComponents(getIdentifiers(dbObj.getSubcomponents()), getIdentifiers(subcomponents), ceq);
dbObj.setName(component.getName());
dbObj.setVersion(component.getVersion());
dbObj.setDependenciesRequired(component.getDependenciesRequired());
dbObj.setNodeIdentification(component.getNodeIdentification());
dbObj.setUpEventUei(component.getUpEventUei());
dbObj.setDownEventUei(component.getDownEventUei());
dbObj.setAttributes(component.getAttributes());
dbObj.setSubcomponents(subcomponents);
m_componentDao.update(dbObj);
ceq.componentUpdated(getIdentifier(dbObj));
return dbObj;
}
}.execute();
return existing;
}
use of org.opennms.netmgt.model.ncs.NCSComponent in project opennms by OpenNMS.
the class NCSComponentServiceImpl method deleteComponent.
private void deleteComponent(final ComponentIdentifier id, final ComponentEventQueue ceq, final boolean deleteOrphans) {
final NCSComponent component = getComponent(id);
if (component == null) {
throw new WebApplicationException(Status.BAD_REQUEST);
}
final Set<NCSComponent> parentComponents = component.getParentComponents();
final Set<ComponentIdentifier> childrenIdentifiers = getIdentifiers(component.getSubcomponents());
// first, we deal with orphans
if (deleteOrphans) {
for (final ComponentIdentifier subId : childrenIdentifiers) {
handleOrphanedComponents(component, subId, ceq, deleteOrphans);
}
}
// first, we remove this component from each of its parents
for (final NCSComponent parent : parentComponents) {
parent.getSubcomponents().remove(component);
m_componentDao.update(parent);
}
// then we delete this component
component.setSubcomponents(EMPTY_COMPONENT_SET);
m_componentDao.delete(component);
// and any events or alarms depending on it
deleteEvents(id.getForeignSource(), id.getForeignId());
deleteAlarms(id.getForeignSource(), id.getForeignId());
// alert that the component is deleted
ceq.componentDeleted(getIdentifier(component));
// then alert about the parents
sendUpdateEvents(ceq, getIdentifiers(parentComponents));
}
Aggregations