Search in sources :

Example 11 with TypedReadWriteTransaction

use of org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction in project netvirt by opendaylight.

the class MergeCommandsAggregator method mergeUpdate.

@SuppressWarnings("illegalcatch")
public <D extends Datastore> void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, Class<D> datastoreType, TypedReadWriteTransaction<D> transaction, ManagedNewTransactionRunner txRunner) {
    BatchedTransaction tx = null;
    if (mod == null || mod.getModifiedChildren() == null) {
        return;
    }
    if (!(transaction instanceof BatchedTransaction)) {
        return;
    } else {
        tx = (BatchedTransaction) transaction;
    }
    final BatchedTransaction transaction1 = tx;
    String srcNodeId = transaction1.getSrcNodeId().getValue();
    String dstNodeId = dstPath.firstKeyOf(Node.class).getNodeId().getValue();
    Collection<DataObjectModification> modifications = mod.getModifiedChildren();
    modifications.stream().filter(modification -> skipCopy.negate().test(datastoreType, modification.getDataType())).filter(modification -> commands.get(modification.getDataType()) != null).peek(modification -> LOG.debug("Received {} modification {} copy/delete to {}", datastoreType, modification, dstPath)).forEach(modification -> {
        try {
            copyModification(dstPath, datastoreType, transaction1, srcNodeId, dstNodeId, modification, txRunner);
        } catch (Exception e) {
            LOG.error("Failed to copy mod from {} to {} {} {} id  {}", srcNodeId, dstNodeId, modification.getDataType().getSimpleName(), modification, modification.getIdentifier(), e);
        }
    });
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) LoggerFactory(org.slf4j.LoggerFactory) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) HashMap(java.util.HashMap) RemoteUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteUcastCmd) RemoteMcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.RemoteMcastCmd) Tunnels(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels) BiPredicate(java.util.function.BiPredicate) Map(java.util.Map) Datastore(org.opendaylight.mdsal.binding.util.Datastore) LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) Builder(org.opendaylight.yangtools.concepts.Builder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification) BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) TunnelIpCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.TunnelIpCmd) Logger(org.slf4j.Logger) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Collection(java.util.Collection) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) Operational(org.opendaylight.mdsal.binding.util.Datastore.Operational) SuperTypeUtil(org.opendaylight.genius.utils.SuperTypeUtil) LocalUcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.LocalUcastCmd) FutureCallback(com.google.common.util.concurrent.FutureCallback) RemoteUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs) LocalMcastCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.LocalMcastCmd) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) RemoteMcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs) TerminationPointCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.TerminationPointCmd) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PhysicalLocatorCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.PhysicalLocatorCmd) LocalMcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs) Optional(java.util.Optional) TunnelCmd(org.opendaylight.netvirt.elan.l2gw.ha.commands.TunnelCmd) CacheBuilder(com.google.common.cache.CacheBuilder) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) Cache(com.google.common.cache.Cache) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification)

Example 12 with TypedReadWriteTransaction

use of org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction in project netvirt by opendaylight.

the class FloatingIPListener method addOrDelDefaultFibRouteForDnat.

private void addOrDelDefaultFibRouteForDnat(Uint64 dpnId, String routerName, Uint32 routerId, @Nullable TypedReadWriteTransaction<Configuration> confTx, boolean create) throws ExecutionException, InterruptedException {
    if (confTx == null) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, newTx -> addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, newTx, create)), LOG, "Error handling default FIB route for DNAT");
        return;
    }
    // Check if the router to bgp-vpn association is present
    Uint32 associatedVpnId = NatConstants.INVALID_ID;
    Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
    if (associatedVpn != null) {
        associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
    }
    if (create) {
        if (associatedVpnId != NatConstants.INVALID_ID) {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, associatedVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
        } else {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, routerId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
        }
    } else {
        if (associatedVpnId != NatConstants.INVALID_ID) {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, associatedVpnId);
            defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
        } else {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, routerId);
            defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
        }
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) LoggerFactory(org.slf4j.LoggerFactory) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) InetAddress(java.net.InetAddress) NatSwitchCache(org.opendaylight.netvirt.natservice.api.NatSwitchCache) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) PreDestroy(javax.annotation.PreDestroy) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) Nullable(org.eclipse.jdt.annotation.Nullable) BigInteger(java.math.BigInteger) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) ActionSetDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) List(java.util.List) FloatingIpInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) Optional(java.util.Optional) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) UnknownHostException(java.net.UnknownHostException) InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) ExecutionException(java.util.concurrent.ExecutionException) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) CentralizedSwitchScheduler(org.opendaylight.netvirt.natservice.api.CentralizedSwitchScheduler) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsBuilder) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) InternalToExternalPortMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Aggregations

TypedReadWriteTransaction (org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction)12 ExecutionException (java.util.concurrent.ExecutionException)11 CONFIGURATION (org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION)10 Configuration (org.opendaylight.mdsal.binding.util.Datastore.Configuration)10 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Optional (java.util.Optional)9 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)9 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)9 Collections (java.util.Collections)8 Inject (javax.inject.Inject)8 Singleton (javax.inject.Singleton)8 LoggingFutures (org.opendaylight.infrautils.utils.concurrent.LoggingFutures)8 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)8 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)8 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)7 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)7