Search in sources :

Example 1 with Requisition

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

the class VmwareRequisitionProvider method getRequest.

@Override
public VmwareImportRequest getRequest(Map<String, String> parameters) {
    // Generate a request using the parameter map
    final VmwareImportRequest request = new VmwareImportRequest(parameters);
    if (StringUtils.isBlank(request.getUsername()) || StringUtils.isBlank(request.getPassword())) {
        // No credentials were specified in the parameter map, attempt to look these up
        final Map<String, VmwareServer> serverMap = vmwareConfigDao.getServerMap();
        final VmwareServer vmwareServer = serverMap.get(request.getHostname());
        if (vmwareServer != null) {
            // We found a corresponding entry - copy the credentials to the request
            request.setUsername(vmwareServer.getUsername());
            request.setPassword(vmwareServer.getPassword());
        }
    }
    // Lookup the existing requisition, and store it in the request
    final Requisition existingRequisition = getExistingRequisition(request.getForeignSource());
    request.setExistingRequisition(existingRequisition);
    return request;
}
Also used : VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 2 with Requisition

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

the class VmwareImporter method getRequisition.

public Requisition getRequisition() {
    logger.debug("Getting existing requisition (if any) for VMware management server {}", request.getHostname());
    Requisition curReq = request.getExistingRequisition();
    logger.debug("Building new requisition for VMware management server {}", request.getHostname());
    Requisition newReq = buildVMwareRequisition();
    logger.debug("Finished building new requisition for VMware management server {}", request.getHostname());
    if (curReq == null) {
        if (newReq == null) {
            // FIXME Is this correct ? This is the old behavior
            newReq = new Requisition(request.getForeignSource());
        }
    } else {
        if (newReq == null) {
            // If there is a requisition and the vCenter is not responding for some reason, it is better to use the old requisition,
            // instead of returning an empty one, which can cause the lost of all the nodes from the DB.
            newReq = curReq;
        } else {
            // The VMWare related assets and categories will be preserved.
            for (RequisitionNode newNode : newReq.getNodes()) {
                for (RequisitionNode curNode : curReq.getNodes()) {
                    if (newNode.getForeignId().equals(curNode.getForeignId())) {
                        // Add existing custom assets
                        for (RequisitionAsset asset : curNode.getAssets()) {
                            if (!asset.getName().startsWith("vmware")) {
                                newNode.putAsset(asset);
                            }
                        }
                        // Add existing custom categories
                        for (RequisitionCategory cat : curNode.getCategories()) {
                            if (!cat.getName().startsWith("VMWare")) {
                                newNode.putCategory(cat);
                            }
                        }
                        /*
                             * For each interface on the new requisition,
                             * - Retrieve the list of custom services from the corresponding interface on the existing requisition,
                             *   matching the interface by the IP address
                             * - If the list of services is not empty, add them to the new interface
                             */
                        for (RequisitionInterface intf : curNode.getInterfaces()) {
                            List<RequisitionMonitoredService> services = getManualyConfiguredServices(intf);
                            if (!services.isEmpty()) {
                                RequisitionInterface newIntf = getRequisitionInterface(newNode, intf.getIpAddr());
                                if (newIntf != null) {
                                    newIntf.getMonitoredServices().addAll(services);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return newReq;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Example 3 with Requisition

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

the class HandlerTest method dwOpenConnectionURL.

@Test
@Ignore
public void dwOpenConnectionURL() throws IOException {
    URL url = new URL(DNS_URL);
    UrlResource resource = new UrlResource(url);
    MockForeignSourceRepository fsr = new MockForeignSourceRepository();
    Requisition r = fsr.importResourceRequisition(resource);
    Assert.assertTrue("Number of nodes in Model Import > 1", 1 == r.getNodeCount());
    Assert.assertTrue("NodeLabel isn't localhost", "localhost".equals(r.getNodes().get(0).getNodeLabel()));
    Assert.assertTrue("127.0.0.1".equals(r.getNodes().get(0).getInterfaces().get(0).getIpAddr()));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) URL(java.net.URL) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) MockForeignSourceRepository(org.opennms.netmgt.provision.persist.MockForeignSourceRepository) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Requisition

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

the class RequisitionUrlConnection method getInputStream.

@Override
public InputStream getInputStream() throws IOException {
    try {
        final Requisition requisition = getClient().requisition().withRequisitionProviderType(type).withParameters(parameters).execute().get();
        if (requisition == null) {
            throw new IOException(String.format("Invalid (null) requisition was returned by the provider for type '%s'", type));
        }
        // The XmlHandler is not thread safe
        // Marshaling is quick, so we opt to use a single instance of the handler
        // instead of using thread-local variables
        final String requisitionXml;
        synchronized (s_xmlHandler) {
            requisitionXml = s_xmlHandler.marshal(requisition);
        }
        return new ByteArrayInputStream(requisitionXml.getBytes());
    } catch (ExecutionException | InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 5 with Requisition

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

the class RequisitionUrlConnectionTest method canRetrieveRequisition.

@Test
public void canRetrieveRequisition() throws Exception {
    Requisition expectedRequisition = new Requisition();
    LocationAwareRequisitionClient client = mock(LocationAwareRequisitionClient.class, RETURNS_DEEP_STUBS);
    when(client.requisition().withRequisitionProviderType("test").withParameters(any()).execute().get()).thenReturn(expectedRequisition);
    try {
        RequisitionUrlConnection.setClient(client);
        final String requisitionAsStr = urlToString("requisition://test/");
        Requisition actualRequisition = JaxbUtils.unmarshal(Requisition.class, requisitionAsStr);
        assertEquals(expectedRequisition, actualRequisition);
    } finally {
        RequisitionUrlConnection.setClient(null);
    }
}
Also used : LocationAwareRequisitionClient(org.opennms.netmgt.provision.persist.LocationAwareRequisitionClient) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

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