private HttpResponse executeRequest(Function<String, String> hostToUri, String type, Optional<?> body, Method method, Optional<Map<String, Object>> queryParams) { final long start = System.currentTimeMillis(); HttpResponse response = executeRequest(hostToUri, method, body, queryParams.or(Collections.emptyMap())); checkResponse(type, response); LOG.info("Successfully {}ed {} in {}ms", method, type, System.currentTimeMillis() - start); return response; }
private <T> Collection<T> getCollectionWithParams(Function<String, String> hostToUrl, String type, Optional<Map<String, Object>> queryParams, TypeReference<Collection<T>> typeReference) { final long start = System.currentTimeMillis(); HttpResponse response = executeRequest(hostToUrl, Method.GET, Optional.absent(), queryParams.or(Collections.emptyMap())); if (response.getStatusCode() == 404) { return ImmutableList.of(); } checkResponse(type, response); LOG.info("Got {} in {}ms", type, System.currentTimeMillis() - start); return response.getAs(typeReference); }
private <T> Optional<T> deleteWithParams(Function<String, String> hostToUrl, String type, String id, Optional<?> body, Optional<Map<String, Object>> queryParams, Optional<Class<T>> clazz) { LOG.info("Deleting {} {} from Singularity", type, id); final long start = System.currentTimeMillis(); HttpResponse response = executeRequest(hostToUrl, Method.DELETE, body, queryParams.or(Collections.emptyMap())); if (response.getStatusCode() == 404) { LOG.info("{} ({}) was not found", type, id); return Optional.absent(); } checkResponse(type, response); LOG.info("Deleted {} ({}) from Singularity in %sms", type, id, System.currentTimeMillis() - start); if (clazz.isPresent()) { return Optional.of(response.getAs(clazz.get())); } return Optional.absent(); }
private <T> Optional<T> getSingleWithParams(Function<String, String> hostToUrl, String type, String id, Optional<Map<String, Object>> queryParams, TypeReference<T> typeReference) { final long start = System.currentTimeMillis(); HttpResponse response = executeGetSingleWithParams(hostToUrl, type, id, queryParams); if (response.getStatusCode() == 404) { return Optional.absent(); } checkResponse(type, response); LOG.info("Got {} {} in {}ms", type, id, System.currentTimeMillis() - start); return Optional.fromNullable(response.getAs(typeReference)); }
public Optional<SingularityTaskReconciliationStatistics> getTaskReconciliationStatistics() { final Function<String, String> uri = (host) -> String.format(TASK_RECONCILIATION_FORMAT, getApiBase(host)); LOG.info("Fetch task reconciliation statistics from {}", uri); final long start = System.currentTimeMillis(); HttpResponse response = executeRequest(uri, Method.GET, Optional.absent(), Collections.emptyMap()); if (response.getStatusCode() == 404) { return Optional.absent(); } checkResponse("task reconciliation statistics", response); LOG.info("Got task reconciliation statistics in {}ms", System.currentTimeMillis() - start); return Optional.of(response.getAs(SingularityTaskReconciliationStatistics.class)); }
private <T> Optional<T> getSingleWithParams(Function<String, String> hostToUrl, String type, String id, Optional<Map<String, Object>> queryParams, Class<T> clazz) { final long start = System.currentTimeMillis(); HttpResponse response = executeGetSingleWithParams(hostToUrl, type, id, queryParams); if (response.getStatusCode() == 404) { return Optional.absent(); } checkResponse(type, response); LOG.info("Got {} {} in {}ms", type, id, System.currentTimeMillis() - start); return Optional.fromNullable(response.getAs(clazz)); }
public SingularityState getState(Optional<Boolean> skipCache, Optional<Boolean> includeRequestIds) { final Function<String, String> uri = (host) -> String.format(STATE_FORMAT, getApiBase(host)); LOG.info("Fetching state from {}", uri); final long start = System.currentTimeMillis(); Map<String, Boolean> queryParams = new HashMap<>(); if (skipCache.isPresent()) { queryParams.put("skipCache", skipCache.get()); } if (includeRequestIds.isPresent()) { queryParams.put("includeRequestIds", includeRequestIds.get()); } HttpResponse response = executeRequest(uri, Method.GET, Optional.absent(), queryParams); checkResponse("state", response); LOG.info("Got state in {}ms", System.currentTimeMillis() - start); return response.getAs(SingularityState.class); }