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);
}
}
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()));
}
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;
}
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);
}
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;
}
Aggregations