Search in sources :

Example 36 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.

the class LocalProxyTransaction method forwardToRemote.

@Override
final void forwardToRemote(final RemoteProxyTransaction successor, final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
    if (request instanceof CommitLocalTransactionRequest) {
        final CommitLocalTransactionRequest req = (CommitLocalTransactionRequest) request;
        final DataTreeModification mod = req.getModification();
        LOG.debug("Applying modification {} to successor {}", mod, successor);
        mod.applyToCursor(new AbstractDataTreeModificationCursor() {

            @Override
            public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
                successor.write(current().node(child), data);
            }

            @Override
            public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
                successor.merge(current().node(child), data);
            }

            @Override
            public void delete(final PathArgument child) {
                successor.delete(current().node(child));
            }
        });
        successor.sealOnly();
        final ModifyTransactionRequest successorReq = successor.commitRequest(req.isCoordinated());
        successor.sendRequest(successorReq, callback);
    } else if (request instanceof AbortLocalTransactionRequest) {
        LOG.debug("Forwarding abort {} to successor {}", request, successor);
        successor.abort();
    } else if (request instanceof TransactionPurgeRequest) {
        LOG.debug("Forwarding purge {} to successor {}", request, successor);
        successor.enqueuePurge(callback);
    } else if (request instanceof ModifyTransactionRequest) {
        successor.handleForwardedRequest(request, callback);
    } else {
        throwUnhandledRequest(request);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)

Example 37 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.

the class ResolveDataChangeEventsTask method resolveAnyChangeEvent.

/**
 * Resolves data change event for supplied node.
 *
 * @param path
 *            Path to current node in tree
 * @param listeners
 *            Collection of Listener registration nodes interested in
 *            subtree
 * @param modification
 *            Modification of current node
 * @param before
 *            - Original (before) state of current node
 * @param after
 *            - After state of current node
 * @return True if the subtree changed, false otherwise
 */
private boolean resolveAnyChangeEvent(final ResolveDataChangeState state, final DataTreeCandidateNode node) {
    final Optional<NormalizedNode<?, ?>> maybeBefore = node.getDataBefore();
    final Optional<NormalizedNode<?, ?>> maybeAfter = node.getDataAfter();
    final ModificationType type = node.getModificationType();
    if (type != ModificationType.UNMODIFIED && !maybeAfter.isPresent() && !maybeBefore.isPresent()) {
        LOG.debug("Modification at {} has type {}, but no before- and after-data. Assuming unchanged.", state.getPath(), type);
        return false;
    }
    switch(type) {
        case SUBTREE_MODIFIED:
            return resolveSubtreeChangeEvent(state, node);
        case APPEARED:
        case WRITE:
            Preconditions.checkArgument(maybeAfter.isPresent(), "Modification at {} has type {} but no after-data", state.getPath(), type);
            if (!maybeBefore.isPresent()) {
                @SuppressWarnings({ "unchecked", "rawtypes" }) final NormalizedNode<PathArgument, ?> afterNode = (NormalizedNode) maybeAfter.get();
                resolveSameEventRecursivelly(state, afterNode, DOMImmutableDataChangeEvent.getCreateEventFactory());
                return true;
            }
            return resolveReplacedEvent(state, maybeBefore.get(), maybeAfter.get());
        case DISAPPEARED:
        case DELETE:
            Preconditions.checkArgument(maybeBefore.isPresent(), "Modification at {} has type {} but no before-data", state.getPath(), type);
            @SuppressWarnings({ "unchecked", "rawtypes" }) final NormalizedNode<PathArgument, ?> beforeNode = (NormalizedNode) maybeBefore.get();
            resolveSameEventRecursivelly(state, beforeNode, DOMImmutableDataChangeEvent.getRemoveEventFactory());
            return true;
        case UNMODIFIED:
            return false;
        default:
            break;
    }
    throw new IllegalStateException(String.format("Unhandled node state %s at %s", type, state.getPath()));
}
Also used : ModificationType(org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 38 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.

the class ResolveDataChangeEventsTask method resolveNodeContainerReplaced.

private boolean resolveNodeContainerReplaced(final ResolveDataChangeState state, final NormalizedNodeContainer<?, PathArgument, NormalizedNode<PathArgument, ?>> beforeCont, final NormalizedNodeContainer<?, PathArgument, NormalizedNode<PathArgument, ?>> afterCont) {
    if (!state.needsProcessing()) {
        LOG.trace("Not processing replaced container {}", state.getPath());
        return true;
    }
    // We look at all children from before and compare it with after state.
    boolean childChanged = false;
    for (NormalizedNode<PathArgument, ?> beforeChild : beforeCont.getValue()) {
        final PathArgument childId = beforeChild.getIdentifier();
        if (resolveNodeContainerChildUpdated(state.child(childId), beforeChild, afterCont.getChild(childId))) {
            childChanged = true;
        }
    }
    for (NormalizedNode<PathArgument, ?> afterChild : afterCont.getValue()) {
        final PathArgument childId = afterChild.getIdentifier();
        /*
             * We have already iterated of the before-children, so have already
             * emitted modify/delete events. This means the child has been
             * created.
             */
        if (!beforeCont.getChild(childId).isPresent()) {
            resolveSameEventRecursivelly(state.child(childId), afterChild, DOMImmutableDataChangeEvent.getCreateEventFactory());
            childChanged = true;
        }
    }
    if (childChanged) {
        DOMImmutableDataChangeEvent event = DOMImmutableDataChangeEvent.builder(DataChangeScope.BASE).addUpdated(state.getPath(), beforeCont, afterCont).build();
        state.addEvent(event);
    }
    state.collectEvents(beforeCont, afterCont, collectedEvents);
    return childChanged;
}
Also used : PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 39 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.

the class ResolveDataChangeEventsTask method resolveSameEventRecursivelly.

private void resolveSameEventRecursivelly(final ResolveDataChangeState state, final NormalizedNode<PathArgument, ?> node, final SimpleEventFactory eventFactory) {
    if (!state.needsProcessing()) {
        LOG.trace("Skipping child {}", state.getPath());
        return;
    }
    // to do additional processing
    if (node instanceof NormalizedNodeContainer<?, ?, ?>) {
        LOG.trace("Resolving subtree recursive event for {}, type {}", state.getPath(), eventFactory);
        // Node has children, so we will try to resolve it's children
        // changes.
        @SuppressWarnings("unchecked") NormalizedNodeContainer<?, PathArgument, NormalizedNode<PathArgument, ?>> container = (NormalizedNodeContainer<?, PathArgument, NormalizedNode<PathArgument, ?>>) node;
        for (NormalizedNode<PathArgument, ?> child : container.getValue()) {
            final PathArgument childId = child.getIdentifier();
            LOG.trace("Resolving event for child {}", childId);
            resolveSameEventRecursivelly(state.child(childId), child, eventFactory);
        }
    }
    final DOMImmutableDataChangeEvent event = eventFactory.create(state.getPath(), node);
    LOG.trace("Adding event {} at path {}", event, state.getPath());
    state.addEvent(event);
    state.collectEvents(event.getOriginalSubtree(), event.getUpdatedSubtree(), collectedEvents);
}
Also used : NormalizedNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 40 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.

the class AbstractFlowspecNlriParser method createPorts.

private static List<Ports> createPorts(final UnkeyedListNode portsData) {
    final List<Ports> ports = new ArrayList<>();
    for (final UnkeyedListEntryNode node : portsData.getValue()) {
        final PortsBuilder portsBuilder = new PortsBuilder();
        final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
        if (opValue.isPresent()) {
            portsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
        }
        final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
        if (valueNode.isPresent()) {
            portsBuilder.setValue((Integer) valueNode.get().getValue());
        }
        ports.add(portsBuilder.build());
    }
    return ports;
}
Also used : Set(java.util.Set) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) ArrayList(java.util.ArrayList) DestinationPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPorts) SourcePorts(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.port._case.Ports) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder) SourcePortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder) DestinationPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder)

Aggregations

PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)55 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)31 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)18 ArrayList (java.util.ArrayList)17 Set (java.util.Set)12 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)11 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 Test (org.junit.Test)3 AbstractDataTreeModificationCursor (org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor)3 DataNormalizationException (org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)3 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)3 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)3 ImmutableList (com.google.common.collect.ImmutableList)2 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)2 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)2