Search in sources :

Example 6 with ConflictingVersionException

use of org.opendaylight.controller.config.api.ConflictingVersionException 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 7 with ConflictingVersionException

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

the class BlankTransactionServiceTrackerTest method testConflictingException.

@Test
public void testConflictingException() throws Exception {
    int maxAttempts = 2;
    tracker = new BlankTransactionServiceTracker(blankTx, maxAttempts, MoreExecutors.newDirectExecutorService());
    final ConflictingVersionException ex = new ConflictingVersionException();
    doThrow(ex).when(blankTx).hit();
    tracker.addingService(getMockServiceReference());
    verify(blankTx, times(maxAttempts)).hit();
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) Test(org.junit.Test)

Example 8 with ConflictingVersionException

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

the class SimpleConfigurationTest method testOptimisticLock_ConfigRegistry.

@Test
public void testOptimisticLock_ConfigRegistry() throws Exception {
    ConfigTransactionJMXClient transaction1 = configRegistryClient.createTransaction();
    ConfigTransactionJMXClient transaction2 = configRegistryClient.createTransaction();
    transaction2.assertVersion(0, 2);
    transaction2.commit();
    try {
        configRegistryClient.commitConfig(transaction1.getObjectName());
        fail();
    } catch (final ConflictingVersionException e) {
        assertEquals("Optimistic lock failed. Expected parent version 2, was 0", e.getMessage());
    }
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest) Test(org.junit.Test)

Example 9 with ConflictingVersionException

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

the class SimpleConfigurationTest method testOptimisticLock_ConfigTransactionClient.

@Test
public void testOptimisticLock_ConfigTransactionClient() throws Exception {
    ConfigTransactionJMXClient transaction1 = configRegistryClient.createTransaction();
    ConfigTransactionJMXClient transaction2 = configRegistryClient.createTransaction();
    transaction2.assertVersion(0, 2);
    transaction2.commit();
    try {
        transaction1.commit();
        fail();
    } catch (final ConflictingVersionException e) {
        assertEquals("Optimistic lock failed. Expected parent version 2, was 0", e.getMessage());
    }
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest) Test(org.junit.Test)

Aggregations

ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)9 Test (org.junit.Test)4 ValidationException (org.opendaylight.controller.config.api.ValidationException)4 ObjectName (javax.management.ObjectName)2 CommitStatus (org.opendaylight.controller.config.api.jmx.CommitStatus)2 AbstractConfigTest (org.opendaylight.controller.config.manager.impl.AbstractConfigTest)2 ConfigTransactionJMXClient (org.opendaylight.controller.config.util.ConfigTransactionJMXClient)2 Stopwatch (com.google.common.base.Stopwatch)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 MBeanException (javax.management.MBeanException)1 ReflectionException (javax.management.ReflectionException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ExceptionMessageWithStackTrace (org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace)1 ConfigExecution (org.opendaylight.controller.config.facade.xml.ConfigExecution)1 ConfigSubsystemFacade (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade)1 ConfigSubsystemFacadeFactory (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory)1 Config (org.opendaylight.controller.config.facade.xml.mapping.config.Config)1 Capability (org.opendaylight.controller.config.util.capability.Capability)1