Save Storage Policy

根据存储策略ID,更新并保存指定存储策略的配置信息,包括数据存储时长、和存储策略中配置的模型测点信息。

请求格式

POST https://{apigw-address}/tsdb-policy/v2.1/policies/{policyId}

请求参数(URI)

名称

位置(Path/Query)

必需/可选

数据类型

描述

policyId

Path

必需

String

存储策略ID,可通过 EnOS管理门户 > 时序数据管理 > 存储策略 页面获取指定存储类型的存储策略ID。

orgId

Query

必需

String

资产所属的组织ID。如何获取orgId信息>>

请求参数(Body)

名称

必需/可选

数据类型

描述

retention

可选,若模型测点已配置存储时长,此参数为可选。

String

数据存储时长,1M 表示一个月,1y 表示一年。所有可选值有:1M3M6M1y2y3y5y10y15y20y

models

必需

List<JSONObject>

模型测点集合。详见 模型测点结构体

模型测点结构体

名称

必需/可选

数据类型

描述

modelId

必需

String

模型ID。

points

必需

List<JSONObject>

模型中需配置存储策略的测点列表,以及测点数据压缩配置。详见 测点数据压缩配置

错误码

有关错误码的描述,参见 通用错误码

示例

请求示例

url: https://{apigw-address}/tsdb-policy/v2.1/policies/aa8bbcba-2919-4c78-854c-54984d85d2fa

method: POST

requestBody:
{
   "models": [
      {
         "modelId": "model_1",
         "points": [
            {
               "pointId": "test_point1",
               "sdt": {
                  "compdev": 0.22,
                  "compmax": 2200,
                  "compmin": 22
               },
               "db": {
                  "excdev": 0.11,
                  "excmax": 100,
                  "excmin": 11
               }
            },
            {
               "pointId": "test_point2",
               "sdt": null,
               "db": null
            },
            {
               "pointId": "test_point3",
               "sdt": {
                  "compdev": 0.22,
                  "compmax": 2200,
                  "compmin": 22
               },
               "db": null
            }
         ]
      },
      {
         "modelId": "model_2",
         "points": [
            {
               "pointId": "test_point3",
               "sdt": {
                  "compdev": 0.22,
                  "compmax": 2200,
                  "compmin": 22
               },
               "db": {
                  "excdev": 0.11,
                  "excmax": 1100,
                  "excmin": 11
               }
            }
         ]
      }
   ],
   "retention": "6M"
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "data": null
}

Java SDK调用示例

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;
import org.junit.Before;
import org.junit.Test;

public class Sample {
    private static final String APIM_BASE_URL = "https://{domain_url}";
    private Poseidon poseidon;

    private static class Request extends PoseidonRequest {

        public void setBodyParams(String key, Object value) {
            bodyParams().put(key, value);
        }

        public void setMethod(String method) {
            this.method = method;
        }

        private String method;

        @Override
        public String baseUri() {
            return "";
        }

        @Override
        public String method() {
            return method;
        }
    }

    private static class Point {

        private final String pointId;
        private Sdt sdt;
        private Db db;

        private Point(String pointId) {
            this.pointId = pointId;
        }

        public void setSdt(Sdt sdt) {
            this.sdt = sdt;
        }

        public void setDb(Db db) {
            this.db = db;
        }

        public String getPointId() {
            return pointId;
        }

        public Sdt getSdt() {
            return sdt;
        }

        public Db getDb() {
            return db;
        }

        private static class Sdt {
            private final float compdev;
            private final int compmax;
            private final int compmin;

            public Sdt(float compdev, int compmax, int compmin) {
                this.compdev = compdev;
                this.compmax = compmax;
                this.compmin = compmin;
            }

            public float getCompdev() {
                return compdev;
            }

            public int getCompmax() {
                return compmax;
            }

            public int getCompmin() {
                return compmin;
            }
        }

        private static class Db {
            private final float excdev;
            private final int excmax;
            private final int excmin;

            public Db(float excdev, int excmax, int excmin) {
                this.excdev = excdev;
                this.excmax = excmax;
                this.excmin = excmin;
            }

            public float getExcdev() {
                return excdev;
            }

            public int getExcmax() {
                return excmax;
            }

            public int getExcmin() {
                return excmin;
            }
        }
    }

    @Before public void init() {
        poseidon = Poseidon.config(
                PConfig.init()
                        .appKey("AccessKey of your APP")
                        .appSecret("SecretKey of your APP")
        ).method("POST") .header("Content-Type", "application/json");
    }

    @Test
    public void SaveStoragePolicy() {
        Request request = new Request();

        JSONArray models = new JSONArray();
        JSONObject model1 = new JSONObject();
        model1.put("modelId", "yourModelId1");
        JSONArray points1 = new JSONArray();
        Point point1 = new Point("yourPointId1");
        point1.setSdt(new Point.Sdt(1.1f, 600, 1));
        point1.setDb(new Point.Db(1.1f, 600, 1));
        Point point2 = new Point("yourPointId2");
        point2.setDb(new Point.Db(1.1f, 600, 1));
        points1.add(JSONObject.toJSON(point1));
        points1.add(JSONObject.toJSON(point2));
        model1.put("points", points1);
        models.add(model1);

        JSONObject model2 = new JSONObject();
        model2.put("modelId", "yourModelId2");
        JSONArray points2 = new JSONArray();
        model2.put("points", points2);
        models.add(model2);

        request.setBodyParams("models", models);
        request.setBodyParams("retention", "6M");

        String policyId = "yourPolicyId";
        JSONObject resp = poseidon.url(APIM_BASE_URL + "/tsdb-policy/v2.1/policies/" + policyId)
                .queryParam("orgId", "yourOrgId")
                .getResponse(request, JSONObject.class);

        System.out.println(resp);
    }
}