Search in sources :

Example 1 with NodeIdentifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.NodeIdentifier in project controller by opendaylight.

the class WriteTransactionsHandler method start.

public static ListenableFuture<RpcResult<WriteTransactionsOutput>> start(final DOMDataBroker domDataBroker, final WriteTransactionsInput input) {
    LOG.debug("Starting write-transactions.");
    final String id = input.getId();
    final MapEntryNode entry = ImmutableNodes.mapEntryBuilder(ID_INT, ID, id).withChild(ImmutableNodes.mapNodeBuilder(ITEM).build()).build();
    final YangInstanceIdentifier idListItem = ID_INT_YID.node(entry.getIdentifier());
    final ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ID_INTS)).withChild(ImmutableNodes.mapNodeBuilder(ID_INT).build()).build();
    DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
    // write only the top list
    tx.merge(LogicalDatastoreType.CONFIGURATION, ID_INTS_YID, containerNode);
    try {
        tx.submit().checkedGet(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (final OptimisticLockFailedException e) {
        // when multiple write-transactions are executed concurrently we need to ignore this.
        // If we get optimistic lock here it means id-ints already exists and we can continue.
        LOG.debug("Got an optimistic lock when writing initial top level list element.", e);
    } catch (final TransactionCommitFailedException | TimeoutException e) {
        LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
        return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
    }
    tx = domDataBroker.newWriteOnlyTransaction();
    tx.merge(LogicalDatastoreType.CONFIGURATION, idListItem, entry);
    try {
        tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
        return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
    }
    LOG.debug("Filling the item list with initial values.");
    final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = ImmutableNodes.mapNodeBuilder(ITEM);
    final YangInstanceIdentifier itemListId = idListItem.node(ITEM);
    tx = domDataBroker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, itemListId, mapBuilder.build());
    try {
        tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.warn("Unable to fill the initial item list.", e);
        return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
    }
    final WriteTransactionsHandler handler;
    if (input.isChainedTransactions()) {
        handler = new Chained(domDataBroker, idListItem, input);
    } else {
        handler = new Simple(domDataBroker, idListItem, input);
    }
    handler.doStart();
    return handler.completionFuture;
}
Also used : MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) WriteTransactionsOutput(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ExecutionException(java.util.concurrent.ExecutionException) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with NodeIdentifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.NodeIdentifier in project controller by opendaylight.

the class CrossBrokerMountPointTest method testMountPoint.

@Test
public void testMountPoint() throws ReadFailedException, TimeoutException {
    final Integer attrIntValue = 500;
    domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI).addService(DOMDataBroker.class, new DOMDataBroker() {

        @Override
        public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMDataWriteTransaction newWriteOnlyTransaction() {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMDataReadWriteTransaction newReadWriteTransaction() {
            return new DOMDataReadWriteTransaction() {

                @Override
                public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    if (store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
                        final ContainerNode data = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(AUG_CONT)).withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue)).build();
                        return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>>of(data));
                    }
                    return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
                }

                @Override
                public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Object getIdentifier() {
                    return this;
                }

                @Override
                public boolean cancel() {
                    return false;
                }

                @Override
                public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public CheckedFuture<Void, TransactionCommitFailedException> submit() {
                    throw new UnsupportedOperationException();
                }
            };
        }

        @Override
        public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
            throw new UnsupportedOperationException();
        }

        @Override
        public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
            return Collections.emptyMap();
        }
    }).register();
    final Optional<MountPoint> bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
    assertTrue(bindingMountPoint.isPresent());
    final Optional<DataBroker> dataBroker = bindingMountPoint.get().getService(DataBroker.class);
    assertTrue(dataBroker.isPresent());
    final Optional<Cont> data = dataBroker.get().newReadWriteTransaction().read(LogicalDatastoreType.OPERATIONAL, AUG_CONT_ID_BA).checkedGet(5, TimeUnit.SECONDS);
    assertTrue(data.isPresent());
    assertEquals(attrIntValue, data.get().getAttrInt());
}
Also used : DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TimeoutException(java.util.concurrent.TimeoutException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) Cont(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.top.top.level.list.list1.list1._1.Cont) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DOMDataChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Test(org.junit.Test)

Example 3 with NodeIdentifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.NodeIdentifier in project bgpcep by opendaylight.

the class AbstractLabeledUnicastRIBSupport method extractLabel.

public static List<LabelStack> extractLabel(final DataContainerNode<? extends PathArgument> route, final NodeIdentifier labelStackNid, final NodeIdentifier labelValueNid) {
    final List<LabelStack> labels = new ArrayList<>();
    final Optional<DataContainerChild<? extends PathArgument, ?>> labelStacks = route.getChild(labelStackNid);
    if (labelStacks.isPresent()) {
        for (final UnkeyedListEntryNode label : ((UnkeyedListNode) labelStacks.get()).getValue()) {
            final Optional<DataContainerChild<? extends PathArgument, ?>> labelStack = label.getChild(labelValueNid);
            if (labelStack.isPresent()) {
                final LabelStackBuilder labelStackbuilder = new LabelStackBuilder();
                labelStackbuilder.setLabelValue(new MplsLabel((Long) labelStack.get().getValue()));
                labels.add(labelStackbuilder.build());
            }
        }
    }
    return labels;
}
Also used : LabelStackBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.LabelStackBuilder) LabelStack(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.LabelStack) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MplsLabel(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)

Example 4 with NodeIdentifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.NodeIdentifier in project bgpcep by opendaylight.

the class RibImplTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Mockito.doReturn(mock(GeneratedClassLoadingStrategy.class)).when(this.extension).getClassLoadingStrategy();
    Mockito.doReturn(this.ribSupport).when(this.extension).getRIBSupport(any(TablesKey.class));
    final NodeIdentifier nii = new NodeIdentifier(QName.create("", "test").intern());
    Mockito.doReturn(nii).when(this.ribSupport).routeAttributesIdentifier();
    Mockito.doReturn(ImmutableSet.of()).when(this.ribSupport).cacheableAttributeObjects();
    final ChoiceNode choiceNode = mock(ChoiceNode.class);
    Mockito.doReturn(choiceNode).when(this.ribSupport).emptyRoutes();
    Mockito.doReturn(nii).when(choiceNode).getIdentifier();
    Mockito.doReturn(QName.create("", "test").intern()).when(choiceNode).getNodeType();
    Mockito.doReturn(this.domTx).when(this.domDataBroker).createTransactionChain(any());
    final DOMDataTreeChangeService dOMDataTreeChangeService = mock(DOMDataTreeChangeService.class);
    Mockito.doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, dOMDataTreeChangeService)).when(this.domDataBroker).getSupportedExtensions();
    Mockito.doReturn(this.dataTreeRegistration).when(this.domSchemaService).registerSchemaContextListener(any());
    Mockito.doNothing().when(this.dataTreeRegistration).close();
    Mockito.doReturn(mock(ListenerRegistration.class)).when(dOMDataTreeChangeService).registerDataTreeChangeListener(any(), any());
    Mockito.doNothing().when(this.serviceRegistration).unregister();
}
Also used : GeneratedClassLoadingStrategy(org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) Before(org.junit.Before)

Example 5 with NodeIdentifier

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.NodeIdentifier in project bgpcep by opendaylight.

the class NodeChangedListener method remove.

private void remove(final ReadWriteTransaction trans, final InstanceIdentifier<ReportedLsp> identifier, final ReportedLsp value) throws ReadFailedException {
    final InstanceIdentifier<Link> li = linkForLsp(linkIdForLsp(identifier, value));
    final Optional<Link> ol = trans.read(LogicalDatastoreType.OPERATIONAL, li).checkedGet();
    if (!ol.isPresent()) {
        return;
    }
    final Link l = ol.get();
    LOG.debug("Removing link {} (was {})", li, l);
    trans.delete(LogicalDatastoreType.OPERATIONAL, li);
    LOG.debug("Searching for orphan links/nodes");
    final Optional<Topology> ot = trans.read(LogicalDatastoreType.OPERATIONAL, this.target).checkedGet();
    Preconditions.checkState(ot.isPresent());
    final Topology topology = ot.get();
    final NodeId srcNode = l.getSource().getSourceNode();
    final NodeId dstNode = l.getDestination().getDestNode();
    final TpId srcTp = l.getSource().getSourceTp();
    final TpId dstTp = l.getDestination().getDestTp();
    boolean orphSrcNode = true;
    boolean orphDstNode = true;
    boolean orphDstTp = true;
    boolean orphSrcTp = true;
    for (final Link lw : topology.getLink()) {
        LOG.trace("Checking link {}", lw);
        final NodeId sn = lw.getSource().getSourceNode();
        final NodeId dn = lw.getDestination().getDestNode();
        final TpId st = lw.getSource().getSourceTp();
        final TpId dt = lw.getDestination().getDestTp();
        // Source node checks
        if (srcNode.equals(sn)) {
            if (orphSrcNode) {
                LOG.debug("Node {} held by source of link {}", srcNode, lw);
                orphSrcNode = false;
            }
            if (orphSrcTp && srcTp.equals(st)) {
                LOG.debug("TP {} held by source of link {}", srcTp, lw);
                orphSrcTp = false;
            }
        }
        if (srcNode.equals(dn)) {
            if (orphSrcNode) {
                LOG.debug("Node {} held by destination of link {}", srcNode, lw);
                orphSrcNode = false;
            }
            if (orphSrcTp && srcTp.equals(dt)) {
                LOG.debug("TP {} held by destination of link {}", srcTp, lw);
                orphSrcTp = false;
            }
        }
        // Destination node checks
        if (dstNode.equals(sn)) {
            if (orphDstNode) {
                LOG.debug("Node {} held by source of link {}", dstNode, lw);
                orphDstNode = false;
            }
            if (orphDstTp && dstTp.equals(st)) {
                LOG.debug("TP {} held by source of link {}", dstTp, lw);
                orphDstTp = false;
            }
        }
        if (dstNode.equals(dn)) {
            if (orphDstNode) {
                LOG.debug("Node {} held by destination of link {}", dstNode, lw);
                orphDstNode = false;
            }
            if (orphDstTp && dstTp.equals(dt)) {
                LOG.debug("TP {} held by destination of link {}", dstTp, lw);
                orphDstTp = false;
            }
        }
    }
    if (orphSrcNode && !orphSrcTp) {
        LOG.warn("Orphan source node {} but not TP {}, retaining the node", srcNode, srcTp);
        orphSrcNode = false;
    }
    if (orphDstNode && !orphDstTp) {
        LOG.warn("Orphan destination node {} but not TP {}, retaining the node", dstNode, dstTp);
        orphDstNode = false;
    }
    if (orphSrcNode) {
        LOG.debug("Removing orphan node {}", srcNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, nodeIdentifier(srcNode));
    } else if (orphSrcTp) {
        LOG.debug("Removing orphan TP {} on node {}", srcTp, srcNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, tpIdentifier(srcNode, srcTp));
    }
    if (orphDstNode) {
        LOG.debug("Removing orphan node {}", dstNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, nodeIdentifier(dstNode));
    } else if (orphDstTp) {
        LOG.debug("Removing orphan TP {} on node {}", dstTp, dstNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, tpIdentifier(dstNode, dstTp));
    }
}
Also used : TpId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) Link(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)

Aggregations

NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)19 Test (org.junit.Test)13 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)13 ByteBuf (io.netty.buffer.ByteBuf)7 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)7 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)7 BigInteger (java.math.BigInteger)4 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)4 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)4 ImmutableLeafNodeBuilder (org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder)4 ParentRefs (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs)3 TunnelTypeVxlan (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan)3 NodeIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifier)3 Esi (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.Esi)3 DomainIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier)3 CRouterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.CRouterIdentifier)3 ArrayList (java.util.ArrayList)2 TimeoutException (java.util.concurrent.TimeoutException)2 Before (org.junit.Before)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2