Search in sources :

Example 6 with ResourceData

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

the class RestconfManager method runPostOperationOnDataResource.

@Override
public void runPostOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    ResourceData receivedData = convertJsonToDataNode(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.createNode(rl.ridForDynConfig(), dataNode);
    } catch (Exception e) {
        if (e.getMessage().startsWith("Requested node already present")) {
            throw new RestconfException("Already exists", e, RestconfError.ErrorTag.DATA_EXISTS, CONFLICT, Optional.of(uri.getPath()));
        } else {
            log.error("ERROR: DynamicConfigService: creating {} with {}", ResourceIds.toInstanceIdentifier(rl.ridForDynConfig()), dataNode, 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) RestconfException(org.onosproject.restconf.api.RestconfException) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Example 7 with ResourceData

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

the class OdtnDcsModelCheckCommand method getResourceId.

private ResourceId getResourceId(ModelObjectId modelId) {
    ModelObjectData data = DefaultModelObjectData.builder().identifier(modelId).build();
    ResourceData rnode = modelConverter.createDataNode(data);
    return rnode.resourceId();
}
Also used : YangToolUtil.toResourceData(org.onosproject.odtn.utils.YangToolUtil.toResourceData) ResourceData(org.onosproject.yang.model.ResourceData) DefaultModelObjectData(org.onosproject.yang.model.DefaultModelObjectData) ModelObjectData(org.onosproject.yang.model.ModelObjectData)

Example 8 with ResourceData

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

the class TapiObjectHandler method deleteOnDcs.

private void deleteOnDcs() {
    dcsSetup();
    ResourceData rData = toResourceData(getChildModelObjectData());
    dcs.deleteNode(rData.resourceId());
}
Also used : DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceData(org.onosproject.yang.model.ResourceData)

Example 9 with ResourceData

use of org.onosproject.yang.model.ResourceData 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 10 with ResourceData

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

the class TapiObjectHandler method toResourceData.

private ResourceData toResourceData(ModelObjectData data) {
    dcsSetup();
    ResourceData rData = modelConverter.createDataNode(data);
    // for debug
    CharSequence strNode = toCharSequence(toXmlCompositeStream(toCompositeData(rData)));
    log.debug("XML:\n{}", XmlString.prettifyXml(strNode));
    return rData;
}
Also used : DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceData(org.onosproject.yang.model.ResourceData) YangToolUtil.toCharSequence(org.onosproject.odtn.utils.YangToolUtil.toCharSequence)

Aggregations

ResourceData (org.onosproject.yang.model.ResourceData)16 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)15 DataNode (org.onosproject.yang.model.DataNode)7 RestconfException (org.onosproject.restconf.api.RestconfException)6 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)5 DefaultModelObjectData (org.onosproject.yang.model.DefaultModelObjectData)5 ModelObjectData (org.onosproject.yang.model.ModelObjectData)5 FailedException (org.onosproject.config.FailedException)4 ResourceId (org.onosproject.yang.model.ResourceId)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CompositeData (org.onosproject.yang.runtime.CompositeData)2 CompositeStream (org.onosproject.yang.runtime.CompositeStream)2 DefaultCompositeData (org.onosproject.yang.runtime.DefaultCompositeData)2 DefaultCompositeStream (org.onosproject.yang.runtime.DefaultCompositeStream)2 DefaultRuntimeContext (org.onosproject.yang.runtime.DefaultRuntimeContext)2 RuntimeContext (org.onosproject.yang.runtime.RuntimeContext)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 YangToolUtil.toCharSequence (org.onosproject.odtn.utils.YangToolUtil.toCharSequence)1