private Map<String, Object> marshalMetricInfo(MetricInfo metricInfo) throws ParseException { Map<String, Object> unmarshalledMetricInfo = new HashMap<>(); unmarshalledMetricInfo.put(MetricInfoSchema.METRIC_SCOPE_ID, metricInfo.getScopeId().toStringId()); unmarshalledMetricInfo.put(MetricInfoSchema.METRIC_CLIENT_ID, metricInfo.getClientId()); unmarshalledMetricInfo.put(MetricInfoSchema.METRIC_CHANNEL, metricInfo.getChannel()); Map<String, Object> unmarshalledMetricValue = new HashMap<>(); unmarshalledMetricValue.put(MetricInfoSchema.METRIC_MTR_NAME, metricInfo.getName()); unmarshalledMetricValue.put(MetricInfoSchema.METRIC_MTR_TYPE, DatastoreUtils.convertToClientMetricType(metricInfo.getMetricType())); unmarshalledMetricValue.put(MetricInfoSchema.METRIC_MTR_TIMESTAMP, KapuaDateUtils.formatDate(metricInfo.getFirstMessageOn())); unmarshalledMetricValue.put(MetricInfoSchema.METRIC_MTR_MSG_ID, metricInfo.getFirstMessageId().toString()); unmarshalledMetricInfo.put(MetricInfoSchema.METRIC_MTR, unmarshalledMetricValue); return unmarshalledMetricInfo; }
/** * Get the metric identifier getting parameters from the metricInfo. Then it calls {@link MetricInfoField#getOrDeriveId(StorableId id, KapuaId scopeId, String clientId, String channel, String * metricName, Class metricType)} * * @param id * @param metricInfo * @return */ public static String getOrDeriveId(StorableId id, MetricInfo metricInfo) { return getOrDeriveId(id, metricInfo.getScopeId(), metricInfo.getClientId(), metricInfo.getChannel(), metricInfo.getName(), metricInfo.getMetricType()); }
ConfigurationException, ClientException { ArgumentValidator.notNull(metricInfo, "metricInfo"); ArgumentValidator.notNull(metricInfo.getScopeId(), "metricInfo.scopeId"); ArgumentValidator.notNull(metricInfo.getFirstMessageId(), "metricInfoCreator.firstPublishedMessageId"); ArgumentValidator.notNull(metricInfo.getFirstMessageOn(), "metricInfoCreator.firstPublishedMessageTimestamp"); MetricInfo storedField = find(metricInfo.getScopeId(), storableId); if (storedField == null) { Metadata metadata = mediator.getMetadata(metricInfo.getScopeId(), metricInfo.getFirstMessageOn().getTime()); String kapuaIndexName = metadata.getRegistryIndexName();
sort.add(SortField.descending(MessageSchema.MESSAGE_TIMESTAMP)); MessageQuery messageQuery = new MessageQueryImpl(metricInfo.getScopeId()); messageQuery.setAskTotalCount(true); messageQuery.setFetchStyle(StorableFetchStyle.FIELDS); } else if (messageList.isEmpty()) { LOG.warn("Cannot find last timestamp for the specified client id '{}' - account '{}'", metricInfo.getClientId(), metricInfo.getScopeId()); } else { LOG.error("Cannot find last timestamp for the specified client id '{}' - account '{}'. More than one result returned by the query!", metricInfo.getClientId(), metricInfo.getScopeId());
MetricInfo storedField = find(metricInfo.getScopeId(), storableId); if (storedField != null) { DatastoreCacheManager.getInstance().getMetricsCache().put(metricInfoId, true); Metadata metadata = mediator.getMetadata(metricInfo.getScopeId(), metricInfo.getFirstMessageOn().getTime()); bulkRequest.add( new UpdateRequest(metricInfo.getId().toString(), new TypeDescriptor(metadata.getRegistryIndexName(), MetricInfoSchema.METRIC_TYPE_NAME), metricInfo));