use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method getCollectionWithParams.
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);
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method executeRequest.
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;
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method getTaskReconciliationStatistics.
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));
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method isUserAuthorized.
//
// Auth
//
/**
* Check if a user is authorized for the specified scope on the specified request
*
* @param requestId
* The request to check authorization on
* @param userId
* The user whose authorization will be checked
* @param scope
* The scope to check that `user` has
*
* @return
* true if the user is authorized for scope, false otherwise
*/
public boolean isUserAuthorized(String requestId, String userId, SingularityAuthorizationScope scope) {
final Function<String, String> requestUri = (host) -> String.format(AUTH_CHECK_USER_FORMAT, getApiBase(host), requestId, userId);
Map<String, Object> params = Collections.singletonMap("scope", scope.name());
HttpResponse response = executeGetSingleWithParams(requestUri, "auth check", "", Optional.of(params));
return response.isSuccess();
}
use of com.hubspot.horizon.HttpResponse in project Singularity by HubSpot.
the class SingularityClient method getState.
//
// GLOBAL
//
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);
}
Aggregations