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);
}
}
}
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);
}
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);
}
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();
}
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"));
}
Aggregations