Search in sources :

Example 51 with NodeIdentifierWithPredicates

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

the class CandidateListChangeListener method extractEntityPath.

private static YangInstanceIdentifier extractEntityPath(YangInstanceIdentifier candidatePath) {
    List<PathArgument> newPathArgs = new ArrayList<>();
    for (PathArgument pathArg : candidatePath.getPathArguments()) {
        newPathArgs.add(pathArg);
        if (pathArg instanceof NodeIdentifierWithPredicates) {
            NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
            Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
            if (ENTITY_ID_QNAME.equals(key.getKey())) {
                break;
            }
        }
    }
    return YangInstanceIdentifier.create(newPathArgs);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 52 with NodeIdentifierWithPredicates

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

the class EntityOwnersModel method createEntity.

static DOMEntity createEntity(final YangInstanceIdentifier entityPath) {
    String entityType = null;
    YangInstanceIdentifier entityId = null;
    for (PathArgument pathArg : entityPath.getPathArguments()) {
        if (pathArg instanceof NodeIdentifierWithPredicates) {
            NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
            Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
            if (ENTITY_TYPE_QNAME.equals(key.getKey())) {
                entityType = key.getValue().toString();
            } else if (ENTITY_ID_QNAME.equals(key.getKey())) {
                entityId = (YangInstanceIdentifier) key.getValue();
            }
        }
    }
    return new DOMEntity(entityType, entityId);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 53 with NodeIdentifierWithPredicates

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

the class AbstractEntityOwnershipTest method getMapEntryNodeChild.

protected MapEntryNode getMapEntryNodeChild(final DataContainerNode<? extends PathArgument> parent, final QName childMap, final QName child, final Object key, final boolean expectPresent) {
    Optional<DataContainerChild<? extends PathArgument, ?>> childNode = parent.getChild(new NodeIdentifier(childMap));
    assertEquals("Missing " + childMap.toString(), true, childNode.isPresent());
    MapNode entityTypeMapNode = (MapNode) childNode.get();
    Optional<MapEntryNode> entityTypeEntry = entityTypeMapNode.getChild(new NodeIdentifierWithPredicates(childMap, child, key));
    if (expectPresent && !entityTypeEntry.isPresent()) {
        fail("Missing " + childMap.toString() + " entry for " + key + ". Actual: " + entityTypeMapNode.getValue());
    } else if (!expectPresent && entityTypeEntry.isPresent()) {
        fail("Found unexpected " + childMap.toString() + " entry for " + key);
    }
    return entityTypeEntry.isPresent() ? entityTypeEntry.get() : null;
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 54 with NodeIdentifierWithPredicates

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

the class TestModel method createBaseTestContainerBuilder.

public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createBaseTestContainerBuilder() {
    // Create a list of shoes
    // This is to test leaf list entry
    final LeafSetEntryNode<Object> nike = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(SHOE_QNAME, "nike")).withValue("nike").build();
    final LeafSetEntryNode<Object> puma = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(SHOE_QNAME, "puma")).withValue("puma").build();
    final LeafSetNode<Object> shoes = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(SHOE_QNAME)).withChild(nike).withChild(puma).build();
    // Test a leaf-list where each entry contains an identity
    final LeafSetEntryNode<Object> cap1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "capability"), DESC_QNAME)).withValue(DESC_QNAME).build();
    final LeafSetNode<Object> capabilities = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "capability"))).withChild(cap1).build();
    ContainerNode switchFeatures = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(SWITCH_FEATURES_QNAME)).withChild(capabilities).build();
    // Create a leaf list with numbers
    final LeafSetEntryNode<Object> five = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "number"), 5)).withValue(5).build();
    final LeafSetEntryNode<Object> fifteen = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "number"), 15)).withValue(15).build();
    final LeafSetNode<Object> numbers = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "number"))).withChild(five).withChild(fifteen).build();
    // Create augmentations
    MapEntryNode augMapEntry = createAugmentedListEntry(1, "First Test");
    // Create a bits leaf
    NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> myBits = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "my-bits"))).withValue(ImmutableSet.of("foo", "bar"));
    // Create unkeyed list entry
    UnkeyedListEntryNode unkeyedListEntry = Builders.unkeyedListEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_QNAME)).withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name")).build();
    // Create YangInstanceIdentifier with all path arg types.
    YangInstanceIdentifier instanceID = YangInstanceIdentifier.create(new NodeIdentifier(QName.create(TEST_QNAME, "qname")), new NodeIdentifierWithPredicates(QName.create(TEST_QNAME, "list-entry"), QName.create(TEST_QNAME, "key"), 10), new AugmentationIdentifier(ImmutableSet.of(QName.create(TEST_QNAME, "aug1"), QName.create(TEST_QNAME, "aug2"))), new NodeWithValue<>(QName.create(TEST_QNAME, "leaf-list-entry"), "foo"));
    Map<QName, Object> keyValues = new HashMap<>();
    keyValues.put(CHILDREN_QNAME, FIRST_CHILD_NAME);
    // Create the document
    return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(myBits.build()).withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC)).withChild(ImmutableNodes.leafNode(BOOLEAN_LEAF_QNAME, ENABLED)).withChild(ImmutableNodes.leafNode(SHORT_LEAF_QNAME, SHORT_ID)).withChild(ImmutableNodes.leafNode(BYTE_LEAF_QNAME, BYTE_ID)).withChild(ImmutableNodes.leafNode(TestModel.BIGINTEGER_LEAF_QNAME, BigInteger.valueOf(100))).withChild(ImmutableNodes.leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, BigDecimal.valueOf(1.2))).withChild(ImmutableNodes.leafNode(SOME_REF_QNAME, instanceID)).withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME)).withChild(Builders.unkeyedListBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_QNAME)).withChild(unkeyedListEntry).build()).withChild(Builders.choiceBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TWO_THREE_QNAME)).withChild(ImmutableNodes.leafNode(TWO_QNAME, "two")).build()).withChild(Builders.orderedMapBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ORDERED_LIST_QNAME)).withValue(ImmutableList.<MapEntryNode>builder().add(mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "1").build(), mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2").build()).build()).build()).withChild(shoes).withChild(numbers).withChild(switchFeatures).withChild(mapNodeBuilder(AUGMENTED_LIST_QNAME).withChild(augMapEntry).build()).withChild(mapNodeBuilder(OUTER_LIST_QNAME).withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID)).withChild(BAR_NODE).build());
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 55 with NodeIdentifierWithPredicates

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project bgpcep by opendaylight.

the class BmpRouterImpl method onInitiate.

private synchronized void onInitiate(final InitiationMessage initiation) {
    Preconditions.checkState(isDatastoreWritable());
    final DOMDataWriteTransaction wTx = this.domTxChain.newWriteOnlyTransaction();
    wTx.merge(LogicalDatastoreType.OPERATIONAL, this.routerYangIId, Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(Router.QNAME, ROUTER_ID_QNAME, this.routerIp)).withChild(ImmutableNodes.leafNode(ROUTER_NAME_QNAME, initiation.getTlvs().getNameTlv().getName())).withChild(ImmutableNodes.leafNode(ROUTER_DESCRIPTION_QNAME, initiation.getTlvs().getDescriptionTlv().getDescription())).withChild(ImmutableNodes.leafNode(ROUTER_INFO_QNAME, getStringInfo(initiation.getTlvs().getStringInformation()))).withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, UP)).build());
    wTx.submit();
}
Also used : NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Aggregations

NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)97 Test (org.junit.Test)52 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)49 ArrayList (java.util.ArrayList)37 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec)34 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder)34 NumericOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.NumericOperand)20 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)20 QName (org.opendaylight.yangtools.yang.common.QName)15 DestinationFlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv4.DestinationFlowspecBuilder)12 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)11 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)6 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)6 BitmaskOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.BitmaskOperand)6 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)5 DestinationFlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv6.DestinationFlowspecBuilder)5