Search in sources :

Example 1 with ResourceData

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

the class DcsBasedTapiDataProducer method getResourceId.

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

Example 2 with ResourceData

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

the class DcsBasedTapiDataProducer method readContextModelObject.

/**
 * Get Tapi context modelObject from Dcs.
 *
 * @return Tapi context modelObject in Dcs store
 */
// FIXME update this method using TapiContextHandler
private DefaultContext readContextModelObject() {
    // read DataNode from DCS
    ModelObjectId mid = ModelObjectId.builder().addChild(DefaultContext.class).build();
    DataNode node = dcs.readNode(getResourceId(mid), Filter.builder().build());
    // convert to ModelObject
    ResourceData data = DefaultResourceData.builder().addDataNode(node).resourceId(ResourceId.builder().build()).build();
    ModelObjectData modelData = modelConverter.createModel(data);
    DefaultContext context = (DefaultContext) modelData.modelObjects().get(0);
    return context;
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) DataNode(org.onosproject.yang.model.DataNode) DefaultModelObjectData(org.onosproject.yang.model.DefaultModelObjectData) ModelObjectData(org.onosproject.yang.model.ModelObjectData) DefaultContext(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.DefaultContext) ModelObjectId(org.onosproject.yang.model.ModelObjectId)

Example 3 with ResourceData

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

the class TapiObjectHandler method toModelObject.

@SuppressWarnings("unchecked")
protected T toModelObject(DataNode rNode, ResourceId rId) {
    dcsSetup();
    ResourceData rData = toResourceData(rNode, rId);
    ModelObjectData modelObjectData = modelConverter.createModel(rData);
    if (modelObjectData.modelObjects().size() > 1) {
        throw new IllegalStateException("Multiple modelObject found.");
    }
    if (modelObjectData.modelObjects().isEmpty()) {
        throw new IllegalStateException("ModelObject must not be empty.");
    }
    return (T) modelObjectData.modelObjects().get(0);
}
Also used : DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceData(org.onosproject.yang.model.ResourceData) DefaultModelObjectData(org.onosproject.yang.model.DefaultModelObjectData) ModelObjectData(org.onosproject.yang.model.ModelObjectData)

Example 4 with ResourceData

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

the class TapiObjectHandler method createOnDcs.

private void createOnDcs() {
    dcsSetup();
    ResourceData rData = toResourceData(getModelObjectData());
    addResourceDataToDcs(rData, rData.resourceId());
}
Also used : DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceData(org.onosproject.yang.model.ResourceData)

Example 5 with ResourceData

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

the class RestconfUtils method convertJsonToDataNode.

/**
 * Convert URI and ObjectNode to ResourceData.
 *
 * @param uri      URI of the data resource
 * @param rootNode JSON representation of the data resource
 * @return represents type of node in data store
 */
public static ResourceData convertJsonToDataNode(URI uri, ObjectNode rootNode) {
    RuntimeContext.Builder runtimeContextBuilder = new DefaultRuntimeContext.Builder();
    runtimeContextBuilder.setDataFormat(JSON_FORMAT);
    RuntimeContext context = runtimeContextBuilder.build();
    ResourceData resourceData = null;
    InputStream jsonData = null;
    try {
        if (rootNode != null) {
            jsonData = convertObjectNodeToInputStream(rootNode);
        }
        String uriString = getRawUriPath(uri);
        CompositeStream compositeStream = new DefaultCompositeStream(uriString, jsonData);
        // CompositeStream --- YangRuntimeService ---> CompositeData.
        CompositeData compositeData = YANG_RUNTIME.decode(compositeStream, context);
        resourceData = compositeData.resourceData();
    } catch (RestconfException ex) {
        throw ex;
    } catch (Exception ex) {
        log.error("convertJsonToDataNode failure: {}", ex.getMessage(), ex);
        log.info("Failed JSON: \n{}", rootNode);
        log.debug("convertJsonToDataNode failure", ex);
        throw new RestconfException("ERROR: JSON cannot be converted to DataNode", ex, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
    }
    if (resourceData == null) {
        throw new RestconfException("ERROR: JSON cannot be converted to DataNode", RestconfError.ErrorTag.DATA_MISSING, CONFLICT, Optional.of(uri.getPath()), Optional.empty());
    }
    return resourceData;
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) InputStream(java.io.InputStream) RestconfException(org.onosproject.restconf.api.RestconfException) UriBuilder(javax.ws.rs.core.UriBuilder) DefaultCompositeStream(org.onosproject.yang.runtime.DefaultCompositeStream) CompositeData(org.onosproject.yang.runtime.CompositeData) DefaultCompositeData(org.onosproject.yang.runtime.DefaultCompositeData) RuntimeContext(org.onosproject.yang.runtime.RuntimeContext) DefaultRuntimeContext(org.onosproject.yang.runtime.DefaultRuntimeContext) DefaultCompositeStream(org.onosproject.yang.runtime.DefaultCompositeStream) CompositeStream(org.onosproject.yang.runtime.CompositeStream) IOException(java.io.IOException) RestconfException(org.onosproject.restconf.api.RestconfException)

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