Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Datetime 

    • Data in last X hours 
    • Data after a particular DateTime
    • Data before a particular DateTime 
    • Last X network data
  • DataTypes in CPS Core
    • Dataspace & schema-set

    • Dataspace & anchor
    • Dataspace & multiple anchors - To improve performance, if there is a need to fetch data for multiple anchors.
    • Dataspace
  • Payload
    • Based on a subsection or field in the payload. These criteria do need schema-set to be fixed to search in the same set of anchors. The payload will be passed in JSON format as it is more flexible and the user will not expect to implement functionality similar to cps-path query. 

We will implement only the basic APIs first and will add complex ones when required. 

...

There are other parameters, listed below, that can have an impact on the response. 

NoNameTypeDefaultPurposeExample
1indexint0

The query output can have many rows so it is important to limit the fetched data. To limit the number of records and to provide pagination, these two parameters can be used. 

"index" parameter represents the page number, starts with 0, and maxSize is the page size.


2maxSizeint1000
3
point-in-time
pointInTimeDateTimeCurrentDateTimePagination does not work well if new data gets added which fulfils the search criteria. The user must provide this value to avoid this issue.

Assumptions

  • Temporal database stores full information in the payload ( CPS-192: Design data store for Temporal Service). 
  • It is possible that data stored for the different timestamps is the same, especially if the payload is used to filter data.
  • Data in the response body will always contain the entire payload data.
  • If the payload is passed as XPath, it is not expected to support all cps-path query and XPath functionalities. 

Proposed APIs

NoPurpose
1

Return data entries for an anchor after the specified Datetime, which matches the payload format.

2

Return data entries based on provided schema-set after the specified Datetime, which matches the payload format.

Approach 1 - GET

In the GET APIs, all the filtering parameters are passed as query parameter. 

The payload can be passed as JSON or XPath. But, XPath is more concise and more readable than JSON when passed as a query parameter. 

NoAPI endpointDescriptionExample
1.

GET /dataspaces/{dataspace-name}​/anchors/{anchor-name}​?after=<epoch-time>2021-03-21T00:00:00-0:00&maxSize=1000&?payload={"status" : "UP"}=/device[@status=up]&maxSize=500

Return all the data entries for an anchor after the specified epoch in nanoseconds
2.​GET /dataspaces/{dataspace-name}/schema-sets/{schema-set}?after=<epochtime>&maxSize=5002021-03-21T00:00:00-0:00Return all the data entries based on provided schema-set after the specified epoch in nanoseconds.




...

Code Block
{
  "nextRecordsLink": "cps-temporal/api/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}?after=<epoch-time>2021-03-21T00:00:00-0:00&maxSize=1000500&before=<epoch-time>pointInTime=2021-04-21T00:00:00-0:00&index=2&point-in-time=DATE",
  "previousRecordsLink": "cps-temporal/api/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}?after=<epoch-time>2021-03-21T00:00:00-0:00&maxSize=1000500&before=<epoch-time>pointInTime=2021-04-21T00:00:00-0:00&index=0&point-in-time=DATE",
  "records": [
    {
      "timestamp": "1234567788889",
      "dataspace": "my-dataspace",
      "schemaSet": "my-schema-set",
      "anchor": "my-anchor",
      "data": {
        "status" : "UP"
      }
    }
  ]
}

...

  • Provides the ability to cache data based on URL. It is not relevant as data can change based on when the API is called.
  • Can provide links for the next record and previous record link in the response itself.
  • point-in-time pointInTime can have the current timestamp as the default value because we can add it in the next record and previous record link as a part of the response.
Cons
  • The payload is JSON can be a little longer and If the payload filter condition becomes longer, it will not fit within the GET URL length limit.
Questions
  1. Should we disable caching or ask the user to pass the pointInTime parameter value?

Approach 2 - POST

As we are query data, POST is not intuitive but the search can be considered as a resource with different filtering criteria. We need only one API as the filtering criteria will be provided in the body, which allows the payload to be big if required.

...

Code Block
[
  {
    "timestamp": "1234567788889",
    "dataspace": "my-dataspace",
    "schemaSet": "my-schema-set",
    "anchor": "my-anchor",
    "data": {
      "status": "UP"
    }
  }
]

Questions

...

Pros:
  • The payload can be big and we will still be able to support it.
Cons
  • No right place to pass pagination related parameters ( maxSize & index)
  • Less user-friendly than the GET approach.
  • Using POST for query will break many rest principles. 

...

Open Items