Search in sources :

Example 21 with CommitStatus

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

the class TransactionProvider method commitTransaction.

/**
 * Commit and notification send must be atomic.
 */
public synchronized CommitStatus commitTransaction(final ConfigRegistryClient client) throws ValidationException, ConflictingVersionException {
    if (!getTransaction().isPresent()) {
        // making empty commit without prior opened transaction, just return commit
        // status with empty lists
        LOG.debug("Making commit without open candidate transaction for session {}", sessionIdForReporting);
        return new CommitStatus(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    }
    final Optional<ObjectName> maybeTaON = getTransaction();
    ObjectName taON = maybeTaON.get();
    try {
        CommitStatus status = client.commitConfig(taON);
        // clean up
        allOpenedTransactions.remove(candidateTx);
        candidateTx = null;
        return status;
    } catch (final ValidationException validationException) {
        // no clean up: user can reconfigure and recover this transaction
        LOG.warn("Transaction {} failed on {}", taON, validationException.toString());
        throw validationException;
    } catch (final ConflictingVersionException e) {
        LOG.debug("Exception while commit of {}, aborting transaction", taON, e);
        // clean up
        abortTransaction();
        throw e;
    }
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) ValidationException(org.opendaylight.controller.config.api.ValidationException) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) ObjectName(javax.management.ObjectName)

Example 22 with CommitStatus

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

the class RuntimeBeanTest method testRecreate.

@Test
public void testRecreate() throws Exception {
    ObjectName createdConfigBean = createScheduled();
    // empty transaction
    ConfigTransactionJMXClient configTransaction = configRegistryClient.createTransaction();
    ObjectName scheduledWritableON = configTransaction.lookupConfigBean(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
    TestingScheduledThreadPoolConfigBeanMXBean scheduledWritableProxy = configTransaction.newMXBeanProxy(scheduledWritableON, TestingScheduledThreadPoolConfigBeanMXBean.class);
    scheduledWritableProxy.setRecreate(true);
    CommitStatus commitInfo = configTransaction.commit();
    // check that it was recreated
    ObjectName readableConfigBean = ObjectNameUtil.withoutTransactionName(createdConfigBean);
    List<ObjectName> newInstances = Collections.<ObjectName>emptyList();
    List<ObjectName> reusedInstances = Collections.<ObjectName>emptyList();
    List<ObjectName> recreatedInstaces = Lists.newArrayList(readableConfigBean);
    assertEquals(new CommitStatus(newInstances, reusedInstances, recreatedInstaces), commitInfo);
    checkRuntimeBeans();
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) TestingScheduledThreadPoolConfigBeanMXBean(org.opendaylight.controller.config.manager.testingservices.scheduledthreadpool.TestingScheduledThreadPoolConfigBeanMXBean) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 23 with CommitStatus

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

the class SimpleConfigurationTest method testCreateAndDestroyBeanInSameTransaction.

@Test
public void testCreateAndDestroyBeanInSameTransaction() throws Exception {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    ObjectName fixed1names = createFixedThreadPool(transaction);
    transaction.destroyModule(fixed1names);
    CommitStatus commitStatus = transaction.commit();
    assertStatus(commitStatus, 0, 0, 0);
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) ObjectName(javax.management.ObjectName) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest) Test(org.junit.Test)

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