Search in sources :

Example 1 with OnmsNodeRequisition

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

the class ProvisionerIT method testDnsVisit.

/**
     * We have to ignore this test until there is a DNS service available in the test harness
     * 
     * @throws ForeignSourceRepositoryException
     * @throws MalformedURLException
     */
@Test(timeout = 300000)
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "opennms.com.", v4address = "1.2.3.4", entries = { @DNSEntry(hostname = "www", address = "1.2.3.4") }) })
public void testDnsVisit() throws ForeignSourceRepositoryException, MalformedURLException {
    final Requisition requisition = m_foreignSourceRepository.importResourceRequisition(new UrlResource("dns://localhost:9153/opennms.com"));
    final CountingVisitor visitor = new CountingVisitor() {

        @Override
        public void visitNode(final OnmsNodeRequisition req) {
            LOG.debug("visitNode: {}/{} {}", req.getForeignSource(), req.getForeignId(), req.getNodeLabel());
            m_nodes.add(req);
            m_nodeCount++;
        }

        @Override
        public void visitInterface(final OnmsIpInterfaceRequisition req) {
            LOG.debug("visitInterface: {}", req.getIpAddr());
            m_ifaces.add(req);
            m_ifaceCount++;
        }
    };
    requisition.visit(visitor);
    verifyDnsImportCounts(visitor);
}
Also used : OnmsIpInterfaceRequisition(org.opennms.netmgt.provision.persist.OnmsIpInterfaceRequisition) UrlResource(org.springframework.core.io.UrlResource) OnmsNodeCategoryRequisition(org.opennms.netmgt.provision.persist.OnmsNodeCategoryRequisition) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) OnmsMonitoredServiceRequisition(org.opennms.netmgt.provision.persist.OnmsMonitoredServiceRequisition) OnmsServiceCategoryRequisition(org.opennms.netmgt.provision.persist.OnmsServiceCategoryRequisition) OnmsIpInterfaceRequisition(org.opennms.netmgt.provision.persist.OnmsIpInterfaceRequisition) OnmsAssetRequisition(org.opennms.netmgt.provision.persist.OnmsAssetRequisition) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 2 with OnmsNodeRequisition

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

the class Requisition method putNode.

/**
     * <p>putNode</p>
     *
     * @param node a {@link org.opennms.netmgt.provision.persist.requisition.RequisitionNode} object.
     */
public void putNode(final RequisitionNode node) {
    updateNodeCacheIfNecessary();
    if (m_nodeReqs.containsKey(node.getForeignId())) {
        final RequisitionNode n = m_nodeReqs.get(node.getForeignId()).getNode();
        m_nodes.remove(n);
    }
    m_nodes.add(node);
    m_nodeReqs.put(node.getForeignId(), new OnmsNodeRequisition(getForeignSource(), node));
}
Also used : OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition)

Example 3 with OnmsNodeRequisition

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

the class Requisition method insertNode.

/**
     * <p>insertNode</p>
     *
     * @param node a {@link org.opennms.netmgt.provision.persist.requisition.RequisitionNode} object.
     */
public void insertNode(final RequisitionNode node) {
    updateNodeCacheIfNecessary();
    if (m_nodeReqs.containsKey(node.getForeignId())) {
        final RequisitionNode n = m_nodeReqs.get(node.getForeignId()).getNode();
        m_nodes.remove(n);
    }
    m_nodes.add(0, node);
    m_nodeReqs.put(node.getForeignId(), new OnmsNodeRequisition(getForeignSource(), node));
}
Also used : OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition)

Example 4 with OnmsNodeRequisition

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

the class Requisition method visit.

/**
     * <p>visit</p>
     *
     * @param visitor a {@link org.opennms.netmgt.provision.persist.RequisitionVisitor} object.
     */
public void visit(final RequisitionVisitor visitor) {
    updateNodeCacheIfNecessary();
    if (visitor == null) {
        LOG.warn("no visitor specified!");
        return;
    }
    visitor.visitModelImport(this);
    for (final OnmsNodeRequisition nodeReq : m_nodeReqs.values()) {
        nodeReq.visit(visitor);
    }
    visitor.completeModelImport(this);
}
Also used : OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition)

Example 5 with OnmsNodeRequisition

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

the class DefaultProvisionService method getRequisitionedNode.

/** {@inheritDoc} */
@Transactional
@Override
public OnmsNode getRequisitionedNode(final String foreignSource, final String foreignId) throws ForeignSourceRepositoryException {
    OnmsNodeRequisition nodeReq = null;
    try {
        nodeReq = m_foreignSourceRepository.getNodeRequisition(foreignSource, foreignId);
    } catch (ForeignSourceRepositoryException e) {
    // just fall through, nodeReq will be null
    }
    if (nodeReq == null) {
        LOG.warn("nodeReq for node {}:{} cannot be null!", foreignSource, foreignId);
        return null;
    }
    final OnmsNode node = nodeReq.constructOnmsNodeFromRequisition();
    // fill in real database categories
    final HashSet<OnmsCategory> dbCategories = new HashSet<OnmsCategory>();
    for (final OnmsCategory category : node.getCategories()) {
        dbCategories.add(createCategoryIfNecessary(category.getName()));
    }
    node.setCategories(dbCategories);
    if (node.getLocation() == null || Strings.isNullOrEmpty(node.getLocation().getLocationName())) {
        node.setLocation(m_monitoringLocationDao.getDefaultLocation());
    }
    // fill in real service types
    node.visit(new ServiceTypeFulfiller());
    return node;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)6 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)2 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 JUnitDNSServer (org.opennms.core.test.dns.annotations.JUnitDNSServer)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 AbstractRequisitionVisitor (org.opennms.netmgt.provision.persist.AbstractRequisitionVisitor)1 ForeignSourceRepositoryException (org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException)1 OnmsAssetRequisition (org.opennms.netmgt.provision.persist.OnmsAssetRequisition)1 OnmsIpInterfaceRequisition (org.opennms.netmgt.provision.persist.OnmsIpInterfaceRequisition)1 OnmsMonitoredServiceRequisition (org.opennms.netmgt.provision.persist.OnmsMonitoredServiceRequisition)1 OnmsNodeCategoryRequisition (org.opennms.netmgt.provision.persist.OnmsNodeCategoryRequisition)1 OnmsServiceCategoryRequisition (org.opennms.netmgt.provision.persist.OnmsServiceCategoryRequisition)1 RequisitionVisitor (org.opennms.netmgt.provision.persist.RequisitionVisitor)1 Activity (org.opennms.netmgt.provision.service.lifecycle.annotations.Activity)1 UrlResource (org.springframework.core.io.UrlResource)1 Transactional (org.springframework.transaction.annotation.Transactional)1