开发者中心

留存规则

留存规则用于每天从数据库删除数据。留存规则设定删除哪些数据。例如,dataType=EVENT 并且 maximumAge=30 的规则删除系统中超过30天的所有事件。 留存规则接口组成:

  • 留存规则集合, 通过 url /retention/retentions 访问
  • 单个留存规则, 通过 url /retetion/retentions/{留存规则Id} 访问

留存规则集合

留存规则集合 [application/vnd.com.nsn.cumulocity.retentionRuleCollection+json]
名称 类型 次数 描述
self URI 1 资源链接。
retentionRules RetentionRule 0..n 留存规则列表, 如下所示。
statistics PagingStatistics 1 分页统计信息。
prev URI 0..1 上一页链接。
next URI 0..1 下一页链接。
GET - 查询留存规则集合

应答正文: 留存规则集合

所需角色: ROLE_RETENTION_RULE_READ

请求示例: 查询留存规则集合。

GET ...
                            Host: ...
                            Authorization: Basic ...
                            Accept: application/vnd.com.nsn.cumulocity.retentionRuleCollection+json;ver=...
                        

应答示例:

HTTP/1.1 200 OK
                            Content-Type: application/vnd.com.nsn.cumulocity.retentionRuleCollection+json;ver=...
                            Content-Length: ...
                            {
                            "statistics": {
                            "currentPage": 1,
                            "pageSize": 5,
                            "totalPages": 1
                        },
                        "retentionRules": [
                        {
                        "dataType": "ALARM",
                        "fragmentType": "fragmentType",
                        "id": 1,
                        "maximumAge": 12,
                        "self": "<<URL of retentionRule>>",
                        "source": "source",
                        "type": "type"
                    },
                    {
                    "dataType": "ALARM",
                    "fragmentType": "fragmentType",
                    "id": 2,
                    "maximumAge": 12,
                    "self": "<<URL of retentionRule>>",
                    "source": "source",
                    "type": "type"
                },
                {
                "dataType": "*",
                "fragmentType": "*",
                "id": 5,
                "maximumAge": 12,
                "self": "<<URL of retentionRule>>",
                "source": "*",
                "type": "*"
            },
            {
            "dataType": "ALARM",
            "fragmentType": "fragmentTypeUpdated",
            "id": 3,
            "maximumAge": 24,
            "self": "<<URL of retentionRule>>",
            "source": "source",
            "type": "type"
        }
        ],
        "self": "<<URL of current page>>"
    }
POST - 创建一条留存规则

请求正文: 留存规则

应答正文: 留存规则

所需角色: ROLE_RETENTION_RULE_ADMIN

请求示例 (完整POST):

POST ...
    Host: ...
    Authorization: Basic ...
    Content-Length: ...
    Content-Type: application/vnd.com.nsn.cumulocity.retentionRule+json;ver...

    {
    "dataType":"ALARM",
    "fragmentType":"fragmentType",
    "type":"type",
    "source":"source",
    "maximumAge":"12"
}

应答示例 (完整POST):

HTTP/1.1 201 Created
    Content-Type: application/vnd.com.nsn.cumulocity.retentionRule+json;ver=...
    Content-Length: ...
    Location: <<URL of new retentionRule>>

    {
    "id" : "<<ID of new retetionRule>>",
    "self" : "<<URL of new retetionRule>>",
    "dataType":"ALARM",
    "fragmentType":"fragmentType",
    "type":"type",
    "source":"source",
    "maximumAge":"12"
}

请求示例 (部分POST):

POST ...
    Host: ...
    Authorization: Basic ...
    Content-Length: ...
    Content-Type: application/vnd.com.nsn.cumulocity.retentionRule+json;ver...

    {
    "dataType":"ALARM",
    "maximumAge":"12"
}

应答示例 (部分POST):

HTTP/1.1 201 Created
    Content-Type: application/vnd.com.nsn.cumulocity.retentionRule+json;ver=...
    Content-Length: ...
    Location: <<URL of new retentionRule>>

    {
    "id" : "<<ID of new retetionRule>>",
    "self" : "<<URL of new retetionRule>>",
    "dataType":"ALARM",
    "fragmentType":"*",
    "type":"*",
    "source":"*",
    "maximumAge":"12"
}

留存规则

留存规则 [application/vnd.com.nsn.cumulocity.retentionRule+json]
名称 类型 次数 描述 可视性
self URI 0..1 此资源的链接地址。 Public
id Long 1 留存规则id。 Public
dataType String 0..1 留存规则对此数据类型文档有效, 取值范围 [ALARM, AUDIT, EVENT, MEASUREMENT, OPERATION, *]。 Public
fragmentType String 0..1 留存规则对此片段类型文档有效。 Public
type String 0..1 留存规则对此类型文档有效。 Public
source String 0..1 留存规则对此源(设备)有效。 Public
maximumAge Long 1 文档留存最大天数。 Public
  • 留存规则按逻辑与组合。
  • 字段说明: 数据类型, 片段类型, 类型, 源可以设置为 ""。值为 "" 的字段表示匹配所有。
GET - 查询留存规则

应答正文: 留存规则

所需角色: ROLE_RETENTION_RULE_READ

请求示例: 查询单条留存规则。

GET ...
                        Host: ...
                        Authorization: Basic ...
                        Accept: application/vnd.com.nsn.cumulocity.retentionRule+json;ver=...
                    

应答示例:

HTTP/1.1 200 OK
                        Content-Type: application/vnd.com.nsn.cumulocity.retentionRule+json;ver=...
                        Content-Length: ...
                        {
                        "dataType": "EVENT",
                        "fragmentType": "*",
                        "id" : "<<ID of new retetionRule>>",
                        "maximumAge": 12,
                        "self" : "<<URL of new retetionRule>>",
                        "source": "source",
                        "type": "*"
                    

}

PUT - 更新已有的留存规则

请求正文: 留存规则

应答正文: 留存规则

所需角色: ROLE_RETENTION_RULE_ADMIN

请求示例:

PUT ...
                        Host: ...
                        Authorization: Basic ...
                        Content-Length: ...
                        Accept: application/vnd.com.nsn.cumulocity.retentionRule+json;ver=...
                        Content-Type: application/vnd.com.nsn.cumulocity.retentionRule+json;ver=...

                        {
                        "fragmentType":"fragmentTypeUpdated"
                    }
                    

应答示例:

HTTP/1.1 200 OK
                        Content-Type: application/vnd.com.nsn.cumulocity.tenant+json;ver=...
                        Content-Length: ...
                        {
                        "dataType": "EVENT",
                        "fragmentType": "fragmentTypeUpdated",
                        "id" : "<<ID of new retetionRule>>",
                        "maximumAge": 12,
                        "self" : "<<URL of new retetionRule>>",
                        "source": "source",
                        "type": "*"
                    }
                    
DELETE - 删除一条留存规则

请求正文: N/A

应答正文: N/A

所需角色: ROLE_RETENTION_RULE_ADMIN

请求示例:

DELETE [URL to the resource]
                        Host: [hostname]
                        Authorization: Basic xxxxxxxxxxxxxxxxxxx
                    

应答示例:

HTTP/1.1  204 NO CONTENT