@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceIds() == null) ? 0 : getInstanceIds().hashCode()); hashCode = prime * hashCode + ((getAutoScalingGroupName() == null) ? 0 : getAutoScalingGroupName().hashCode()); hashCode = prime * hashCode + ((getShouldDecrementDesiredCapacity() == null) ? 0 : getShouldDecrementDesiredCapacity().hashCode()); return hashCode; }
/** * <p> * The IDs of the instances. You can specify up to 20 instances. * </p> * * @param instanceIds * The IDs of the instances. You can specify up to 20 instances. * @return Returns a reference to this object so that method calls can be chained together. */ public DetachInstancesRequest withInstanceIds(java.util.Collection<String> instanceIds) { setInstanceIds(instanceIds); return this; }
/** * <p> * The name of the Auto Scaling group. * </p> * * @param autoScalingGroupName * The name of the Auto Scaling group. * @return Returns a reference to this object so that method calls can be chained together. */ public DetachInstancesRequest withAutoScalingGroupName(String autoScalingGroupName) { setAutoScalingGroupName(autoScalingGroupName); return this; }
@Override public Void call() { DetachInstancesRequest request = new DetachInstancesRequest().withAutoScalingGroupName(this.autoScalingGroup) .withInstanceIds(this.instanceId).withShouldDecrementDesiredCapacity(true); getClient().getApi().detachInstances(request); return null; } }
/** * <p> * The IDs of the instances. You can specify up to 20 instances. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param instanceIds <p> * The IDs of the instances. You can specify up to 20 instances. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public DetachInstancesRequest withInstanceIds(String... instanceIds) { if (getInstanceIds() == null) { this.instanceIds = new java.util.ArrayList<String>(instanceIds.length); } for (String value : instanceIds) { this.instanceIds.add(value); } return this; }
AmazonAutoScaling asClient = AmazonAutoScalingClientBuilder.defaultClient(); DetachInstancesResult result = asClient.detachInstances(new DetachInstancesRequest() .withAutoScalingGroupName(asgName) .withInstanceIds(asgInstances) .withShouldDecrementDesiredCapacity(decrementSize)); logger.info("Result of detachment: {}", result); terminateInstances(hosts.stream().map(DockerHost::getInstanceId).collect(Collectors.toList()));
public boolean checkEc2Instance(String instanceId) { boolean instanceTerminated = false; try { DescribeInstancesResult result = awsEc2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId)); List<com.amazonaws.services.ec2.model.Instance> instances = result.getReservations().stream() .flatMap(r -> r.getInstances().stream()) .filter(i -> i.getInstanceId().equals(instanceId)) .collect(Collectors.toList()); instanceTerminated = instances.isEmpty() || instances.stream() .map(com.amazonaws.services.ec2.model.Instance::getState) .anyMatch(s -> s.getCode().equals(48)); } catch (AmazonServiceException e) { log.info(e.toString(), e); if (e.getStatusCode() == 400) { instanceTerminated = true; } } if (instanceTerminated) { log.warn("Invalid instance " + instanceId + " in group " + activeConfiguration.getAutoScalingGroupId() + ". Detaching instance."); awsAsClient.detachInstances(new DetachInstancesRequest() .withAutoScalingGroupName(activeConfiguration.getAutoScalingGroupId()) .withInstanceIds(instanceId) .withShouldDecrementDesiredCapacity(false)); } return instanceTerminated; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DetachInstancesRequest == false) return false; DetachInstancesRequest other = (DetachInstancesRequest) obj; if (other.getInstanceIds() == null ^ this.getInstanceIds() == null) return false; if (other.getInstanceIds() != null && other.getInstanceIds().equals(this.getInstanceIds()) == false) return false; if (other.getAutoScalingGroupName() == null ^ this.getAutoScalingGroupName() == null) return false; if (other.getAutoScalingGroupName() != null && other.getAutoScalingGroupName().equals(this.getAutoScalingGroupName()) == false) return false; if (other.getShouldDecrementDesiredCapacity() == null ^ this.getShouldDecrementDesiredCapacity() == null) return false; if (other.getShouldDecrementDesiredCapacity() != null && other.getShouldDecrementDesiredCapacity().equals(this.getShouldDecrementDesiredCapacity()) == false) return false; return true; }
/** * <p> * The IDs of the instances. You can specify up to 20 instances. * </p> * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setInstanceIds(java.util.Collection)} or {@link #withInstanceIds(java.util.Collection)} if you want to * override the existing values. * </p> * * @param instanceIds * The IDs of the instances. You can specify up to 20 instances. * @return Returns a reference to this object so that method calls can be chained together. */ public DetachInstancesRequest withInstanceIds(String... instanceIds) { if (this.instanceIds == null) { setInstanceIds(new com.amazonaws.internal.SdkInternalList<String>(instanceIds.length)); } for (String ele : instanceIds) { this.instanceIds.add(ele); } return this; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getInstanceIds() != null) sb.append("InstanceIds: ").append(getInstanceIds()).append(","); if (getAutoScalingGroupName() != null) sb.append("AutoScalingGroupName: ").append(getAutoScalingGroupName()).append(","); if (getShouldDecrementDesiredCapacity() != null) sb.append("ShouldDecrementDesiredCapacity: ").append(getShouldDecrementDesiredCapacity()); sb.append("}"); return sb.toString(); }
/** * <p> * The IDs of the instances. You can specify up to 20 instances. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param instanceIds <p> * The IDs of the instances. You can specify up to 20 instances. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public DetachInstancesRequest withInstanceIds(java.util.Collection<String> instanceIds) { setInstanceIds(instanceIds); return this; }
public Request<DetachInstancesRequest> marshall(DetachInstancesRequest detachInstancesRequest) { if (detachInstancesRequest == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } Request<DetachInstancesRequest> request = new DefaultRequest<DetachInstancesRequest>(detachInstancesRequest, "AmazonAutoScaling"); request.addParameter("Action", "DetachInstances"); request.addParameter("Version", "2011-01-01"); request.setHttpMethod(HttpMethodName.POST); if (!detachInstancesRequest.getInstanceIds().isEmpty() || !((com.amazonaws.internal.SdkInternalList<String>) detachInstancesRequest.getInstanceIds()).isAutoConstruct()) { com.amazonaws.internal.SdkInternalList<String> instanceIdsList = (com.amazonaws.internal.SdkInternalList<String>) detachInstancesRequest .getInstanceIds(); int instanceIdsListIndex = 1; for (String instanceIdsListValue : instanceIdsList) { if (instanceIdsListValue != null) { request.addParameter("InstanceIds.member." + instanceIdsListIndex, StringUtils.fromString(instanceIdsListValue)); } instanceIdsListIndex++; } } if (detachInstancesRequest.getAutoScalingGroupName() != null) { request.addParameter("AutoScalingGroupName", StringUtils.fromString(detachInstancesRequest.getAutoScalingGroupName())); } if (detachInstancesRequest.getShouldDecrementDesiredCapacity() != null) { request.addParameter("ShouldDecrementDesiredCapacity", StringUtils.fromBoolean(detachInstancesRequest.getShouldDecrementDesiredCapacity())); } return request; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceIds() == null) ? 0 : getInstanceIds().hashCode()); hashCode = prime * hashCode + ((getAutoScalingGroupName() == null) ? 0 : getAutoScalingGroupName().hashCode()); hashCode = prime * hashCode + ((getShouldDecrementDesiredCapacity() == null) ? 0 : getShouldDecrementDesiredCapacity().hashCode()); return hashCode; }
DetachInstancesRequest other = (DetachInstancesRequest) obj; if (other.getInstanceIds() == null ^ this.getInstanceIds() == null) return false; if (other.getInstanceIds() != null && other.getInstanceIds().equals(this.getInstanceIds()) == false) return false; if (other.getAutoScalingGroupName() == null ^ this.getAutoScalingGroupName() == null) return false; if (other.getAutoScalingGroupName() != null && other.getAutoScalingGroupName().equals(this.getAutoScalingGroupName()) == false) return false; if (other.getShouldDecrementDesiredCapacity() == null ^ this.getShouldDecrementDesiredCapacity() == null) return false; if (other.getShouldDecrementDesiredCapacity() != null && other.getShouldDecrementDesiredCapacity().equals( this.getShouldDecrementDesiredCapacity()) == false) return false; return true;
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getInstanceIds() != null) sb.append("InstanceIds: " + getInstanceIds() + ","); if (getAutoScalingGroupName() != null) sb.append("AutoScalingGroupName: " + getAutoScalingGroupName() + ","); if (getShouldDecrementDesiredCapacity() != null) sb.append("ShouldDecrementDesiredCapacity: " + getShouldDecrementDesiredCapacity()); sb.append("}"); return sb.toString(); }
if (detachInstancesRequest.getInstanceIds() != null) { prefix = "InstanceIds"; java.util.List<String> instanceIds = detachInstancesRequest.getInstanceIds(); int instanceIdsIndex = 1; String instanceIdsPrefix = prefix; if (detachInstancesRequest.getAutoScalingGroupName() != null) { prefix = "AutoScalingGroupName"; String autoScalingGroupName = detachInstancesRequest.getAutoScalingGroupName(); request.addParameter(prefix, StringUtils.fromString(autoScalingGroupName)); if (detachInstancesRequest.getShouldDecrementDesiredCapacity() != null) { prefix = "ShouldDecrementDesiredCapacity"; Boolean shouldDecrementDesiredCapacity = detachInstancesRequest .getShouldDecrementDesiredCapacity(); request.addParameter(prefix, StringUtils.fromBoolean(shouldDecrementDesiredCapacity));