Search in sources :

Example 1 with ResourceTypesDao

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();
}
Also used : JdbcDataCollectionConfigDao(org.opennms.netmgt.dao.JdbcDataCollectionConfigDao) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) JdbcDataCollection(org.opennms.netmgt.config.jdbc.JdbcDataCollection) JdbcRrd(org.opennms.netmgt.config.jdbc.JdbcRrd) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with ResourceTypesDao

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;
}
Also used : ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) XmpConfig(org.opennms.netmgt.config.xmpConfig.XmpConfig)

Example 3 with ResourceTypesDao

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();
}
Also used : ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) TcaDataCollectionConfigDao(org.opennms.netmgt.collectd.tca.dao.TcaDataCollectionConfigDao) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File) TcaDataCollectionConfig(org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with ResourceTypesDao

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));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Aggregations

ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)2 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)2 File (java.io.File)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 Test (org.junit.Test)1 TcaDataCollectionConfig (org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig)1 TcaDataCollectionConfigDao (org.opennms.netmgt.collectd.tca.dao.TcaDataCollectionConfigDao)1 IndexStorageStrategy (org.opennms.netmgt.collection.support.IndexStorageStrategy)1 PersistAllSelectorStrategy (org.opennms.netmgt.collection.support.PersistAllSelectorStrategy)1 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)1 InterfaceLevelResource (org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)1 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)1 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)1 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)1 JdbcDataCollection (org.opennms.netmgt.config.jdbc.JdbcDataCollection)1 JdbcRrd (org.opennms.netmgt.config.jdbc.JdbcRrd)1 XmpConfig (org.opennms.netmgt.config.xmpConfig.XmpConfig)1 JdbcDataCollectionConfigDao (org.opennms.netmgt.dao.JdbcDataCollectionConfigDao)1