Skip to content

Package: MetricInfoField

MetricInfoField

nameinstructionbranchcomplexitylinemethod
MetricInfoField(String, int, String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
field()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getOrDeriveId(StorableId, KapuaId, String, String, String, Class)
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getOrDeriveId(StorableId, MetricInfo)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getOrDeriveId(StorableId, MetricInfoCreator)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 92 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 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.mediator;
14:
15: import org.eclipse.kapua.model.id.KapuaId;
16: import org.eclipse.kapua.service.datastore.internal.schema.MetricInfoSchema;
17: import org.eclipse.kapua.service.datastore.model.MetricInfo;
18: import org.eclipse.kapua.service.datastore.model.MetricInfoCreator;
19: import org.eclipse.kapua.service.storable.model.id.StorableId;
20: import org.eclipse.kapua.service.storable.model.query.StorableField;
21:
22: /**
23: * This enumeration defines the fields names used in the {@link MetricInfo} client schema
24: *
25: * @since 1.0.0
26: */
27: public enum MetricInfoField implements StorableField {
28: /**
29: * Account name
30: *
31: * @since 1.0.0
32: */
33: SCOPE_ID(MetricInfoSchema.METRIC_SCOPE_ID),
34:
35: /**
36: * Client identifier
37: *
38: * @since 1.0.0
39: */
40: CLIENT_ID(MetricInfoSchema.METRIC_CLIENT_ID),
41:
42: /**
43: * Channel
44: *
45: * @since 1.0.0
46: */
47: CHANNEL(MetricInfoSchema.METRIC_CHANNEL),
48:
49: /**
50: * Full metric name (so with the metric type suffix)
51: *
52: * @since 1.0.0
53: */
54: NAME_FULL(MetricInfoSchema.METRIC_MTR_NAME_FULL),
55:
56: /**
57: * Metric type full name (not the acronym)
58: *
59: * @since 1.0.0
60: */
61: TYPE_FULL(MetricInfoSchema.METRIC_MTR_TYPE_FULL),
62:
63: /**
64: * Metric timestamp (derived from the message that published the metric)
65: *
66: * @since 1.3.0
67: */
68: TIMESTAMP(MetricInfoSchema.METRIC_MTR_TIMESTAMP),
69:
70: /**
71: * Metric timestamp (derived from the message that published the metric)
72: *
73: * @since 1.0.0
74: */
75: TIMESTAMP_FULL(MetricInfoSchema.METRIC_MTR_TIMESTAMP_FULL),
76:
77:
78: /**
79: * Message identifier
80: *
81: * @since 1.0.0
82: */
83: MESSAGE_ID_FULL(MetricInfoSchema.METRIC_MTR_MSG_ID_FULL);
84:
85: private String field;
86:
87: private MetricInfoField(String name) {
88: this.field = name;
89: }
90:
91: @Override
92: public String field() {
93: return field;
94: }
95:
96: /**
97: * Get the metric identifier (return the hash code of the string obtained by combining accountName, clientId, channel and the converted metricName and metricType).<br>
98: * <b>If the id is null then it is generated.</b>
99: *
100: * @param id
101: * @param scopeId
102: * @param clientId
103: * @param channel
104: * @param metricName
105: * @param metricType
106: * @return
107: */
108: private static String getOrDeriveId(StorableId id, KapuaId scopeId, String clientId, String channel, String metricName, Class<?> metricType) {
109:• if (id == null) {
110: String metricMappedName = DatastoreUtils.getMetricValueQualifier(metricName, DatastoreUtils.convertToClientMetricType(metricType));
111:
112: return DatastoreUtils.getHashCode(scopeId.toCompactId(), clientId, channel, metricMappedName);
113: } else {
114: return id.toString();
115: }
116: }
117:
118: /**
119: * Get the metric identifier getting parameters from the metricInfoCreator. Then it calls {@link MetricInfoField#getOrDeriveId(StorableId id, KapuaId scopeId, String clientId, String channel, String
120: * metricName, Class metricType)}
121: *
122: * @param id
123: * @param metricInfoCreator
124: * @return
125: */
126: public static String getOrDeriveId(StorableId id, MetricInfoCreator metricInfoCreator) {
127: return getOrDeriveId(id,
128: metricInfoCreator.getScopeId(),
129: metricInfoCreator.getClientId(),
130: metricInfoCreator.getChannel(),
131: metricInfoCreator.getName(),
132: metricInfoCreator.getMetricType());// use short me
133: }
134:
135: /**
136: * Get the metric identifier getting parameters from the metricInfo. Then it calls {@link MetricInfoField#getOrDeriveId(StorableId id, KapuaId scopeId, String clientId, String channel, String
137: * metricName, Class metricType)}
138: *
139: * @param id
140: * @param metricInfo
141: * @return
142: */
143: public static String getOrDeriveId(StorableId id, MetricInfo metricInfo) {
144: return getOrDeriveId(id,
145: metricInfo.getScopeId(),
146: metricInfo.getClientId(),
147: metricInfo.getChannel(),
148: metricInfo.getName(),
149: metricInfo.getMetricType());
150: }
151:
152: }