@Override public Boolean call() { LOGGER.info( "Checking if AWS CloudFormation stack '{}' reached status '{}'", cloudFormationStackName, successStatus); try { com.amazonaws.services.cloudformation.model.Stack cfStack = cfClient.describeStacks(describeStacksRequest).getStacks().get(0); List<StackEvent> stackEvents = cfClient.describeStackEvents(stackEventsRequest).getStackEvents(); return doCheck(cfStack, stackEvents); } catch (AmazonServiceException e) { return handleError(e); } }
public void make() { TvaritEnvironment tvaritEnvironment = TvaritEnvironment.getInstance(); AmazonCloudFormationClient amazonCloudFormationClient = TvaritEnvironment.getInstance().getAmazonCloudFormationClient(); CreateStackRequest createVpcStackRequest = new CreateStackRequest(); URL url; try { url = tvaritEnvironment.getTemplateUrlMaker().makeUrl("base/main.template"); } catch (MalformedURLException e) { throw new RuntimeException(e); } createVpcStackRequest .withTemplateURL(url.toString()) .withStackName("tvarit-base-infrastructure"); List<Parameter> makeVpcParameters = new MakeBaseInfrastructureParameterMaker().make(); createVpcStackRequest .withParameters(makeVpcParameters) .withCapabilities(Capability.CAPABILITY_IAM); amazonCloudFormationClient.createStack(createVpcStackRequest); }
@Override public void execute() throws BuildException { checkParams(); AmazonCloudFormationClient client = getOrCreateClient(AmazonCloudFormationClient.class); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(stackName); try { DescribeStacksResult result = client.describeStacks(describeStacksRequest); Stack stack = result.getStacks().get(0); // put the desired stack parameters into properties if (stack.getParameters() != null) { for (Parameter parameter : stack.getParameters()) { StackItem item = parameters.remove(parameter.getParameterKey()); if (item != null) { getProject().setNewProperty(item.getProperty(), parameter.getParameterValue()); } } } for (StackItem item : parameters.values()) { getProject().setNewProperty(item.getName(), item.getDefault()); } if (stack.getTags() != null) { for (Tag tag : stack.getTags()) { StackItem item = tags.remove(tag.getKey()); if (item != null) { getProject().setNewProperty(item.getName(), tag.getValue()); } } } for (StackItem item : tags.values()) { getProject().setNewProperty(item.getProperty(), item.getDefault()); } } catch (Exception e) { throw new BuildException("Could not describe stack " + e.getMessage(), e); } }
/** * Shuts down the client, releasing all managed resources. This includes forcibly terminating all * pending asynchronous service calls. Clients who wish to give pending asynchronous service calls * time to complete should call {@code getExecutorService().shutdown()} followed by {@code * getExecutorService().awaitTermination()} prior to calling this method. */ @Override public void shutdown() { super.shutdown(); executorService.shutdownNow(); }