Search in sources :

Example 1 with StorageStrategy

use of org.opennms.netmgt.collection.api.StorageStrategy in project opennms by OpenNMS.

the class GenericTypeResource method instantiateStorageStrategy.

private StorageStrategy instantiateStorageStrategy(String className, String resourceTypeName) {
    Class<?> cinst;
    try {
        cinst = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class", e);
    }
    try {
        StorageStrategy storageStrategy = (StorageStrategy) cinst.newInstance();
        storageStrategy.setResourceTypeName(resourceTypeName);
        return storageStrategy;
    } catch (InstantiationException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    } catch (IllegalAccessException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    }
}
Also used : StorageStrategy(org.opennms.netmgt.collection.api.StorageStrategy) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 2 with StorageStrategy

use of org.opennms.netmgt.collection.api.StorageStrategy in project opennms by OpenNMS.

the class WmiResourceType method instantiateStorageStrategy.

private void instantiateStorageStrategy(String className) {
    Class<?> cinst;
    try {
        cinst = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class", e);
    }
    try {
        m_storageStrategy = (StorageStrategy) cinst.newInstance();
    } catch (InstantiationException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    } catch (IllegalAccessException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    }
    m_storageStrategy.setResourceTypeName(m_resourceType);
}
Also used : StorageStrategy(org.opennms.netmgt.collection.api.StorageStrategy) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 3 with StorageStrategy

use of org.opennms.netmgt.collection.api.StorageStrategy in project opennms by OpenNMS.

the class GenericIndexResourceType method createTypes.

protected static Map<String, GenericIndexResourceType> createTypes(Map<String, ResourceType> configuredResourceTypes, ResourceStorageDao resourceStorageDao) {
    Map<String, GenericIndexResourceType> resourceTypes = Maps.newLinkedHashMap();
    List<ResourceType> resourceTypeList = new LinkedList<ResourceType>(configuredResourceTypes.values());
    Collections.sort(resourceTypeList, new Comparator<ResourceType>() {

        @Override
        public int compare(ResourceType r0, ResourceType r1) {
            // Sort by resource label, allowing the resource label to be null
            final Comparator<? super String> comparator = (a, b) -> a.compareTo(b);
            return Objects.compare(r0.getLabel(), r1.getLabel(), Comparator.nullsLast(comparator));
        }
    });
    for (ResourceType resourceType : resourceTypeList) {
        String className = resourceType.getStorageStrategy().getClazz();
        Class<?> cinst;
        try {
            cinst = Class.forName(className);
        } catch (ClassNotFoundException e) {
            throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
        }
        StorageStrategy storageStrategy;
        try {
            storageStrategy = (StorageStrategy) cinst.newInstance();
        } catch (InstantiationException e) {
            throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
        } catch (IllegalAccessException e) {
            throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
        }
        storageStrategy.setResourceTypeName(resourceType.getName());
        GenericIndexResourceType genericIndexResourceType = new GenericIndexResourceType(resourceStorageDao, resourceType.getName(), resourceType.getLabel(), resourceType.getResourceLabel(), storageStrategy);
        resourceTypes.put(genericIndexResourceType.getName(), genericIndexResourceType);
    }
    return resourceTypes;
}
Also used : StorageStrategy(org.opennms.netmgt.collection.api.StorageStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) LinkedList(java.util.LinkedList) Comparator(java.util.Comparator) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 4 with StorageStrategy

use of org.opennms.netmgt.collection.api.StorageStrategy in project opennms by OpenNMS.

the class GenericIndexResourceType method instantiateStorageStrategy.

private void instantiateStorageStrategy(String className) {
    Class<?> cinst;
    try {
        cinst = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class", e);
    }
    try {
        m_storageStrategy = (StorageStrategy) cinst.newInstance();
    } catch (InstantiationException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    } catch (IllegalAccessException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    }
    m_storageStrategy.setResourceTypeName(m_name);
    if (getAgent() != null)
        m_storageStrategy.setStorageStrategyService(getAgent());
}
Also used : StorageStrategy(org.opennms.netmgt.collection.api.StorageStrategy) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Aggregations

StorageStrategy (org.opennms.netmgt.collection.api.StorageStrategy)4 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)4 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)1 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)1