Search in sources :

Example 1 with SchemaId

use of org.onosproject.yang.model.SchemaId in project onos by opennetworkinglab.

the class ResourceIds method resourceId.

/**
 * Builds the ResourceId of specified {@code node}.
 *
 * @param parent ResourceId of {@code node} parent
 * @param node   to create ResourceId.
 * @return ResourceId of {@code node}
 */
public static ResourceId resourceId(ResourceId parent, DataNode node) {
    final ResourceId.Builder builder;
    if (parent == null) {
        builder = ResourceId.builder();
    } else {
        try {
            builder = parent.copyBuilder();
        } catch (CloneNotSupportedException e) {
            throw new IllegalArgumentException(e);
        }
    }
    SchemaId sid = node.key().schemaId();
    switch(node.type()) {
        case MULTI_INSTANCE_LEAF_VALUE_NODE:
            builder.addLeafListBranchPoint(sid.name(), sid.namespace(), ((LeafListKey) node.key()).asString());
            break;
        case MULTI_INSTANCE_NODE:
            builder.addBranchPointSchema(sid.name(), sid.namespace());
            for (KeyLeaf keyLeaf : ((ListKey) node.key()).keyLeafs()) {
                builder.addKeyLeaf(keyLeaf.leafSchema().name(), keyLeaf.leafSchema().namespace(), keyLeaf.leafValAsString());
            }
            break;
        case SINGLE_INSTANCE_LEAF_VALUE_NODE:
        case SINGLE_INSTANCE_NODE:
            builder.addBranchPointSchema(sid.name(), sid.namespace());
            break;
        default:
            throw new IllegalArgumentException("Unknown type " + node);
    }
    return builder.build();
}
Also used : ListKey(org.onosproject.yang.model.ListKey) LeafListKey(org.onosproject.yang.model.LeafListKey) ResourceId(org.onosproject.yang.model.ResourceId) KeyLeaf(org.onosproject.yang.model.KeyLeaf) SchemaId(org.onosproject.yang.model.SchemaId) Builder(org.onosproject.yang.model.ResourceId.Builder)

Example 2 with SchemaId

use of org.onosproject.yang.model.SchemaId in project onos by opennetworkinglab.

the class DeviceResourceIdsTest method testToDeviceId.

@Test
public void testToDeviceId() throws CloneNotSupportedException {
    ResourceId ridAchild = ridA.copyBuilder().addBranchPointSchema("some", "ns").addBranchPointSchema("random", "ns").addBranchPointSchema("child", "ns").build();
    assertEquals(DID_A, DeviceResourceIds.toDeviceId(ridAchild));
    NodeKey<?> nodeKey = ridA.nodeKeys().get(2);
    assertThat(nodeKey, is(instanceOf(ListKey.class)));
    assertThat(nodeKey.schemaId(), is(equalTo(new SchemaId(DEVICE_NAME, DCS_NAMESPACE))));
    ListKey listKey = (ListKey) nodeKey;
    assertThat(listKey.keyLeafs(), is(contains(new KeyLeaf(DEVICE_ID_KL_NAME, DCS_NAMESPACE, DID_A.toString()))));
}
Also used : ListKey(org.onosproject.yang.model.ListKey) ResourceId(org.onosproject.yang.model.ResourceId) KeyLeaf(org.onosproject.yang.model.KeyLeaf) SchemaId(org.onosproject.yang.model.SchemaId) Test(org.junit.Test)

Example 3 with SchemaId

use of org.onosproject.yang.model.SchemaId in project onos by opennetworkinglab.

the class RestconfManager method getDataForStore.

private ResourceData getDataForStore(ResourceData resourceData) {
    List<DataNode> nodes = resourceData.dataNodes();
    ResourceId rid = resourceData.resourceId();
    DataNode.Builder dbr = null;
    ResourceId parentId = null;
    try {
        NodeKey lastKey = rid.nodeKeys().get(rid.nodeKeys().size() - 1);
        SchemaId sid = lastKey.schemaId();
        if (lastKey instanceof ListKey) {
            dbr = InnerNode.builder(sid.name(), sid.namespace()).type(MULTI_INSTANCE_NODE);
            for (KeyLeaf keyLeaf : ((ListKey) lastKey).keyLeafs()) {
                Object val = keyLeaf.leafValue();
                dbr = dbr.addKeyLeaf(keyLeaf.leafSchema().name(), sid.namespace(), val);
                dbr = dbr.createChildBuilder(keyLeaf.leafSchema().name(), sid.namespace(), val).type(SINGLE_INSTANCE_LEAF_VALUE_NODE);
                // Exit for key leaf node
                dbr = dbr.exitNode();
            }
        } else {
            dbr = InnerNode.builder(sid.name(), sid.namespace()).type(SINGLE_INSTANCE_NODE);
        }
        if (nodes != null && !nodes.isEmpty()) {
            // adding the parent node for given list of nodes
            for (DataNode node : nodes) {
                dbr = ((InnerNode.Builder) dbr).addNode(node);
            }
        }
        parentId = rid.copyBuilder().removeLastKey().build();
    } catch (CloneNotSupportedException e) {
        log.error("getDataForStore()", e);
        return null;
    }
    ResourceData.Builder resData = DefaultResourceData.builder();
    resData.addDataNode(dbr.build());
    resData.resourceId(parentId);
    return resData.build();
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) KeyLeaf(org.onosproject.yang.model.KeyLeaf) InnerNode(org.onosproject.yang.model.InnerNode) ListKey(org.onosproject.yang.model.ListKey) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) SchemaId(org.onosproject.yang.model.SchemaId) NodeKey(org.onosproject.yang.model.NodeKey)

Aggregations

KeyLeaf (org.onosproject.yang.model.KeyLeaf)3 ListKey (org.onosproject.yang.model.ListKey)3 ResourceId (org.onosproject.yang.model.ResourceId)3 SchemaId (org.onosproject.yang.model.SchemaId)3 Test (org.junit.Test)1 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)1 DataNode (org.onosproject.yang.model.DataNode)1 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)1 InnerNode (org.onosproject.yang.model.InnerNode)1 LeafListKey (org.onosproject.yang.model.LeafListKey)1 NodeKey (org.onosproject.yang.model.NodeKey)1 ResourceData (org.onosproject.yang.model.ResourceData)1 Builder (org.onosproject.yang.model.ResourceId.Builder)1