Search in sources :

Example 1 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.

the class ServiceReferenceRegistryImpl method createSRWritableRegistry.

public static SearchableServiceReferenceWritableRegistry createSRWritableRegistry(final ServiceReferenceReadableRegistry oldReadableRegistry, final ConfigTransactionLookupRegistry txLookupRegistry, final Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories) {
    if (txLookupRegistry == null) {
        throw new IllegalArgumentException("txLookupRegistry is null");
    }
    ServiceReferenceRegistryImpl old = (ServiceReferenceRegistryImpl) oldReadableRegistry;
    Map<String, ModuleFactory> factories = extractFactoriesMap(currentlyRegisteredFactories);
    ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory = new ServiceReferenceTransactionRegistratorFactoryImpl(txLookupRegistry.getTxModuleJMXRegistrator(), txLookupRegistry.getTxModuleJMXRegistrator().getTransactionName());
    ServiceReferenceRegistryImpl newRegistry = new ServiceReferenceRegistryImpl(factories, txLookupRegistry, serviceReferenceRegistratorFactory, true);
    copy(old, newRegistry, txLookupRegistry.getTransactionIdentifier().getName());
    return newRegistry;
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ServiceReferenceTransactionRegistratorFactoryImpl(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceTransactionRegistratorFactoryImpl) ServiceReferenceTransactionRegistratorFactory(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceTransactionRegistratorFactory)

Example 2 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory 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 3 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory 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 4 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.

the class ModuleQNameUtil method getQNames.

public static Set<String> getQNames(final Map<String, Entry<ModuleFactory, BundleContext>> resolved) {
    final Set<String> result = new HashSet<>();
    for (final Entry<ModuleFactory, BundleContext> entry : resolved.values()) {
        Class<?> inspected = entry.getKey().getClass();
        if (inspected.isInterface()) {
            throw new IllegalArgumentException("Unexpected interface " + inspected);
        }
        ModuleQName annotation = null;
        while (annotation == null && inspected != null) {
            annotation = inspected.getAnnotation(ModuleQName.class);
            inspected = inspected.getSuperclass();
        }
        if (annotation != null) {
            result.add(QName.create(annotation.namespace(), annotation.revision(), annotation.name()).toString());
        }
    }
    return result;
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ModuleQName(org.opendaylight.yangtools.yang.binding.annotations.ModuleQName) HashSet(java.util.HashSet) BundleContext(org.osgi.framework.BundleContext)

Example 5 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.

the class ConfigRegistryImplTest method testFailOnTwoFactoriesExportingSameImpl.

@Test
@SuppressWarnings("IllegalCatch")
public void testFailOnTwoFactoriesExportingSameImpl() {
    ModuleFactory factory = new TestingFixedThreadPoolModuleFactory();
    BundleContext context = mock(BundleContext.class);
    ConfigRegistryImpl configRegistry = null;
    try {
        ModuleFactoriesResolver resolver = new HardcodedModuleFactoriesResolver(mock(BundleContext.class), factory, factory);
        configRegistry = new ConfigRegistryImpl(resolver, ManagementFactory.getPlatformMBeanServer(), null);
        configRegistry.beginConfig();
        fail();
    } catch (final IllegalArgumentException e) {
        assertTrue(e.getMessage(), e.getMessage().startsWith("Module name is not unique. Found two conflicting factories with same name " + "'fixed':"));
        verifyZeroInteractions(context);
    } finally {
        try {
            configRegistry.close();
        } catch (final Exception e) {
            // ignore
            LOG.warn("Ignoring exception", e);
        }
    }
}
Also used : TestingFixedThreadPoolModuleFactory(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory) ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) TestingFixedThreadPoolModuleFactory(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory) ModuleFactoriesResolver(org.opendaylight.controller.config.manager.impl.factoriesresolver.ModuleFactoriesResolver) HardcodedModuleFactoriesResolver(org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver) ConfigRegistryImpl(org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl) HardcodedModuleFactoriesResolver(org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test) AbstractLockedPlatformMBeanServerTest(org.opendaylight.controller.config.manager.impl.AbstractLockedPlatformMBeanServerTest)

Aggregations

ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)13 BundleContext (org.osgi.framework.BundleContext)8 DependencyResolver (org.opendaylight.controller.config.api.DependencyResolver)4 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)4 AbstractModule (org.opendaylight.controller.config.spi.AbstractModule)4 Module (org.opendaylight.controller.config.spi.Module)4 HashMap (java.util.HashMap)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ObjectName (javax.management.ObjectName)2 Test (org.junit.Test)2 ConfigRegistryImpl (org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl)2 JavaParser (com.github.javaparser.JavaParser)1 ParseException (com.github.javaparser.ParseException)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1