use of com.amazonaws.AmazonWebServiceRequest in project elasticsearch by elastic.
the class AwsEc2ServiceImpl method buildConfiguration.
protected static ClientConfiguration buildConfiguration(Logger logger, Settings settings) {
ClientConfiguration clientConfiguration = new ClientConfiguration();
// the response metadata cache is only there for diagnostics purposes,
// but can force objects from every response to the old generation.
clientConfiguration.setResponseMetadataCacheSize(0);
clientConfiguration.setProtocol(CLOUD_EC2.PROTOCOL_SETTING.get(settings));
if (PROXY_HOST_SETTING.exists(settings) || CLOUD_EC2.PROXY_HOST_SETTING.exists(settings)) {
String proxyHost = CLOUD_EC2.PROXY_HOST_SETTING.get(settings);
Integer proxyPort = CLOUD_EC2.PROXY_PORT_SETTING.get(settings);
String proxyUsername = CLOUD_EC2.PROXY_USERNAME_SETTING.get(settings);
String proxyPassword = CLOUD_EC2.PROXY_PASSWORD_SETTING.get(settings);
clientConfiguration.withProxyHost(proxyHost).withProxyPort(proxyPort).withProxyUsername(proxyUsername).withProxyPassword(proxyPassword);
}
// #155: we might have 3rd party users using older EC2 API version
String awsSigner = CLOUD_EC2.SIGNER_SETTING.get(settings);
if (Strings.hasText(awsSigner)) {
logger.debug("using AWS API signer [{}]", awsSigner);
AwsSigner.configureSigner(awsSigner, clientConfiguration);
}
// Increase the number of retries in case of 5xx API responses
final Random rand = Randomness.get();
RetryPolicy retryPolicy = new RetryPolicy(RetryPolicy.RetryCondition.NO_RETRY_CONDITION, new RetryPolicy.BackoffStrategy() {
@Override
public long delayBeforeNextRetry(AmazonWebServiceRequest originalRequest, AmazonClientException exception, int retriesAttempted) {
// with 10 retries the max delay time is 320s/320000ms (10 * 2^5 * 1 * 1000)
logger.warn("EC2 API request failed, retry again. Reason was:", exception);
return 1000L * (long) (10d * Math.pow(2, retriesAttempted / 2.0d) * (1.0d + rand.nextDouble()));
}
}, 10, false);
clientConfiguration.setRetryPolicy(retryPolicy);
clientConfiguration.setSocketTimeout((int) CLOUD_EC2.READ_TIMEOUT.get(settings).millis());
return clientConfiguration;
}
use of com.amazonaws.AmazonWebServiceRequest in project pipeline-aws-plugin by jenkinsci.
the class EventPrinter method waitAndPrintStackEvents.
public void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, long pollIntervalMillis) throws ExecutionException {
final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)), new WaiterHandler() {
@Override
public void onWaitSuccess(AmazonWebServiceRequest request) {
waitResult.completed(request);
}
@Override
public void onWaitFailure(Exception e) {
waitResult.failed(e);
}
});
this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}
use of com.amazonaws.AmazonWebServiceRequest in project photon-model by vmware.
the class AWSTaskStatusChecker method buildHandler.
private AsyncHandler buildHandler(T type) {
return new AsyncHandler<AmazonWebServiceRequest, AmazonWebServiceResult>() {
@Override
public void onError(Exception exception) {
// particular instanceId.
if (exception instanceof AmazonServiceException && ((AmazonServiceException) exception).getErrorCode().equalsIgnoreCase(AWS_INVALID_INSTANCE_ID_ERROR_CODE)) {
AWSTaskStatusChecker.this.service.logWarning("Could not retrieve status for instance %s. Retrying... Exception on AWS is %s", AWSTaskStatusChecker.this.instanceId, exception);
AWSTaskStatusChecker.create(AWSTaskStatusChecker.this.amazonEC2Client, AWSTaskStatusChecker.this.instanceId, AWSTaskStatusChecker.this.desiredState, AWSTaskStatusChecker.this.failureStates, AWSTaskStatusChecker.this.consumer, AWSTaskStatusChecker.this.taskManager, AWSTaskStatusChecker.this.service, AWSTaskStatusChecker.this.expirationTimeMicros).start(type);
return;
} else if (exception instanceof AmazonEC2Exception && ((AmazonEC2Exception) exception).getErrorCode().equalsIgnoreCase(AWS_INVALID_VOLUME_ID_ERROR_CODE)) {
AWSTaskStatusChecker.this.consumer.accept(null);
return;
}
AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(exception);
return;
}
@Override
public void onSuccess(AmazonWebServiceRequest request, AmazonWebServiceResult result) {
String status;
Object instance;
String failureMessage = null;
String stateReason = null;
if (result instanceof DescribeInstancesResult) {
instance = ((DescribeInstancesResult) result).getReservations().get(0).getInstances().get(0);
Instance vm = (Instance) instance;
status = vm.getState().getName();
stateReason = vm.getStateReason() != null ? vm.getStateReason().getMessage() : null;
} else if (result instanceof DescribeNatGatewaysResult) {
instance = ((DescribeNatGatewaysResult) result).getNatGateways().get(0);
status = ((NatGateway) instance).getState();
// if NAT gateway creation fails, the status is still "pending";
// rather than keep checking for status and eventually time out, get the
// failure message and fail the task
failureMessage = ((NatGateway) instance).getFailureMessage();
} else if (result instanceof DescribeVolumesResult) {
instance = ((DescribeVolumesResult) result).getVolumes().get(0);
status = ((Volume) instance).getState().toLowerCase();
} else {
AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(new IllegalArgumentException("Invalid type " + result));
return;
}
if (failureMessage != null) {
// operation failed; no need to keep checking for desired status
AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(new IllegalStateException(failureMessage));
return;
} else if (AWSTaskStatusChecker.this.failureStates.contains(status)) {
// operation failed; no need to keep checking for desired status
AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(new IllegalStateException("Resource is state:[" + status + "]," + "reason:" + stateReason));
return;
} else if (!status.equals(AWSTaskStatusChecker.this.desiredState)) {
AWSTaskStatusChecker.this.service.logInfo("Instance %s not yet in desired state %s. Current state %s, failure states %s, waiting 5s", AWSTaskStatusChecker.this.instanceId, AWSTaskStatusChecker.this.desiredState, status, AWSTaskStatusChecker.this.failureStates);
// if the instance is not in the desired state, schedule thread
// to run again in 5 seconds
AWSTaskStatusChecker.this.service.getHost().schedule(() -> {
AWSTaskStatusChecker.create(AWSTaskStatusChecker.this.amazonEC2Client, AWSTaskStatusChecker.this.instanceId, AWSTaskStatusChecker.this.desiredState, AWSTaskStatusChecker.this.failureStates, AWSTaskStatusChecker.this.consumer, AWSTaskStatusChecker.this.taskManager, AWSTaskStatusChecker.this.service, AWSTaskStatusChecker.this.expirationTimeMicros).start(type);
}, 5, TimeUnit.SECONDS);
return;
}
AWSTaskStatusChecker.this.consumer.accept(instance);
return;
}
};
}
use of com.amazonaws.AmazonWebServiceRequest in project photon-model by vmware.
the class AWSTaskStatusChecker method runSearch.
private void runSearch(T type) {
AmazonWebServiceRequest descRequest = buildRequest(type);
AsyncHandler describeHandler = buildHandler(type);
if (type instanceof Instance) {
this.amazonEC2Client.describeInstancesAsync((DescribeInstancesRequest) descRequest, describeHandler);
} else if (type instanceof NatGateway) {
this.amazonEC2Client.describeNatGatewaysAsync((DescribeNatGatewaysRequest) descRequest, describeHandler);
} else if (type instanceof Volume) {
this.amazonEC2Client.describeVolumesAsync((DescribeVolumesRequest) descRequest, describeHandler);
} else {
AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(new IllegalArgumentException("Invalid type " + type));
}
}
use of com.amazonaws.AmazonWebServiceRequest in project pipeline-aws-plugin by jenkinsci.
the class EventPrinter method waitAndPrintChangeSetEvents.
public void waitAndPrintChangeSetEvents(String stack, String changeSet, Waiter<DescribeChangeSetRequest> waiter, long pollIntervalMillis) throws ExecutionException {
final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
waiter.runAsync(new WaiterParameters<>(new DescribeChangeSetRequest().withStackName(stack).withChangeSetName(changeSet)), new WaiterHandler() {
@Override
public void onWaitSuccess(AmazonWebServiceRequest request) {
waitResult.completed(request);
}
@Override
public void onWaitFailure(Exception e) {
waitResult.failed(e);
}
});
this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}
Aggregations