Search in sources :

Example 21 with PathArgument

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);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) TransactionDelete(org.opendaylight.controller.cluster.access.commands.TransactionDelete) TransactionMerge(org.opendaylight.controller.cluster.access.commands.TransactionMerge)

Example 22 with PathArgument

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));
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) AbstractSchemaAwareTest(org.opendaylight.controller.md.sal.binding.test.AbstractSchemaAwareTest) Test(org.junit.Test)

Example 23 with PathArgument

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));
    }
}
Also used : DataNormalizationException(org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException) ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 24 with PathArgument

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));
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ArrayList(java.util.ArrayList) DataNormalizationException(org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 25 with PathArgument

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));
                }
            }
        }
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) 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) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

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