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