@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStacks() == null) ? 0 : getStacks().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
public DescribeStacksResult unmarshall(StaxUnmarshallerContext context) throws Exception { DescribeStacksResult describeStacksResult = new DescribeStacksResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return describeStacksResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Stacks", targetDepth)) { describeStacksResult.withStacks(new ArrayList<Stack>()); continue; } if (context.testExpression("Stacks/member", targetDepth)) { describeStacksResult.withStacks(StackStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("NextToken", targetDepth)) { describeStacksResult.setNextToken(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return describeStacksResult; } } } }
private Function<DescribeStacksResult, Stack> firstStack() { return (dsr) -> dsr.getStacks().get(0); } }
/** * <p> * If the output exceeds 1 MB in size, a string that identifies the next page of stacks. If no additional page * exists, this value is null. * </p> * * @param nextToken * If the output exceeds 1 MB in size, a string that identifies the next page of stacks. If no additional * page exists, this value is null. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeStacksResult withNextToken(String nextToken) { setNextToken(nextToken); return this; }
public static String getStackOutput(String stackName, String key){ DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.withStackName(stackName); DescribeStacksResult describeStacksResult = client.describeStacks(describeStacksRequest); List<Output> outputs = describeStacksResult.getStacks().get(0).getOutputs(); Optional<Output> output = outputs.stream() .filter(index -> index.getOutputKey().equals(key)) .findFirst(); return output.map(Output::getOutputValue) .orElseThrow(() -> new RuntimeException("Did not find stack output.")); } }
/** * <p> * If the output exceeds 1 MB in size, a string that identifies the next page of stacks. If no additional page * exists, this value is null. * </p> * * @param nextToken * If the output exceeds 1 MB in size, a string that identifies the next page of stacks. If no additional * page exists, this value is null. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeStacksResult withNextToken(String nextToken) { setNextToken(nextToken); return this; }
private Stack getStack(DescribeStacksResult result) { for (Stack aStack : result.getStacks()) { if (getExpandedStackName().equals(aStack.getStackName())) { return aStack; } } return null; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeStacksResult == false) return false; DescribeStacksResult other = (DescribeStacksResult) obj; if (other.getStacks() == null ^ this.getStacks() == null) return false; if (other.getStacks() != null && other.getStacks().equals(this.getStacks()) == false) return false; if (other.getNextToken() == null ^ this.getNextToken() == null) return false; if (other.getNextToken() != null && other.getNextToken().equals(this.getNextToken()) == false) return false; return true; }
public DescribeStacksResult unmarshall(StaxUnmarshallerContext context) throws Exception { DescribeStacksResult describeStacksResult = new DescribeStacksResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return describeStacksResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Stacks", targetDepth)) { describeStacksResult.withStacks(new ArrayList<Stack>()); continue; } if (context.testExpression("Stacks/member", targetDepth)) { describeStacksResult.withStacks(StackStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("NextToken", targetDepth)) { describeStacksResult.setNextToken(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return describeStacksResult; } } } }
/** * 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 (getStacks() != null) sb.append("Stacks: ").append(getStacks()).append(","); if (getNextToken() != null) sb.append("NextToken: ").append(getNextToken()); sb.append("}"); return sb.toString(); }
private void waitForStackCreationToComplete() throws InterruptedException { DescribeStacksRequest check = new DescribeStacksRequest().withStackName(getStackName()); boolean completed = false; while(!completed) { List<Stack> results = client.describeStacks(check).getStacks(); if(results.isEmpty()){ throw new RuntimeException("Stack Does Not Exist."); } else { if(results.stream().anyMatch(this::checkIfStackCreationFailed)) { throw new RuntimeException("Stack Creation or Update Failed"); } else if(results.stream().anyMatch(this::checkIfStackCreationSucceeded)) { System.out.println("Stack Creation Complete"); completed = true; } } if(!completed) Thread.sleep(5000); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStacks() == null) ? 0 : getStacks().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
public static boolean waitForCloudFormationStackToReachStatus( AmazonCloudFormationClient client, String stackName, String status) { int count = 0; while (true) { if (count++ == 100) { System.out .println(stackName + " never reached state " + status); return false; } try { Thread.sleep(1000 * 30); } catch (InterruptedException e) { System.out.println(e.getMessage()); return false; } String stackStatus = client .describeStacks( new DescribeStacksRequest() .withStackName(stackName)).getStacks() .get(0).getStackStatus(); if (stackStatus.equals(status)) { return true; } else if (stackStatus.contains(FAILED)) { System.out.println("The process failed with status " + stackStatus); return false; } System.out.println(stackName + " is in status " + stackStatus); } } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeStacksResult == false) return false; DescribeStacksResult other = (DescribeStacksResult) obj; if (other.getStacks() == null ^ this.getStacks() == null) return false; if (other.getStacks() != null && other.getStacks().equals(this.getStacks()) == false) return false; if (other.getNextToken() == null ^ this.getNextToken() == null) return false; if (other.getNextToken() != null && other.getNextToken().equals(this.getNextToken()) == false) return false; return true; }
protected Optional<Stack> getStack() { final List<Stack> stacks; try { stacks = cloudFormation.describeStacks(new DescribeStacksRequest().withStackName(stackName)).getStacks(); } catch (final AmazonCloudFormationException e) { if (e.getStatusCode() == 400) { return Optional.empty(); } throw e; } if (stacks.isEmpty()) { return Optional.empty(); } if (stacks.size() > 1) { throw new DeploymentException("Found more than one stack for name '" + stackName + "'"); } final Stack stack = stacks.get(0); return Optional.of(stack); } }
/** * 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 (getStacks() != null) sb.append("Stacks: ").append(getStacks()).append(","); if (getNextToken() != null) sb.append("NextToken: ").append(getNextToken()); sb.append("}"); return sb.toString(); }
public boolean exists() { try { DescribeStacksResult result = this.client.describeStacks(new DescribeStacksRequest().withStackName(this.stack)); return !result.getStacks().isEmpty(); } catch (AmazonCloudFormationException e) { if ("AccessDenied".equals(e.getErrorCode())) { this.listener.getLogger().format("Got error from describeStacks: %s %n", e.getErrorMessage()); throw e; } else if ("ValidationError".equals(e.getErrorCode()) && e.getErrorMessage().contains("does not exist")) { return false; } else { throw e; } } }
private Collection<Output> listOutputs() { if (isEmpty(stackId)) { return Collections.emptyList(); } String nextToken = null; final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId); List<Output> result = new ArrayList<>(); do { request.setNextToken(nextToken); final DescribeStacksResult response = getService().describeStacks(request); result.addAll(response.getStacks().stream().flatMap(stack -> stack.getOutputs().stream()).collect(Collectors.toList())); nextToken = response.getNextToken(); } while (null != nextToken); return result; } }
public static List<Stack> describeCloudFormationStack(final String stackName, final AmazonCloudFormation cloudFormationClient) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest() .withStackName(stackName); return cloudFormationClient.describeStacks(describeStacksRequest).getStacks(); }