Search in sources :

Example 1 with ForeignSourceRepositoryException

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

the class DefaultProvisionService method createScheduleForNode.

private NodeScanSchedule createScheduleForNode(final OnmsNode node, final boolean force) {
    Assert.notNull(node, "Node may not be null");
    final String actualForeignSource = node.getForeignSource();
    if (actualForeignSource == null && !isDiscoveryEnabled()) {
        LOG.info("Not scheduling node {} to be scanned since it has a null foreignSource and handling of discovered nodes is disabled in provisiond", node);
        return null;
    }
    final String effectiveForeignSource = actualForeignSource == null ? "default" : actualForeignSource;
    try {
        final ForeignSource fs = m_foreignSourceRepository.getForeignSource(effectiveForeignSource);
        final Duration scanInterval = fs.getScanInterval();
        if (scanInterval.getMillis() <= 0) {
            LOG.debug("Node ({}/{}/{}) scan interval is zero, skipping schedule.", node.getId(), node.getForeignSource(), node.getForeignId());
            return null;
        }
        Duration initialDelay = Duration.ZERO;
        if (node.getLastCapsdPoll() != null && !force) {
            final DateTime nextPoll = new DateTime(node.getLastCapsdPoll().getTime()).plus(scanInterval);
            final DateTime now = new DateTime();
            if (nextPoll.isAfter(now)) {
                initialDelay = new Duration(now, nextPoll);
            }
        }
        return new NodeScanSchedule(node.getId(), actualForeignSource, node.getForeignId(), node.getLocation(), initialDelay, scanInterval);
    } catch (final ForeignSourceRepositoryException e) {
        LOG.warn("unable to get foreign source '{}' from repository", effectiveForeignSource, e);
        return null;
    }
}
Also used : ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Duration(org.joda.time.Duration) DateTime(org.joda.time.DateTime)

Example 2 with ForeignSourceRepositoryException

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

the class DefaultProvisionService method createUpdateRequistion.

private boolean createUpdateRequistion(final String addrString, final OnmsNode node, final String locationName, String m_foreignSource) {
    LOG.debug("Creating/Updating requistion {} for newSuspect {}...", m_foreignSource, addrString);
    try {
        Requisition r = null;
        if (m_foreignSource != null) {
            r = m_foreignSourceRepository.getRequisition(m_foreignSource);
            if (r == null) {
                r = new Requisition(m_foreignSource);
            }
        }
        r.updateDateStamp();
        RequisitionNode rn = new RequisitionNode();
        RequisitionInterface iface = new RequisitionInterface();
        iface.setDescr("disc-if");
        iface.setIpAddr(addrString);
        iface.setManaged(true);
        iface.setSnmpPrimary(PrimaryType.PRIMARY);
        iface.setStatus(Integer.valueOf(1));
        RequisitionInterfaceCollection ric = new RequisitionInterfaceCollection();
        ric.add(iface);
        rn.setInterfaces(ric.getObjects());
        rn.setBuilding(m_foreignSource);
        rn.setForeignId(node.getForeignId());
        rn.setNodeLabel(node.getLabel());
        rn.setLocation(locationName);
        r.putNode(rn);
        m_foreignSourceRepository.save(r);
        m_foreignSourceRepository.flush();
    } catch (ForeignSourceRepositoryException e) {
        LOG.error("Couldn't create/update requistion for newSuspect " + addrString, e);
        return false;
    }
    LOG.debug("Created/Updated requistion {} for newSuspect {}.", m_foreignSource, addrString);
    return true;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 3 with ForeignSourceRepositoryException

use of org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException 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<>();
    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

ForeignSourceRepositoryException (org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException)3 OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)2 HashSet (java.util.HashSet)1 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)1 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)1 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)1 RequisitionInterfaceCollection (org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection)1 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)1 Transactional (org.springframework.transaction.annotation.Transactional)1