Search in sources :

Example 21 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class DependencyResolverImpl method getMaxDepth.

private static int getMaxDepth(final DependencyResolverImpl impl, final DependencyResolverManager manager, final LinkedHashSet<ModuleIdentifier> chainForDetectingCycles) {
    int maxDepth = 0;
    final LinkedHashSet<ModuleIdentifier> chainForDetectingCycles2 = new LinkedHashSet<>(chainForDetectingCycles);
    chainForDetectingCycles2.add(impl.getIdentifier());
    for (final ModuleIdentifier dependencyName : impl.dependencies) {
        final DependencyResolverImpl dependentDRI = manager.getOrCreate(dependencyName);
        if (chainForDetectingCycles2.contains(dependencyName)) {
            throw new IllegalStateException(String.format("Cycle detected, %s contains %s", chainForDetectingCycles2, dependencyName));
        }
        int subDepth;
        if (dependentDRI.maxDependencyDepth != null) {
            subDepth = dependentDRI.maxDependencyDepth;
        } else {
            subDepth = getMaxDepth(dependentDRI, manager, chainForDetectingCycles2);
            dependentDRI.maxDependencyDepth = subDepth;
        }
        if (subDepth + 1 > maxDepth) {
            maxDepth = subDepth + 1;
        }
    }
    impl.maxDependencyDepth = maxDepth;
    return maxDepth;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier)

Example 22 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class DependencyResolverImpl method validateDependency.

/**
 * {@inheritDoc}
 */
// TODO: check for cycles
@Override
public void validateDependency(final Class<? extends AbstractServiceInterface> expectedServiceInterface, final ObjectName dependentReadOnlyON, final JmxAttribute jmxAttribute) {
    this.transactionStatus.checkNotCommitted();
    if (expectedServiceInterface == null) {
        throw new NullPointerException("Parameter 'expectedServiceInterface' is null");
    }
    if (jmxAttribute == null) {
        throw new NullPointerException("Parameter 'jmxAttribute' is null");
    }
    JmxAttributeValidationException.checkNotNull(dependentReadOnlyON, "is null, expected dependency implementing " + expectedServiceInterface, jmxAttribute);
    // check that objectName belongs to this transaction - this should be
    // stripped
    // in DynamicWritableWrapper
    final boolean hasTransaction = ObjectNameUtil.getTransactionName(dependentReadOnlyON) != null;
    JmxAttributeValidationException.checkCondition(!hasTransaction, String.format("ObjectName should not contain " + "transaction name. %s set to %s. ", jmxAttribute, dependentReadOnlyON), jmxAttribute);
    final ObjectName newDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON);
    final ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(newDependentReadOnlyON, ObjectNameUtil.TYPE_MODULE);
    final ModuleFactory foundFactory = this.modulesHolder.findModuleFactory(moduleIdentifier, jmxAttribute);
    final boolean implementsSI = foundFactory.isModuleImplementingServiceInterface(expectedServiceInterface);
    if (!implementsSI) {
        final String message = String.format("Found module factory does not expose expected service interface. " + "Module name is %s : %s, expected service interface %s, dependent module ON %s , " + "attribute %s", foundFactory.getImplementationName(), foundFactory, expectedServiceInterface, newDependentReadOnlyON, jmxAttribute);
        throw new JmxAttributeValidationException(message, jmxAttribute);
    }
    synchronized (this) {
        this.dependencies.add(moduleIdentifier);
    }
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) JmxAttributeValidationException(org.opendaylight.controller.config.api.JmxAttributeValidationException) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ObjectName(javax.management.ObjectName)

Example 23 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class DependencyResolverManager method getSortedModuleIdentifiers.

public List<ModuleIdentifier> getSortedModuleIdentifiers() {
    List<ModuleIdentifier> result = new ArrayList<>(moduleIdentifiersToDependencyResolverMap.size());
    for (DependencyResolverImpl dri : getAllSorted()) {
        ModuleIdentifier driName = dri.getIdentifier();
        result.add(driName);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier)

Example 24 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class ModulesHolder method getAllModules.

public Map<ModuleIdentifier, Module> getAllModules() {
    Map<ModuleIdentifier, Module> result = new HashMap<>();
    for (ModuleInternalTransactionalInfo entry : commitMap.values()) {
        ModuleIdentifier name = entry.getIdentifier();
        result.put(name, entry.getProxiedModule());
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) Module(org.opendaylight.controller.config.spi.Module)

Example 25 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class ClassBasedModuleFactory method constructModule.

private Module constructModule(final String instanceName, final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old) throws InstantiationException, IllegalAccessException, InvocationTargetException {
    Preconditions.checkNotNull(dependencyResolver);
    ModuleIdentifier moduleIdentifier = new ModuleIdentifier(implementationName, instanceName);
    Constructor<? extends Module> declaredConstructor;
    try {
        declaredConstructor = configBeanClass.getDeclaredConstructor(DynamicMBeanWithInstance.class, ModuleIdentifier.class);
    } catch (final NoSuchMethodException e) {
        throw new IllegalStateException("Did not find constructor with parameters (DynamicMBeanWithInstance) in " + configBeanClass, e);
    }
    Preconditions.checkState(declaredConstructor != null);
    return declaredConstructor.newInstance(old, moduleIdentifier);
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) DynamicMBeanWithInstance(org.opendaylight.controller.config.api.DynamicMBeanWithInstance)

Aggregations

ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)30 Module (org.opendaylight.controller.config.spi.Module)11 ObjectName (javax.management.ObjectName)9 AbstractModule (org.opendaylight.controller.config.spi.AbstractModule)6 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)5 DependencyResolver (org.opendaylight.controller.config.api.DependencyResolver)4 BundleContext (org.osgi.framework.BundleContext)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ValidationException (org.opendaylight.controller.config.api.ValidationException)3 ServiceInterfaceAnnotation (org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)2 ModuleInternalTransactionalInfo (org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo)2 RootRuntimeBeanRegistratorImpl (org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl)2 ServiceReference (org.opendaylight.controller.config.manager.impl.jmx.ServiceReference)2 ServiceReferenceMXBeanImpl (org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl)2