Search in sources :

Example 6 with ModuleIdentifier

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

the class DependencyResolverImpl method resolveModuleInstance.

private Module resolveModuleInstance(final ObjectName dependentReadOnlyON, final JmxAttribute jmxAttribute) {
    Preconditions.checkArgument(dependentReadOnlyON != null, "dependentReadOnlyON");
    Preconditions.checkArgument(jmxAttribute != null, "jmxAttribute");
    final ObjectName translatedDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON);
    this.transactionStatus.checkCommitStarted();
    this.transactionStatus.checkNotCommitted();
    final ModuleIdentifier dependentModuleIdentifier = ObjectNameUtil.fromON(translatedDependentReadOnlyON, ObjectNameUtil.TYPE_MODULE);
    return Preconditions.checkNotNull(this.modulesHolder.findModule(dependentModuleIdentifier, jmxAttribute));
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ObjectName(javax.management.ObjectName)

Example 7 with ModuleIdentifier

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

the class ConfigTransactionControllerImpl method copyExistingModule.

@SuppressWarnings("IllegalCatch")
private synchronized void copyExistingModule(final ModuleInternalInfo oldConfigBeanInfo) throws InstanceAlreadyExistsException {
    transactionStatus.checkNotCommitStarted();
    transactionStatus.checkNotAborted();
    ModuleIdentifier moduleIdentifier = oldConfigBeanInfo.getIdentifier();
    dependencyResolverManager.assertNotExists(moduleIdentifier);
    ModuleFactory moduleFactory;
    BundleContext bc;
    try {
        moduleFactory = factoriesHolder.findByModuleName(moduleIdentifier.getFactoryName());
        bc = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
    } catch (final ModuleFactoryNotFoundException e) {
        throw new IllegalStateException(e);
    }
    Module module;
    DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
    try {
        module = moduleFactory.createModule(moduleIdentifier.getInstanceName(), dependencyResolver, oldConfigBeanInfo.getReadableModule(), bc);
    } catch (final Exception e) {
        throw new IllegalStateException(String.format("Error while copying old configuration from %s to %s", oldConfigBeanInfo, moduleFactory), e);
    }
    putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, oldConfigBeanInfo, dependencyResolver, oldConfigBeanInfo.isDefaultBean(), bc);
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(org.opendaylight.controller.config.api.ValidationException) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) BundleContext(org.osgi.framework.BundleContext) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver)

Example 8 with ModuleIdentifier

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

the class ConfigTransactionControllerImpl method createModule.

@Override
public synchronized ObjectName createModule(final String factoryName, final String instanceName) throws InstanceAlreadyExistsException {
    transactionStatus.checkNotCommitStarted();
    transactionStatus.checkNotAborted();
    ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
    dependencyResolverManager.assertNotExists(moduleIdentifier);
    // find factory
    ModuleFactory moduleFactory = factoriesHolder.findByModuleName(factoryName);
    DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
    BundleContext bundleContext = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
    Module module = moduleFactory.createModule(instanceName, dependencyResolver, bundleContext);
    boolean defaultBean = false;
    return putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, null, dependencyResolver, defaultBean, bundleContext);
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver) BundleContext(org.osgi.framework.BundleContext)

Example 9 with ModuleIdentifier

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

the class ConfigTransactionControllerImpl method validateNoLocks.

@SuppressWarnings("IllegalCatch")
private void validateNoLocks() throws ValidationException {
    transactionStatus.checkNotAborted();
    LOG.trace("Validating transaction {}", getTransactionIdentifier());
    // call validate()
    List<ValidationException> collectedExceptions = new ArrayList<>();
    for (Entry<ModuleIdentifier, Module> entry : dependencyResolverManager.getAllModules().entrySet()) {
        ModuleIdentifier name = entry.getKey();
        Module module = entry.getValue();
        try {
            module.validate();
        } catch (final Exception e) {
            LOG.warn("Validation exception in {}", getTransactionName(), e);
            collectedExceptions.add(ValidationException.createForSingleException(name, e));
        }
    }
    if (!collectedExceptions.isEmpty()) {
        throw ValidationException.createFromCollectedValidationExceptions(collectedExceptions);
    }
    LOG.trace("Validated transaction {}", getTransactionIdentifier());
}
Also used : ValidationException(org.opendaylight.controller.config.api.ValidationException) ArrayList(java.util.ArrayList) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(org.opendaylight.controller.config.api.ValidationException) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)

Example 10 with ModuleIdentifier

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

the class DependencyResolverManagerTest method mockedModule.

private static Module mockedModule() {
    Module mockedModule = mock(Module.class);
    doReturn(mock(AutoCloseable.class)).when(mockedModule).getInstance();
    doReturn(new ModuleIdentifier("fact", "instance")).when(mockedModule).getIdentifier();
    return mockedModule;
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) Module(org.opendaylight.controller.config.spi.Module)

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