use of com.netflix.titus.api.connector.cloud.Instance in project titus-control-plane by Netflix.
the class AwsInstanceCloudConnector method getInstance.
@Override
public Mono<Instance> getInstance(String instanceId) {
return Mono.defer(() -> {
DescribeInstancesRequest req = new DescribeInstancesRequest().withInstanceIds(instanceId).withSdkRequestTimeout((int) configuration.getAwsRequestTimeoutMs());
Mono<DescribeInstancesResult> instancesResult = AwsReactorExt.toMono(req, ec2Client::describeInstancesAsync);
return instancesResult.filter(isr -> isr.getReservations() != null && !isr.getReservations().isEmpty() && !isr.getReservations().get(0).getInstances().isEmpty()).map(isr -> {
Reservation reservation = isr.getReservations().get(0);
return toInstance(reservation.getInstances().get(0));
}).onErrorResume(e -> {
if (e instanceof AmazonEC2Exception) {
AmazonEC2Exception ec2Exception = (AmazonEC2Exception) e;
String errorCode = ec2Exception.getErrorCode();
int statusCode = ec2Exception.getStatusCode();
// Instance id provided is unknown / invalid
if (errorCode != null && errorCode.contains(ERROR_INSTANCE_NOT_FOUND) && statusCode == 400) {
logger.info("AWS instance {} NOT FOUND", instanceId);
return Mono.empty();
}
}
// Any other exception should bubble up
return Mono.error(e);
});
});
}
use of com.netflix.titus.api.connector.cloud.Instance in project titus-control-plane by Netflix.
the class AwsInstanceCloudConnector method scaleUp.
@Override
public Completable scaleUp(String instanceGroupId, int scaleUpCount) {
return getInstanceGroups(singletonList(instanceGroupId)).map(list -> list.get(0)).flatMap(instanceGroup -> {
int newDesired = instanceGroup.getDesired() + scaleUpCount;
if (newDesired > instanceGroup.getMax()) {
return Observable.error(CloudConnectorException.invalidArgument("Instance group requested desired size %s > max size %s", newDesired, instanceGroup.getMax()));
}
logger.info("Scaling up instance group {}, by {} instances (desired changed from {} to {})", instanceGroup, scaleUpCount, instanceGroup.getDesired(), newDesired);
UpdateAutoScalingGroupRequest request = new UpdateAutoScalingGroupRequest().withAutoScalingGroupName(instanceGroupId).withDesiredCapacity(newDesired);
Observable<UpdateAutoScalingGroupResult> observable = toObservable(request, autoScalingClient::updateAutoScalingGroupAsync);
return observable;
}).toCompletable().timeout(configuration.getAwsRequestTimeoutMs(), TimeUnit.MILLISECONDS);
}
Aggregations