You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 27 Next »

CPS-461 - Getting issue details... STATUS

Introduction

Yang module used for testing

bookstore.yang
module stores {
    yang-version 1.1;
    namespace "org:onap:ccsdk:sample";

    prefix book-store;

    revision "2020-09-15" {
        description
        "Sample Model";
    }

    typedef year {
        type uint16 {
            range "1000..9999";
        }
    }

    container bookstore {

        leaf bookstore-name {
            type string;
        }

    list categories {

        key "code";

        leaf code {
            type string;
        }

        leaf name {
            type string;
        }

        list books {
            key title;

            leaf title {
                type string;
            }
            leaf lang {
                type string;
            }
            leaf-list authors {
                type string;
            }
            leaf pub_year {
                type year;
            }
            leaf price {
                type uint64;
            }
        }
    }
    }
}


It has been noted that the json content for read and write requests in CPS-Core is inconsistent

DescriptionResponse for getDataNode root nodeResponse for getDataNode non root node body when writing (root) DataNode
OperationGETGETPOST/PUT
xPath//bookstore/categories[@code='01']/

Response

/Body

{
   "bookstore-name":"Chapters",
   "categories":[ ... ]
}

{
    "code": "01",
    "name": "SciFi",
     ...

}

{
   "bookstore":{
     "bookstore-name":"Chapters",
      "categories":[ ... ]
  }
}

NotesThe response includes the 'value' of the bookstore node ie. the leaves and children<= Same the body needs to include the whole container object.


Solution

#SolutionsIssues
1Use the parent node xpath in order to wrap the queried leaves. eg query xpath = /bookstore/categories[@code='01'] => categoriesThis should be reasonably straightforward as the node is named after the container name given by the module yang file.

For the JSON output of Get DataNode we need to alter the DataMapUtils class. The function toDataMap translates a datanode object to a JSON output. We only want this to occur on the top node and as such we can create a new method which is called before toDataMap:

public static Map<String, Object> toDataMapTopNode(final DataNode dataNode) {
final String nodeName = dataNode.getXpath().substring(dataNode.getXpath().lastIndexOf('/') + 1)
.replaceAll("\\[.*?\\]", "");
return ImmutableMap.<String, Object>builder().put(nodeName,
toDataMap(dataNode)
).build();
}

We only want the container name on the top level of the JSON output and as such have to distinguish between a top level node and non top level node. We create an outer map to wrap the inner map which creates the appropriate levels in the JSON output. 

This produces the following response in the Post Request output:

DescriptionResponse for getDataNode root nodeResponse for getDataNode non root nodeResponse for queryDataNode root nodeResponse for queryDataNode non root node
OperationGETGETGETGET
xPath//bookstore/categories[@code='01']/bookstore/bookstore/categories[@code='01']

Response

/Body

{
    "bookstore": {
        "bookstore-name": "Easons",
        "categories": [...]

    }

}

{
    "categories": {
        "code": "01",
        "name": "SciFi",
        "books": [...] 

     }

}

{
    "bookstore": {
        "bookstore-name": "Easons",
        "categories": [...]

    }

}

{
    "categories": {
        "code": "01",
        "name": "SciFi",
        "books": [...] 

     }

}

NotesResponse includes the container bookstoreThe response includes the list categoriesResponse includes the container bookstoreThe response includes the list categories

Tests would need to be updated to accept the new JSON output which is returned. Examples would need to be updated in openapi

Backwards Compatibility 

Queries which use toDataMap:

Query/ServiceClassNotesResponse nowResponse After
Get Data Node (as above)DataRestController.javaThis change is given in the example above. The JSON output for Get Node will be updated.

{
   "bookstore-name":"Chapters",
   "categories":[ ... ]
}

{
   "bookstore":{
     "bookstore-name":"Chapters",
      "categories":[ ... ]
  }
}
Notification ServiceCpsDataUpdatedEventFactory,javaNotification Service response should be the same as CPS Core for consistency. CPS Temporal

cpsDataUpdatedEvent Object content.data.additionalProperties.toString():

[[bookstore-name:Chapters]]


cpsDataUpdatedEvent Object content.data.additionalProperties.toString():

[bookstore:[bookstore-name:Chapters]]

Query data nodesQueryRestController.java

Query DataNodes will produce a datanode within an array with the container ID

and then the relevant data:

http://localhost:8883/cps/api/v1/dataspaces/test/anchors/bookstore-anchor-test2/nodes/query?cps-path=/bookstore/categories[@code='01']&include-descendants=true

[

     {

        "code": "01",
        "name": "SciFi",
        "books": [
            ...
        ]
    }
]

[

     "categories": {

        "code": "01",
        "name": "SciFi",
        "books": [
            ...
        ]
    }
]

get Node by CMHandle and Xpath (NCMP)NetworkCmProxyController.javaThis method is deprecated and is no longer used as part of NCMP.

Outstanding issues:

Backwards Incompatibility:New endpoint vs new version of interface
  • No labels