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; }
private void checkMetricInfoAgainstPreparedMessages(MetricInfoListResult metInfo, List<KapuaDataMessage> msgLst) { Set<String> msgMetrics = new HashSet<>(); Set<String> msgClients = new HashSet<>(); Set<String> infoMetrics = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No channel info data!", metInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); for (String tmpMet : tmpMsg.getPayload().getMetrics().keySet()) { msgMetrics.add(tmpMet); } } for (MetricInfo tmpMet : metInfo.getItems()) { infoClients.add(tmpMet.getClientId()); infoMetrics.add(tmpMet.getName()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); assertEquals("The number of topics does not match!", msgMetrics.size(), infoMetrics.size()); for (String tmpMetric : msgMetrics) { assertTrue(String.format("The topic [%s] is not found in the info list!", tmpMetric), infoMetrics.contains(tmpMetric)); } for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
@Then("^Client \"(.+)\" first published a metric in the list \"(.+)\" on \"(.+)\"$") public void checkFirstPublishDateOfClientMetric(String clientId, String lstKey, String date) throws Exception { MetricInfoListResult metList = (MetricInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (MetricInfo tmpMet : metList.getItems()) { if (tmpMet.getClientId().equals(clientId)) { assertEquals(tmpMet.getFirstMessageOn(), tmpCaptured); return; } } fail(String.format("No metric matches the client id [%s]", clientId)); }
@Then("^Client \"(.+)\" last published a metric in the list \"(.+)\" on \"(.+)\"$") public void checkLastPublishDateOfClientMetric(String clientId, String lstKey, String date) throws Exception { MetricInfoListResult metList = (MetricInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (MetricInfo tmpMet : metList.getItems()) { if (tmpMet.getClientId().equals(clientId)) { assertEquals(tmpMet.getLastMessageOn(), tmpCaptured); return; } } fail(String.format("No metric matches the client id [%s]", clientId)); }
/** * 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()); }
TermPredicate clientIdPredicate = storablePredicateFactory.newTermPredicate(MessageField.CLIENT_ID, metricInfo.getClientId()); ExistsPredicate metricPredicate = new ExistsPredicateImpl(MessageField.METRICS.field(), metricInfo.getName()); } 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());