@Override public String replayAsyncSince(String apiKey, String subscription, Date since) { checkNotNull(subscription, "subscription"); try { UriBuilder uriBuilder = _databus.clone().segment(subscription, "replay"); if (since != null) { SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"); dateFmt.setTimeZone(TimeZone.getTimeZone("UTC")); uriBuilder.queryParam("since", dateFmt.format(since)); } URI uri = uriBuilder.build(); Map<String, Object> response = _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(new TypeReference<Map<String, Object>>(){}, null); return response.get("id").toString(); } catch (EmoClientException e) { throw convertException(e); } }
protected String doMoveAsync(String apiKey, String from, String to) { checkNotNull(from, "from"); checkNotNull(to, "to"); try { URI uri = _queueService.clone() .segment("_move") .queryParam("from", from) .queryParam("to", to) .build(); Map<String, Object> response = _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(new TypeReference<Map<String, Object>>(){}, null); return response.get("id").toString(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void injectEvent(String apiKey, String subscription, String table, String key) { checkNotNull(subscription, "subscription"); checkNotNull(table, "table"); checkNotNull(key, "key"); try { URI uri = _databus.clone() .segment(subscription, "inject") .queryParam("table", table) .queryParam("key", key) .build(); _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public String moveAsync(String apiKey, String from, String to) { checkNotNull(from, "from"); checkNotNull(to, "to"); try { URI uri = _databus.clone() .segment("_move") .queryParam("from", from) .queryParam("to", to) .build(); Map<String, Object> response = _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(new TypeReference<Map<String, Object>>(){}, null); return response.get("id").toString(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void compact(String apiKey, String table, String key, @Nullable Duration ttlOverride, ReadConsistency readConsistency, WriteConsistency writeConsistency) { checkNotNull(table, "table"); checkNotNull(key, "key"); checkNotNull(readConsistency, "readConsistency"); checkNotNull(writeConsistency, "writeConsistency"); try { Integer ttlOverrideSeconds = (ttlOverride != null) ? Ttls.toSeconds(ttlOverride, 0, Integer.MAX_VALUE) : null; URI uri = _dataStore.clone() .segment(table, key, "compact") .queryParam("ttl", (ttlOverrideSeconds != null) ? new Object[]{ttlOverrideSeconds} : new Object[0]) .queryParam("readConsistency", readConsistency) .queryParam("writeConsistency", writeConsistency) .build(); _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void updateStashTime(String id, long timestamp, List<String> placements, long expiredTimestamp, String dataCenter) { checkNotNull(id, "id"); checkNotNull(placements, "placements"); checkNotNull(dataCenter, "dataCenter"); try { UriBuilder uriBuilder = _compactionControlSource.clone() .segment("_compcontrol", "stash-time", id) .queryParam("timestamp", timestamp) .queryParam("expiredTimestamp", expiredTimestamp) .queryParam("dataCenter", dataCenter); for (String placement : placements) { uriBuilder.queryParam("placement", placement); } URI uri = uriBuilder.build(); _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, _apiKey) .post(); } catch (UniformInterfaceException e) { throw convertException(e); } }
protected void doUnclaimAll(String apiKey, String queue) { checkNotNull(queue, "queue"); try { URI uri = _queueService.clone() .segment(queue, "unclaimall") .queryParam("partitioned", _partitionSafe) .build(); _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(); } catch (EmoClientException e) { throw convertException(e); } }
protected void doRenew(String apiKey, String queue, Collection<String> messageIds, Duration claimTtl) { checkNotNull(queue, "queue"); checkNotNull(messageIds, "messageIds"); checkNotNull(claimTtl, "claimTtl"); try { URI uri = _queueService.clone() .segment(queue, "renew") .queryParam("ttl", Ttls.toSeconds(claimTtl, 0, Integer.MAX_VALUE)) .queryParam("partitioned", _partitionSafe) .build(); _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(messageIds); } catch (EmoClientException e) { throw convertException(e); } }
protected void doAcknowledge(String apiKey, String queue, Collection<String> messageIds) { checkNotNull(queue, "queue"); checkNotNull(messageIds, "messageIds"); try { URI uri = _queueService.clone() .segment(queue, "ack") .queryParam("partitioned", _partitionSafe) .build(); _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(messageIds); } catch (EmoClientException e) { throw convertException(e); } }
private void update(String apiKey, String table, String key, UUID changeId, Delta delta, Audit audit, WriteConsistency consistency, boolean facade, Set<String> tags) { checkNotNull(table, "table"); checkNotNull(key, "key"); checkNotNull(delta, "delta"); checkNotNull(audit, "audit"); checkNotNull(consistency, "consistency"); try { UriBuilder uriBuilder = _dataStore.clone() .segment(facade ? "_facade" : "", table, key) .queryParam("changeId", (changeId != null) ? changeId : TimeUUIDs.newUUID()) .queryParam("audit", RisonHelper.asORison(audit)) .queryParam("consistency", consistency); for(String tag : tags) { uriBuilder.queryParam("tag", tag); } _client.resource(uriBuilder.build()) .type(APPLICATION_X_JSON_DELTA_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(delta.toString()); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void unclaimAll(String apiKey, @PartitionKey String subscription) { checkNotNull(subscription, "subscription"); try { URI uri = _databus.clone() .segment(subscription, "unclaimall") .queryParam("partitioned", _partitionSafe) .build(); _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void renew(String apiKey, @PartitionKey String subscription, Collection<String> eventKeys, Duration claimTtl) { checkNotNull(subscription, "subscription"); checkNotNull(eventKeys, "eventKeys"); checkNotNull(claimTtl, "claimTtl"); try { URI uri = _databus.clone() .segment(subscription, "renew") .queryParam("ttl", Ttls.toSeconds(claimTtl, 0, Integer.MAX_VALUE)) .queryParam("partitioned", _partitionSafe) .build(); _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(eventKeys); } catch (EmoClientException e) { throw convertException(e); } }
public void sendAll(String apiKey, String queue, Collection<?> messages) { checkNotNull(queue, "queue"); checkNotNull(messages, "messages"); if (messages.isEmpty()) { return; } try { URI uri = _queueService.clone() .segment(queue, "sendbatch") .build(); _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(messages); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void acknowledge(String apiKey, @PartitionKey String subscription, Collection<String> eventKeys) { checkNotNull(subscription, "subscription"); checkNotNull(eventKeys, "eventKeys"); try { URI uri = _databus.clone() .segment(subscription, "ack") .queryParam("partitioned", _partitionSafe) .build(); _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(eventKeys); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void purge(String apiKey, @PartitionKey String subscription) { checkNotNull(subscription, "subscription"); try { URI uri = _databus.clone() .segment(subscription, "purge") .queryParam("partitioned", _partitionSafe) .build(); _client.resource(uri) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void purgeTableUnsafe(String apiKey, String table, Audit audit) { checkNotNull(table, "table"); checkNotNull(audit, "audit"); URI uri = _blobStore.clone() .segment("_table", table, "purge") .queryParam("audit", RisonHelper.asORison(audit)) .build(); try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void purgeTableUnsafe(String apiKey, String table, Audit audit) { checkNotNull(table, "table"); checkNotNull(audit, "audit"); URI uri = _blobStore.clone() .segment("_table", table, "purge") .queryParam("audit", RisonHelper.asORison(audit)) .build(); try { _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(); } catch (EmoClientException e) { throw convertException(e); } }
@Override public CreateEmoApiKeyResponse createApiKey(String apiKey, CreateEmoApiKeyRequest request) throws EmoApiKeyNotFoundException { checkNotNull(request, "request"); checkArgument(!Strings.isNullOrEmpty(request.getOwner()), "Non-empty owner is required"); try { URI uri = _uac.clone() .segment("api-key") .build(); EmoResource resource = _client.resource(uri); for (Map.Entry<String, String> customQueryParam : request.getCustomRequestParameters().entries()) { resource = resource.queryParam(customQueryParam.getKey(), customQueryParam.getValue()); } return resource .type(APPLICATION_X_CREATE_API_KEY_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(CreateEmoApiKeyResponse.class, JsonHelper.asJson(request)); } catch (EmoClientException e) { throw convertException(e); } }
public void send(String apiKey, String queue, final Object message) { checkNotNull(queue, "queue"); try { URI uri = _queueService.clone() .segment(queue, "send") .build(); _client.resource(uri) .type(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) // Wrap the message in a JSONWrappedObject that forces Jersey to use Jackson to serialize it // no matter what the type. Otherwise null and String objects don't get serialized correctly. .post(new JSONWrappedObject("", "", message)); } catch (EmoClientException e) { throw convertException(e); } }
@Override public void createRole(String apiKey, CreateEmoRoleRequest request) throws EmoRoleExistsException { checkNotNull(request, "request"); EmoRoleKey roleKey = checkNotNull(request.getRoleKey(), "roleKey"); try { URI uri = _uac.clone() .segment("role") .segment(roleKey.getGroup()) .segment(roleKey.getId()) .build(); _client.resource(uri) .type(APPLICATION_X_CREATE_ROLE_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .post(JsonHelper.asJson(request)); } catch (EmoClientException e) { throw convertException(e); } }