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("^There (?:is|are) exactly (\\d+) metric(?:|s) in the list \"(.*)\"$") public void checkNumberOfQueriedMetrics(int cnt, String lstKey) { MetricInfoListResult tmpResults = (MetricInfoListResult) stepData.get(lstKey); assertEquals(cnt, tmpResults.getSize()); }
@Then("^I get empty metric info list result$") public void getEmptyMetricInfoListResult() { MetricInfoListResult result = (MetricInfoListResult) stepData.get("metricInfoListResult"); assertTrue(result.isEmpty()); }
private void isMetricForFirstMessageInStoreOK(StorableId msgId, Date storedOn) throws KapuaException { KapuaId tmpAccId = ((Account) stepData.get("LastAccount")).getId(); String tmpClId = ((Device) stepData.get("LastDevice")).getClientId(); AndPredicate andPredicate = new AndPredicateImpl(); andPredicate.getPredicates().add(new TermPredicateImpl(MetricInfoField.CLIENT_ID, tmpClId)); MetricInfoQuery metricInfoQuery = DatastoreQueryFactory.createBaseMetricInfoQuery(tmpAccId, 100); metricInfoQuery.setPredicate(andPredicate); metricInfoQuery.addFetchAttributes(MetricInfoField.TIMESTAMP_FULL.field()); MetricInfoListResult metricInfoList = metricInfoRegistryService.query(metricInfoQuery); assertNotNull("Cannot find the metric info registry!", metricInfoList); assertNotEquals("Cannot find the metric info registry!", metricInfoList.getSize(), 0); assertNotNull("Cannot find the metric info registry!", metricInfoList.getFirstItem()); assertEquals("Wrong metric info message id!", metricInfoList.getFirstItem().getFirstMessageId(), msgId); assertEquals("Wrong metric info message on!", metricInfoList.getFirstItem().getFirstMessageOn(), storedOn); }
/** * Find metric information by identifier * * @param scopeId * @param id * @return * @throws KapuaIllegalArgumentException * @throws ConfigurationException * @throws QueryMappingException * @throws ClientException */ public MetricInfo find(KapuaId scopeId, StorableId id) throws KapuaIllegalArgumentException, ConfigurationException, QueryMappingException, ClientException { ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(id, "id"); MetricInfoQueryImpl idsQuery = new MetricInfoQueryImpl(scopeId); idsQuery.setLimit(1); IdsPredicateImpl idsPredicate = new IdsPredicateImpl(MetricInfoSchema.METRIC_TYPE_NAME); idsPredicate.addValue(id); idsQuery.setPredicate(idsPredicate); MetricInfoListResult result = query(idsQuery); return result.getFirstItem(); }
@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); } }