@Test @Ignore public void testEnterStandby() throws AwsException { util.enterStandby(AS_GROUP_ID, false); }
public boolean enterStandby(final String groupId, boolean decrementDesiredCapacity) { try { DescribeAutoScalingInstancesResult result = asyncClient.describeAutoScalingInstances(new DescribeAutoScalingInstancesRequest().withMaxRecords(1).withInstanceIds(instanceId)); Optional<AutoScalingInstanceDetails> state = result.getAutoScalingInstances() .stream() .filter(asi -> asi.getInstanceId().equals(instanceId)).findFirst(); state.ifPresent(s -> LOG.trace("enterStandby() instance {} current state : {}", instanceId, s.getLifecycleState())); if (state.isPresent() && state.get().getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name())) { return true; } else { asyncClient.enterStandby(new EnterStandbyRequest().withAutoScalingGroupName(groupId).withInstanceIds(instanceId).withShouldDecrementDesiredCapacity(decrementDesiredCapacity)); return true; } } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); return false; } }
AwsAutoScalingUtil { public boolean enterStandby(final String groupId, boolean decrementDesiredCapacity) { try { DescribeAutoScalingInstancesResult result = asyncClient.describeAutoScalingInstances(new DescribeAutoScalingInstancesRequest().withMaxRecords(1).withInstanceIds(instanceId)); Optional<AutoScalingInstanceDetails> state = result.getAutoScalingInstances() .stream() .filter(asi -> asi.getInstanceId().equals(instanceId)).findFirst(); state.ifPresent(s -> LOG.trace("enterStandby() instance {} current state : {}", instanceId, s.getLifecycleState())); if (state.isPresent() && state.get().getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name())) { return true; } else { asyncClient.enterStandby(new EnterStandbyRequest().withAutoScalingGroupName(groupId).withInstanceIds(instanceId).withShouldDecrementDesiredCapacity(decrementDesiredCapacity)); return true; } } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); return false; } } }
AwsAutoScalingUtil { public boolean enterStandby(final String groupId, boolean decrementDesiredCapacity) { try { DescribeAutoScalingInstancesResult result = asyncClient.describeAutoScalingInstances(new DescribeAutoScalingInstancesRequest().withMaxRecords(1).withInstanceIds(instanceId)); Optional<AutoScalingInstanceDetails> state = result.getAutoScalingInstances() .stream() .filter(asi -> asi.getInstanceId().equals(instanceId)).findFirst(); state.ifPresent(s -> LOG.trace("enterStandby() instance {} current state : {}", instanceId, s.getLifecycleState())); if (state.isPresent() && state.get().getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name())) { return true; } else { asyncClient.enterStandby(new EnterStandbyRequest().withAutoScalingGroupName(groupId).withInstanceIds(instanceId).withShouldDecrementDesiredCapacity(decrementDesiredCapacity)); return true; } } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); return false; } } AwsAutoScalingUtil(DeployConfig config); }
AwsAutoScalingUtil { public boolean enterStandby(final String groupId, boolean decrementDesiredCapacity) { try { DescribeAutoScalingInstancesResult result = asyncClient.describeAutoScalingInstances(new DescribeAutoScalingInstancesRequest().withMaxRecords(1).withInstanceIds(instanceId)); Optional<AutoScalingInstanceDetails> state = result.getAutoScalingInstances() .stream() .filter(asi -> asi.getInstanceId().equals(instanceId)).findFirst(); state.ifPresent(s -> LOG.trace("enterStandby() instance {} current state : {}", instanceId, s.getLifecycleState())); if (state.isPresent() && state.get().getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name())) { return true; } else { asyncClient.enterStandby(new EnterStandbyRequest().withAutoScalingGroupName(groupId).withInstanceIds(instanceId).withShouldDecrementDesiredCapacity(decrementDesiredCapacity)); return true; } } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); return false; } } AwsAutoScalingUtil(DeployConfig config); Observable<AwsState> pollForInstanceState(); Observable<String> listLoadBalancers(final String groupId); boolean enterStandby(final String groupId, boolean decrementDesiredCapacity); boolean exitStandby(final String groupId); Map<String, String> getDeployTags(); String getInstanceId(); }
AwsAutoScalingUtil { public boolean enterStandby(final String groupId, boolean decrementDesiredCapacity) { try { DescribeAutoScalingInstancesResult result = asyncClient.describeAutoScalingInstances(new DescribeAutoScalingInstancesRequest().withMaxRecords(1).withInstanceIds(instanceId)); Optional<AutoScalingInstanceDetails> state = result.getAutoScalingInstances() .stream() .filter(asi -> asi.getInstanceId().equals(instanceId)).findFirst(); state.ifPresent(s -> LOG.trace("enterStandby() instance {} current state : {}", instanceId, s.getLifecycleState())); if (state.isPresent() && state.get().getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name())) { return true; } else { asyncClient.enterStandby(new EnterStandbyRequest().withAutoScalingGroupName(groupId).withInstanceIds(instanceId).withShouldDecrementDesiredCapacity(decrementDesiredCapacity)); return true; } } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); return false; } } AwsAutoScalingUtil(DeployConfig config); Observable<AwsState> pollForInstanceState(); Observable<String> listLoadBalancers(final String groupId); boolean enterStandby(final String groupId, boolean decrementDesiredCapacity); boolean exitStandby(final String groupId); Map<String, String> getDeployTags(); String getInstanceId();  }