Search in sources :

Example 1 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode 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 2 with RequisitionNode

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

the class FusedForeignSourceRepositoryTest method createNode.

protected RequisitionNode createNode(final String id) {
    RequisitionNode node = new RequisitionNode();
    node.setForeignId(id);
    node.setNodeLabel("node " + id);
    RequisitionInterface iface = new RequisitionInterface();
    iface.setIpAddr("172.16.0." + id);
    node.putInterface(iface);
    return node;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)

Example 3 with RequisitionNode

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

the class FusedForeignSourceRepositoryTest method getSummaryForRequisition.

protected String getSummaryForRequisition(final File file) {
    final Requisition requisition = JaxbUtils.unmarshal(Requisition.class, new FileSystemResource(file));
    final StringBuilder sb = new StringBuilder();
    if (requisition.getNodeCount() > 0) {
        sb.append("(");
        final Iterator<RequisitionNode> nodeIterator = requisition.getNodes().iterator();
        while (nodeIterator.hasNext()) {
            sb.append(nodeIterator.next().getNodeLabel());
            if (nodeIterator.hasNext())
                sb.append(", ");
        }
        sb.append(")");
    }
    final String requisitionSummary = file.getPath() + sb.toString() + ": " + requisition.getDate().getTime();
    return requisitionSummary;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) FileSystemResource(org.springframework.core.io.FileSystemResource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 4 with RequisitionNode

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

the class HeartbeatConsumer method provision.

private void provision(final OnmsMinion minion, final String prevLocation, final String nextLocation) {
    // Return fast if automatic provisioning is disabled
    if (!PROVISIONING) {
        return;
    }
    // Return fast until the provisioner is running to pick up the events sent below
    if (!this.eventSubscriptionService.hasEventListener(EventConstants.RELOAD_IMPORT_UEI)) {
        return;
    }
    final String prevForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, prevLocation);
    final String nextForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, nextLocation);
    final Set<String> alteredForeignSources = Sets.newHashSet();
    // Remove the node from the previous requisition, if location has changed
    if (!Objects.equals(prevForeignSource, nextForeignSource)) {
        final Requisition prevRequisition = this.deployedForeignSourceRepository.getRequisition(prevForeignSource);
        if (prevRequisition != null && prevRequisition.getNode(minion.getId()) != null) {
            prevRequisition.deleteNode(minion.getId());
            prevRequisition.updateDateStamp();
            deployedForeignSourceRepository.save(prevRequisition);
            deployedForeignSourceRepository.flush();
            alteredForeignSources.add(prevForeignSource);
        }
    }
    Requisition nextRequisition = deployedForeignSourceRepository.getRequisition(nextForeignSource);
    if (nextRequisition == null) {
        nextRequisition = new Requisition(nextForeignSource);
        nextRequisition.updateDateStamp();
        // We have to save the requisition before we can alter the according foreign source definition
        deployedForeignSourceRepository.save(nextRequisition);
        // Remove all policies and detectors from the foreign source
        final ForeignSource foreignSource = deployedForeignSourceRepository.getForeignSource(nextForeignSource);
        foreignSource.setDetectors(Collections.emptyList());
        foreignSource.setPolicies(Collections.emptyList());
        deployedForeignSourceRepository.save(foreignSource);
        alteredForeignSources.add(nextForeignSource);
    }
    RequisitionNode requisitionNode = nextRequisition.getNode(minion.getId());
    if (requisitionNode == null) {
        final RequisitionInterface requisitionInterface = new RequisitionInterface();
        requisitionInterface.setIpAddr(MINION_INTERFACE);
        ensureServicesAreOnInterface(requisitionInterface);
        requisitionNode = new RequisitionNode();
        requisitionNode.setNodeLabel(minion.getId());
        requisitionNode.setForeignId(minion.getLabel() != null ? minion.getLabel() : minion.getId());
        requisitionNode.setLocation(minion.getLocation());
        requisitionNode.putInterface(requisitionInterface);
        nextRequisition.putNode(requisitionNode);
        nextRequisition.setDate(new Date());
        deployedForeignSourceRepository.save(nextRequisition);
        deployedForeignSourceRepository.flush();
        alteredForeignSources.add(nextForeignSource);
    } else {
        // The node already exists in the requisition
        RequisitionInterface requisitionInterface = requisitionNode.getInterface(MINION_INTERFACE);
        if (requisitionInterface == null) {
            // The interface was deleted, add it again
            requisitionInterface = new RequisitionInterface();
            requisitionInterface.setIpAddr(MINION_INTERFACE);
            requisitionNode.putInterface(requisitionInterface);
        }
        if (ensureServicesAreOnInterface(requisitionInterface)) {
            // We've altered the set of services on the interface
            nextRequisition.setDate(new Date());
            deployedForeignSourceRepository.save(nextRequisition);
            deployedForeignSourceRepository.flush();
            alteredForeignSources.add(nextForeignSource);
        }
    }
    for (final String alteredForeignSource : alteredForeignSources) {
        final EventBuilder eventBuilder = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
        eventBuilder.addParam(EventConstants.PARM_URL, String.valueOf(deployedForeignSourceRepository.getRequisitionURL(alteredForeignSource)));
        try {
            eventProxy.send(eventBuilder.getEvent());
        } catch (final EventProxyException e) {
            throw new DataAccessResourceFailureException("Unable to send event to import group " + alteredForeignSource, e);
        }
    }
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Date(java.util.Date)

Example 5 with RequisitionNode

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

the class NewSuspectScanIT method testScanNewSuspectWithForeignSourceAndLocation.

@Test(timeout = 300000)
public void testScanNewSuspectWithForeignSourceAndLocation() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    // Verify empty database
    assertEquals(1, getDistPollerDao().countAll());
    assertEquals(0, getNodeDao().countAll());
    assertEquals(0, getInterfaceDao().countAll());
    assertEquals(0, getMonitoredServiceDao().countAll());
    assertEquals(0, getServiceTypeDao().countAll());
    assertEquals(0, getSnmpInterfaceDao().countAll());
    final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    final String foreignSource = "Testie";
    final String locationName = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), foreignSource, locationName);
    runScan(scan);
    anticipator.verifyAnticipated(20000, 0, 0, 0, 0);
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    // Verify ipinterface count
    assertEquals("Unexpected number of interfaces found: " + getInterfaceDao().findAll(), 1, getInterfaceDao().countAll());
    // Verify ifservices count - discover snmp service on other if
    assertEquals("Unexpected number of services found: " + getMonitoredServiceDao().findAll(), 0, getMonitoredServiceDao().countAll());
    // Verify service count
    assertEquals(0, getServiceTypeDao().countAll());
    // Verify snmpInterface count
    assertEquals(0, getSnmpInterfaceDao().countAll());
    // HZN-960: Verify that the location name was properly set on the node in the requisition
    final Requisition requisition = m_foreignSourceRepository.getRequisition(foreignSource);
    final List<RequisitionNode> requisitionNodes = requisition.getNodes();
    assertEquals(1, requisitionNodes.size());
    final RequisitionNode requisitionNode = requisitionNodes.get(0);
    assertEquals(locationName, requisitionNode.getLocation());
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Aggregations

RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)20 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)15 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)14 RequisitionMonitoredService (org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)7 Test (org.junit.Test)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 InetAddress (java.net.InetAddress)4 RequisitionAsset (org.opennms.netmgt.provision.persist.requisition.RequisitionAsset)4 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)3 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)3 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)3 VirtualMachineRuntimeInfo (com.vmware.vim25.VirtualMachineRuntimeInfo)3 Datastore (com.vmware.vim25.mo.Datastore)3 DistributedVirtualPortgroup (com.vmware.vim25.mo.DistributedVirtualPortgroup)3 HostSystem (com.vmware.vim25.mo.HostSystem)3 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)3 Network (com.vmware.vim25.mo.Network)3 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3