Skip to content

Package: MetricInfoSchema

MetricInfoSchema

nameinstructionbranchcomplexitylinemethod
getMetricTypeSchema(boolean)
M: 271 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 28 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.datastore.internal.schema;
14:
15: import org.eclipse.kapua.service.datastore.internal.mediator.DatastoreUtils;
16: import org.eclipse.kapua.service.datastore.model.MetricInfo;
17: import org.eclipse.kapua.service.elasticsearch.client.SchemaKeys;
18: import org.eclipse.kapua.service.storable.exception.MappingException;
19: import org.eclipse.kapua.service.storable.model.utils.KeyValueEntry;
20: import org.eclipse.kapua.service.storable.model.utils.MappingUtils;
21:
22: import com.fasterxml.jackson.databind.JsonNode;
23: import com.fasterxml.jackson.databind.node.ObjectNode;
24:
25: /**
26: * {@link MetricInfo} schema definition.
27: *
28: * @since 1.0.0
29: */
30: public class MetricInfoSchema {
31:
32: /**
33: * @since 1.0.0
34: */
35: private MetricInfoSchema() {
36: }
37:
38: /**
39: * Metric information schema name
40: *
41: * @since 1.0.0
42: */
43: public static final String METRIC_TYPE_NAME = "metric";
44:
45: /**
46: * Metric information - channel
47: *
48: * @since 1.0.0
49: */
50: public static final String METRIC_CHANNEL = "channel";
51:
52: /**
53: * Metric information - client identifier
54: *
55: * @since 1.0.0
56: */
57: public static final String METRIC_CLIENT_ID = "client_id";
58:
59: /**
60: * Metric information - scope id
61: *
62: * @since 1.0.0
63: */
64: public static final String METRIC_SCOPE_ID = "scope_id";
65:
66: /**
67: * Metric information - metric map prefix
68: *
69: * @since 1.0.0
70: */
71: public static final String METRIC_MTR = "metric";
72:
73: /**
74: * Metric information - name
75: *
76: * @since 1.0.0
77: */
78: public static final String METRIC_MTR_NAME = "name";
79:
80: /**
81: * Metric information - full name (so with the metric type suffix)
82: *
83: * @since 1.0.0
84: */
85: public static final String METRIC_MTR_NAME_FULL = "metric.name";
86:
87: /**
88: * Metric information - type
89: *
90: * @since 1.0.0
91: */
92: public static final String METRIC_MTR_TYPE = "type";
93:
94: /**
95: * Metric information - full type (so with the metric type suffix)
96: *
97: * @since 1.0.0
98: */
99: public static final String METRIC_MTR_TYPE_FULL = "metric.type";
100:
101: /**
102: * Metric information - value
103: *
104: * @since 1.0.0
105: */
106: public static final String METRIC_MTR_VALUE = "value";
107:
108: /**
109: * Metric information - full value (so with the metric type suffix)
110: *
111: * @since 1.0.0
112: */
113: public static final String METRIC_MTR_VALUE_FULL = "metric.value";
114:
115: /**
116: * Metric information - message timestamp (of the first message published in this channel)
117: *
118: * @since 1.0.0
119: */
120: public static final String METRIC_MTR_TIMESTAMP = "timestamp";
121:
122: /**
123: * Metric information - message timestamp (of the first message published in this channel, with the metric type suffix)
124: *
125: * @since 1.0.0
126: */
127: public static final String METRIC_MTR_TIMESTAMP_FULL = "metric.timestamp";
128:
129: /**
130: * Metric information - message identifier (of the first message published in this channel)
131: *
132: * @since 1.0.0
133: */
134: public static final String METRIC_MTR_MSG_ID = "message_id";
135:
136: /**
137: * Metric information - full message identifier (of the first message published in this channel, with the metric type suffix)
138: *
139: * @since 1.0.0
140: */
141: public static final String METRIC_MTR_MSG_ID_FULL = "metric.message_id";
142:
143: /**
144: * Create and return the Json representation of the metric info schema
145: *
146: * @param sourceEnable
147: * @return
148: * @throws MappingException
149: * @since 1.0.0
150: */
151: public static JsonNode getMetricTypeSchema(boolean sourceEnable) throws MappingException {
152:
153: ObjectNode metricNode = MappingUtils.newObjectNode();
154:
155: ObjectNode sourceMetric = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_ENABLED, sourceEnable) });
156: metricNode.set(SchemaKeys.KEY_SOURCE, sourceMetric);
157:
158: ObjectNode propertiesNode = MappingUtils.newObjectNode();
159: {
160: ObjectNode metricAccount = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
161: propertiesNode.set(METRIC_SCOPE_ID, metricAccount);
162:
163: ObjectNode metricClientId = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
164: propertiesNode.set(METRIC_CLIENT_ID, metricClientId);
165:
166: ObjectNode metricChannel = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
167: propertiesNode.set(METRIC_CHANNEL, metricChannel);
168:
169: ObjectNode metricMtrNode = MappingUtils.newObjectNode(
170: new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_OBJECT), new KeyValueEntry(SchemaKeys.KEY_ENABLED, true),
171: new KeyValueEntry(SchemaKeys.KEY_DYNAMIC, false) });
172: ObjectNode metricMtrPropertiesNode = MappingUtils.newObjectNode();
173: {
174: ObjectNode metricMtrNameNode = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
175: metricMtrPropertiesNode.set(METRIC_MTR_NAME, metricMtrNameNode);
176:
177: ObjectNode metricMtrTypeNode = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
178: metricMtrPropertiesNode.set(METRIC_MTR_TYPE, metricMtrTypeNode);
179:
180: ObjectNode metricMtrValueNode = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
181: metricMtrPropertiesNode.set(METRIC_MTR_VALUE, metricMtrValueNode);
182:
183: ObjectNode metricMtrTimestampNode = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_DATE), new KeyValueEntry(SchemaKeys.KEY_FORMAT, DatastoreUtils.DATASTORE_DATE_FORMAT) });
184: metricMtrPropertiesNode.set(METRIC_MTR_TIMESTAMP, metricMtrTimestampNode);
185:
186: ObjectNode metricMtrMsgIdNode = MappingUtils.newObjectNode(new KeyValueEntry[]{ new KeyValueEntry(SchemaKeys.KEY_TYPE, SchemaKeys.TYPE_KEYWORD), new KeyValueEntry(SchemaKeys.KEY_INDEX, SchemaKeys.VALUE_TRUE) });
187: metricMtrPropertiesNode.set(METRIC_MTR_MSG_ID, metricMtrMsgIdNode);
188: }
189: metricMtrNode.set(SchemaKeys.FIELD_NAME_PROPERTIES, metricMtrPropertiesNode);
190:
191: propertiesNode.set(METRIC_MTR, metricMtrNode);
192: }
193: metricNode.set(SchemaKeys.FIELD_NAME_PROPERTIES, propertiesNode);
194:
195: return metricNode;
196: }
197:
198: }