use of com.netflix.titus.api.connector.cloud.InstanceGroup 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);
}
use of com.netflix.titus.api.connector.cloud.InstanceGroup in project titus-control-plane by Netflix.
the class Main method scaleUp.
private void scaleUp(List<String> params) {
String instanceGroupId = params.get(0);
int scaleUpCount = Integer.parseInt(params.get(1));
InstanceGroup current = connector.getInstanceGroups(Collections.singletonList(instanceGroupId)).toBlocking().first().get(0);
System.out.println("Desired before scale-up: " + current.getDesired());
Throwable error = connector.scaleUp(instanceGroupId, scaleUpCount).get();
if (error != null) {
System.err.println("Scale-up error: " + error.getMessage());
error.printStackTrace();
}
InstanceGroup after = connector.getInstanceGroups(Collections.singletonList(instanceGroupId)).toBlocking().first().get(0);
System.out.println("Desired after scale-up: " + after.getDesired());
}
use of com.netflix.titus.api.connector.cloud.InstanceGroup in project titus-control-plane by Netflix.
the class Main method scaleDown.
private void scaleDown(List<String> params) {
String instanceGroupId = params.get(0);
int scaleDownCount = Integer.parseInt(params.get(1));
InstanceGroup current = connector.getInstanceGroups(Collections.singletonList(instanceGroupId)).toBlocking().first().get(0);
System.out.println("Desired before scale-down: " + current.getDesired());
Throwable error = connector.updateCapacity(instanceGroupId, Optional.empty(), Optional.of(current.getDesired() - scaleDownCount)).get();
if (error != null) {
System.err.println("Scale-down error: " + error.getMessage());
error.printStackTrace();
}
InstanceGroup after = connector.getInstanceGroups(Collections.singletonList(instanceGroupId)).toBlocking().first().get(0);
System.out.println("Desired after scale-down: " + after.getDesired());
}
use of com.netflix.titus.api.connector.cloud.InstanceGroup in project titus-control-plane by Netflix.
the class AwsInstanceCloudConnector method getInstanceGroups.
@Override
public Observable<List<InstanceGroup>> getInstanceGroups(List<String> instanceGroupIds) {
if (instanceGroupIds.isEmpty()) {
return Observable.just(Collections.emptyList());
}
DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(instanceGroupIds);
Observable<DescribeAutoScalingGroupsResult> observable = toObservable(request, autoScalingClient::describeAutoScalingGroupsAsync);
return observable.map(response -> toInstanceGroups(response.getAutoScalingGroups())).timeout(configuration.getAwsRequestTimeoutMs(), TimeUnit.MILLISECONDS);
}
use of com.netflix.titus.api.connector.cloud.InstanceGroup in project titus-control-plane by Netflix.
the class AwsInstanceCloudConnector method toInstanceGroup.
private InstanceGroup toInstanceGroup(AutoScalingGroup awsScalingGroup) {
boolean isLaunchSuspended = false;
boolean isTerminateSuspended = false;
for (SuspendedProcess suspendedProcess : awsScalingGroup.getSuspendedProcesses()) {
if (suspendedProcess.getProcessName().equals("Launch")) {
isLaunchSuspended = true;
} else if (suspendedProcess.getProcessName().equals("Terminate")) {
isTerminateSuspended = true;
}
}
Map<String, String> attributes = CollectionsExt.isNullOrEmpty(awsScalingGroup.getTags()) ? Collections.emptyMap() : awsScalingGroup.getTags().stream().collect(Collectors.toMap(TagDescription::getKey, TagDescription::getValue));
return new InstanceGroup(awsScalingGroup.getAutoScalingGroupName(), awsScalingGroup.getLaunchConfigurationName(), DEFAULT_INSTANCE_TYPE, awsScalingGroup.getMinSize(), awsScalingGroup.getDesiredCapacity(), awsScalingGroup.getMaxSize(), isLaunchSuspended, isTerminateSuspended, attributes, awsScalingGroup.getInstances().stream().map(com.amazonaws.services.autoscaling.model.Instance::getInstanceId).collect(Collectors.toList()));
}
Aggregations