Search in sources :

Example 6 with DataNode

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

the class OdtnDcsModelCheckCommand method dumpDcsStore.

private <T extends InnerModelObject> void dumpDcsStore(Class<T> cls) {
    ModelObjectId mid = ModelObjectId.builder().addChild(cls).build();
    DataNode all = dcs.readNode(getResourceId(mid), Filter.builder().build());
    ResourceId empty = ResourceId.builder().build();
    CharSequence strNode = toCharSequence(toXmlCompositeStream(toCompositeData(toResourceData(empty, all))));
    printlog("XML:\n{}", XmlString.prettifyXml(strNode));
}
Also used : ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) YangToolUtil.toCharSequence(org.onosproject.odtn.utils.YangToolUtil.toCharSequence) ModelObjectId(org.onosproject.yang.model.ModelObjectId)

Example 7 with DataNode

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

the class TapiObjectHandler method readOnDcs.

@SuppressWarnings("unchecked")
private T readOnDcs() {
    dcsSetup();
    ResourceData rData1 = toResourceData(getChildModelObjectData());
    ResourceData rData2 = toResourceData(getModelObjectData());
    DataNode rNode = dcs.readNode(rData1.resourceId(), Filter.builder().build());
    obj = toModelObject(rNode, rData2.resourceId());
    return obj;
}
Also used : DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceData(org.onosproject.yang.model.ResourceData) DataNode(org.onosproject.yang.model.DataNode)

Example 8 with DataNode

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

the class RestconfManager method runPutOperationOnDataResource.

@Override
public void runPutOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(rl.uriForYangRuntime()), rootNode);
    List<DataNode> dataNodeList = receivedData.dataNodes();
    if (dataNodeList == null || dataNodeList.isEmpty()) {
        log.warn("There is no one Data Node can be proceed.");
        return;
    }
    if (dataNodeList.size() > 1) {
        log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size());
    }
    DataNode dataNode = dataNodeList.get(0);
    try {
        /*
             * If the data node already exists, then replace it.
             * Otherwise, create it.
             */
        if (dynamicConfigService.nodeExist(rl.ridForDynConfig())) {
            dynamicConfigService.replaceNode(parentOf(rl.ridForDynConfig()), dataNode);
        } else {
            dynamicConfigService.createNode(parentOf(rl.ridForDynConfig()), dataNode);
        }
    } catch (FailedException e) {
        log.error("ERROR: DynamicConfigService: ", e);
        throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
    }
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Example 9 with DataNode

use of org.onosproject.yang.model.DataNode 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();
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) KeyLeaf(org.onosproject.yang.model.KeyLeaf) InnerNode(org.onosproject.yang.model.InnerNode) ListKey(org.onosproject.yang.model.ListKey) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) SchemaId(org.onosproject.yang.model.SchemaId) NodeKey(org.onosproject.yang.model.NodeKey)

Example 10 with DataNode

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

the class RestconfManager method runPatchOperationOnDataResource.

@Override
public void runPatchOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(rl.uriForYangRuntime()), rootNode);
    ResourceId rid = receivedData.resourceId();
    List<DataNode> dataNodeList = receivedData.dataNodes();
    if (dataNodeList == null || dataNodeList.isEmpty()) {
        log.warn("There is no one Data Node can be proceed.");
        return;
    }
    if (dataNodeList.size() > 1) {
        log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size());
    }
    DataNode dataNode = dataNodeList.get(0);
    if (rid == null) {
        rid = ResourceId.builder().addBranchPointSchema("/", null).build();
        dataNode = removeTopNode(dataNode);
    }
    try {
        dynamicConfigService.updateNode(parentOf(rl.ridForDynConfig()), dataNode);
    } catch (FailedException e) {
        log.error("ERROR: DynamicConfigService: ", e);
        throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
    }
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Aggregations

DataNode (org.onosproject.yang.model.DataNode)14 FailedException (org.onosproject.config.FailedException)8 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)7 ResourceData (org.onosproject.yang.model.ResourceData)7 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)6 ResourceId (org.onosproject.yang.model.ResourceId)6 RestconfException (org.onosproject.restconf.api.RestconfException)5 NodeKey (org.onosproject.yang.model.NodeKey)3 Filter (org.onosproject.config.Filter)2 DocumentPath (org.onosproject.store.service.DocumentPath)2 Versioned (org.onosproject.store.service.Versioned)2 InnerNode (org.onosproject.yang.model.InnerNode)2 KeyLeaf (org.onosproject.yang.model.KeyLeaf)2 ModelObjectId (org.onosproject.yang.model.ModelObjectId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Test (org.junit.Test)1 DynamicConfigService (org.onosproject.config.DynamicConfigService)1 YangToolUtil.toCharSequence (org.onosproject.odtn.utils.YangToolUtil.toCharSequence)1 RestconfError (org.onosproject.restconf.api.RestconfError)1 RestconfRpcOutput (org.onosproject.restconf.api.RestconfRpcOutput)1