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);
}
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));
}
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());
}
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\"]"));
}
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());
}
Aggregations