use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method removeFromNeutronRouterInterfacesMap.
protected void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
synchronized (routerId.getValue().intern()) {
InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
try {
Optional<RouterInterfaces> optRouterInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId(interfaceName).build();
if (optRouterInterfaces.isPresent()) {
RouterInterfaces routerInterfaces = optRouterInterfaces.get();
List<Interfaces> interfaces = routerInterfaces.getInterfaces();
if (interfaces != null && interfaces.remove(routerInterface)) {
if (interfaces.isEmpty()) {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
} else {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
}
}
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
}
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method addToNeutronRouterInterfacesMap.
protected void addToNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
synchronized (routerId.getValue().intern()) {
InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
try {
Optional<RouterInterfaces> optRouterInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId(interfaceName).build();
if (optRouterInterfaces.isPresent()) {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
} else {
// TODO Shouldn't we be doing something with builder and interfaces?
// RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
// List<Interfaces> interfaces = new ArrayList<>();
// interfaces.add(routerInterface);
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Error reading router interfaces for {}", routerInterfacesId, e);
}
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class L2GatewayListener method remove.
@Override
protected void remove(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
LOG.info("Removing L2gateway with ID: {}", input.getUuid());
List<L2gatewayConnection> connections = l2gwService.getL2GwConnectionsByL2GatewayId(input.getUuid());
try {
ReadWriteTransaction tx = this.dataBroker.newReadWriteTransaction();
for (L2gatewayConnection connection : connections) {
InstanceIdentifier<L2gatewayConnection> iid = InstanceIdentifier.create(Neutron.class).child(L2gatewayConnections.class).child(L2gatewayConnection.class, connection.getKey());
tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
}
tx.submit().checkedGet();
} catch (TransactionCommitFailedException e) {
LOG.error("Failed to delete associated l2gwconnection while deleting l2gw {} with id beacause of {}", input.getUuid(), e.getLocalizedMessage());
// TODO :retry
}
List<Devices> l2Devices = input.getDevices();
for (Devices l2Device : l2Devices) {
LOG.trace("Removing L2gateway device: {}", l2Device);
removeL2Device(l2Device, input);
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method testWriteOnlyTransaction.
@Test
public void testWriteOnlyTransaction() throws Exception {
// Test successful write operations and submit
DOMDataWriteTransaction tx = adapter.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
tx.merge(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
verify(mockWriteTx).merge(TestModel.TEST_PATH, dataNode);
tx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
verify(mockWriteTx).delete(TestModel.TEST_PATH);
CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
submitFuture.get(5, TimeUnit.SECONDS);
InOrder inOrder = inOrder(mockCommitCohort);
inOrder.verify(mockCommitCohort).canCommit();
inOrder.verify(mockCommitCohort).preCommit();
inOrder.verify(mockCommitCohort).commit();
// Test cancel
tx = adapter.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
tx.cancel();
verify(mockWriteTx).close();
// Test submit with OptimisticLockFailedException
String errorMsg = "mock OptimisticLockFailedException";
Throwable cause = new ConflictingModificationAppliedException(TestModel.TEST_PATH, "mock");
doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.OptimisticLockFailedException(errorMsg, cause))).when(mockCommitCohort).canCommit();
try {
tx = adapter.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
submitFuture = tx.submit();
submitFuture.checkedGet(5, TimeUnit.SECONDS);
fail("Expected OptimisticLockFailedException");
} catch (OptimisticLockFailedException e) {
assertEquals("getMessage", errorMsg, e.getMessage());
assertEquals("getCause", cause, e.getCause());
}
// Test submit with TransactionCommitFailedException
errorMsg = "mock TransactionCommitFailedException";
cause = new DataValidationFailedException(TestModel.TEST_PATH, "mock");
doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException(errorMsg, cause))).when(mockCommitCohort).canCommit();
try {
tx = adapter.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
submitFuture = tx.submit();
submitFuture.checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (TransactionCommitFailedException e) {
assertEquals("getMessage", errorMsg, e.getMessage());
assertEquals("getCause", cause, e.getCause());
}
// Test submit with DataStoreUnavailableException
errorMsg = "mock NoShardLeaderException";
cause = new NoShardLeaderException("mock");
doReturn(Futures.immediateFailedFuture(cause)).when(mockCommitCohort).canCommit();
try {
tx = adapter.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
submitFuture = tx.submit();
submitFuture.checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (TransactionCommitFailedException e) {
assertEquals("getCause type", DataStoreUnavailableException.class, e.getCause().getClass());
assertEquals("Root cause", cause, e.getCause().getCause());
}
// Test submit with RuntimeException
errorMsg = "mock RuntimeException";
cause = new RuntimeException(errorMsg);
doReturn(Futures.immediateFailedFuture(cause)).when(mockCommitCohort).canCommit();
try {
tx = adapter.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
submitFuture = tx.submit();
submitFuture.checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (TransactionCommitFailedException e) {
assertEquals("getCause", cause, e.getCause());
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project controller by opendaylight.
the class DsbenchmarkProvider method setTestOperData.
private void setTestOperData(final ExecStatus sts, final long tstCompl) {
TestStatus status = new TestStatusBuilder().setExecStatus(sts).setTestsCompleted(tstCompl).build();
WriteTransaction tx = simpleTxDataBroker.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.OPERATIONAL, TEST_STATUS_IID, status);
try {
tx.submit().checkedGet();
} catch (final TransactionCommitFailedException e) {
throw new IllegalStateException(e);
}
LOG.debug("DataStore test oper status populated: {}", status);
}
Aggregations