Search in sources :

Example 16 with CommitStatus

use of org.opendaylight.controller.config.api.jmx.CommitStatus in project controller by opendaylight.

the class GlobalEventExecutorModuleTest method testCreateBean.

@Test
public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    createInstance(transaction, instanceName);
    transaction.validateConfig();
    CommitStatus status = transaction.commit();
    assertBeanCount(1, factory.getImplementationName());
    assertStatus(status, 1, 0, 0);
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) Test(org.junit.Test) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest)

Example 17 with CommitStatus

use of org.opendaylight.controller.config.api.jmx.CommitStatus in project controller by opendaylight.

the class GlobalEventExecutorModuleTest method testReusingOldInstance.

@Test
public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    createInstance(transaction, instanceName);
    transaction.commit();
    transaction = configRegistryClient.createTransaction();
    assertBeanCount(1, factory.getImplementationName());
    CommitStatus status = transaction.commit();
    assertBeanCount(1, factory.getImplementationName());
    assertStatus(status, 0, 0, 1);
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) Test(org.junit.Test) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest)

Example 18 with CommitStatus

use of org.opendaylight.controller.config.api.jmx.CommitStatus in project controller by opendaylight.

the class ImmediateEventExecutorModuleTest method testCreateBean.

@Test
public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    createInstance(transaction, instanceName);
    transaction.validateConfig();
    CommitStatus status = transaction.commit();
    assertBeanCount(1, factory.getImplementationName());
    assertStatus(status, 1, 0, 0);
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest) Test(org.junit.Test)

Example 19 with CommitStatus

use of org.opendaylight.controller.config.api.jmx.CommitStatus in project controller by opendaylight.

the class NettyThreadgroupModuleTest method testReusingOldInstance.

@Test
public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    createInstance(transaction, instanceName, null);
    transaction.commit();
    transaction = configRegistryClient.createTransaction();
    assertBeanCount(1, factory.getImplementationName());
    CommitStatus status = transaction.commit();
    assertBeanCount(1, factory.getImplementationName());
    assertStatus(status, 0, 0, 1);
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) Test(org.junit.Test) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest)

Example 20 with CommitStatus

use of org.opendaylight.controller.config.api.jmx.CommitStatus in project controller by opendaylight.

the class ConfigRegistryImpl method secondPhaseCommit.

@GuardedBy("configTransactionLock")
private CommitStatus secondPhaseCommit(final ConfigTransactionControllerInternal configTransactionController, final CommitInfo commitInfo, final ConfigTransactionLookupRegistry txLookupRegistry) {
    // (hopefully) runtime beans
    for (DestroyedModule toBeDestroyed : commitInfo.getDestroyedFromPreviousTransactions()) {
        // closes instance (which should close
        // runtime jmx registrator),
        // also closes osgi registration and ModuleJMXRegistrator
        // registration
        toBeDestroyed.close();
        currentConfig.remove(toBeDestroyed.getIdentifier());
    }
    // set RuntimeBeanRegistrators on beans implementing
    // RuntimeBeanRegistratorAwareModule
    Map<ModuleIdentifier, RootRuntimeBeanRegistratorImpl> runtimeRegistrators = new HashMap<>();
    for (ModuleInternalTransactionalInfo entry : commitInfo.getCommitted().values()) {
        // set runtime jmx registrator if required
        Module module = entry.getProxiedModule();
        RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator = null;
        if (module instanceof RuntimeBeanRegistratorAwareModule) {
            if (entry.hasOldModule()) {
                if (module.canReuse(entry.getOldInternalInfo().getReadableModule().getModule())) {
                    runtimeBeanRegistrator = entry.getOldInternalInfo().getRuntimeBeanRegistrator();
                    ((RuntimeBeanRegistratorAwareModule) module).setRuntimeBeanRegistrator(runtimeBeanRegistrator);
                } else {
                    runtimeBeanRegistrator = baseJMXRegistrator.createRuntimeBeanRegistrator(entry.getIdentifier());
                    entry.getOldInternalInfo().getRuntimeBeanRegistrator().close();
                    ((RuntimeBeanRegistratorAwareModule) module).setRuntimeBeanRegistrator(runtimeBeanRegistrator);
                }
            } else {
                runtimeBeanRegistrator = baseJMXRegistrator.createRuntimeBeanRegistrator(entry.getIdentifier());
                ((RuntimeBeanRegistratorAwareModule) module).setRuntimeBeanRegistrator(runtimeBeanRegistrator);
            }
        }
        // save it to info so it is accessible afterwards
        if (runtimeBeanRegistrator != null) {
            runtimeRegistrators.put(entry.getIdentifier(), runtimeBeanRegistrator);
        }
    }
    // can register runtime beans
    List<ModuleIdentifier> orderedModuleIdentifiers = configTransactionController.secondPhaseCommit();
    txLookupRegistry.close();
    configTransactionController.close();
    // copy configuration to read only mode
    List<ObjectName> newInstances = new LinkedList<>();
    List<ObjectName> reusedInstances = new LinkedList<>();
    List<ObjectName> recreatedInstances = new LinkedList<>();
    Map<Module, ModuleInternalInfo> newConfigEntries = new HashMap<>();
    int orderingIdx = 0;
    for (ModuleIdentifier moduleIdentifier : orderedModuleIdentifiers) {
        LOG.trace("Registering {}", moduleIdentifier);
        ModuleInternalTransactionalInfo entry = commitInfo.getCommitted().get(moduleIdentifier);
        if (entry == null) {
            throw new NullPointerException("Module not found " + moduleIdentifier);
        }
        ObjectName primaryReadOnlyON = ObjectNameUtil.createReadOnlyModuleON(moduleIdentifier);
        // determine if current instance was recreated or reused or is new
        // rules for closing resources:
        // osgi registration - will be reused if possible.
        // module jmx registration - will be (re)created every time, needs
        // to be closed here
        // runtime jmx registration - should be taken care of by module
        // itself
        // instance - is closed only if it was destroyed
        ModuleJMXRegistrator newModuleJMXRegistrator = baseJMXRegistrator.createModuleJMXRegistrator();
        OsgiRegistration osgiRegistration = null;
        AutoCloseable instance = entry.getProxiedModule().getInstance();
        if (entry.hasOldModule()) {
            ModuleInternalInfo oldInternalInfo = entry.getOldInternalInfo();
            DynamicReadableWrapper oldReadableConfigBean = oldInternalInfo.getReadableModule();
            currentConfig.remove(entry.getIdentifier());
            // test if old instance == new instance
            if (oldReadableConfigBean.getInstance().equals(instance)) {
                // reused old instance:
                // wrap in readable dynamic mbean
                reusedInstances.add(primaryReadOnlyON);
                osgiRegistration = oldInternalInfo.getOsgiRegistration();
            } else {
                // recreated instance:
                // it is responsibility of module to call the old instance -
                // we just need to unregister configbean
                recreatedInstances.add(primaryReadOnlyON);
                // close old osgi registration
                oldInternalInfo.getOsgiRegistration().close();
            }
            // close old module jmx registrator
            oldInternalInfo.getModuleJMXRegistrator().close();
            // We no longer need old internal info. Clear it out, so we do not create a
            // serial leak evidenced
            // by BUG-4514. The reason is that modules retain their resolver, which retains
            // modules. If we retain
            // the old module, we would have the complete reconfiguration history held in
            // heap for no good reason.
            entry.clearOldInternalInfo();
        } else {
            // new instance:
            // wrap in readable dynamic mbean
            newInstances.add(primaryReadOnlyON);
        }
        Module realModule = entry.getRealModule();
        DynamicReadableWrapper newReadableConfigBean = new DynamicReadableWrapper(realModule, instance, moduleIdentifier, registryMBeanServer, configMBeanServer);
        // register to JMX
        try {
            newModuleJMXRegistrator.registerMBean(newReadableConfigBean, primaryReadOnlyON);
        } catch (final InstanceAlreadyExistsException e) {
            throw new IllegalStateException("Possible code error, already registered:" + primaryReadOnlyON, e);
        }
        // register services to OSGi
        Map<ServiceInterfaceAnnotation, String> annotationMapping = configTransactionController.getWritableRegistry().findServiceInterfaces(moduleIdentifier);
        BundleContext bc = configTransactionController.getModuleFactoryBundleContext(entry.getModuleFactory().getImplementationName());
        if (osgiRegistration == null) {
            osgiRegistration = beanToOsgiServiceManager.registerToOsgi(newReadableConfigBean.getInstance(), moduleIdentifier, bc, annotationMapping);
        } else {
            osgiRegistration.updateRegistrations(annotationMapping, bc, instance);
        }
        RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator = runtimeRegistrators.get(entry.getIdentifier());
        ModuleInternalInfo newInfo = new ModuleInternalInfo(entry.getIdentifier(), newReadableConfigBean, osgiRegistration, runtimeBeanRegistrator, newModuleJMXRegistrator, orderingIdx, entry.isDefaultBean(), entry.getModuleFactory(), entry.getBundleContext());
        newConfigEntries.put(realModule, newInfo);
        orderingIdx++;
    }
    currentConfig.addAll(newConfigEntries.values());
    // update version
    version = configTransactionController.getVersion();
    // switch readable Service Reference Registry
    synchronized (readableSRRegistryLock) {
        readableSRRegistry.close();
        readableSRRegistry = ServiceReferenceRegistryImpl.createSRReadableRegistry(configTransactionController.getWritableRegistry(), this, baseJMXRegistrator);
    }
    return new CommitStatus(newInstances, reusedInstances, recreatedInstances);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ServiceInterfaceAnnotation(org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation) DynamicReadableWrapper(org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) OsgiRegistration(org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration) ModuleJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.ModuleJMXRegistrator) DestroyedModule(org.opendaylight.controller.config.manager.impl.dependencyresolver.DestroyedModule) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) RuntimeBeanRegistratorAwareModule(org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule) ModuleInternalTransactionalInfo(org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo) LinkedList(java.util.LinkedList) ObjectName(javax.management.ObjectName) DestroyedModule(org.opendaylight.controller.config.manager.impl.dependencyresolver.DestroyedModule) RuntimeBeanRegistratorAwareModule(org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule) Module(org.opendaylight.controller.config.spi.Module) RootRuntimeBeanRegistratorImpl(org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl) BundleContext(org.osgi.framework.BundleContext) GuardedBy(javax.annotation.concurrent.GuardedBy)

Aggregations

CommitStatus (org.opendaylight.controller.config.api.jmx.CommitStatus)23 Test (org.junit.Test)15 ConfigTransactionJMXClient (org.opendaylight.controller.config.util.ConfigTransactionJMXClient)15 AbstractConfigTest (org.opendaylight.controller.config.manager.impl.AbstractConfigTest)13 ObjectName (javax.management.ObjectName)8 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)2 ValidationException (org.opendaylight.controller.config.api.ValidationException)2 TestingFixedThreadPoolConfigMXBean (org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GuardedBy (javax.annotation.concurrent.GuardedBy)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 Before (org.junit.Before)1 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)1 RuntimeBeanRegistratorAwareModule (org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule)1 ServiceInterfaceAnnotation (org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation)1 DestroyedModule (org.opendaylight.controller.config.manager.impl.dependencyresolver.DestroyedModule)1 ModuleInternalTransactionalInfo (org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo)1 DynamicReadableWrapper (org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper)1