1. Overview
This service shall be used to map the erstwhile Config-DB-like REST APIs to appropriate CPS API calls. The purpose of this service is to abstract the details of (possibly multiple, and complex) XPath queries from the users of CPS. It enables CPS-users to continue using simple REST API calls that are intuitive and easy-to-understand and implement. The mapping to appropriate queries to CPS (including mapping of one API call to many Xpath queries) shall be done in a generic way by the API Mapper CPS-TBDMT service.
2. Architecture
Drawio |
---|
border | true |
---|
| |
---|
diagramName | mapper service arch |
---|
simpleViewer | false |
---|
width | |
---|
links | auto |
---|
tbstyle | top |
---|
lbox | true |
---|
diagramWidth | 447 |
---|
revision | 12 |
---|
|
3. API definition guide
Swagger file: CPS-TBDMT-swagger.yaml
Template CRUD operations
Create xpath template
Interface definition | Description |
---|
Content-Type | application/json |
Operation | POST |
URI | / |
api/v1/Request Body
Attribute | Required | Type | Description |
---|
idtemplateId | Y | String | Identifier for the template |
schema-setmodel | Y | String | schema set on which xpath query should be executed |
requestType | Y | String | request type(get, post ..) |
xpathTemplate | Y | String | xpath template |
includeDescendants | Y | boolean | include descendants |
multipleQueryTemplateId | N | String |
xpath template | multiple query template Id |
transformParam | N | String | tranformation format("param1, param2") |
Response Codes
Code | Description |
---|
201 | Template created successfully |
400 | Bad Request (Error in request attributes) |
500 | Internal server error |
List all xpath template
Interface definition | Description |
---|
Content-Type | application/json |
Operation | GET |
URI |
/api/v1Response Codes
Code | Description |
---|
200 | Templates returned successfully |
404 | No templates found |
500 | Internal server error |
Response Body
Attribute | Required | Type | Description |
---|
templates | Y | List | List of template objects |
Template Object
Attribute | Required | Type | Description |
---|
idtemplateId | Y | String | Identifier for the template |
schema-setmodel | Y | String | schema set on which xpath query should be executed |
requestType | Y | String | request type(get, post ..) |
xpathTemplate | Y | String | xpath template |
includeDescendants | Y | boolean | include descendants |
multipleQueryTemplateId | N | String |
xpath multiple query template Id |
transformParam | N | String | tranformation format("param1, param2") |
Get a xpath template by id
Interface definition | Description |
---|
Content-Type | application/json |
Operation | GET |
URI |
/api/v1/{schema-set}Response Codes
Code | Description |
---|
200 | Template found and returned |
404 | Template not found |
500 | Internal server error |
Response Body
Same as template Object
Delete xpath template
Interface definition | Description |
---|
Content-Type | application/json |
Operation | DELETE |
URI |
/apiv1/schema-set}/{Response Codes
Code | Description |
---|
200 | Template deleted successfully |
400 | Bad Request (Error in request attributes) |
500 | Internal server error |
Execute template
Interface definition | Description |
---|
Content-Type | application/json |
Operation | POST |
URI |
/api/v1schema-setRequest Body
Attribute | Required | Type | Description |
---|
InputinputParameters | Y | JSON blob | Input dictionary to be applied to the template |
payload | N | JSON blob | Payload to be used during edit/patch |
Response Codes
Code | Description |
---|
200 | Template executed successfully |
400 | Bad Request (Error in request attributes) |
404 | Template Not found |
500 | Internal server error |
Response Body
Attribute | Required | Type | Description |
---|
result | Y | JSON Blob | Result of the xpath query as JSON object |
4. Dependencies
Definition of templates
Sample xpath query
/NearRTRIC[idNearRTRIC=11]/GNBDUFunction[idGNBDUFunction=1]/NRCellDU[idNRCellDU=15296]/attributes/RRMPolicyRatio[id=123]
Sample xpath template
/NearRTRIC[idNearRTRIC={{nearrtric_id}}]/GNBDUFunction[idGNBDUFunction={{gnbdu_id}}]/NRCellDU[idNRCellDU={{nrcelldu_id}}]/attributes/RRMPolicyRatio[id={{rrmpolicy_id}}]
Sample API for the above template
Elite soft json viewer |
---|
{
"inputParameters": {
"nearrtric_id": 11,
"gnbdu_id": 1,
"nrcelldu_id": 15296,
"rrmpolicy_id": 123
}
} |
Response Object
Elite soft json viewer |
---|
{
"result": {
"key": "value"
}
} |
5. Output Transformation Template Example
curl --location --request POST 'http://localhost:8080/templates' --header 'Content-Type: application/json' --data-raw '{
"templateId": "get-ric",
"model": "ns-schemaset",
"requestType": "get",
"xpathTemplate": "/",
"includeDescendants": true,
"transformParam":"NearRTRIC,GNBDUFunction,NRCellDU,idNRCellDU"
}'
6. Multiple query Example
Example test-tree model:
{"branch":[{"name":"Right","nest":{"name":"Big","birds":["Owl","Raven","Crow"]}},{"name":"Left","nest":{"name":"Small","birds":["Robin","Sparrow","Finch"]}}]}
Get-all-data
curl --location --request POST 'http://localhost:8080/templates' --header 'Content-Type: application/json' --data-raw '{
"templateId": "get-all-data",
"model": "CSIT-SchemaSet",
"requestType": "get",
"xpathTemplate": "/test-tree",
"includeDescendants": true,
"transformParam":"branch,name"
}' -i
curl --location --request POST 'http://localhost:8080/execute/CSIT-SchemaSet/get-all-data' --header 'Content-Type: application/json' --data-raw '{
"inputParameters": {
}
}' -i
Response:
["Left","Right"]
The above response will be inserted ({{name}}) in the below template and will be executed twice(First "/test-tree/branch[@name='Left']/nest" and then "/test-tree/branch[@name='Right']/nest") to give collective output.
Get-branch
curl --location --request POST 'http://localhost:8080/templates' --header 'Content-Type: application/json' --data-raw '{
"templateId": "get-branch",
"model": "CSIT-SchemaSet",
"requestType": "get",
"xpathTemplate": "/test-tree/branch[@name='\''{{name}}'\'']/nest",
"includeDescendants": true,
"multipleQueryTemplateId":"get-all-data",
"transformParam":"birds"
}' -i
Responses
//get-all-data
["Left","Right"]
//get-branch
[["Owl","Raven","Crow"]], [["Robin","Sparrow","Finch"]]
6. Supported requestTypes:
- get (/anchors/{anchor}/node?xpath=)
- query (/anchors/{anchor}/nodes/query?xpath)
- query-cps-path (/anchors/{anchor}/nodes/query?cps-path)
- post (/anchors/{anchor}/nodes?xpath=)
- put (/anchors/{anchor}/nodes?xpath=)
- patch (/anchors/{anchor}/nodes?xpath=)
- post-list-node (/anchors/{anchor}/list-node?xpath=)
7. Deployment aspects
...
To be updated
- git clone "https://gerrit.onap.org/r/cps/cps-tbdmt"
- cd cps-tbdmt/
- mvn clean install
- cd docker-compose/
- update cps & ncmp ip-address in application.yml
- docker-compose up (use the image built using the above steps in the docker-compose file)