@Override public String marshal(StorableId v) throws Exception { return v.toString(); }
@Override public String marshal(StorableId v) throws Exception { return v.toString(); }
/** * Stores a new Message under the account of the currently connected user. * In this case, the provided message will only be stored in the back-end * database and it will not be forwarded to the message broker. * * @param message The {@link KapuaDataMessage } to be stored * @return an {@link InsertResponse} object encapsulating the response from * the datastore * @throws Exception Whenever something bad happens. See specific * {@link KapuaService} exceptions. */ @POST @Consumes({ MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_XML }) @ApiOperation(nickname = "dataMessageStore", value = "Stores a new KapuaDataMessage", // notes = "Stores a new KapuaDataMessage under the account of the currently connected user. In this case, the provided message will only be stored in the back-end database and it will not be forwarded to the message broker.", // response = StorableId.class) public StorableEntityId storeMessage( @ApiParam(value = "The ScopeId in which to store the message", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId,// @ApiParam(value = "The KapuaDataMessage to be stored") KapuaDataMessage message) throws Exception { message.setScopeId(scopeId); return new StorableEntityId(MESSAGE_STORE_SERVICE.store(message).toString()); }
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; }
/** * Get the client identifier (combining accountName and clientId).<br> * <b>If the id is null then it is generated</b> * * @param id * @param scopeId * @param clientId * @return */ public static String getOrDeriveId(StorableId id, KapuaId scopeId, String clientId) { if (id == null) { return DatastoreUtils.getHashCode(scopeId.toCompactId(), clientId); } else { return id.toString(); } }
private Map<String, Object> marshalChannelInfo(ChannelInfo channelInfo) throws ParseException { Map<String, Object> unmarshalledChannelInfo = new HashMap<>(); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_NAME, channelInfo.getName()); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_TIMESTAMP, KapuaDateUtils.formatDate(channelInfo.getFirstMessageOn())); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_CLIENT_ID, channelInfo.getClientId()); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_SCOPE_ID, channelInfo.getScopeId().toStringId()); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_MESSAGE_ID, channelInfo.getFirstMessageId().toString()); return unmarshalledChannelInfo; }
/** * Get the channel identifier (combining accountName clientId and c).<br> * <b>If the id is null then it is generated</b> * * @param id * @param scopeId * @param clientId * @param channel * @return */ private static String getOrDeriveId(StorableId id, KapuaId scopeId, String clientId, String channel) { if (id == null) { return DatastoreUtils.getHashCode(scopeId.toCompactId(), clientId, channel); } else { return id.toString(); } }
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; }
@Override /** * <pre> * { * "query": { * "ids" : { * "type" : "kapua_id", * "values" : ["abcdef1234", "abcdef1235", "zzzyyyy1234"] * } * } * } * </pre> */ public ObjectNode toSerializedMap() { ObjectNode rootNode = SchemaUtil.getObjectNode(); ObjectNode idsNode = SchemaUtil.getObjectNode(); ArrayNode idsList = SchemaUtil.getArrayNode(); for (StorableId id : idSet) { idsList.add(id.toString()); } idsNode.set(PredicateConstants.TYPE_KEY, SchemaUtil.getTextNode(type)); idsNode.set(PredicateConstants.VALUES_KEY, idsList); rootNode.set(PredicateConstants.IDS_KEY, idsNode); return rootNode; }
node.set(name, FACTORY.textNode(((StorableId) value).toString())); } else { throw new DatamodelMappingException(String.format(UNSUPPORTED_OBJECT_TYPE_ERROR_MSG, value != null ? value.getClass() : "null"));
/** * Get the metric identifier (return the hash code of the string obtained by combining accountName, clientId, channel and the converted metricName and metricType).<br> * <b>If the id is null then it is generated.</b> * * @param id * @param scopeId * @param clientId * @param channel * @param metricName * @param metricType * @return */ private static String getOrDeriveId(StorableId id, KapuaId scopeId, String clientId, String channel, String metricName, Class<?> metricType) { if (id == null) { String metricMappedName = DatastoreUtils.getMetricValueQualifier(metricName, DatastoreUtils.convertToClientMetricType(metricType)); return DatastoreUtils.getHashCode(scopeId.toCompactId(), clientId, channel, metricMappedName); } else { return id.toString(); } }
String indexName = schemaMetadata.getDataIndexName(); TypeDescriptor typeDescriptor = new TypeDescriptor(indexName, MessageSchema.MESSAGE_TYPE_NAME); client.delete(typeDescriptor, id.toString()); } else { logger.warn("Cannot find the message to be deleted. scopeId: '{}' - id: '{}'", scopeId, id);
/** * Delete client information by identifier.<br> * <b>Be careful using this function since it doesn't guarantee the datastore consistency.<br> * It just deletes the client info registry entry by id without checking the consistency of the others registries or the message store.</b> * * @param scopeId * @param id * @throws KapuaIllegalArgumentException * @throws ConfigurationException * @throws ClientException */ public void delete(KapuaId scopeId, StorableId id) throws KapuaIllegalArgumentException, ConfigurationException, ClientException { ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(id, "id"); MessageStoreConfiguration accountServicePlan = configProvider.getConfiguration(scopeId); long ttl = accountServicePlan.getDataTimeToLiveMilliseconds(); if (!accountServicePlan.getDataStorageEnabled() || ttl == MessageStoreConfiguration.DISABLED) { logger.debug("Storage not enabled for account {}, return", scopeId); return; } String indexName = SchemaUtil.getKapuaIndexName(scopeId); TypeDescriptor typeDescriptor = new TypeDescriptor(indexName, ClientInfoSchema.CLIENT_TYPE_NAME); client.delete(typeDescriptor, id.toString()); }
/** * Delete metric information by identifier.<br> * <b>Be careful using this function since it doesn't guarantee the datastore consistency.<br> * It just deletes the metric info registry entry by id without checking the consistency of the others registries or the message store.</b> * * @param scopeId * @param id * @throws KapuaIllegalArgumentException * @throws ConfigurationException * @throws ClientException */ public void delete(KapuaId scopeId, StorableId id) throws KapuaIllegalArgumentException, ConfigurationException, ClientException { ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(id, "id"); MessageStoreConfiguration accountServicePlan = configProvider.getConfiguration(scopeId); long ttl = accountServicePlan.getDataTimeToLiveMilliseconds(); if (!accountServicePlan.getDataStorageEnabled() || ttl == MessageStoreConfiguration.DISABLED) { logger.debug("Storage not enabled for account {}, return", scopeId); return; } String indexName = SchemaUtil.getKapuaIndexName(scopeId); TypeDescriptor typeDescriptor = new TypeDescriptor(indexName, MetricInfoSchema.METRIC_TYPE_NAME); client.delete(typeDescriptor, id.toString()); }
mediator.onBeforeChannelInfoDelete(channelInfo); TypeDescriptor typeDescriptor = new TypeDescriptor(indexName, ChannelInfoSchema.CHANNEL_TYPE_NAME); client.delete(typeDescriptor, id.toString());
InsertRequest insertRequest = new InsertRequest(messageToStore.getDatastoreId().toString(), typeDescriptor, messageToStore);
String kapuaIndexName = metadata.getRegistryIndexName(); UpdateRequest request = new UpdateRequest(metricInfo.getId().toString(), new TypeDescriptor(metadata.getRegistryIndexName(), MetricInfoSchema.METRIC_TYPE_NAME), metricInfo); response = client.upsert(request);
String id = metrics.getResult().get(i).getId().toString(); if (metricsCache.get(id)) { metricsCache.remove(id); String id = channels.getResult().get(0).getId().toString(); if (channelsCache.get(id)) { channelsCache.remove(id); String id = clients.getResult().get(i).getId().toString(); if (clientsCache.get(id)) { clientsCache.remove(id);
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));
String registryIndexName = metadata.getRegistryIndexName(); UpdateRequest request = new UpdateRequest(channelInfo.getId().toString(), new TypeDescriptor(metadata.getRegistryIndexName(), ChannelInfoSchema.CHANNEL_TYPE_NAME), channelInfo); response = client.upsert(request);