Search in sources :

Example 31 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FusedForeignSourceRepository method importResourceRequisition.

/**
 * {@inheritDoc}
 */
@Override
public synchronized Requisition importResourceRequisition(final Resource resource) throws ForeignSourceRepositoryException {
    final Requisition requisition = m_deployedForeignSourceRepository.importResourceRequisition(resource);
    final String foreignSource = requisition.getForeignSource();
    cleanUpDeployedForeignSources(foreignSource);
    cleanUpSnapshots(requisition);
    return requisition;
}
Also used : Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 32 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class DetectorsOnMinionIT method checkServicesDetectedOnMinion.

@Test
public void checkServicesDetectedOnMinion() throws ClientProtocolException, IOException, InterruptedException {
    final InetSocketAddress opennmsHttp = m_testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 8980);
    RestClient client = new RestClient(opennmsHttp);
    Requisition requisition = new Requisition("foreignSource");
    List<RequisitionInterface> interfaces = new ArrayList<>();
    RequisitionInterface requisitionInterface = new RequisitionInterface();
    requisitionInterface.setIpAddr(LOCALHOST);
    requisitionInterface.setManaged(true);
    requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
    interfaces.add(requisitionInterface);
    RequisitionNode node = new RequisitionNode();
    node.setNodeLabel("label");
    node.setLocation("MINION");
    node.setInterfaces(interfaces);
    node.setForeignId("foreignId");
    requisition.insertNode(node);
    client.addOrReplaceRequisition(requisition);
    client.importRequisition("foreignSource");
    await().atMost(5, MINUTES).pollDelay(0, SECONDS).pollInterval(30, SECONDS).until(getnumberOfServicesDetected(client), greaterThan(0));
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) InetSocketAddress(java.net.InetSocketAddress) RestClient(org.opennms.smoketest.utils.RestClient) ArrayList(java.util.ArrayList) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 33 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class NxosTelemetryIT method addRequisition.

public static OnmsNode addRequisition(InetSocketAddress opennmsHttp, boolean isMinion, Date startOfTest) {
    RestClient client = new RestClient(opennmsHttp);
    Requisition requisition = new Requisition("telemetry");
    List<RequisitionInterface> interfaces = new ArrayList<>();
    RequisitionInterface requisitionInterface = new RequisitionInterface();
    requisitionInterface.setIpAddr("192.168.0.1");
    requisitionInterface.setManaged(true);
    requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
    interfaces.add(requisitionInterface);
    RequisitionNode node = new RequisitionNode();
    String label = "nexus9k";
    node.setNodeLabel(label);
    node.setForeignId("nxos");
    node.setInterfaces(interfaces);
    if (isMinion) {
        // For a requisition, foreignId needs to be unique, change foreignId
        node.setLocation("MINION");
        node.setForeignId("nexus9k");
        // Change label so that node matches with foreignId
        label = "nxos";
        node.setNodeLabel(label);
    }
    requisition.insertNode(node);
    client.addOrReplaceRequisition(requisition);
    client.importRequisition("telemetry");
    InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
    final OnmsNode onmsNode = await().atMost(3, MINUTES).pollInterval(30, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).ge("createTime", startOfTest).eq("label", label).toCriteria()), notNullValue());
    assertNotNull(onmsNode);
    return onmsNode;
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) RestClient(org.opennms.smoketest.utils.RestClient) ArrayList(java.util.ArrayList) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 34 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class SyslogOverlappingIpAddressIT method testAssociateSyslogsWithNodesWithOverlappingIpAddresses.

/**
 * @see https://issues.opennms.org/browse/NMS-8798
 *
 * @throws Exception
 */
@Test
public void testAssociateSyslogsWithNodesWithOverlappingIpAddresses() throws Exception {
    final Date startOfTest = new Date();
    final String hostIpAddress = "1.2.3.4";
    // Create requisition with two node in different locations but same IP
    final RestClient client = new RestClient(testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 8980));
    final Requisition requisition = new Requisition("overlapping");
    final RequisitionNode node1 = new RequisitionNode();
    node1.setNodeLabel("node_1");
    node1.setLocation("MINION");
    final RequisitionInterface interface1 = new RequisitionInterface();
    interface1.setIpAddr(hostIpAddress);
    interface1.setManaged(true);
    interface1.setSnmpPrimary(PrimaryType.PRIMARY);
    node1.setInterfaces(ImmutableList.of(interface1));
    node1.setForeignId("node_1");
    requisition.insertNode(node1);
    final RequisitionNode node2 = new RequisitionNode();
    node2.setNodeLabel("node_2");
    node2.setLocation("BANANA");
    final RequisitionInterface interface2 = new RequisitionInterface();
    interface2.setIpAddr(hostIpAddress);
    interface2.setManaged(true);
    interface2.setSnmpPrimary(PrimaryType.PRIMARY);
    node2.setInterfaces(ImmutableList.of(interface2));
    node2.setForeignId("node_2");
    requisition.insertNode(node2);
    client.addOrReplaceRequisition(requisition);
    client.importRequisition("overlapping");
    // Wait for the nodes to be provisioned
    final OnmsNode onmsNode1 = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(getDaoFactory().getDao(NodeDaoHibernate.class), new CriteriaBuilder(OnmsNode.class).eq("label", "node_1").toCriteria()), notNullValue());
    final OnmsNode onmsNode2 = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(getDaoFactory().getDao(NodeDaoHibernate.class), new CriteriaBuilder(OnmsNode.class).eq("label", "node_2").toCriteria()), notNullValue());
    // Sending syslog messages to each node and expect it to appear on the node
    sendMessage(ContainerAlias.MINION, hostIpAddress, 1);
    await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).eq("node", onmsNode1).toCriteria()), is(1));
    sendMessage(ContainerAlias.MINION_OTHER_LOCATION, hostIpAddress, 1);
    await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).eq("node", onmsNode2).toCriteria()), is(1));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) OnmsNode(org.opennms.netmgt.model.OnmsNode) RestClient(org.opennms.smoketest.utils.RestClient) Date(java.util.Date) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 35 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class ShowImport method execute.

@Override
public Object execute() throws Exception {
    final CompletableFuture<Requisition> future = client.requisition().withRequisitionProviderType(type).withParameters(parse(parameters)).withLocation(location).withSystemId(systemId).withTimeToLive(ttlInMs).execute();
    while (true) {
        try {
            try {
                Requisition requisition = future.get(1, TimeUnit.SECONDS);
                if (xmlOutput) {
                    return JaxbUtils.marshal(requisition);
                } else {
                    return requisition;
                }
            } catch (InterruptedException e) {
                System.out.println("\nInterrupted.");
            } catch (ExecutionException e) {
                System.out.printf("\nRequisition retrieval failed with: %s\n", e);
            }
            break;
        } catch (TimeoutException e) {
        // pass
        }
        System.out.print(".");
        System.out.flush();
    }
    return null;
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)70 Test (org.junit.Test)31 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)16 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)11 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)11 UrlResource (org.springframework.core.io.UrlResource)10 File (java.io.File)9 OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)8 Resource (org.springframework.core.io.Resource)8 IOException (java.io.IOException)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 InetAddress (java.net.InetAddress)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStream (java.io.InputStream)3 RemoteException (java.rmi.RemoteException)3 Date (java.util.Date)3