Search in sources :

Example 1 with PathArgument

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

the class LocalReadWriteProxyTransaction method flushState.

@Override
Optional<ModifyTransactionRequest> flushState() {
    final ModifyTransactionRequestBuilder b = new ModifyTransactionRequestBuilder(getIdentifier(), localActor());
    b.setSequence(0);
    sealedModification.applyToCursor(new AbstractDataTreeModificationCursor() {

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

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

        @Override
        public void delete(final PathArgument child) {
            b.addModification(new TransactionDelete(current().node(child)));
        }
    });
    return Optional.of(b.build());
}
Also used : AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) 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 2 with PathArgument

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

the class DataNormalizer method toLegacy.

public YangInstanceIdentifier toLegacy(final YangInstanceIdentifier normalized) throws DataNormalizationException {
    ImmutableList.Builder<PathArgument> legacyArgs = ImmutableList.builder();
    DataNormalizationOperation<?> currentOp = operation;
    for (PathArgument normalizedArg : normalized.getPathArguments()) {
        currentOp = currentOp.getChild(normalizedArg);
        if (!currentOp.isMixin()) {
            legacyArgs.add(normalizedArg);
        }
    }
    return YangInstanceIdentifier.create(legacyArgs.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 3 with PathArgument

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

the class DataNormalizer method toNormalized.

public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) {
    ImmutableList.Builder<PathArgument> normalizedArgs = ImmutableList.builder();
    DataNormalizationOperation<?> currentOp = operation;
    Iterator<PathArgument> arguments = legacy.getPathArguments().iterator();
    try {
        while (arguments.hasNext()) {
            PathArgument legacyArg = arguments.next();
            currentOp = currentOp.getChild(legacyArg);
            checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s", legacy, normalizedArgs.build());
            while (currentOp.isMixin()) {
                normalizedArgs.add(currentOp.getIdentifier());
                currentOp = currentOp.getChild(legacyArg.getNodeType());
            }
            normalizedArgs.add(legacyArg);
        }
    } catch (DataNormalizationException e) {
        throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e);
    }
    return YangInstanceIdentifier.create(normalizedArgs.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 4 with PathArgument

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

the class AbstractDOMBrokerWriteTransaction method checkInstanceIdentifierReferencesData.

private static void checkInstanceIdentifierReferencesData(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
    Preconditions.checkArgument(data != null, "Attempted to store null data at %s", path);
    final PathArgument lastArg = path.getLastPathArgument();
    Preconditions.checkArgument(lastArg == data.getIdentifier() || lastArg != null && lastArg.equals(data.getIdentifier()), "Instance identifier references %s but data identifier is %s", lastArg, data);
}
Also used : PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 5 with PathArgument

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

the class BindingNormalizedCodecTest method testComplexAugmentationSerialization.

@Test
public void testComplexAugmentationSerialization() {
    this.codec.onGlobalContextUpdated(this.context);
    final PathArgument lastArg = this.codec.toYangInstanceIdentifier(BA_TREE_COMPLEX_USES).getLastPathArgument();
    assertTrue(lastArg instanceof AugmentationIdentifier);
}
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)

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