Search in sources :

Example 1 with ResourceId

use of org.onosproject.yang.model.ResourceId 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 ResourceId

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

the class DeviceResourceIdsTest method testDeviceSubtreeEventTest.

@Test
public void testDeviceSubtreeEventTest() {
    // root relative ResourceId used by DynamicConfigEvent
    ResourceId evtDevice = ResourceId.builder().addBranchPointSchema(DEVICES_NAME, DCS_NAMESPACE).addBranchPointSchema(DEVICE_NAME, DCS_NAMESPACE).addKeyLeaf(DEVICE_ID_KL_NAME, DCS_NAMESPACE, DID_A.toString()).build();
    NodeKey<?> deviceKey = evtDevice.nodeKeys().get(1);
    assertThat(deviceKey, is(instanceOf(ListKey.class)));
    assertThat(deviceKey.schemaId().namespace(), is(equalTo(DCS_NAMESPACE)));
    assertThat(deviceKey.schemaId().name(), is(equalTo(DEVICE_NAME)));
    assertTrue(DeviceResourceIds.isUnderDeviceRootNode(evtDevice));
}
Also used : ResourceId(org.onosproject.yang.model.ResourceId) Test(org.junit.Test)

Example 3 with ResourceId

use of org.onosproject.yang.model.ResourceId 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 4 with ResourceId

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

the class DynamicDeviceConfigServiceViewTest method testListener.

// FIXME add test scenario where irrelevant event get discarded.
@Test
public void testListener() throws CloneNotSupportedException, InterruptedException {
    ResourceId realIntf = ResourceId.builder().append(rid).addBranchPointSchema("intf", "test").build();
    final CountDownLatch received = new CountDownLatch(1);
    DynamicConfigListener lsnr = new DynamicConfigListener() {

        @Override
        public boolean isRelevant(DynamicConfigEvent event) {
            viewRelevantEvent = event;
            return true;
        }

        @Override
        public void event(DynamicConfigEvent event) {
            viewEvent = event;
            received.countDown();
        }
    };
    view.addListener(lsnr);
    service.post(new DynamicConfigEvent(Type.NODE_ADDED, realIntf));
    assertTrue(received.await(5, TimeUnit.SECONDS));
    assertFalse("Expect relative path but was" + viewRelevantEvent.subject(), ResourceIds.isPrefix(rid, viewRelevantEvent.subject()));
    assertFalse("Expect relative path but was" + viewEvent.subject(), ResourceIds.isPrefix(rid, viewEvent.subject()));
    view.removeListener(lsnr);
}
Also used : ResourceId(org.onosproject.yang.model.ResourceId) DynamicConfigEvent(org.onosproject.config.DynamicConfigEvent) DynamicConfigListener(org.onosproject.config.DynamicConfigListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with ResourceId

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

the class ResourceIdsTest method testConcat.

@Test
public void testConcat() {
    ResourceId devices = ResourceId.builder().addBranchPointSchema(DeviceResourceIds.DEVICES_NAME, DCS_NAMESPACE).build();
    assertEquals(DEVICES, ResourceIds.concat(ResourceIds.ROOT_ID, devices));
}
Also used : DeviceResourceIds.toResourceId(org.onosproject.d.config.DeviceResourceIds.toResourceId) ResourceId(org.onosproject.yang.model.ResourceId) Test(org.junit.Test)

Aggregations

ResourceId (org.onosproject.yang.model.ResourceId)30 Test (org.junit.Test)21 Field (java.lang.reflect.Field)12 DeviceResourceIds.toResourceId (org.onosproject.d.config.DeviceResourceIds.toResourceId)6 DataNode (org.onosproject.yang.model.DataNode)6 FailedException (org.onosproject.config.FailedException)4 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)4 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)4 ResourceData (org.onosproject.yang.model.ResourceData)4 RestconfException (org.onosproject.restconf.api.RestconfException)3 KeyLeaf (org.onosproject.yang.model.KeyLeaf)3 ListKey (org.onosproject.yang.model.ListKey)3 SchemaId (org.onosproject.yang.model.SchemaId)3 DeviceId (org.onosproject.net.DeviceId)2 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 DynamicConfigEvent (org.onosproject.config.DynamicConfigEvent)1 DynamicConfigListener (org.onosproject.config.DynamicConfigListener)1 DynamicConfigService (org.onosproject.config.DynamicConfigService)1 YangToolUtil.toCharSequence (org.onosproject.odtn.utils.YangToolUtil.toCharSequence)1