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("^The metric \"(.+)\" was last published in the list \"(.+)\" on \"(.+)\"$") public void checkLastPublishDateOfMetricInList(String metric, String lstKey, String date) throws Exception { MetricInfoListResult metList = (MetricInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (MetricInfo tmpMet : metList.getItems()) { if (tmpMet.getName().equals(metric)) { assertEquals(tmpMet.getLastMessageOn(), tmpCaptured); return; } } fail(String.format("There is no metric [%s]", metric)); }
@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)); }
@Then("^The metric \"(.+)\" was first published in the list \"(.+)\" on \"(.+)\"$") public void checkFirstPublishDateOfMetricInList(String metric, String lstKey, String date) throws Exception { MetricInfoListResult metList = (MetricInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (MetricInfo tmpMet : metList.getItems()) { if (tmpMet.getName().equals(metric)) { assertEquals(tmpMet.getFirstMessageOn(), tmpCaptured); return; } } fail(String.format("There is no metric [%s]", metric)); }
@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)); }
@When("^I delete all metrics from the list \"(.*)\"$") public void deleteAllMetricsFromList(String lstKey) throws KapuaException { Account account = (Account) stepData.get("LastAccount"); MetricInfoListResult tmpList = (MetricInfoListResult) stepData.get(lstKey); for (MetricInfo tmpItem : tmpList.getItems()) { metricInfoRegistryServiceProxy.delete(account.getId(), tmpItem.getId()); } }
@Override public MetricInfoListResult query(MetricInfoQuery query) throws KapuaException { ArgumentValidator.notNull(query, "query"); ArgumentValidator.notNull(query.getScopeId(), "query.scopeId"); checkDataAccess(query.getScopeId(), Actions.read); try { MetricInfoListResult result = metricInfoRegistryFacade.query(query); if (result != null && query.getFetchAttributes().contains(MetricInfoField.TIMESTAMP_FULL.field())) { // populate the lastMessageTimestamp for (MetricInfo metricInfo : result.getItems()) { updateLastPublishedFields(metricInfo); } } return result; } catch (Exception e) { throw KapuaException.internalError(e); } }