Save Storage Policy

Update and save the configuration of the specified storage policy, including the data storage time and models and measurement points that are configured with it.

Request Format

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

Request Parameters (Header)

Name Mandatory/Optional Data Type Description
Content-Type Mandatory String Content or file type. The default value is application/json.

Request Parameters (URI)

Name Location (Path/Query) Mandatory/Optional Data Type Description
policyId Path Mandatory String The storage policy ID, which can be retrieved through the EnOS Management Console > Time Series Data Management > Storage Policy page.
orgId Query Mandatory String The organization ID which the asset belongs to. How to get organization ID>>

Request Parameters (Body)

Name Mandatory/Optional Data Type Description
retention Optional String The data storage time. If the models and measurement points already have the storage time configured, this parameter is optional. All supported retention include 1M, 3M, 6M, 1y, 2y, 3y, 5y, 10y, 15y, 20y.
models Mandatory List<JSONObject> The list of models and measurement points. See Model and Point Struct

Model and Point Struct

Name Mandatory/Optional Data Type Description
modelId Mandatory String Model ID.
points Mandatory List<JSONObject> A list of measurement points in the model that need storage policy configuration and point data compression configuration. See Point Compression Configuration

Error Code

For the description of error codes, see Common Error Codes.

Sample

Request Sample

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"
}

Return Sample

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

Java SDK Sample

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);
    }
}