Search in sources :

Example 21 with TransactionCommitFailedException

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);
        }
    }
}
Also used : VpnInterfaces(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces) RouterInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RouterInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesKey) InterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesKey) InterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesBuilder)

Example 22 with TransactionCommitFailedException

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);
        }
    }
}
Also used : VpnInterfaces(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces) RouterInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RouterInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesKey) InterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesKey) InterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesBuilder)

Example 23 with TransactionCommitFailedException

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);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)

Example 24 with TransactionCommitFailedException

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());
    }
}
Also used : DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) InOrder(org.mockito.InOrder) DataStoreUnavailableException(org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) Test(org.junit.Test)

Example 25 with TransactionCommitFailedException

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);
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TestStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestStatus) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) TestStatusBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestStatusBuilder)

Aggregations

TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)117 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)32 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)21 Test (org.junit.Test)19 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)16 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)13 ArrayList (java.util.ArrayList)12 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)12 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)11 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)9 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)9 OptimisticLockFailedException (org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)8 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)8 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)8 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)7 Optional (com.google.common.base.Optional)6 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)6 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)6 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)6