@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getOutputKey() == null) ? 0 : getOutputKey().hashCode()); hashCode = prime * hashCode + ((getOutputValue() == null) ? 0 : getOutputValue().hashCode()); hashCode = prime * hashCode + ((getDescription() == null) ? 0 : getDescription().hashCode()); hashCode = prime * hashCode + ((getExportName() == null) ? 0 : getExportName().hashCode()); return hashCode; }
public Output unmarshall(StaxUnmarshallerContext context) throws Exception { Output output = new Output(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; output.setOutputKey(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; output.setOutputValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; output.setDescription(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; output.setExportName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
private void logStackOutput() { getStackOutput().forEach( output -> logger.lifecycle("Stack output {} = {}", output.getOutputKey(), output.getOutputValue())); }
private void printOutputs(Stack stack) { getLogger().info("==== Outputs ===="); stack.getOutputs().stream() .forEach(o -> getLogger().info("{} ({}) = {}", o.getOutputKey(), o.getDescription(), o.getOutputValue())); } }
private String resolvePropertyName(Output o) { // TODO Handle Globs + Eventual Replacements if (outputMapping.containsKey(o.getOutputKey())) { final String replacementKey = outputMapping.get(o.getOutputKey()); getLog().info("There's a <outputMapping/> entry for '" + o.getOutputKey() + "' (set to '" + replacementKey + "') declared. Using it instead."); return replacementKey; } return "cloudformation.stack." + o.getOutputKey(); }
getLog().info(" * Setting as:"); getLog().info(" * key: " + propertyName); getLog().info(" * value: " + o.getOutputValue()); result.put(propertyName, o.getOutputValue());
private Properties getCloudformationOutputs(AmazonCloudFormation cloudFormation, CreateStackResult stack) { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.setStackName(stack.getStackId()); final DescribeStacksResult describeStacksResult = cloudFormation .describeStacks(describeStacksRequest); Properties outputProps = new Properties(); for (Stack st : describeStacksResult.getStacks()) { StringBuilder outputsStr = new StringBuilder("Infrastructure/Deployment outputs {\n"); for (Output output : st.getOutputs()) { outputProps.setProperty(output.getOutputKey(), output.getOutputValue()); outputsStr.append(output.getOutputKey()).append("=").append(output.getOutputValue()).append("\n"); } //Log cfn outputs logger.info(outputsStr.toString() + "\n}"); } return outputProps; }
public String findStackOutputValue(String stackName, String key) { Optional<Output> output = getStackOutputs(stackName).stream() .filter(p -> p.getOutputKey().equals(key)) .findAny(); if (output.isPresent() == false) { logger.warn("WARN: output {} for stack {} is not found", key, stackName); } return output.map(Output::getOutputValue).orElse(null); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof Output == false) return false; Output other = (Output) obj; if (other.getOutputKey() == null ^ this.getOutputKey() == null) return false; if (other.getOutputKey() != null && other.getOutputKey().equals(this.getOutputKey()) == false) return false; if (other.getOutputValue() == null ^ this.getOutputValue() == null) return false; if (other.getOutputValue() != null && other.getOutputValue().equals(this.getOutputValue()) == 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.getExportName() == null ^ this.getExportName() == null) return false; if (other.getExportName() != null && other.getExportName().equals(this.getExportName()) == false) return false; return true; }
public Map<String, String> describeOutputs() { DescribeStacksResult result = this.client.describeStacks(new DescribeStacksRequest().withStackName(this.stack)); Stack cfnStack = result.getStacks().get(0); Map<String, String> map = new HashMap<>(); for (Output output : cfnStack.getOutputs()) { map.put(output.getOutputKey(), output.getOutputValue()); } return map; }
/** * Gets the given stack's output by its key. * * @param stackName the stack name * @param outputKey the output key * @return future of stack's output of failed future if stack or output does not exist */ public CompletableFuture<Output> getStackOutput(String stackName, String outputKey) { return getStackOutputs(stackName) .thenApply(findFirst(o -> o.getOutputKey().equals(outputKey))) .thenApply(Optional::get); }
public Output unmarshall(StaxUnmarshallerContext context) throws Exception { Output output = new Output(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; output.setOutputKey(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; output.setOutputValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; output.setDescription(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; output.setExportName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
/** * 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 (getOutputKey() != null) sb.append("OutputKey: ").append(getOutputKey()).append(","); if (getOutputValue() != null) sb.append("OutputValue: ").append(getOutputValue()).append(","); if (getDescription() != null) sb.append("Description: ").append(getDescription()).append(","); if (getExportName() != null) sb.append("ExportName: ").append(getExportName()); sb.append("}"); return sb.toString(); }
@TaskAction public void writeStackOutput() { final DeployService deployService = new DeployService(config, getLogger()); final List<Output> output = deployService.getStackOutput(); final Properties prop = new Properties(); output.forEach(o -> prop.setProperty(o.getOutputKey(), o.getOutputValue())); getLogger().info("Writing {} stack outputs to {}", prop.size(), outputFile); try (Writer writer = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) { prop.store(writer, "Output of stack " + config.getStackName()); } catch (final IOException e) { throw new DeploymentException("Error writing to file " + outputFile, e); } } }
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.")); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getOutputKey() == null) ? 0 : getOutputKey().hashCode()); hashCode = prime * hashCode + ((getOutputValue() == null) ? 0 : getOutputValue().hashCode()); hashCode = prime * hashCode + ((getDescription() == null) ? 0 : getDescription().hashCode()); hashCode = prime * hashCode + ((getExportName() == null) ? 0 : getExportName().hashCode()); return hashCode; }
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."); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof Output == false) return false; Output other = (Output) obj; if (other.getOutputKey() == null ^ this.getOutputKey() == null) return false; if (other.getOutputKey() != null && other.getOutputKey().equals(this.getOutputKey()) == false) return false; if (other.getOutputValue() == null ^ this.getOutputValue() == null) return false; if (other.getOutputValue() != null && other.getOutputValue().equals(this.getOutputValue()) == 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.getExportName() == null ^ this.getExportName() == null) return false; if (other.getExportName() != null && other.getExportName().equals(this.getExportName()) == false) return false; return true; }
List<Output> outputs = stack.getOutputs(); for (Output output : outputs) { stackOutput.put(output.getOutputKey(), output.getOutputValue());
/** * 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 (getOutputKey() != null) sb.append("OutputKey: ").append(getOutputKey()).append(","); if (getOutputValue() != null) sb.append("OutputValue: ").append(getOutputValue()).append(","); if (getDescription() != null) sb.append("Description: ").append(getDescription()).append(","); if (getExportName() != null) sb.append("ExportName: ").append(getExportName()); sb.append("}"); return sb.toString(); }