Search in sources :

Example 1 with ManagedNewTransactionRunner

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

the class NodeConnectedHandlerTest method testD1Connect.

@Test
// need to fix this Test. Actual functionality is fine
@Ignore
public void testD1Connect() throws Exception {
    ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(getDataBroker());
    txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> handlerUtils.addPsNode(d1PsNodePath, d1NodePath, DataProvider.getPortNameListD1(), tx)).get();
    txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> handlerUtils.addNode(d1NodePath, d1PsNodePath, DataProvider.getLogicalSwitchDataD1(), DataProvider.getLocalUcasMacDataD1(), DataProvider.getLocalMcastDataD1(), DataProvider.getRemoteMcastDataD1(), DataProvider.getRemoteUcasteMacDataD1(), DataProvider.getGlobalTerminationPointIpD1(), tx)).get();
    readNodes();
    txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> nodeConnectedHandler.handleNodeConnected(d1GlobalOpNode.get(), d1NodePath, haNodePath, haGlobalConfigNode, haPsConfigNode, confTx, operTx)).get()).get();
    readNodes();
    // verify global ha manager config should have ha_children
    Assert.assertTrue(haGlobalConfigNode.isPresent());
    Assert.assertTrue(d1GlobalOpNode.isPresent());
    TestUtil.verifyHAconfigNode(haGlobalConfigNode.get(), d1GlobalOpNode.get());
    Assert.assertTrue(d1GlobalOpNode.isPresent());
    Assert.assertTrue(haGlobalOpNode.isPresent());
    Assert.assertTrue(d1PsOpNode.isPresent());
    Assert.assertTrue(haPsOpNode.isPresent());
    TestUtil.verifyHAOpNode(d1GlobalOpNode.get(), haGlobalOpNode.get(), d1PsOpNode.get(), haPsOpNode.get(), haNodePath, d1PsNodePath, haPsNodePath, getDataBroker());
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) LoggerFactory(org.slf4j.LoggerFactory) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) NodeConnectedHandler(org.opendaylight.netvirt.elan.l2gw.ha.handlers.NodeConnectedHandler) AbstractConcurrentDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) Before(org.junit.Before) Logger(org.slf4j.Logger) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) TopologyId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId) Test(org.junit.Test) UUID(java.util.UUID) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) Ignore(org.junit.Ignore) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Optional(java.util.Optional) TopologyKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) Assert(org.junit.Assert) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Ignore(org.junit.Ignore) AbstractConcurrentDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 2 with ManagedNewTransactionRunner

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

the class NetworkL2gwDeviceInfoCli method doExecute.

@Override
@Nullable
@SuppressWarnings("illegalcatch")
protected Object doExecute() {
    ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
    try {
        txRunner.callWithNewReadOnlyTransactionAndClose(OPERATIONAL, operTx -> {
            List<Node> nodes = new ArrayList<>();
            Set<String> networks = new HashSet<>();
            if (nodeId == null) {
                Optional<Topology> topologyOptional = operTx.read(createHwvtepTopologyInstanceIdentifier()).get();
                if (topologyOptional.isPresent()) {
                    nodes = new ArrayList<>(topologyOptional.get().getNode().values());
                }
            } else {
                Optional<Node> nodeOptional = operTx.read(createInstanceIdentifier(new NodeId(new Uri(nodeId)))).get();
                if (nodeOptional.isPresent()) {
                    nodes.add(nodeOptional.get());
                }
            }
            if (elanName == null) {
                // get all elan instance
                // get all device node id
                // print result
                Optional<ElanInstances> elanInstancesOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(ElanInstances.class).build());
                if (elanInstancesOptional.isPresent()) {
                    List<ElanInstance> elans = new ArrayList<>(elanInstancesOptional.get().getElanInstance().values());
                    if (elans != null) {
                        for (ElanInstance elan : elans) {
                            networks.add(elan.getElanInstanceName());
                        }
                    }
                }
            } else {
                networks.add(elanName);
            }
            if (nodes != null) {
                for (Node node : nodes) {
                    if (node.getNodeId().getValue().contains("physicalswitch")) {
                        continue;
                    }
                    Node hwvtepConfigNode = HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION, node.getNodeId());
                    Node hwvtepOpPsNode = getPSnode(node, LogicalDatastoreType.OPERATIONAL);
                    Node hwvtepConfigPsNode = null;
                    if (hwvtepOpPsNode != null) {
                        hwvtepConfigPsNode = HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION, hwvtepOpPsNode.getNodeId());
                        opPSNodes.put(node.getNodeId(), hwvtepOpPsNode);
                    }
                    opNodes.put(node.getNodeId(), node);
                    configNodes.put(node.getNodeId(), hwvtepConfigNode);
                    if (hwvtepConfigPsNode != null) {
                        configPSNodes.put(node.getNodeId(), hwvtepConfigPsNode);
                    }
                }
            }
            if (!networks.isEmpty()) {
                for (String network : networks) {
                    session.getConsole().println("Network info for " + network);
                    if (nodes != null) {
                        for (Node node : nodes) {
                            if (node.getNodeId().getValue().contains("physicalswitch")) {
                                continue;
                            }
                            session.getConsole().println("Printing for node " + node.getNodeId().getValue());
                            process(node.getNodeId(), network);
                        }
                    }
                }
            }
        });
    } catch (Exception e) {
        session.getConsole().println("Failed with error " + e.getMessage());
    }
    return null;
}
Also used : ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ArrayList(java.util.ArrayList) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) ElanInstances(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) ExecutionException(java.util.concurrent.ExecutionException) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) HashSet(java.util.HashSet) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with ManagedNewTransactionRunner

use of org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner 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)

Aggregations

ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)3 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)3 Optional (java.util.Optional)2 CONFIGURATION (org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION)2 OPERATIONAL (org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL)2 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)2 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1