use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class RemoteProxyTransaction method replayLocalCommitRequest.
private void replayLocalCommitRequest(final CommitLocalTransactionRequest request, final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
final DataTreeModification mod = request.getModification();
final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
mod.applyToCursor(new AbstractDataTreeModificationCursor() {
@Override
public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
appendModification(new TransactionWrite(current().node(child), data), optTicks);
}
@Override
public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
appendModification(new TransactionMerge(current().node(child), data), optTicks);
}
@Override
public void delete(final PathArgument child) {
appendModification(new TransactionDelete(current().node(child)), optTicks);
}
});
enqueueRequest(commitRequest(request.isCoordinated()), callback, enqueuedTicks);
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class BindingNormalizedCodecTest method testLeafOnlyAugmentationSerialization.
@Test
public void testLeafOnlyAugmentationSerialization() {
this.codec.onGlobalContextUpdated(this.context);
final PathArgument leafOnlyLastArg = this.codec.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY).getLastPathArgument();
assertTrue(leafOnlyLastArg instanceof AugmentationIdentifier);
assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class BindingDOMWriteTransactionAdapter method ensureParentsByMerge.
@Override
protected void ensureParentsByMerge(final LogicalDatastoreType store, final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath, final InstanceIdentifier<?> path) {
List<PathArgument> currentArguments = new ArrayList<>();
DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
for (PathArgument currentArg : normalizedPath.getPathArguments()) {
try {
currentOp = currentOp.getChild(currentArg);
} catch (DataNormalizationException e) {
throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
}
currentArguments.add(currentArg);
YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(currentArguments);
getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class AbstractReadWriteTransaction method ensureParentsByMerge.
@Override
protected final void ensureParentsByMerge(final LogicalDatastoreType store, final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath, final InstanceIdentifier<?> path) {
List<PathArgument> currentArguments = new ArrayList<>();
DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
Iterator<PathArgument> iterator = normalizedPath.getPathArguments().iterator();
while (iterator.hasNext()) {
PathArgument currentArg = iterator.next();
try {
currentOp = currentOp.getChild(currentArg);
} catch (DataNormalizationException e) {
throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
}
currentArguments.add(currentArg);
org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier currentPath = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.create(currentArguments);
final Boolean exists;
try {
exists = getDelegate().exists(store, currentPath).checkedGet();
} catch (ReadFailedException e) {
LOG.error("Failed to read pre-existing data from store {} path {}", store, currentPath, e);
throw new IllegalStateException("Failed to read pre-existing data", e);
}
if (!exists && iterator.hasNext()) {
getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
}
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class MockDataTreeChangeListener method waitForChangeEvents.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void waitForChangeEvents(final YangInstanceIdentifier... expPaths) {
boolean done = Uninterruptibles.awaitUninterruptibly(changeLatch, 5, TimeUnit.SECONDS);
if (!done) {
fail(String.format("Missing change notifications. Expected: %d. Actual: %d", expChangeEventCount, expChangeEventCount - changeLatch.getCount()));
}
for (int i = 0; i < expPaths.length; i++) {
final DataTreeCandidate candidate = changeList.get(i);
final Optional<NormalizedNode<?, ?>> maybeDataAfter = candidate.getRootNode().getDataAfter();
if (!maybeDataAfter.isPresent()) {
fail(String.format("Change %d does not contain data after. Actual: %s", i + 1, candidate.getRootNode()));
}
final NormalizedNode<?, ?> dataAfter = maybeDataAfter.get();
final Optional<YangInstanceIdentifier> relativePath = expPaths[i].relativeTo(candidate.getRootPath());
if (!relativePath.isPresent()) {
assertEquals(String.format("Change %d does not contain %s. Actual: %s", i + 1, expPaths[i], dataAfter), expPaths[i].getLastPathArgument(), dataAfter.getIdentifier());
} else {
NormalizedNode<?, ?> nextChild = dataAfter;
for (PathArgument pathArg : relativePath.get().getPathArguments()) {
boolean found = false;
if (nextChild instanceof NormalizedNodeContainer) {
Optional<NormalizedNode<?, ?>> maybeChild = ((NormalizedNodeContainer) nextChild).getChild(pathArg);
if (maybeChild.isPresent()) {
found = true;
nextChild = maybeChild.get();
}
}
if (!found) {
fail(String.format("Change %d does not contain %s. Actual: %s", i + 1, expPaths[i], dataAfter));
}
}
}
}
}
Aggregations