use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class BindingToNormalizedNodeCodec method getDefaultNodeFor.
/**
* Returns an default object according to YANG schema for supplied path.
*
* @param path DOM Path
* @return Node with defaults set on.
*/
public NormalizedNode<?, ?> getDefaultNodeFor(final YangInstanceIdentifier path) {
final Iterator<PathArgument> iterator = path.getPathArguments().iterator();
DataNormalizationOperation<?> currentOp = this.legacyToNormalized.getRootOperation();
while (iterator.hasNext()) {
final PathArgument currentArg = iterator.next();
try {
currentOp = currentOp.getChild(currentArg);
} catch (final DataNormalizationException e) {
throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
}
}
return currentOp.createDefault(path.getLastPathArgument());
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class DOMDataTreeIdentifier method compareTo.
@Override
public int compareTo(final DOMDataTreeIdentifier obj) {
int cmp = datastoreType.compareTo(obj.datastoreType);
if (cmp != 0) {
return cmp;
}
final Iterator<PathArgument> mi = rootIdentifier.getPathArguments().iterator();
final Iterator<PathArgument> oi = obj.rootIdentifier.getPathArguments().iterator();
while (mi.hasNext()) {
if (!oi.hasNext()) {
return 1;
}
final PathArgument ma = mi.next();
final PathArgument oa = oi.next();
cmp = ma.compareTo(oa);
if (cmp != 0) {
return cmp;
}
}
return oi.hasNext() ? -1 : 0;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class CarEntryDataTreeCommitCohort method canCommit.
@Override
public CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(final Object txId, final DOMDataTreeCandidate candidate, final SchemaContext ctx) {
// Simple data validation - verify the year, if present, is >= 1990
final DataTreeCandidateNode rootNode = candidate.getRootNode();
final Optional<NormalizedNode<?, ?>> dataAfter = rootNode.getDataAfter();
LOG.info("In canCommit: modificationType: {}, dataBefore: {}, dataAfter: {}", rootNode.getModificationType(), rootNode.getDataBefore(), dataAfter);
// MapEntryNode but we verify anyway.
if (dataAfter.isPresent()) {
final NormalizedNode<?, ?> normalizedNode = dataAfter.get();
Verify.verify(normalizedNode instanceof DataContainerNode, "Expected type DataContainerNode, actual was %s", normalizedNode.getClass());
DataContainerNode<?> entryNode = (DataContainerNode<?>) normalizedNode;
final Optional<DataContainerChild<? extends PathArgument, ?>> possibleYear = entryNode.getChild(YEAR_NODE_ID);
if (possibleYear.isPresent()) {
final Number year = (Number) possibleYear.get().getValue();
LOG.info("year is {}", year);
if (!(year.longValue() >= 1990)) {
return Futures.immediateFailedCheckedFuture(new DataValidationFailedException(DOMDataTreeIdentifier.class, candidate.getRootPath(), String.format("Invalid year %d - year must be >= 1990", year)));
}
}
}
// remaining 3PC stages (pre-commit and commit).
return PostCanCommitStep.NOOP_SUCCESS_FUTURE;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.
the class AbstractLabeledUnicastRIBSupport method createRouteKey.
private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode labeledUnicast) {
final ByteBuf buffer = Unpooled.buffer();
final CLabeledUnicastDestination dest = extractCLabeledUnicastDestination(labeledUnicast);
LUNlriParser.serializeNlri(Collections.singletonList(dest), false, buffer);
final String routeKeyValue = ByteArray.encodeBase64(buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = labeledUnicast.getChild(routePathIdNid());
final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
return routeKey;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.
the class AbstractLabeledUnicastRIBSupport method processDestination.
@Override
protected void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
if (destination != null) {
final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(NLRI_ROUTES_LIST);
if (maybeRoutes.isPresent()) {
final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
if (routes instanceof UnkeyedListNode) {
final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
function.apply(tx, base, routeKey, e, attributes);
}
} else {
LOG.warn("Routes {} are not a map", routes);
}
}
}
}
Aggregations