private boolean setStackState(Stack stack, boolean stopped) {
MDCBuilder.buildMdcContext(stack);
boolean result = true;
Regions region = ((AwsTemplate) stack.getTemplate()).getRegion();
AwsCredential credential = (AwsCredential) stack.getCredential();
AmazonAutoScalingClient amazonASClient = awsStackUtil.createAutoScalingClient(region, credential);
AmazonEC2Client amazonEC2Client = awsStackUtil.createEC2Client(region, credential);
String asGroupName = cfStackUtil.getAutoscalingGroupName(stack);
Set<InstanceMetaData> instanceMetaData = stack.getInstanceMetaData();
Collection<String> instances = new ArrayList<>(instanceMetaData.size());
for (InstanceMetaData instance : instanceMetaData) {
instances.add(instance.getInstanceId());
}
try {
if (stopped) {
amazonASClient.suspendProcesses(new SuspendProcessesRequest().withAutoScalingGroupName(asGroupName));
amazonEC2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instances));
} else {
amazonASClient.resumeProcesses(new ResumeProcessesRequest().withAutoScalingGroupName(asGroupName));
amazonEC2Client.startInstances(new StartInstancesRequest().withInstanceIds(instances));
awsPollingService.pollWithTimeout(
new AwsInstanceStatusCheckerTask(),
new AwsInstances(stack, amazonEC2Client, new ArrayList(instances), "Running"),
AmbariClusterConnector.POLLING_INTERVAL,