use of org.onosproject.yang.model.ListKey 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()))));
}
use of org.onosproject.yang.model.ListKey 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();
}
use of org.onosproject.yang.model.ListKey in project onos by opennetworkinglab.
the class ResourceIds method toInstanceIdentifier.
/**
* Converts ResourceId to instance-identifier.
*
* @param rid to convert
* @return instance-identifier
*
* @see <a href="https://tools.ietf.org/html/rfc7951#section-6.11">RFC 7951</a>
* @see <a href="https://tools.ietf.org/html/rfc7950#section-14">RFC 7950 for ABNF</a>
*/
public static String toInstanceIdentifier(ResourceId rid) {
StringBuilder s = new StringBuilder();
String lastNamespace = null;
for (NodeKey nk : rid.nodeKeys()) {
if (nk.schemaId().name().equals("/")) {
// DCS root: org.onosproject.dcs:/
continue;
}
s.append('/');
if (!Objects.equals(lastNamespace, nk.schemaId().namespace())) {
s.append(nk.schemaId().namespace());
s.append(':');
lastNamespace = nk.schemaId().namespace();
}
s.append(nk.schemaId().name());
if (nk instanceof LeafListKey) {
LeafListKey llk = (LeafListKey) nk;
s.append('[');
s.append('.');
s.append('=');
s.append('"').append(StringEscapeUtils.escapeJson(llk.asString())).append('"');
s.append(']');
} else if (nk instanceof ListKey) {
ListKey lk = (ListKey) nk;
for (KeyLeaf kl : lk.keyLeafs()) {
s.append('[');
if (!Objects.equals(kl.leafSchema().namespace(), lastNamespace)) {
s.append(kl.leafSchema().namespace());
s.append(':');
}
s.append(kl.leafSchema().name());
s.append('=');
s.append('"').append(StringEscapeUtils.escapeJson(kl.leafValAsString())).append('"');
s.append(']');
}
} else {
// normal NodeKey
// nothing to do
}
}
if (s.length() == 0) {
return "/";
}
return s.toString();
}
Aggregations