Search in sources :

Example 26 with ResourceId

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

the class DistributedDynamicConfigStore method addNode.

@Override
public CompletableFuture<Boolean> addNode(ResourceId parent, DataNode node) {
    String spath = ResourceIdParser.parseResId(parent);
    log.trace(" addNode({}, {})", parent, node);
    log.trace(" spath={}", spath);
    if (spath == null) {
        throw new FailedException("Invalid ResourceId, cannot create Node");
    }
    if (spath.equals(ResourceIdParser.ROOT)) {
        // If not present, adding static ROOT node after immutable documentTree root.
        if (complete(keystore.get(DocumentPath.from(spath))) == null) {
            addLeaf(spath, LeafNode.builder(DeviceResourceIds.ROOT_NAME, DCS_NAMESPACE).type(DataNode.Type.SINGLE_INSTANCE_NODE).build());
        }
        ResourceId abs = ResourceIds.resourceId(parent, node);
        parseNode(ResourceIdParser.parseResId(abs), node);
        return CompletableFuture.completedFuture(true);
    } else if (complete(keystore.get(DocumentPath.from(spath))) == null) {
        throw new FailedException("Node or parent does not exist for " + spath);
    }
    ResourceId abs = ResourceIds.resourceId(parent, node);
    // spath = ResourceIdParser.appendNodeKey(spath, node.key());
    parseNode(ResourceIdParser.parseResId(abs), node);
    return CompletableFuture.completedFuture(true);
}
Also used : ResourceId(org.onosproject.yang.model.ResourceId) FailedException(org.onosproject.config.FailedException)

Example 27 with ResourceId

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

the class DeviceResourceIdsTest method testDeviceSubtreeTest.

@Test
public void testDeviceSubtreeTest() {
    ResourceId absDevice = ResourceId.builder().addBranchPointSchema(ROOT_NAME, DCS_NAMESPACE).addBranchPointSchema(DEVICES_NAME, DCS_NAMESPACE).addBranchPointSchema(DEVICE_NAME, DCS_NAMESPACE).addKeyLeaf(DEVICE_ID_KL_NAME, DCS_NAMESPACE, DID_A.toString()).build();
    NodeKey<?> deviceKey = absDevice.nodeKeys().get(2);
    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(absDevice));
}
Also used : ResourceId(org.onosproject.yang.model.ResourceId) Test(org.junit.Test)

Example 28 with ResourceId

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

the class ResourceIdsTest method testRelativizeEmpty.

@Test
public void testRelativizeEmpty() {
    ResourceId relDevices = ResourceIds.relativize(DEVICES, DEVICES);
    // equivalent of . in file path, expressed as ResourceId with empty
    assertTrue(relDevices.nodeKeys().isEmpty());
}
Also used : DeviceResourceIds.toResourceId(org.onosproject.d.config.DeviceResourceIds.toResourceId) ResourceId(org.onosproject.yang.model.ResourceId) Test(org.junit.Test)

Example 29 with ResourceId

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

the class ResourceIdsTest method testToInstanceIdentifier.

@Test
public void testToInstanceIdentifier() {
    assertThat(ResourceIds.toInstanceIdentifier(ResourceIds.ROOT_ID), is("/"));
    assertThat(ResourceIds.toInstanceIdentifier(DEVICES_ID), is("/org.onosproject.dcs:devices"));
    DeviceId deviceId = DeviceId.deviceId("test:device-identifier");
    assertThat(ResourceIds.toInstanceIdentifier(toResourceId(deviceId)), is("/org.onosproject.dcs:devices/device[device-id=\"test:device-identifier\"]"));
    assertThat(ResourceIds.toInstanceIdentifier(ResourceIds.relativize(DEVICES_ID, toResourceId(deviceId))), is("/org.onosproject.dcs:device[device-id=\"test:device-identifier\"]"));
    ResourceId eth0 = ResourceId.builder().addBranchPointSchema("interfaces", "ietf-interfaces").addBranchPointSchema("interface", "ietf-interfaces").addKeyLeaf("name", "ietf-interfaces", "eth0").build();
    assertThat(ResourceIds.toInstanceIdentifier(eth0), is("/ietf-interfaces:interfaces/interface[name=\"eth0\"]"));
    assertThat(ResourceIds.toInstanceIdentifier(ResourceIds.concat(toResourceId(deviceId), eth0)), is("/org.onosproject.dcs:devices/device[device-id=\"test:device-identifier\"]" + "/ietf-interfaces:interfaces/interface[name=\"eth0\"]"));
}
Also used : DeviceResourceIds.toResourceId(org.onosproject.d.config.DeviceResourceIds.toResourceId) ResourceId(org.onosproject.yang.model.ResourceId) DeviceId(org.onosproject.net.DeviceId) Test(org.junit.Test)

Example 30 with ResourceId

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

the class ResourceIdsTest method testRelativize.

@Test
public void testRelativize() {
    ResourceId relDevices = ResourceIds.relativize(ResourceIds.ROOT_ID, DEVICES);
    assertEquals(DeviceResourceIds.DEVICES_NAME, relDevices.nodeKeys().get(0).schemaId().name());
    assertEquals(DCS_NAMESPACE, relDevices.nodeKeys().get(0).schemaId().namespace());
    assertEquals(1, relDevices.nodeKeys().size());
}
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