@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStackId() == null) ? 0 : getStackId().hashCode()); hashCode = prime * hashCode + ((getStackName() == null) ? 0 : getStackName().hashCode()); hashCode = prime * hashCode + ((getChangeSetId() == null) ? 0 : getChangeSetId().hashCode()); hashCode = prime * hashCode + ((getDescription() == null) ? 0 : getDescription().hashCode()); hashCode = prime * hashCode + ((getParameters() == null) ? 0 : getParameters().hashCode()); hashCode = prime * hashCode + ((getCreationTime() == null) ? 0 : getCreationTime().hashCode()); hashCode = prime * hashCode + ((getDeletionTime() == null) ? 0 : getDeletionTime().hashCode()); hashCode = prime * hashCode + ((getLastUpdatedTime() == null) ? 0 : getLastUpdatedTime().hashCode()); hashCode = prime * hashCode + ((getRollbackConfiguration() == null) ? 0 : getRollbackConfiguration().hashCode()); hashCode = prime * hashCode + ((getStackStatus() == null) ? 0 : getStackStatus().hashCode()); hashCode = prime * hashCode + ((getStackStatusReason() == null) ? 0 : getStackStatusReason().hashCode()); hashCode = prime * hashCode + ((getDisableRollback() == null) ? 0 : getDisableRollback().hashCode()); hashCode = prime * hashCode + ((getNotificationARNs() == null) ? 0 : getNotificationARNs().hashCode()); hashCode = prime * hashCode + ((getTimeoutInMinutes() == null) ? 0 : getTimeoutInMinutes().hashCode()); hashCode = prime * hashCode + ((getCapabilities() == null) ? 0 : getCapabilities().hashCode()); hashCode = prime * hashCode + ((getOutputs() == null) ? 0 : getOutputs().hashCode()); hashCode = prime * hashCode + ((getRoleARN() == null) ? 0 : getRoleARN().hashCode()); hashCode = prime * hashCode + ((getTags() == null) ? 0 : getTags().hashCode()); hashCode = prime * hashCode + ((getEnableTerminationProtection() == null) ? 0 : getEnableTerminationProtection().hashCode()); hashCode = prime * hashCode + ((getParentId() == null) ? 0 : getParentId().hashCode()); hashCode = prime * hashCode + ((getRootId() == null) ? 0 : getRootId().hashCode()); hashCode = prime * hashCode + ((getDriftInformation() == null) ? 0 : getDriftInformation().hashCode()); return hashCode; }
stackAttributes.put("stackId", stack.getStackId()); stackAttributes.put("tags", stack.getTags().stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue))); stackAttributes.put("outputs", stack.getOutputs().stream().collect(Collectors.toMap(Output::getOutputKey, Output::getOutputValue))); stackAttributes.put("stackName", stack.getStackName()); stackAttributes.put("region", region); stackAttributes.put("accountName", account.getName()); stackAttributes.put("accountId", account.getAccountId()); stackAttributes.put("stackStatus", stack.getStackStatus()); stackAttributes.put("creationTime", stack.getCreationTime()); if (stack.getStackStatus().equals("ROLLBACK_COMPLETE")) { DescribeStackEventsRequest request = new DescribeStackEventsRequest().withStackName(stack.getStackName()); cloudformation.describeStackEvents(request).getStackEvents() .stream() .map(statusReason -> stackAttributes.put("stackStatusReason", statusReason)); String stackCacheKey = Keys.getCloudFormationKey(stack.getStackId(), region, account.getName()); Map<String, Collection<String>> relationships = new HashMap<>(); relationships.put(STACKS.getNs(), Collections.singletonList(stackCacheKey));
results.put(Outputs.RETURN_RESULT, stack.getStackName() + "[" + stack.getStackStatus() + "]" ); results.put(Outputs.STACK_NAME_RESULT, stack.getStackName()); results.put(Outputs.STACK_ID_RESULT,stack.getStackId()); results.put(Outputs.STACK_STATUS_RESULT,stack.getStackStatus()); results.put(Outputs.STACK_STATUS_RESULT_REASON,stack.getStackStatusReason()); results.put(Outputs.STACK_CREATION_TIME_RESULT,stack.getCreationTime().toString()); results.put(Outputs.STACK_DESCRIPTION_RESULT,stack.getDescription()); results.put(Outputs.STACK_OUTPUTS_RESULT,stack.getOutputs().toString()); stackResourceRequest.setStackName(stack.getStackName()); results.put(Outputs.STACK_RESOURCES_RESULT,stackBuilder.describeStackResources(stackResourceRequest).getStackResources().toString());
@Override public String getStatus() { return getStack().flatMap(stack -> Optional.of(stack.getStackStatus())) // .orElse(STACK_DOES_NOT_EXIST_STATUS); }
public CompletableFuture<Stack> getStackWhen(String stackName, String... statuses) { DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackName); return describeStacks(request).thenApply(firstStack()).thenComposeAsync(stack -> { if (ImmutableSet.copyOf(statuses).contains(stack.getStackStatus()) && !stack.getOutputs().isEmpty()) { return CompletableFuture.completedFuture(stack); } else { Threads.sleep(1000); return getStackWhen(stackName, statuses); } }, executor); }
StackStatus status = getStackStatus(stack.getStackStatus()); List<Output> outputs = stack.getOutputs(); for (Output output : outputs) { stackOutput.put(output.getOutputKey(), output.getOutputValue()); return true; } else { logger.println("Failed to create stack: " + getExpandedStackName() + ". Reason: " + stack.getStackStatusReason()); return false;
public static String getStackOutputsToJson(Stack stack) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, stack.getOutputs()); final byte[] stackOutputs = out.toByteArray(); return new String(stackOutputs); } }
public boolean stackExists(String stackName) { try { return describeStack(stackName).stream() // .peek(s -> logger.info("Found stack {}", s)) // .filter(s -> s.getStackName().equals(stackName)) // .anyMatch(s -> !s.getStackStatus().equals("REVIEW_IN_PROGRESS")); } catch (final AmazonCloudFormationException e) { if (e.getStatusCode() == 400) { logger.trace("Got exception {}", e.getMessage(), e); return false; } throw e; } }
for (Stack stack : stacks) { if (stack.getStackStatus().contains("FAILED") || stack.getStackStatus().equals(StackStatus.UPDATE_ROLLBACK_COMPLETE.toString()) || stack.getStackStatus().equals(StackStatus.ROLLBACK_COMPLETE.toString()) ) { throw new Exception("Cloudformation failed. Please check AWS Console for details"); if (stack.getStackStatus().equals(StackStatus.UPDATE_COMPLETE.toString()) || stack.getStackStatus().equals(StackStatus.CREATE_COMPLETE.toString()) ) { completed = true; stackStatus = stack.getStackStatus(); stackReason = stack.getStackStatusReason();
public CloudFormationOutput getStackOutputs(AmazonCloudFormation stackbuilder, String stackName) { DescribeStacksRequest wait = new DescribeStacksRequest(); wait.setStackName(stackName); List<Stack> stacks = getCloudFormationClient().describeStacks(wait).getStacks(); CloudFormationOutput cloudFormationOutput = new CloudFormationOutput(); for (Stack stack : stacks) { if (stack.getStackName().equals(stackName)) { stack.getOutputs().forEach(output -> { if (output.getOutputKey().equals(LAMBDA_EXECUTION_IAM_RESOURCE_NAME)) { cloudFormationOutput.setLambdaExecutionRole(output.getOutputValue()); } if (output.getOutputKey().equals(LAMBDA_EXECUTION_NAME)) { cloudFormationOutput.setLambdaFunctionArn(output.getOutputValue()); } }); return cloudFormationOutput; } } throw new RuntimeException("Unknown Cloudformation error. Try deploying."); }
results.put(STACK_NAME, getStack(stacks).getStackName()); results.put(STACK_ID, getStack(stacks).getStackId()); results.put(STACK_OUTPUTS, stackOutputs); results.put(STACK_RESOURCES, stackResources);
private Stack getStack(DescribeStacksResult result) { for (Stack aStack : result.getStacks()) { if (getExpandedStackName().equals(aStack.getStackName())) { return aStack; } } return null; }
if(stack.getParameters() != null) { for(Parameter parameter : stack.getParameters()) { StackItem item = parameters.remove(parameter.getParameterKey()); if(item != null) { if(stack.getTags() != null) { for(Tag tag : stack.getTags()) { StackItem item = tags.remove(tag.getKey()); if(item != null) {
@Override protected Map<String, String> createInstance() throws Exception { LinkedHashMap<String, String> userTags = new LinkedHashMap<>(); DescribeStacksResult stacksResult = this.amazonCloudFormation.describeStacks(new DescribeStacksRequest().withStackName(this.stackNameProvider.getStackName())); for (Stack stack : stacksResult.getStacks()) { for (Tag tag : stack.getTags()) { userTags.put(tag.getKey(), tag.getValue()); } } return userTags; } }
public Map<String, String> getStackParameters(String stackName) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.setStackName(stackName); DescribeStacksResult describeStacksResult = client .describeStacks(describeStacksRequest); List<Stack> stacks = describeStacksResult.getStacks(); Stack stack = stacks.get(0); List<Parameter> parameters = stack.getParameters(); Map<String, String> map = new LinkedHashMap<String, String>(); for (Parameter parameter : parameters) { map.put(parameter.getParameterKey(), parameter.getParameterValue()); } return map; }
@Override public String getStatus() { final Optional<Stack> stack = getStack(); if (!stack.isPresent()) { throw new DeploymentException("Stack " + stackName + " not found"); } return stack.get().getStackStatus(); }
public List<Output> getOutputParameters(String stackName) { final Stack stack = describeStack(stackName).stream().findFirst() .orElseThrow(() -> new DeploymentException("Stack not found")); return stack.getOutputs(); }
listOfStacksResult.append(stack.getStackName() + Constants.Miscellaneous.COMMA_DELIMITER);
@Override protected Map<String, String> createInstance() throws Exception { LinkedHashMap<String, String> userTags = new LinkedHashMap<>(); DescribeStacksResult stacksResult = this.amazonCloudFormation.describeStacks(new DescribeStacksRequest().withStackName(this.stackNameProvider.getStackName())); for (Stack stack : stacksResult.getStacks()) { for (Tag tag : stack.getTags()) { userTags.put(tag.getKey(), tag.getValue()); } } return userTags; } }
return false; Stack other = (Stack) obj; if (other.getStackId() == null ^ this.getStackId() == null) return false; if (other.getStackId() != null && other.getStackId().equals(this.getStackId()) == false) return false; if (other.getStackName() == null ^ this.getStackName() == null) return false; if (other.getStackName() != null && other.getStackName().equals(this.getStackName()) == false) return false; if (other.getChangeSetId() == null ^ this.getChangeSetId() == null) return false; if (other.getChangeSetId() != null && other.getChangeSetId().equals(this.getChangeSetId()) == false) return false; if (other.getDescription() == null ^ this.getDescription() == null) return false; if (other.getDescription() != null && other.getDescription().equals(this.getDescription()) == false) return false; if (other.getParameters() == null ^ this.getParameters() == null) return false; if (other.getParameters() != null && other.getParameters().equals(this.getParameters()) == false) return false; if (other.getCreationTime() == null ^ this.getCreationTime() == null) return false; if (other.getCreationTime() != null && other.getCreationTime().equals(this.getCreationTime()) == false) return false; if (other.getDeletionTime() == null ^ this.getDeletionTime() == null) return false; if (other.getDeletionTime() != null && other.getDeletionTime().equals(this.getDeletionTime()) == false)