use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.
the class EventReceiverFirehoseTestClient method postEvents.
/**
* post events from the collection and return the count of events accepted
*
* @param events Collection of events to be posted
*
* @return
*/
public int postEvents(Collection<Map<String, Object>> events, ObjectMapper objectMapper, String mediaType) {
try {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(getURL())).setContent(mediaType, objectMapper.writeValueAsBytes(events)), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while posting events to url[%s] status[%s] content[%s]", getURL(), response.getStatus(), response.getContent());
}
Map<String, Integer> responseData = objectMapper.readValue(response.getContent(), new TypeReference<Map<String, Integer>>() {
});
return responseData.get("eventCount");
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.
the class OverlordResourceTestClient method submitSupervisor.
public String submitSupervisor(String spec) {
try {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(getIndexerURL() + "supervisor")).setContent("application/json", spec.getBytes()), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while submitting supervisor to overlord, response [%s %s]", response.getStatus(), response.getContent());
}
Map<String, String> responseData = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, String>>() {
});
String id = responseData.get("id");
LOG.info("Submitted supervisor with id[%s]", id);
return id;
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.
the class OverlordResourceTestClient method shutdownSupervisor.
public void shutdownSupervisor(String id) {
try {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(String.format("%ssupervisor/%s/shutdown", getIndexerURL(), id))), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while shutting down supervisor, response [%s %s]", response.getStatus(), response.getContent());
}
LOG.info("Shutdown supervisor with id[%s]", id);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.
the class OverlordResourceTestClient method getTaskStatus.
public TaskStatus.Status getTaskStatus(String taskID) {
try {
StatusResponseHolder response = makeRequest(HttpMethod.GET, String.format("%stask/%s/status", getIndexerURL(), URLEncoder.encode(taskID, "UTF-8")));
LOG.info("Index status response" + response.getContent());
Map<String, Object> responseData = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, Object>>() {
});
//TODO: figure out a better way to parse the response...
String status = (String) ((Map) responseData.get("status")).get("status");
return TaskStatus.Status.valueOf(status);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.
the class RemoteTaskActionClient method submit.
@Override
public <RetType> RetType submit(TaskAction<RetType> taskAction) throws IOException {
log.info("Performing action for task[%s]: %s", task.getId(), taskAction);
byte[] dataToSend = jsonMapper.writeValueAsBytes(new TaskActionHolder(task, taskAction));
final RetryPolicy retryPolicy = retryPolicyFactory.makeRetryPolicy();
while (true) {
try {
final Server server;
final URI serviceUri;
try {
server = getServiceInstance();
serviceUri = makeServiceUri(server);
} catch (Exception e) {
// Want to retry, so throw an IOException.
throw new IOException("Failed to locate service uri", e);
}
final StatusResponseHolder response;
log.info("Submitting action for task[%s] to overlord[%s]: %s", task.getId(), serviceUri, taskAction);
try {
response = httpClient.go(new Request(HttpMethod.POST, serviceUri.toURL()).setContent(MediaType.APPLICATION_JSON, dataToSend), new StatusResponseHandler(Charsets.UTF_8)).get();
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e.getCause(), IOException.class);
Throwables.propagateIfInstanceOf(e.getCause(), ChannelException.class);
throw Throwables.propagate(e);
}
if (response.getStatus().getCode() / 100 == 2) {
final Map<String, Object> responseDict = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, Object>>() {
});
return jsonMapper.convertValue(responseDict.get("result"), taskAction.getReturnTypeReference());
} else {
// Want to retry, so throw an IOException.
throw new IOException(String.format("Scary HTTP status returned: %s. Check your overlord[%s] logs for exceptions.", response.getStatus(), server.getHost()));
}
} catch (IOException | ChannelException e) {
log.warn(e, "Exception submitting action for task[%s]", task.getId());
final Duration delay = retryPolicy.getAndIncrementRetryDelay();
if (delay == null) {
throw e;
} else {
try {
final long sleepTime = jitter(delay.getMillis());
log.info("Will try again in [%s].", new Duration(sleepTime).toString());
Thread.sleep(sleepTime);
} catch (InterruptedException e2) {
throw Throwables.propagate(e2);
}
}
}
}
}
Aggregations