Search in sources :

Example 1 with Module

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

the class AbsFactoryGeneratedObjectFactory method getCreateModule.

private static String getCreateModule(FullyQualifiedName moduleFQN, List<Field> moduleFields) {
    StringBuilder result = new StringBuilder("\n" + "@Override\n");
    result.append(format("public %s createModule(String instanceName, %s dependencyResolver, %s old, %s bundleContext) " + "throws Exception {\n", Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(), DynamicMBeanWithInstance.class.getCanonicalName(), BUNDLE_CONTEXT)).append(format("%s oldModule;\n", moduleFQN)).append("try {\n").append(format("oldModule = (%s) old.getModule();\n", moduleFQN)).append("} catch(Exception e) {\n" + "return handleChangedClass(dependencyResolver, old, bundleContext);\n" + "}\n").append(format("%s module = instantiateModule(instanceName, dependencyResolver, oldModule, old" + ".getInstance(), bundleContext);\n", moduleFQN));
    for (Field field : moduleFields) {
        result.append(format("module.set%s(oldModule.get%1$s());\n", field.getName()));
    }
    result.append("\n" + "return module;\n" + "}\n");
    return result.toString();
}
Also used : Field(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field) Module(org.opendaylight.controller.config.spi.Module) DynamicMBeanWithInstance(org.opendaylight.controller.config.api.DynamicMBeanWithInstance) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver)

Example 2 with Module

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

the class DependencyResolverImpl method canReuseDependency.

@Override
public boolean canReuseDependency(final ObjectName objectName, final JmxAttribute jmxAttribute) {
    Preconditions.checkNotNull(objectName);
    Preconditions.checkNotNull(jmxAttribute);
    final Module currentModule = resolveModuleInstance(objectName, jmxAttribute);
    final ModuleIdentifier identifier = currentModule.getIdentifier();
    final ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = this.modulesHolder.findModuleInternalTransactionalInfo(identifier);
    if (moduleInternalTransactionalInfo.hasOldModule()) {
        final Module oldModule = moduleInternalTransactionalInfo.getOldInternalInfo().getReadableModule().getModule();
        return currentModule.canReuse(oldModule);
    }
    return false;
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) Module(org.opendaylight.controller.config.spi.Module)

Example 3 with Module

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

the class DependencyResolverImpl method resolveInstance.

// TODO: check for cycles
@Override
public <T> T resolveInstance(final Class<T> expectedType, final ObjectName dependentReadOnlyON, final JmxAttribute jmxAttribute) {
    final Module module = resolveModuleInstance(dependentReadOnlyON, jmxAttribute);
    synchronized (this) {
        this.dependencies.add(module.getIdentifier());
    }
    final AutoCloseable instance = module.getInstance();
    if (instance == null) {
        final String message = String.format("Error while %s resolving instance %s. getInstance() returned null. Expected type %s, attribute %s", this.name, module.getIdentifier(), expectedType, jmxAttribute);
        throw new JmxAttributeValidationException(message, jmxAttribute);
    }
    try {
        return expectedType.cast(instance);
    } catch (final ClassCastException e) {
        final String message = String.format("Instance cannot be cast to expected type. Instance class is %s, expected type %s , attribute %s", instance.getClass(), expectedType, jmxAttribute);
        throw new JmxAttributeValidationException(message, e, jmxAttribute);
    }
}
Also used : JmxAttributeValidationException(org.opendaylight.controller.config.api.JmxAttributeValidationException) Module(org.opendaylight.controller.config.spi.Module)

Example 4 with Module

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

the class DependencyResolverManager method put.

public void put(final ModuleIdentifier moduleIdentifier, final Module module, final ModuleFactory moduleFactory, final ModuleInternalInfo maybeOldInternalInfo, final TransactionModuleJMXRegistration transactionModuleJMXRegistration, final boolean isDefaultBean, final BundleContext bundleContext) {
    transactionStatus.checkNotCommitted();
    Class<? extends Module> moduleClass = Module.class;
    if (module instanceof RuntimeBeanRegistratorAwareModule) {
        moduleClass = RuntimeBeanRegistratorAwareModule.class;
    }
    Module proxiedModule = Reflection.newProxy(moduleClass, new ModuleInvocationHandler(deadlockMonitor, moduleIdentifier, module));
    ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = new ModuleInternalTransactionalInfo(moduleIdentifier, proxiedModule, moduleFactory, maybeOldInternalInfo, transactionModuleJMXRegistration, isDefaultBean, module, bundleContext);
    modulesHolder.put(moduleInternalTransactionalInfo);
}
Also used : RuntimeBeanRegistratorAwareModule(org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule) RuntimeBeanRegistratorAwareModule(org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule) Module(org.opendaylight.controller.config.spi.Module)

Example 5 with Module

use of org.opendaylight.controller.config.spi.Module 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)

Aggregations

Module (org.opendaylight.controller.config.spi.Module)15 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)11 AbstractModule (org.opendaylight.controller.config.spi.AbstractModule)7 DependencyResolver (org.opendaylight.controller.config.api.DependencyResolver)5 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)5 BundleContext (org.osgi.framework.BundleContext)5 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 ObjectName (javax.management.ObjectName)2 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)2 ValidationException (org.opendaylight.controller.config.api.ValidationException)2 ServiceInterfaceAnnotation (org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation)2 ModuleInternalTransactionalInfo (org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo)2 JavaParser (com.github.javaparser.JavaParser)1 ParseException (com.github.javaparser.ParseException)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableSet (com.google.common.collect.ImmutableSet)1