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;
}
}
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();
}
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());
}
}
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());
}
}
Aggregations