use of org.opennms.netmgt.config.api.ResourceTypesDao in project opennms by OpenNMS.
the class JdbcCollectorComplianceIT method getRequiredBeans.
@Override
public Map<String, Object> getRequiredBeans() {
JdbcDataCollection collection = new JdbcDataCollection();
collection.setJdbcRrd(new JdbcRrd());
JdbcDataCollectionConfigDao jdbcCollectionDao = mock(JdbcDataCollectionConfigDao.class, RETURNS_DEEP_STUBS);
when(jdbcCollectionDao.getDataCollectionByName(COLLECTION)).thenReturn(collection);
when(jdbcCollectionDao.getConfig().buildRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
return new ImmutableMap.Builder<String, Object>().put("jdbcDataCollectionConfigDao", jdbcCollectionDao).put("resourceTypesDao", resourceTypesDao).build();
}
use of org.opennms.netmgt.config.api.ResourceTypesDao in project opennms by OpenNMS.
the class XmpCollector method initialize.
/* handleTableQuery() */
/* public methods ************************************ */
/**
* {@inheritDoc}
*
* initialize our XmpCollector with global parameters *
*/
@Override
public void initialize() {
// initialize our data collection factory
LOG.debug("initialize(params) called");
try {
XmpCollectionFactory.init();
} catch (Throwable e) {
LOG.error("initialize: XmpCollectionFactory failed to initialize");
throw new UndeclaredThrowableException(e);
}
try {
XmpPeerFactory.init();
} catch (Throwable e) {
LOG.error("initialize: XmpPeerFactory failed to initialize");
throw new UndeclaredThrowableException(e);
}
try {
XmpConfigFactory.init();
} catch (Throwable e) {
LOG.error("initialize: config factory failed to initialize");
throw new UndeclaredThrowableException(e);
}
if (m_resourceTypesDao == null) {
m_resourceTypesDao = BeanUtils.getBean("daoContext", "resourceTypesDao", ResourceTypesDao.class);
}
// get our top-level object for our protocol config file,
// xmp-config.xml, already parsed and ready to examine
XmpConfig protoConfig = XmpConfigFactory.getInstance().getXmpConfig();
if (protoConfig.hasPort())
xmpPort = protoConfig.getPort();
if (protoConfig.hasTimeout())
timeout = protoConfig.getTimeout();
// be non-null
if (protoConfig.getAuthenUser() != null)
authenUser = protoConfig.getAuthenUser();
LOG.debug("initialize: authenUser '{}' port {}", authenUser, xmpPort);
LOG.debug("initialize: keystore found? {}", sockopts.getKeystoreFound());
return;
}
use of org.opennms.netmgt.config.api.ResourceTypesDao in project opennms by OpenNMS.
the class TcaCollectorComplianceIT method getRequiredBeans.
@Override
public Map<String, Object> getRequiredBeans() {
TcaDataCollectionConfig config = mock(TcaDataCollectionConfig.class);
RrdRepository rrdRepository = new RrdRepository();
rrdRepository.setRrdBaseDir(new File("target"));
when(config.buildRrdRepository(COLLECTION)).thenReturn(rrdRepository);
TcaDataCollectionConfigDao tcaDataCollectionConfigDao = mock(TcaDataCollectionConfigDao.class);
when(tcaDataCollectionConfigDao.getConfig()).thenReturn(config);
ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
ResourceType resourceType = TcaCollectorIT.getJuniperTcaEntryResourceType();
when(resourceTypesDao.getResourceTypeByName(TcaCollectionHandler.RESOURCE_TYPE_NAME)).thenReturn(resourceType);
return new ImmutableMap.Builder<String, Object>().put("tcaDataCollectionConfigDao", tcaDataCollectionConfigDao).put("resourceStorageDao", resourceStorageDao).put("resourceTypesDao", resourceTypesDao).put("locationAwareSnmpClient", m_client).build();
}
use of org.opennms.netmgt.config.api.ResourceTypesDao in project opennms by OpenNMS.
the class XmpCollectorTest method canDetermineAppropriateResourceType.
@Test
public void canDetermineAppropriateResourceType() throws CollectionException {
NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
// Define the resource type
ResourceType resourceType = new ResourceType();
resourceType.setName("rt");
resourceType.setLabel("rt label");
resourceType.setResourceLabel("${instance}");
StorageStrategy storageStrategy = new StorageStrategy();
storageStrategy.setClazz(IndexStorageStrategy.class.getCanonicalName());
resourceType.setStorageStrategy(storageStrategy);
PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
persistenceSelectorStrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
resourceType.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
when(resourceTypesDao.getResourceTypeByName(resourceType.getName())).thenReturn(resourceType);
xmpCollector.setResourceTypesDao(resourceTypesDao);
// If the nodeTypeName is set to "node" it should always return a node level resource
assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, null, "instance"), instanceOf(NodeLevelResource.class));
assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, "some-resource", "instance"), instanceOf(NodeLevelResource.class));
// If a resource-type is set, it should always return a generic type resource
assertThat(xmpCollector.getResource(nodeLevelResource, null, "rt", "instance"), instanceOf(GenericTypeResource.class));
// Otherwise, falls back to an instance level resource
assertThat(xmpCollector.getResource(nodeLevelResource, null, null, "instance"), instanceOf(InterfaceLevelResource.class));
}
Aggregations