Search in sources :

Example 36 with ForeignSource

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

the class FusedForeignSourceRepository method cleanUpDeployedForeignSources.

private synchronized void cleanUpDeployedForeignSources(String foreignSourceName) {
    ForeignSource deployed = m_deployedForeignSourceRepository.getForeignSource(foreignSourceName);
    ForeignSource pending = m_pendingForeignSourceRepository.getForeignSource(foreignSourceName);
    if (pending.isDefault()) {
        // if pending is default, assume deployed is valid, be it default or otherwise
        m_pendingForeignSourceRepository.delete(pending);
    } else {
        if (deployed.isDefault()) {
            // if pending is not default, and deployed is, assume pending should override deployed
            m_deployedForeignSourceRepository.save(pending);
        } else {
            // otherwise, compare dates, pending updates deployed if it's timestamp is newer
            Date pendingDate = pending.getDateStampAsDate();
            Date deployedDate = deployed.getDateStampAsDate();
            if (!deployedDate.after(pendingDate)) {
                m_deployedForeignSourceRepository.save(pending);
            }
        }
    }
    m_pendingForeignSourceRepository.delete(pending);
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Date(java.util.Date)

Example 37 with ForeignSource

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

the class QueueingForeignSourceRepository method clear.

@Override
public void clear() throws ForeignSourceRepositoryException {
    m_pendingForeignSources.clear();
    m_pendingRequisitions.clear();
    for (final Requisition req : getRequisitions()) {
        if (req != null)
            delete(req);
    }
    for (final ForeignSource fs : getForeignSources()) {
        if (fs != null)
            delete(fs);
    }
    m_executor.execute(new QueuePersistRunnable());
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 38 with ForeignSource

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

the class DragonWaveNodeSwitchingIT method setUp.

@Before
public void setUp() throws Exception {
    final ForeignSource fs = new ForeignSource();
    fs.setName("default");
    fs.addDetector(new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector"));
    final MockForeignSourceRepository mfsr = new MockForeignSourceRepository();
    mfsr.putDefaultForeignSource(fs);
    m_provisioner.getProvisionService().setForeignSourceRepository(mfsr);
    m_provisioner.start();
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) MockForeignSourceRepository(org.opennms.netmgt.provision.persist.MockForeignSourceRepository) Before(org.junit.Before)

Example 39 with ForeignSource

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

the class DefaultProvisionService method createUndiscoveredNode.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public OnmsNode createUndiscoveredNode(final String ipAddress, final String foreignSource, final String locationString) {
    final String effectiveForeignSource = foreignSource == null ? FOREIGN_SOURCE_FOR_DISCOVERED_NODES : foreignSource;
    final String effectiveLocationName = MonitoringLocationUtils.isDefaultLocationName(locationString) ? null : locationString;
    final OnmsNode node = new UpsertTemplate<OnmsNode, NodeDao>(m_transactionManager, m_nodeDao) {

        @Override
        protected OnmsNode query() {
            // Find all of the nodes in the target requisition with the given IP address
            return m_nodeDao.findByForeignSourceAndIpAddress(effectiveForeignSource, ipAddress).stream().filter(n -> {
                // Now filter the nodes by location
                final String existingLocationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(n);
                return Objects.equals(existingLocationName, effectiveLocationName);
            }).findFirst().orElse(null);
        }

        @Override
        protected OnmsNode doUpdate(OnmsNode existingNode) {
            // we found an existing node so exit by returning null;
            return null;
        }

        @Override
        protected OnmsNode doInsert() {
            final Date now = new Date();
            OnmsMonitoringLocation location = createLocationIfNecessary(locationString);
            // Associate the location with the node
            final OnmsNode node = new OnmsNode(location);
            final String hostname = getHostnameResolver().getHostname(addr(ipAddress), locationString);
            if (hostname == null || ipAddress.equals(hostname)) {
                node.setLabel(ipAddress);
                node.setLabelSource(NodeLabelSource.ADDRESS);
            } else {
                node.setLabel(hostname);
                node.setLabelSource(NodeLabelSource.HOSTNAME);
            }
            node.setForeignSource(effectiveForeignSource);
            node.setType(NodeType.ACTIVE);
            node.setLastCapsdPoll(now);
            final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr(ipAddress), node);
            iface.setIsManaged("M");
            iface.setIpHostName(hostname);
            iface.setIsSnmpPrimary(PrimaryType.NOT_ELIGIBLE);
            iface.setIpLastCapsdPoll(now);
            m_nodeDao.save(node);
            m_nodeDao.flush();
            return node;
        }
    }.execute();
    if (node != null) {
        if (effectiveForeignSource != null) {
            node.setForeignId(node.getNodeId());
            createUpdateRequistion(ipAddress, node, effectiveLocationName, effectiveForeignSource);
        }
        // we do this here rather than in the doInsert method because
        // the doInsert may abort
        node.visit(new AddEventVisitor(m_eventForwarder));
    }
    return node;
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) NodeType(org.opennms.netmgt.model.OnmsNode.NodeType) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) Date(java.util.Date) MonitoringLocationUtils(org.opennms.netmgt.dao.api.MonitoringLocationUtils) UpsertTemplate(org.opennms.netmgt.dao.support.UpsertTemplate) LocationAwareDnsLookupClient(org.opennms.netmgt.provision.LocationAwareDnsLookupClient) InetAddressUtils.str(org.opennms.core.utils.InetAddressUtils.str) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventUtils(org.opennms.netmgt.model.events.EventUtils) InetAddressUtils.addr(org.opennms.core.utils.InetAddressUtils.addr) IpInterfacePolicy(org.opennms.netmgt.provision.IpInterfacePolicy) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) InetAddress(java.net.InetAddress) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) NodeLabelSource(org.opennms.netmgt.model.OnmsNode.NodeLabelSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Map(java.util.Map) Resource(org.springframework.core.io.Resource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Collection(java.util.Collection) UpdateEventVisitor(org.opennms.netmgt.model.events.UpdateEventVisitor) Set(java.util.Set) CreateIfNecessaryTemplate(org.opennms.netmgt.dao.support.CreateIfNecessaryTemplate) AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) BeanUtils(org.opennms.core.spring.BeanUtils) Objects(java.util.Objects) List(java.util.List) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) PathElement(org.opennms.netmgt.model.PathElement) LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) RequisitionedCategoryAssociation(org.opennms.netmgt.model.RequisitionedCategoryAssociation) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) NodePolicy(org.opennms.netmgt.provision.NodePolicy) Duration(org.joda.time.Duration) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) HashMap(java.util.HashMap) EventConstants(org.opennms.netmgt.events.api.EventConstants) RequisitionedCategoryAssociationDao(org.opennms.netmgt.dao.api.RequisitionedCategoryAssociationDao) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) TreeSet(java.util.TreeSet) InitializingBean(org.springframework.beans.factory.InitializingBean) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) PrimaryType(org.opennms.netmgt.model.PrimaryType) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ServiceTypeDao(org.opennms.netmgt.dao.api.ServiceTypeDao) ForeignSourceRepository(org.opennms.netmgt.provision.persist.ForeignSourceRepository) PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsNode(org.opennms.netmgt.model.OnmsNode) RequisitionFileUtils(org.opennms.netmgt.provision.persist.RequisitionFileUtils) CategoryDao(org.opennms.netmgt.dao.api.CategoryDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DateTime(org.joda.time.DateTime) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) LocationAwareDetectorClient(org.opennms.netmgt.provision.LocationAwareDetectorClient) MonitoringLocationDao(org.opennms.netmgt.dao.api.MonitoringLocationDao) EventForwarder(org.opennms.netmgt.events.api.EventForwarder) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) Collections(java.util.Collections) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) SnmpInterfacePolicy(org.opennms.netmgt.provision.SnmpInterfacePolicy) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with ForeignSource

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

the class DefaultProvisionService method getPluginsForForeignSource.

/**
 * <p>getPluginsForForeignSource</p>
 *
 * @param pluginClass a {@link java.lang.Class} object.
 * @param foreignSourceName a {@link java.lang.String} object.
 * @param <T> a T object.
 * @return a {@link java.util.List} object.
 */
public <T> List<T> getPluginsForForeignSource(final Class<T> pluginClass, final String foreignSourceName) {
    final ForeignSource foreignSource = m_foreignSourceRepository.getForeignSource(foreignSourceName);
    assertNotNull(foreignSource, "Expected a foreignSource with name %s", foreignSourceName);
    final List<PluginConfig> configs = foreignSource.getPolicies();
    if (configs == null) {
        return Collections.emptyList();
    }
    final List<T> plugins = new ArrayList<T>(configs.size());
    for (final PluginConfig config : configs) {
        final T plugin = m_pluginRegistry.getPluginInstance(pluginClass, config);
        if (plugin == null) {
            LOG.trace("Configured plugin is not appropropriate for policy class {}: {}", pluginClass, config);
        } else {
            plugins.add(plugin);
        }
    }
    return plugins;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList)

Aggregations

ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)72 PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)31 Test (org.junit.Test)23 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)11 Before (org.junit.Before)10 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 Transactional (org.springframework.transaction.annotation.Transactional)8 TreeSet (java.util.TreeSet)6 File (java.io.File)4 DELETE (javax.ws.rs.DELETE)4 Date (java.util.Date)3 Consumes (javax.ws.rs.Consumes)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 Duration (org.joda.time.Duration)2