Search in sources :

Example 6 with TypedReadWriteTransaction

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

the class VrfEntryListener method handleAdjacencyAndVpnOpInterfaceDeletion.

/**
 * Check all the adjacency in VpnInterfaceOpData and decide whether to delete the entire interface or only adj.
 * Remove Adjacency from VPNInterfaceOpData.
 * if Adjacency != primary.
 * if Adjacency == primary , then mark it for deletion.
 * Remove entire VPNinterfaceOpData Entry.
 * if sie of Adjacency <= 2 and all are marked for deletion , delete the entire VPNinterface Op entry.
 * @param vrfEntry - VrfEntry removed
 * @param ifName - Interface name from VRFentry
 * @param vpnName - VPN name of corresponding VRF
 * @param tx - ReadWrite Tx
 */
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void handleAdjacencyAndVpnOpInterfaceDeletion(VrfEntry vrfEntry, String ifName, String vpnName, TypedReadWriteTransaction<Operational> tx) throws ExecutionException, InterruptedException {
    InstanceIdentifier<Adjacency> adjacencyIid = FibUtil.getAdjacencyIdentifierOp(ifName, vpnName, vrfEntry.getDestPrefix());
    Optional<Adjacency> adjacencyOptional = tx.read(adjacencyIid).get();
    if (adjacencyOptional.isPresent()) {
        if (adjacencyOptional.get().getAdjacencyType() != Adjacency.AdjacencyType.PrimaryAdjacency) {
            tx.delete(FibUtil.getAdjacencyIdentifierOp(ifName, vpnName, vrfEntry.getDestPrefix()));
        } else {
            tx.merge(adjacencyIid, new AdjacencyBuilder(adjacencyOptional.get()).setMarkedForDeletion(true).build());
        }
    }
    Optional<AdjacenciesOp> optAdjacencies = tx.read(FibUtil.getAdjListPathOp(ifName, vpnName)).get();
    if (!optAdjacencies.isPresent() || optAdjacencies.get().getAdjacency() == null) {
        return;
    }
    @NonNull List<Adjacency> adjacencies = new ArrayList<Adjacency>(optAdjacencies.get().nonnullAdjacency().values());
    if (adjacencies.size() <= 2 && adjacencies.stream().allMatch(adjacency -> adjacency.getAdjacencyType() == Adjacency.AdjacencyType.PrimaryAdjacency && adjacency.isMarkedForDeletion() != null && adjacency.isMarkedForDeletion())) {
        LOG.info("Clean up vpn interface {} to vpn {} list.", ifName, vpnName);
        tx.delete(FibUtil.getVpnInterfaceOpDataEntryIdentifier(ifName, vpnName));
    }
}
Also used : Arrays(java.util.Arrays) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) InetAddress(java.net.InetAddress) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) Map(java.util.Map) Datastore(org.opendaylight.mdsal.binding.util.Datastore) BigInteger(java.math.BigInteger) LabelRouteInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoBuilder) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) UpgradeState(org.opendaylight.serviceutils.upgrade.UpgradeState) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) NWUtil.isIpv4Address(org.opendaylight.genius.mdsalutil.NWUtil.isIpv4Address) NonNull(org.eclipse.jdt.annotation.NonNull) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LabelRouteMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.LabelRouteMap) RoutePathsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePathsKey) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) Uint64(org.opendaylight.yangtools.yang.common.Uint64) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Callable(java.util.concurrent.Callable) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) InstanceIdentifierBuilder(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder) Lists(com.google.common.collect.Lists) LabelRouteInfoKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoKey) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) UnknownHostException(java.net.UnknownHostException) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) AdjacencyResult(org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) LoggerFactory(org.slf4j.LoggerFactory) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) Nullable(org.eclipse.jdt.annotation.Nullable) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) RetryingManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.RetryingManagedNewTransactionRunner) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) VpnToDpnListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey) LabelRouteInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfo) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.PrefixesBuilder) Objects(java.util.Objects) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) Optional(java.util.Optional) SubnetRoute(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.SubnetRoute) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) NWUtil(org.opendaylight.genius.mdsalutil.NWUtil) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) TransactionAdapter(org.opendaylight.mdsal.binding.util.TransactionAdapter) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) Inject(javax.inject.Inject) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) Objects.requireNonNull(java.util.Objects.requireNonNull) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) VpnExtraRouteHelper(org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Operational(org.opendaylight.mdsal.binding.util.Datastore.Operational) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) MatchMplsLabel(org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey) Collections(java.util.Collections) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) JvmGlobalLocks(org.opendaylight.genius.utils.JvmGlobalLocks) AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) NonNull(org.eclipse.jdt.annotation.NonNull) Objects.requireNonNull(java.util.Objects.requireNonNull) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 7 with TypedReadWriteTransaction

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

the class HAOpNodeListener method readAndCopyChildPsOpToParent.

private void readAndCopyChildPsOpToParent(Node childNode, TypedReadWriteTransaction<Operational> tx) {
    String childGlobalNodeId = childNode.getNodeId().getValue();
    List<InstanceIdentifier> childPsIids = new ArrayList<>();
    HwvtepGlobalAugmentation hwvtepGlobalAugmentation = childNode.augmentation(HwvtepGlobalAugmentation.class);
    if (hwvtepGlobalAugmentation == null || HwvtepHAUtil.isEmpty(hwvtepGlobalAugmentation.nonnullSwitches().values())) {
        haOpClusteredListener.getConnectedNodes().stream().filter(connectedIid -> IS_PS_CHILD_TO_GLOBAL_NODE.test(childGlobalNodeId, connectedIid)).forEach(connectedIid -> childPsIids.add(connectedIid));
    } else {
        hwvtepGlobalAugmentation.getSwitches().values().forEach(switches -> childPsIids.add(switches.getSwitchRef().getValue()));
    }
    if (childPsIids.isEmpty()) {
        LOG.info("HAOpNodeListener No child ps found for global {}", childGlobalNodeId);
    }
    childPsIids.forEach(psIid -> {
        try {
            InstanceIdentifier<Node> childPsIid = psIid;
            Optional<Node> childPsNode = tx.read(childPsIid).get();
            if (childPsNode.isPresent()) {
                LOG.debug("Child oper PS node found");
                onPsNodeAdd(childPsIid, childPsNode.get(), tx);
            } else {
                LOG.error("HAOpNodeListener Child oper ps node not found {}", childPsIid);
            }
        } catch (ExecutionException | InterruptedException e) {
            LOG.error("HAOpNodeListener Failed to read child ps node {}", psIid);
        }
    });
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) IHAEventHandler(org.opendaylight.netvirt.elan.l2gw.ha.handlers.IHAEventHandler) TerminationPointBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder) HAEventHandler(org.opendaylight.netvirt.elan.l2gw.ha.handlers.HAEventHandler) L2GatewayServiceRecoveryHandler(org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayServiceRecoveryHandler) LoggerFactory(org.slf4j.LoggerFactory) HwvtepGlobalAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) RecoverableListener(org.opendaylight.serviceutils.srm.RecoverableListener) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) BiPredicate(java.util.function.BiPredicate) HwvtepHAUtil(org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) NodeCopier(org.opendaylight.netvirt.elan.l2gw.ha.handlers.NodeCopier) DataObjectModification(org.opendaylight.mdsal.binding.api.DataObjectModification) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) ResourceBatchingManager(org.opendaylight.genius.utils.batching.ResourceBatchingManager) Logger(org.slf4j.Logger) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Predicate(java.util.function.Predicate) Managers(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers) 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) Set(java.util.Set) ServiceRecoveryRegistry(org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry) Collectors(java.util.stream.Collectors) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) HwvtepPhysicalPortAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentationBuilder) Optional(java.util.Optional) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) HwvtepPhysicalPortAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) PhysicalSwitchAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ArrayList(java.util.ArrayList) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with TypedReadWriteTransaction

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

the class ElanNodeListener method createArpRequestMatchFlows.

private void createArpRequestMatchFlows(Uint64 dpId, TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
    long arpRequestGroupId = ArpResponderUtil.retrieveStandardArpResponderGroupId(idManagerService);
    List<BucketInfo> buckets = ArpResponderUtil.getDefaultBucketInfos(NwConstants.ARP_RESPONDER_TABLE);
    LOG.trace("Installing group flow on dpn {}", dpId);
    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpId, arpRequestGroupId, ArpResponderConstant.GROUP_FLOW_NAME.value(), GroupTypes.GroupAll, buckets);
    mdsalManager.addGroup(tx, groupEntity);
    InstanceIdentifier<Group> groupIid = ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId);
    if (tx.read(groupIid).get().isPresent()) {
        LOG.info("group {} is present in the config hence adding the flow", arpRequestGroupId);
        createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId, tx);
        return;
    }
    eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION, ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId), (unused, newGroupId) -> {
        LOG.info("group {} added in the config", arpRequestGroupId);
        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId, innerConfTx)), LOG, "Error adding flow for the group {}", arpRequestGroupId);
        return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
    }, Duration.ofSeconds(5), iid -> LOG.error("arpRequestGroupId {} not found in Config datastore", arpRequestGroupId));
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) Arrays(java.util.Arrays) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) ElanConstants(org.opendaylight.netvirt.elan.utils.ElanConstants) LoggerFactory(org.slf4j.LoggerFactory) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) PreDestroy(javax.annotation.PreDestroy) ElanUtils(org.opendaylight.netvirt.elan.utils.ElanUtils) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) NxmNxReg4(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) Duration(java.time.Duration) 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) ActionLearn(org.opendaylight.genius.mdsalutil.actions.ActionLearn) NxMatchRegister(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) LoggingFutures.addErrorLogging(org.opendaylight.infrautils.utils.concurrent.LoggingFutures.addErrorLogging) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) ElanConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) MatchFromValue(org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromValue) Uint64(org.opendaylight.yangtools.yang.common.Uint64) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) MatchArpOp(org.opendaylight.genius.mdsalutil.matches.MatchArpOp) Singleton(javax.inject.Singleton) NxmOfFieldType(org.opendaylight.genius.mdsalutil.NwConstants.NxmOfFieldType) ArpResponderConstant(org.opendaylight.netvirt.elan.arp.responder.ArpResponderConstant) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ArpResponderUtil(org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil) ActionRegLoad(org.opendaylight.genius.mdsalutil.actions.ActionRegLoad) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionPuntToController(org.opendaylight.genius.mdsalutil.actions.ActionPuntToController) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Logger(org.slf4j.Logger) Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) MatchFromField(org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromField) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) ExecutionException(java.util.concurrent.ExecutionException) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) GroupTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) CopyFromValue(org.opendaylight.genius.mdsalutil.actions.ActionLearn.CopyFromValue) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo)

Example 9 with TypedReadWriteTransaction

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

the class NodeCopier method copyPSNode.

public <D extends Datastore> void copyPSNode(Optional<Node> srcPsNodeOptional, InstanceIdentifier<Node> srcPsPath, InstanceIdentifier<Node> dstPsPath, InstanceIdentifier<Node> dstGlobalPath, Class<D> logicalDatastoreType, TypedReadWriteTransaction<D> tx) {
    if (!srcPsNodeOptional.isPresent() && Configuration.class.equals(logicalDatastoreType)) {
        Futures.addCallback(tx.read(srcPsPath), new FutureCallback<Optional<Node>>() {

            @Override
            public void onSuccess(Optional<Node> nodeOptional) {
                HAJobScheduler.getInstance().submitJob(() -> {
                    TypedReadWriteTransaction<D> tx1 = new BatchedTransaction(logicalDatastoreType);
                    if (nodeOptional.isPresent()) {
                        copyPSNode(nodeOptional, srcPsPath, dstPsPath, dstGlobalPath, logicalDatastoreType, tx1);
                    } else {
                        tx1.put(dstPsPath, new NodeBuilder().setNodeId(dstPsPath.firstKeyOf(Node.class).getNodeId()).build());
                    }
                });
            }

            @Override
            public void onFailure(Throwable throwable) {
            }
        }, MoreExecutors.directExecutor());
        return;
    }
    NodeBuilder dstPsNodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(dstPsPath);
    PhysicalSwitchAugmentationBuilder dstPsAugmentationBuilder = new PhysicalSwitchAugmentationBuilder();
    PhysicalSwitchAugmentation srcPsAugmenatation = srcPsNodeOptional.get().augmentation(PhysicalSwitchAugmentation.class);
    Node existingDstPsNode = null;
    try {
        existingDstPsNode = HwvtepHAUtil.readNode(tx, dstPsPath);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("NodeCopier Read Failed for Node:{}", dstPsPath);
    }
    PhysicalSwitchAugmentation existingDstPsAugmentation = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(existingDstPsNode);
    mergeOpManagedByAttributes(srcPsAugmenatation, dstPsAugmentationBuilder, dstGlobalPath);
    if (Operational.class.equals(logicalDatastoreType)) {
        psAugmentationMerger.mergeOperationalData(dstPsAugmentationBuilder, existingDstPsAugmentation, srcPsAugmenatation, dstPsPath);
        psNodeMerger.mergeOperationalData(dstPsNodeBuilder, existingDstPsNode, srcPsNodeOptional.get(), dstPsPath);
        dstPsNodeBuilder.addAugmentation(dstPsAugmentationBuilder.build());
        Node dstPsNode = dstPsNodeBuilder.build();
        tx.mergeParentStructureMerge(dstPsPath, dstPsNode);
    } else {
        /* Below Change done to rerduce the side of tx.put() generated here.
            1. Check if child node already exists in config-topo.
            2. If not present, then construct Child ps-node with augmentation data only and do tx.put(node).
            Followed by, then tx.put(termination-points) for each of termination-points present in parent ps-node.
            3. If present, then construct augmentation data and do tx.put(augmentation) then followed by
            tx.put(termination-points) for each of termination-points present in parent ps-node.
             */
        String dstNodeName = dstPsNodeBuilder.getNodeId().getValue();
        psAugmentationMerger.mergeConfigData(dstPsAugmentationBuilder, srcPsAugmenatation, dstPsPath);
        try {
            boolean isEntryExists = tx.exists(dstPsPath).get();
            if (isEntryExists) {
                LOG.info("Destination PS Node: {} already exists in config-topo.", dstNodeName);
                InstanceIdentifier<PhysicalSwitchAugmentation> dstPsAugPath = dstPsPath.augmentation(PhysicalSwitchAugmentation.class);
                tx.put(dstPsAugPath, dstPsAugmentationBuilder.build());
            } else {
                LOG.info("Destination PS Node: {} doesn't still exist in config-topo.", dstNodeName);
                dstPsNodeBuilder.addAugmentation(dstPsAugmentationBuilder.build());
                Node dstPsNode = dstPsNodeBuilder.build();
                tx.put(dstPsPath, dstPsNode);
            }
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("Error While checking Existing on Node {} in config-topo", dstPsPath);
        }
        psNodeMerger.mergeConfigData(dstPsNodeBuilder, srcPsNodeOptional.get(), dstPsPath);
        if (dstPsNodeBuilder.getTerminationPoint() != null) {
            dstPsNodeBuilder.getTerminationPoint().values().forEach(terminationPoint -> {
                InstanceIdentifier<TerminationPoint> terminationPointPath = dstPsPath.child(TerminationPoint.class, terminationPoint.key());
                tx.put(terminationPointPath, terminationPoint);
                LOG.trace("Destination PS Node: {} updated with termination-point : {}", dstNodeName, terminationPoint.key());
            });
        }
    }
    LOG.debug("Copied {} physical switch node from {} to {}", logicalDatastoreType, srcPsPath, dstPsPath);
}
Also used : BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) PhysicalSwitchAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) Optional(java.util.Optional) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) ExecutionException(java.util.concurrent.ExecutionException) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint)

Example 10 with TypedReadWriteTransaction

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

the class HwvtepNodeBaseListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
    // Batch Transaction used to internally submit to ResourceBatching Manager here
    HAJobScheduler.getInstance().submitJob(() -> {
        TypedReadWriteTransaction tx = getTx();
        try {
            processConnectedNodes(changes, tx);
            processUpdatedNodes(changes, tx);
            processDisconnectedNodes(changes, tx);
        // tx.submit().get();
        } catch (InterruptedException | ExecutionException | ReadFailedException e) {
            LOG.error("Error processing data-tree changes", e);
        }
    });
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) ExecutionException(java.util.concurrent.ExecutionException)

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