Search in sources :

Example 31 with ForeignSource

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();
    }
}
Also used : ForeignSourceCollection(org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) TreeSet(java.util.TreeSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with ForeignSource

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();
    }
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with ForeignSource

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();
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 34 with ForeignSource

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();
    }
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 35 with ForeignSource

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();
            }
        }
    };
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

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