use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class AWSRDSTokenPasswordProvider method getPassword.
@JsonIgnore
@Override
public String getPassword() {
try {
RdsIamAuthTokenGenerator generator = RdsIamAuthTokenGenerator.builder().credentials(awsCredentialsProvider).region(region).build();
String authToken = generator.getAuthToken(GetIamAuthTokenRequest.builder().hostname(host).port(port).userName(user).build());
return authToken;
} catch (Exception ex) {
LOGGER.error(ex, "Couldn't generate AWS token.");
throw new RE(ex, "Couldn't generate AWS token.");
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class BasicAuthUtils method hashPassword.
public static byte[] hashPassword(final char[] password, final byte[] salt, final int iterations) {
try {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(password, salt, iterations, KEY_LENGTH));
return key.getEncoded();
} catch (InvalidKeySpecException ikse) {
log.error("Invalid keyspec");
throw new RuntimeException("Invalid keyspec", ikse);
} catch (NoSuchAlgorithmException nsae) {
log.error("%s not supported on this system.", ALGORITHM);
throw new RE(nsae, "%s not supported on this system.", ALGORITHM);
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class WorkerHolder method assignTask.
public boolean assignTask(Task task) {
if (disabled.get()) {
log.info("Received task[%s] assignment on worker[%s] when worker is disabled.", task.getId(), worker.getHost());
return false;
}
URL url = TaskRunnerUtils.makeWorkerURL(worker, "/druid-internal/v1/worker/assignTask");
int numTries = config.getAssignRequestMaxRetries();
try {
return RetryUtils.retry(() -> {
try {
final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, url).addHeader(HttpHeaders.Names.CONTENT_TYPE, SmileMediaTypes.APPLICATION_JACKSON_SMILE).setContent(smileMapper.writeValueAsBytes(task)), StatusResponseHandler.getInstance(), config.getAssignRequestHttpTimeout().toStandardDuration()).get();
if (response.getStatus().getCode() == 200) {
return true;
} else {
throw new RE("Failed to assign task[%s] to worker[%s]. Response Code[%s] and Message[%s]. Retrying...", task.getId(), worker.getHost(), response.getStatus().getCode(), response.getContent());
}
} catch (ExecutionException ex) {
throw new RE(ex, "Request to assign task[%s] to worker[%s] failed. Retrying...", task.getId(), worker.getHost());
}
}, e -> !(e instanceof InterruptedException), numTries);
} catch (Exception ex) {
log.info("Not sure whether task[%s] was successfully assigned to worker[%s].", task.getId(), worker.getHost());
return true;
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class OverlordResourceTest method testDisableWorkerWhenWorkerAPIRaisesError.
@Test
public void testDisableWorkerWhenWorkerAPIRaisesError() {
final String host = "worker-host";
workerTaskRunnerQueryAdapter.disableWorker(host);
EasyMock.expectLastCall().andThrow(new RE("Worker API returns error!")).once();
EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req, workerTaskRunnerQueryAdapter);
final Response response = overlordResource.disableWorker(host);
Assert.assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode(), response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", "Worker API returns error!"), response.getEntity());
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class DruidLeaderClient method go.
/**
* Executes a Request object aimed at the leader. Throws IOException if the leader cannot be located.
*/
public <T, H extends FullResponseHolder<T>> H go(Request request, HttpResponseHandler<H, H> responseHandler) throws IOException, InterruptedException {
Preconditions.checkState(lifecycleLock.awaitStarted(1, TimeUnit.MILLISECONDS));
for (int counter = 0; counter < MAX_RETRIES; counter++) {
final H fullResponseHolder;
try {
try {
fullResponseHolder = httpClient.go(request, responseHandler).get();
} catch (ExecutionException e) {
// Unwrap IOExceptions and ChannelExceptions, re-throw others
Throwables.propagateIfInstanceOf(e.getCause(), IOException.class);
Throwables.propagateIfInstanceOf(e.getCause(), ChannelException.class);
throw new RE(e, "HTTP request to[%s] failed", request.getUrl());
}
} catch (IOException | ChannelException ex) {
// can happen if the node is stopped.
log.warn(ex, "Request[%s] failed.", request.getUrl());
try {
if (request.getUrl().getQuery() == null) {
request = withUrl(request, new URL(StringUtils.format("%s%s", getCurrentKnownLeader(false), request.getUrl().getPath())));
} else {
request = withUrl(request, new URL(StringUtils.format("%s%s?%s", getCurrentKnownLeader(false), request.getUrl().getPath(), request.getUrl().getQuery())));
}
continue;
} catch (MalformedURLException e) {
// Not an IOException; this is our own fault.
throw new ISE(e, "failed to build url with path[%] and query string [%s].", request.getUrl().getPath(), request.getUrl().getQuery());
}
}
if (HttpResponseStatus.TEMPORARY_REDIRECT.equals(fullResponseHolder.getResponse().getStatus())) {
String redirectUrlStr = fullResponseHolder.getResponse().headers().get("Location");
if (redirectUrlStr == null) {
throw new IOE("No redirect location is found in response from url[%s].", request.getUrl());
}
log.info("Request[%s] received redirect response to location [%s].", request.getUrl(), redirectUrlStr);
final URL redirectUrl;
try {
redirectUrl = new URL(redirectUrlStr);
} catch (MalformedURLException ex) {
throw new IOE(ex, "Malformed redirect location is found in response from url[%s], new location[%s].", request.getUrl(), redirectUrlStr);
}
// update known leader location
currentKnownLeader.set(StringUtils.format("%s://%s:%s", redirectUrl.getProtocol(), redirectUrl.getHost(), redirectUrl.getPort()));
request = withUrl(request, redirectUrl);
} else {
return fullResponseHolder;
}
}
throw new IOE("Retries exhausted, couldn't fulfill request to [%s].", request.getUrl());
}
Aggregations