private Map<String, Object> marshalClientInfo(ClientInfo clientInfo) throws ParseException { Map<String, Object> unmarshalledClientInfo = new HashMap<>(); unmarshalledClientInfo.put(ClientInfoSchema.CLIENT_ID, clientInfo.getClientId()); unmarshalledClientInfo.put(ClientInfoSchema.CLIENT_MESSAGE_ID, clientInfo.getFirstMessageId().toString()); unmarshalledClientInfo.put(ClientInfoSchema.CLIENT_TIMESTAMP, KapuaDateUtils.formatDate(clientInfo.getFirstMessageOn())); unmarshalledClientInfo.put(ClientInfoSchema.CLIENT_SCOPE_ID, clientInfo.getScopeId().toStringId()); return unmarshalledClientInfo; }
@Then("^Client \"(.+)\" last message in the list \"(.+)\" is on \"(.+)\"$") public void checkLastPublishDateForClient(String clientId, String lstKey, String date) throws Exception { ClientInfoListResult cliList = (ClientInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ClientInfo tmpInfo : cliList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpInfo.getLastMessageOn(), tmpCaptured); return; } } fail(String.format("No client info item matches the client id [%s]", clientId)); }
private ClientInfo unmarshalClientInfo(Map<String, Object> clientInfoMap) throws DatamodelMappingException, JsonParseException, JsonMappingException, IOException, ParseException { KapuaId scopeId = new KapuaEid(new BigInteger((String) clientInfoMap.get(ClientInfoSchema.CLIENT_SCOPE_ID))); ClientInfo clientInfo = new ClientInfoImpl(scopeId); String id = (String) clientInfoMap.get(ModelContext.DATASTORE_ID_KEY); clientInfo.setId(new StorableIdImpl(id)); clientInfo.setClientId((String) clientInfoMap.get(ClientInfoSchema.CLIENT_ID)); clientInfo.setFirstMessageId(new StorableIdImpl((String) clientInfoMap.get(ClientInfoSchema.CLIENT_MESSAGE_ID))); clientInfo.setFirstMessageOn(KapuaDateUtils.parseDate((String) clientInfoMap.get(ClientInfoSchema.CLIENT_TIMESTAMP))); return clientInfo; }
/** * Get the client identifier (combining accountName and clientId).<br> * <b>If the id is null then it is generated</b> * * @param id * @param clientInfo * @return */ public static String getOrDeriveId(StorableId id, ClientInfo clientInfo) { return getOrDeriveId(id, clientInfo.getScopeId(), clientInfo.getClientId()); }
sort.add(SortField.descending(MessageSchema.MESSAGE_TIMESTAMP)); MessageQuery messageQuery = new MessageQueryImpl(clientInfo.getScopeId()); messageQuery.setAskTotalCount(true); messageQuery.setFetchStyle(StorableFetchStyle.FIELDS); messageQuery.setSortFields(sort); RangePredicate messageIdPredicate = new RangePredicateImpl(new StorableFieldImpl(ClientInfoSchema.CLIENT_TIMESTAMP), clientInfo.getFirstMessageOn(), null); TermPredicate clientIdPredicate = storablePredicateFactory.newTermPredicate(MessageField.CLIENT_ID, clientInfo.getClientId()); } else if (messageList.isEmpty()) { LOG.warn("Cannot find last timestamp for the specified client id '{}' - account '{}'", clientInfo.getScopeId(), clientInfo.getClientId()); } else { LOG.error("Cannot find last timestamp for the specified client id '{}' - account '{}'. More than one result returned by the query!", clientInfo.getScopeId(), clientInfo.getClientId()); clientInfo.setLastMessageId(lastPublishedMessageId); clientInfo.setLastMessageOn(lastPublishedMessageTimestamp);
@Then("^Client \"(.+)\" first message in the list \"(.+)\" is on \"(.+)\"$") public void checkFirstPublishDateForClient(String clientId, String lstKey, String date) throws Exception { ClientInfoListResult cliList = (ClientInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ClientInfo tmpInfo : cliList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpInfo.getFirstMessageOn(), tmpCaptured); return; } } fail(String.format("No client info item matches the client id [%s]", clientId)); }
private void isClientForFirstMessageInStoreOK(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(ClientInfoField.CLIENT_ID, tmpClId)); ClientInfoQuery clientInfoQuery = DatastoreQueryFactory.createBaseClientInfoQuery(tmpAccId, 100); clientInfoQuery.setPredicate(andPredicate); clientInfoQuery.addFetchAttributes(ClientInfoField.TIMESTAMP.field()); ClientInfoListResult clientInfoList = clientInfoRegistryService.query(clientInfoQuery); assertNotNull("Cannot find the client info registry!", clientInfoList); assertNotEquals("Cannot find the client info registry!", clientInfoList.getSize(), 0); assertNotNull("Cannot find the client info registry!", clientInfoList.getFirstItem()); assertEquals("Wrong client info message id!", clientInfoList.getFirstItem().getFirstMessageId(), msgId); assertEquals("Wrong client info message on!", clientInfoList.getFirstItem().getFirstMessageOn(), storedOn); }
@When("^I delete all clients from the list \"(.*)\"$") public void deleteAllClientsFromList(String lstKey) throws KapuaException { Account account = (Account) stepData.get("LastAccount"); ClientInfoListResult tmpList = (ClientInfoListResult) stepData.get(lstKey); for (ClientInfo tmpItem : tmpList.getItems()) { clientInfoRegistryServiceProxy.delete(account.getId(), tmpItem.getId()); } }
private void checkClientInfoAgainstPreparedMessages(ClientInfoListResult cliInfo, List<KapuaDataMessage> msgLst) { Set<String> msgClients = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No client info data!", cliInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); } for (ClientInfo tmpClient : cliInfo.getItems()) { infoClients.add(tmpClient.getClientId()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
@When("^I delete client number (\\d+) from the list \"(.*)\"$") public void deleteClientFromList(int index, String lstKey) throws KapuaException { Account account = (Account) stepData.get("LastAccount"); ClientInfoListResult tmpList = (ClientInfoListResult) stepData.get(lstKey); clientInfoRegistryServiceProxy.delete(account.getId(), tmpList.getItem(index).getId()); }
ConfigurationException, ClientException { ArgumentValidator.notNull(clientInfo, "clientInfo"); ArgumentValidator.notNull(clientInfo.getScopeId(), "clientInfo.scopeId"); ArgumentValidator.notNull(clientInfo.getFirstMessageId(), "clientInfo.firstPublishedMessageId"); ArgumentValidator.notNull(clientInfo.getFirstMessageOn(), "clientInfo.firstPublishedMessageTimestamp"); String clientInfoId = ClientInfoField.getOrDeriveId(clientInfo.getId(), clientInfo); StorableId storableId = new StorableIdImpl(clientInfoId); if (!DatastoreCacheManager.getInstance().getClientsCache().get(clientInfo.getClientId())) { if (!DatastoreCacheManager.getInstance().getClientsCache().get(clientInfo.getClientId())) { ClientInfo storedField = find(clientInfo.getScopeId(), storableId); if (storedField == null) { Metadata metadata = mediator.getMetadata(clientInfo.getScopeId(), clientInfo.getFirstMessageOn().getTime()); String kapuaIndexName = metadata.getRegistryIndexName(); UpdateRequest request = new UpdateRequest(clientInfo.getId().toString(), new TypeDescriptor(kapuaIndexName, ClientInfoSchema.CLIENT_TYPE_NAME), clientInfo); response = client.upsert(request); DatastoreCacheManager.getInstance().getClientsCache().put(clientInfo.getClientId(), true);
String id = clients.getResult().get(i).getId().toString(); if (clientsCache.get(id)) { clientsCache.remove(id);