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