use of org.onosproject.yang.model.KeyLeaf in project onos by opennetworkinglab.
the class ResourceIdParser method appendKeyList.
public static String appendKeyList(String path, ListKey key) {
StringBuilder bldr = new StringBuilder();
for (KeyLeaf keyLeaf : key.keyLeafs()) {
bldr.append(KEY_SEP);
bldr.append(keyLeaf.leafSchema().name());
bldr.append(NM_SEP);
bldr.append(keyLeaf.leafSchema().namespace());
bldr.append(NM_SEP);
bldr.append(keyLeaf.leafValue().toString());
}
return (path + bldr.toString());
}
use of org.onosproject.yang.model.KeyLeaf in project onos by opennetworkinglab.
the class ResourceIdParser method parseKeyList.
private static void parseKeyList(ListKey key, StringBuilder bldr) {
bldr.append(key.schemaId().name());
bldr.append(NM_SEP);
bldr.append(key.schemaId().namespace());
Iterator<KeyLeaf> iter = key.keyLeafs().iterator();
KeyLeaf next;
while (iter.hasNext()) {
next = iter.next();
bldr.append(KEY_SEP);
bldr.append(next.leafSchema().name());
bldr.append(NM_SEP);
bldr.append(next.leafSchema().namespace());
bldr.append(NM_SEP);
bldr.append(next.leafValue().toString());
}
}
use of org.onosproject.yang.model.KeyLeaf in project onos by opennetworkinglab.
the class DeviceResourceIds method toDeviceId.
/**
* Transforms root node of a device to corresponding DeviceId.
*
* @param deviceRoot NodeKey of a device root node
* @return DeviceId
* @throws IllegalArgumentException if not a device node
*/
public static DeviceId toDeviceId(NodeKey<?> deviceRoot) {
if (!DEVICE_SCHEMA.equals(deviceRoot.schemaId())) {
throw new IllegalArgumentException(deviceRoot + " is not a device node");
}
if (deviceRoot instanceof ListKey) {
ListKey device = (ListKey) deviceRoot;
Optional<DeviceId> did = device.keyLeafs().stream().filter(kl -> DEVICE_ID_KL_NAME.equals(kl.leafSchema().name())).map(KeyLeaf::leafValAsString).map(DeviceId::deviceId).findFirst();
if (did.isPresent()) {
return did.get();
}
throw new IllegalArgumentException("device-id not found in " + deviceRoot);
}
throw new IllegalArgumentException("Unexpected type " + deviceRoot.getClass());
}
use of org.onosproject.yang.model.KeyLeaf in project onos by opennetworkinglab.
the class ResourceIds method fromInstanceIdentifier.
/**
* Converts instance-identifier String into a ResourceId.
*
* @param input instance-identifier
* @return Corresponding ResourceId relative to root or null if {@code iid} is '/'
* Returned ResourceId will not have root NodeKey in it's path.
* consider using {@link #prefixDcsRoot(ResourceId)},
* {@link #prefixYrsRoot(ResourceId)} to add them.
*/
public static ResourceId fromInstanceIdentifier(String input) {
String[] nodes = input.split("/");
List<NodeKey> nodeKeys = Arrays.stream(nodes).filter(s -> !s.isEmpty()).map(ResourceIds::toNodeKey).collect(Collectors.toList());
if (nodeKeys.isEmpty()) {
return null;
}
Builder builder = ResourceId.builder();
// fill-in null (=inherit from parent) nameSpace
String lastNamespace = null;
for (NodeKey nodeKey : nodeKeys) {
if (nodeKey.schemaId().namespace() != null) {
lastNamespace = nodeKey.schemaId().namespace();
}
if (nodeKey instanceof LeafListKey) {
builder.addLeafListBranchPoint(nodeKey.schemaId().name(), firstNonNull(nodeKey.schemaId().namespace(), lastNamespace), ((LeafListKey) nodeKey).value());
} else if (nodeKey instanceof ListKey) {
builder.addBranchPointSchema(nodeKey.schemaId().name(), lastNamespace);
for (KeyLeaf kl : ((ListKey) nodeKey).keyLeafs()) {
builder.addKeyLeaf(kl.leafSchema().name(), firstNonNull(kl.leafSchema().namespace(), lastNamespace), kl.leafValue());
}
} else {
builder.addBranchPointSchema(nodeKey.schemaId().name(), lastNamespace);
}
}
return builder.build();
}
use of org.onosproject.yang.model.KeyLeaf 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();
}
Aggregations