Search in sources :

Example 41 with WriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class VpnUtil method unbindService.

static void unbindService(DataBroker dataBroker, final String vpnInterfaceName, boolean isInterfaceStateDown, JobCoordinator jobCoordinator) {
    if (!isInterfaceStateDown) {
        jobCoordinator.enqueueJob(vpnInterfaceName, () -> {
            WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
            writeTxn.delete(LogicalDatastoreType.CONFIGURATION, InterfaceUtils.buildServiceId(vpnInterfaceName, ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME, NwConstants.L3VPN_SERVICE_INDEX)));
            List<ListenableFuture<Void>> futures = new ArrayList<>();
            futures.add(writeTxn.submit());
            return futures;
        }, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 42 with WriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class VpnUtil method delete.

public static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path, FutureCallback<Void> callback) {
    WriteTransaction tx = broker.newWriteOnlyTransaction();
    tx.delete(datastoreType, path);
    Futures.addCallback(tx.submit(), callback, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction)

Example 43 with WriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class InterVpnLinkListener method setInError.

protected void setInError(final InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid, final InterVpnLinkState vpnLinkState, String errorMsg) {
    LOG.error("Setting InterVpnLink {} in error. Reason: {}", vpnLinkState.getInterVpnLinkName(), errorMsg);
    // Setting InterVPNLink in error state in MDSAL
    InterVpnLinkState vpnLinkErrorState = new InterVpnLinkStateBuilder(vpnLinkState).setState(InterVpnLinkState.State.Error).setErrorDescription(errorMsg).build();
    WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, vpnLinkStateIid, vpnLinkErrorState, WriteTransaction.CREATE_MISSING_PARENTS);
    tx.submit();
    // Sending out an error Notification
    InterVpnLinkCreationErrorMessage errMsg = new InterVpnLinkCreationErrorMessageBuilder().setErrorMessage(errorMsg).build();
    InterVpnLinkCreationError notif = new InterVpnLinkCreationErrorBuilder().setInterVpnLinkCreationErrorMessage(errMsg).build();
    final ListenableFuture<?> eventFuture = this.notificationsService.offerNotification(notif);
    Futures.addCallback(eventFuture, new FutureCallback<Object>() {

        @Override
        public void onFailure(Throwable error) {
            LOG.warn("Error when sending notification about InterVpnLink creation issue. InterVpnLink name={} " + "state={}.", vpnLinkState.getInterVpnLinkName(), vpnLinkState, error);
        }

        @Override
        public void onSuccess(Object arg) {
            LOG.trace("Error notification for InterVpnLink successfully sent. VpnLinkName={} state={}", vpnLinkState.getInterVpnLinkName(), vpnLinkState);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) InterVpnLinkCreationErrorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinkCreationErrorBuilder) InterVpnLinkCreationErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.creation.error.InterVpnLinkCreationErrorMessageBuilder) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState) InterVpnLinkCreationError(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinkCreationError) InterVpnLinkCreationErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.creation.error.InterVpnLinkCreationErrorMessage) InterVpnLinkStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder)

Example 44 with WriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class InterVpnLinkNodeAddTask method updateInterVpnLinkState.

private ListenableFuture<Void> updateInterVpnLinkState(InterVpnLinkState interVpnLinkState, List<BigInteger> firstDpnList, List<BigInteger> secondDpnList) {
    FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder(interVpnLinkState.getFirstEndpointState()).setDpId(firstDpnList).build();
    SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder(interVpnLinkState.getSecondEndpointState()).setDpId(secondDpnList).build();
    InterVpnLinkState newInterVpnLinkState = new InterVpnLinkStateBuilder(interVpnLinkState).setState(InterVpnLinkState.State.Active).setFirstEndpointState(firstEndPointState).setSecondEndpointState(secondEndPointState).build();
    WriteTransaction tx = broker.newWriteOnlyTransaction();
    tx.merge(LogicalDatastoreType.CONFIGURATION, InterVpnLinkUtil.getInterVpnLinkStateIid(interVpnLinkState.getInterVpnLinkName()), newInterVpnLinkState, true);
    return tx.submit();
}
Also used : FirstEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointStateBuilder) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) SecondEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointStateBuilder) SecondEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointState) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState) FirstEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointState) InterVpnLinkStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder)

Example 45 with WriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class InterVpnLinkLocatorTest method setUp.

@Before
public void setUp() throws Exception {
    dataBroker = getDataBroker();
    // Creating both empty containers: InterVpnLinks and InterVpnLinkStates
    WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
    writeTx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(InterVpnLinks.class).build(), new InterVpnLinksBuilder().setInterVpnLink(Collections.emptyList()).build(), true);
    writeTx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(InterVpnLinkStates.class).build(), new InterVpnLinkStatesBuilder().setInterVpnLinkState(Collections.emptyList()).build(), true);
    writeTx.submit().checkedGet();
    interVpnLinkCache = new InterVpnLinkCacheImpl(dataBroker);
    interVpnLinkCache.initialFeed();
    // Prepare
    populateL3Vpns(dataBroker, L3VpnTestCatalog.ALL_VPNS);
    InterVpnLinkTestCatalog.populateIvpnLinks(dataBroker, ALL_IVPN_LINKS);
    for (InterVpnLinkDataComposite ivl : ALL_IVPN_LINKS) {
        interVpnLinkCache.addInterVpnLinkToCaches(ivl.getInterVpnLinkConfig());
        interVpnLinkCache.addInterVpnLinkStateToCaches(ivl.getInterVpnLinkState());
    }
    // SUT
    sut = new InterVpnLinkLocator(dataBroker, interVpnLinkCache);
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) InterVpnLinksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinksBuilder) InterVpnLinkStatesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinkStatesBuilder) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) Before(org.junit.Before)

Aggregations

WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)320 ArrayList (java.util.ArrayList)74 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)60 BigInteger (java.math.BigInteger)43 Test (org.junit.Test)38 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)37 ExecutionException (java.util.concurrent.ExecutionException)33 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)28 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)25 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)23 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)23 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)22 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)19 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)17 List (java.util.List)16 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)16 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)16 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)15 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)14 VpnToDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList)14