Search in sources :

Example 1 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource 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 RequisitionMonitoredService requisitionMonitoredService = new RequisitionMonitoredService();
        requisitionMonitoredService.setServiceName("Minion-Heartbeat");
        final RequisitionInterface requisitionInterface = new RequisitionInterface();
        requisitionInterface.setIpAddr("127.0.0.1");
        requisitionInterface.putMonitoredService(requisitionMonitoredService);
        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);
    }
    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) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService) Date(java.util.Date)

Example 2 with ForeignSource

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

the class IfIndexNullIT method setUp.

@Before
public void setUp() {
    MockLogAppender.setupLogging();
    final MockForeignSourceRepository mfsr = new MockForeignSourceRepository();
    final ForeignSource fs = new ForeignSource();
    fs.setName("default");
    fs.addDetector(new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector"));
    mfsr.putDefaultForeignSource(fs);
    m_provisioner.getProvisionService().setForeignSourceRepository(mfsr);
}
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 3 with ForeignSource

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

the class MultipleImportIT method setUp.

@Before
public void setUp() {
    MockLogAppender.setupLogging();
    final MockForeignSourceRepository mfsr = new MockForeignSourceRepository();
    final ForeignSource fs = new ForeignSource();
    fs.setName("default");
    fs.addDetector(new PluginConfig("ICMP", "org.opennms.netmgt.provision.service.MockServiceDetector"));
    mfsr.putDefaultForeignSource(fs);
    m_provisioner.getProvisionService().setForeignSourceRepository(mfsr);
}
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 4 with ForeignSource

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

the class NewSuspectScanIT method setUp.

@Before
public void setUp() throws Exception {
    m_eventSubscriber.getEventAnticipator().reset();
    if (m_distPollerDao.findAll().size() == 0) {
        OnmsDistPoller distPoller = new OnmsDistPoller(DistPollerDao.DEFAULT_DIST_POLLER_ID);
        distPoller.setLabel("localhost");
        distPoller.setLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
        distPoller.setType(OnmsMonitoringSystem.TYPE_OPENNMS);
        m_distPollerDao.save(distPoller);
    }
    m_foreignSource = new ForeignSource();
    m_foreignSource.setName("imported:");
    m_foreignSource.setScanInterval(Duration.standardDays(1));
    final PluginConfig detector = new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector");
    detector.addParameter("timeout", "1000");
    detector.addParameter("retries", "0");
    m_foreignSource.addDetector(detector);
    m_foreignSourceRepository = new MockForeignSourceRepository();
    m_foreignSourceRepository.putDefaultForeignSource(m_foreignSource);
    m_provisionService.setForeignSourceRepository(m_foreignSourceRepository);
    m_provisioner.start();
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) MockForeignSourceRepository(org.opennms.netmgt.provision.persist.MockForeignSourceRepository) Before(org.junit.Before)

Example 5 with ForeignSource

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

the class ProvisionerIT method testRequisitionedCategoriesWithPolicies.

@Test(timeout = 300000)
public void testRequisitionedCategoriesWithPolicies() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    final ForeignSource fs = m_foreignSourceRepository.getForeignSource("empty");
    final PluginConfig policy = new PluginConfig("addDumbCategory", NodeCategorySettingPolicy.class.getName());
    policy.addParameter("category", "Dumb");
    policy.addParameter("label", "test");
    fs.addPolicy(policy);
    m_foreignSourceRepository.save(fs);
    importFromResource("classpath:/provisioner-testCategories-oneCategory.xml", Boolean.TRUE.toString());
    // after import, we should have 1 category, because policies haven't been applied yet
    OnmsNode n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertEquals("TotallyMadeUpCategoryName", n.getCategories().iterator().next().getName());
    assertEquals(0, n.getRequisitionedCategories().size());
    runPendingScans();
    // when the scan has completed, both categories should have been applied
    n = getNodeDao().get(nextNodeId);
    assertEquals(2, n.getCategories().size());
    assertTrue(n.hasCategory("TotallyMadeUpCategoryName"));
    assertTrue(n.hasCategory("Dumb"));
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsNode(org.opennms.netmgt.model.OnmsNode) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) NodeCategorySettingPolicy(org.opennms.netmgt.provision.persist.policies.NodeCategorySettingPolicy) Test(org.junit.Test)

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