use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class ForeignSourceRestService method getForeignSources.
/**
* Returns the union of deployed and pending foreign sources
*
* @return Collection of OnmsForeignSources (ready to be XML-ified)
* @throws java.text.ParseException if any.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public ForeignSourceCollection getForeignSources() {
readLock();
try {
final Set<ForeignSource> foreignSources = new TreeSet<>();
for (final String fsName : getActiveForeignSourceNames()) {
foreignSources.add(getActiveForeignSource(fsName));
}
ForeignSourceCollection retval = new ForeignSourceCollection();
retval.getForeignSources().addAll(foreignSources);
return retval;
} finally {
readUnlock();
}
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class ForeignSourceRestService method deleteDeployedForeignSource.
/**
* <p>deleteDeployedForeignSource</p>
*
* @param foreignSource a {@link java.lang.String} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@DELETE
@Path("deployed/{foreignSource}")
@Transactional
public Response deleteDeployedForeignSource(@PathParam("foreignSource") final String foreignSource) {
writeLock();
try {
ForeignSource fs = getForeignSource(foreignSource);
LOG.debug("deleteDeployedForeignSource: deleting foreign source {}", foreignSource);
if ("default".equals(foreignSource)) {
m_deployedForeignSourceRepository.resetDefaultForeignSource();
} else {
m_deployedForeignSourceRepository.delete(fs);
}
return Response.accepted().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class DefaultProvisionService method getDetectorsForForeignSource.
/**
* {@inheritDoc}
*/
@Override
public List<PluginConfig> getDetectorsForForeignSource(final String foreignSourceName) {
final ForeignSource foreignSource = m_foreignSourceRepository.getForeignSource(foreignSourceName);
assertNotNull(foreignSource, "Expected a foreignSource with name %s", foreignSourceName);
return foreignSource.getDetectors();
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class CachingForeignSourceRepository method getForeignSource.
@Override
public ForeignSource getForeignSource(final String foreignSourceName) throws ForeignSourceRepositoryException {
readLock();
try {
ForeignSource fs = getForeignSourceMap().get(foreignSourceName);
if (fs == null) {
fs = getDefaultForeignSource();
fs.setName(foreignSourceName);
}
return fs;
} finally {
readUnlock();
}
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class CachingForeignSourceRepository method getRefreshRunnable.
protected Runnable getRefreshRunnable() {
return new Runnable() {
@Override
public void run() {
writeLock();
try {
// clear foreign source name cache
m_foreignSourceNames = null;
// clear the foreign source cache
if (m_dirtyForeignSources.size() > 0) {
for (final String dirtyForeignSource : m_dirtyForeignSources) {
final ForeignSource fs = getForeignSourceMap().get(dirtyForeignSource);
try {
if (fs == null) {
final ForeignSource current = m_foreignSourceRepository.getForeignSource(dirtyForeignSource);
if (current != null) {
m_foreignSourceRepository.delete(current);
}
} else {
m_foreignSourceRepository.save(fs);
}
} catch (final ForeignSourceRepositoryException e) {
LOG.error("Failed to persist foreign source {}", dirtyForeignSource, e);
}
}
m_dirtyForeignSources.clear();
}
m_foreignSources = null;
// clear the requisition cache
if (m_dirtyRequisitions.size() > 0) {
for (final String dirtyRequisition : m_dirtyRequisitions) {
final Requisition r = getRequisitionMap().get(dirtyRequisition);
try {
if (r == null) {
final Requisition current = m_foreignSourceRepository.getRequisition(dirtyRequisition);
if (current != null) {
m_foreignSourceRepository.delete(r);
}
} else {
m_foreignSourceRepository.save(r);
}
} catch (final ForeignSourceRepositoryException e) {
LOG.error("Failed to persist requisition {}", dirtyRequisition, e);
}
}
m_dirtyForeignSources.clear();
}
m_requisitions = null;
} finally {
writeUnlock();
}
}
};
}
Aggregations