本文整理汇总了Java中org.opennms.netmgt.provision.persist.foreignsource.ForeignSource类的典型用法代码示例。如果您正苦于以下问题:Java ForeignSource类的具体用法?Java ForeignSource怎么用?Java ForeignSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ForeignSource类属于org.opennms.netmgt.provision.persist.foreignsource包,在下文中一共展示了ForeignSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDetectorsForForeignSource
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/** {@inheritDoc} */
public List<ServiceDetector> getDetectorsForForeignSource(final String foreignSourceName) {
final ForeignSource foreignSource = m_foreignSourceRepository.getForeignSource(foreignSourceName);
assertNotNull(foreignSource, "Expected a foreignSource with name %s", foreignSourceName);
final List<PluginConfig> detectorConfigs = foreignSource.getDetectors();
if (detectorConfigs == null) {
return new ArrayList<ServiceDetector>(m_pluginRegistry.getAllPlugins(ServiceDetector.class));
}
final List<ServiceDetector> detectors = new ArrayList<ServiceDetector>(detectorConfigs.size());
for(final PluginConfig detectorConfig : detectorConfigs) {
final ServiceDetector detector = m_pluginRegistry.getPluginInstance(ServiceDetector.class, detectorConfig);
if (detector == null) {
errorf(this, "Configured plugin does not exist: %s", detectorConfig);
} else {
detector.setServiceName(detectorConfig.getName());
detector.init();
detectors.add(detector);
}
}
return detectors;
}
示例2: getPluginsForForeignSource
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/**
* <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) {
LogUtils.tracef(this, "Configured plugin is not appropropriate for policy class %s: %s", pluginClass, config);
} else {
plugins.add(plugin);
}
}
return plugins;
}
示例3: deletePolicy
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/**
* <p>deletePolicy</p>
*
* @param foreignSource a {@link java.lang.String} object.
* @param policy a {@link java.lang.String} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@DELETE
@Path("{foreignSource}/policies/{policy}")
@Transactional
public Response deletePolicy(@PathParam("foreignSource") String foreignSource, @PathParam("policy") String policy) {
writeLock();
try {
ForeignSource fs = getActiveForeignSource(foreignSource);
List<PluginConfig> policies = fs.getPolicies();
PluginConfig removed = removeEntry(policies, policy);
if (removed != null) {
fs.updateDateStamp();
fs.setPolicies(policies);
m_pendingForeignSourceRepository.save(fs);
return Response.ok().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
示例4: setUp
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
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.setEventForwarder(m_eventSubscriber);
m_provisioner.start();
}
示例5: integrationTest
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
@Test
public void integrationTest() throws Exception {
assertTrue(m_deployed.getForeignSources().isEmpty());
assertTrue(m_pending.getForeignSources().isEmpty());
assertEquals(0, m_service.getAllForeignSources().size());
// create a new foreign source
ForeignSource fs = m_service.getForeignSource("test");
// test doesn't exist, so it should tell us that it's based on the default foreign source
assertTrue(fs.isDefault());
// modify it and save
fs.setDetectors(new ArrayList<PluginConfig>());
m_service.saveForeignSource("test", fs);
// now it shouln't be marked as default, since we've saved a modified version
fs = m_service.getForeignSource("test");
assertFalse(fs.isDefault());
// we like it so much, let's make it the default!
m_service.saveForeignSource("default", fs);
fs = m_service.getForeignSource("monkey");
assertTrue(fs.isDefault());
}
示例6: testDefaultForeignSource
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
@Test
public void testDefaultForeignSource() throws Exception {
createRequisition();
List<String> detectorList = Arrays.asList(new String[]{ "DNS", "FTP", "HTTP", "HTTPS", "ICMP", "IMAP", "LDAP", "NRPE", "POP3", "SMTP", "SNMP", "SSH" });
String uuid = UUID.randomUUID().toString();
ForeignSource defaultForeignSource = m_foreignSourceRepository.getForeignSource(uuid);
assertEquals("name must match requested foreign source repository name", uuid, defaultForeignSource.getName());
assertEquals("scan-interval must be 1 day", 86400000, defaultForeignSource.getScanInterval().getMillis());
assertEquals("foreign source must have no default policies", 0, defaultForeignSource.getPolicies().size());
List<String> fsNames = new ArrayList<String>();
for (PluginConfig config : defaultForeignSource.getDetectors()) {
fsNames.add(config.getName());
}
assertEquals("detector list must match expected defaults", detectorList, fsNames);
assertTrue("foreign source must be tagged as default", defaultForeignSource.isDefault());
}
示例7: putDefaultForeignSource
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/** {@inheritDoc} */
public void putDefaultForeignSource(ForeignSource foreignSource) throws ForeignSourceRepositoryException {
if (foreignSource == null) {
throw new ForeignSourceRepositoryException("foreign source was null");
}
foreignSource.setName("default");
final File outputFile = new File(ConfigFileConstants.getFilePathString() + "default-foreign-source.xml");
Writer writer = null;
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(outputFile);
writer = new OutputStreamWriter(outputStream, "UTF-8");
JaxbUtils.marshal(foreignSource, writer);
} catch (final Throwable e) {
throw new ForeignSourceRepositoryException("unable to write requisition to " + outputFile.getPath(), e);
} finally {
IOUtils.closeQuietly(writer);
IOUtils.closeQuietly(outputStream);
}
}
示例8: getServiceTypeNames
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/**
* <p>getServiceTypeNames</p>
*
* @return a {@link java.util.Collection} object.
*/
public Collection<String> getServiceTypeNames(String groupName) {
final SortedSet<String> serviceNames = new TreeSet<String>();
m_readLock.lock();
try {
m_pendingForeignSourceRepository.flush();
final ForeignSource pendingForeignSource = m_pendingForeignSourceRepository.getForeignSource(groupName);
serviceNames.addAll(pendingForeignSource.getDetectorNames());
m_deployedForeignSourceRepository.flush();
final ForeignSource deployedForeignSource = m_deployedForeignSourceRepository.getForeignSource(groupName);
serviceNames.addAll(deployedForeignSource.getDetectorNames());
for (final OnmsServiceType type : m_serviceTypeDao.findAll()) {
serviceNames.add(type.getName());
}
serviceNames.addAll(m_capsdConfig.getConfiguredProtocols());
return serviceNames;
} finally {
m_readLock.unlock();
}
}
示例9: getForeignSourceMap
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
private Map<String,ForeignSource> getForeignSourceMap() {
readLock();
try {
if (m_foreignSources == null) {
writeLock();
try {
final Map<String,ForeignSource> fses = new TreeMap<String,ForeignSource>();
for (final ForeignSource fs : m_foreignSourceRepository.getForeignSources()) {
fses.put(fs.getName(), fs);
}
m_foreignSources = fses;
} finally {
readLock();
writeUnlock();
}
}
return m_foreignSources;
} finally {
readUnlock();
}
}
示例10: getDefaultForeignSource
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
@Override
public ForeignSource getDefaultForeignSource() throws ForeignSourceRepositoryException {
readLock();
try {
if (m_defaultForeignSource == null) {
writeLock();
try {
m_defaultForeignSource = m_foreignSourceRepository.getDefaultForeignSource();
} finally {
readLock();
readUnlock();
}
}
return m_defaultForeignSource;
} finally {
readUnlock();
}
}
示例11: getForeignSources
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/**
* 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() throws ParseException {
readLock();
try {
final Set<ForeignSource> foreignSources = new TreeSet<ForeignSource>();
for (final String fsName : getActiveForeignSourceNames()) {
foreignSources.add(getActiveForeignSource(fsName));
}
return new ForeignSourceCollection(foreignSources);
} finally {
readUnlock();
}
}
示例12: addDetector
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/**
* <p>addDetector</p>
*
* @param foreignSource a {@link java.lang.String} object.
* @param detector a {@link org.opennms.netmgt.provision.persist.foreignsource.DetectorWrapper} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@POST
@Path("{foreignSource}/detectors")
@Consumes(MediaType.APPLICATION_XML)
@Transactional
public Response addDetector(@PathParam("foreignSource") String foreignSource, DetectorWrapper detector) {
writeLock();
try {
debug("addDetector: Adding detector " + detector.getName());
ForeignSource fs = getActiveForeignSource(foreignSource);
fs.updateDateStamp();
fs.addDetector(detector);
m_pendingForeignSourceRepository.save(fs);
return Response.seeOther(getRedirectUri(m_uriInfo, detector.getName())).build();
} finally {
writeUnlock();
}
}
示例13: cleanUpDeployedForeignSources
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
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);
}
示例14: getForeignSources
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/**
* <p>getForeignSources</p>
*
* @return a {@link java.util.Set} object.
* @throws org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException if any.
*/
public Set<ForeignSource> getForeignSources() throws ForeignSourceRepositoryException {
m_readLock.lock();
try {
final File directory = new File(m_foreignSourcePath);
final TreeSet<ForeignSource> foreignSources = new TreeSet<ForeignSource>();
if (directory.exists()) {
for (final File file : directory.listFiles()) {
if (file.getName().endsWith(".xml")) {
foreignSources.add(RequisitionFileUtils.getForeignSourceFromFile(file));
}
}
}
return foreignSources;
} finally {
m_readLock.unlock();
}
}
示例15: getForeignSource
import org.opennms.netmgt.provision.persist.foreignsource.ForeignSource; //导入依赖的package包/类
/** {@inheritDoc} */
public ForeignSource getForeignSource(final String foreignSourceName) throws ForeignSourceRepositoryException {
if (foreignSourceName == null) {
throw new ForeignSourceRepositoryException("can't get a foreign source with a null name!");
}
m_readLock.lock();
try {
final File inputFile = RequisitionFileUtils.encodeFileName(m_foreignSourcePath, foreignSourceName);
if (inputFile != null && inputFile.exists()) {
return RequisitionFileUtils.getForeignSourceFromFile(inputFile);
} else {
final ForeignSource fs = getDefaultForeignSource();
fs.setName(foreignSourceName);
return fs;
}
} finally {
m_readLock.unlock();
}
}