Search in sources :

Example 1 with DescribeStacksRequest

use of com.amazonaws.services.cloudformation.model.DescribeStacksRequest in project pipeline-aws-plugin by jenkinsci.

the class CloudFormationStack method describeOutputs.

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;
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) HashMap(java.util.HashMap) Output(com.amazonaws.services.cloudformation.model.Output) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack)

Example 2 with DescribeStacksRequest

use of com.amazonaws.services.cloudformation.model.DescribeStacksRequest in project pipeline-aws-plugin by jenkinsci.

the class EventPrinter method waitAndPrintStackEvents.

public void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, long pollIntervalMillis) throws ExecutionException {
    final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
    waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)), new WaiterHandler() {

        @Override
        public void onWaitSuccess(AmazonWebServiceRequest request) {
            waitResult.completed(request);
        }

        @Override
        public void onWaitFailure(Exception e) {
            waitResult.failed(e);
        }
    });
    this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) BasicFuture(org.apache.http.concurrent.BasicFuture) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) WaiterHandler(com.amazonaws.waiters.WaiterHandler) ExecutionException(java.util.concurrent.ExecutionException) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)

Example 3 with DescribeStacksRequest

use of com.amazonaws.services.cloudformation.model.DescribeStacksRequest in project cloudbreak by hortonworks.

the class AwsResourceConnector method getOutputs.

private Map<String, String> getOutputs(String cFStackName, AmazonCloudFormation client) {
    DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
    String outputNotFound = String.format("Couldn't get Cloudformation stack's('%s') output", cFStackName);
    List<Output> cfStackOutputs = client.describeStacks(describeStacksRequest).getStacks().stream().findFirst().orElseThrow(getCloudConnectorExceptionSupplier(outputNotFound)).getOutputs();
    return cfStackOutputs.stream().collect(Collectors.toMap(Output::getOutputKey, Output::getOutputValue));
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) Output(com.amazonaws.services.cloudformation.model.Output)

Example 4 with DescribeStacksRequest

use of com.amazonaws.services.cloudformation.model.DescribeStacksRequest in project cloudbreak by hortonworks.

the class AwsStackValidator method validate.

@Override
public void validate(AuthenticatedContext ac, CloudStack cloudStack) {
    AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
    String regionName = ac.getCloudContext().getLocation().getRegion().value();
    AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
    String cFStackName = cfStackUtil.getCfStackName(ac);
    try {
        cfClient.describeStacks(new DescribeStacksRequest().withStackName(cFStackName));
        throw new CloudConnectorException(String.format("Stack is already exists with the given name: %s", cFStackName));
    } catch (AmazonServiceException ignored) {
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient)

Example 5 with DescribeStacksRequest

use of com.amazonaws.services.cloudformation.model.DescribeStacksRequest in project cloudbreak by hortonworks.

the class AwsCreateVpcNetworkTest method getOutputForRequest.

private List<Output> getOutputForRequest(String vpcStackName, AmazonCloudFormation client) {
    int tried = 0;
    while (tried < MAX_TRY) {
        LOGGER.info("checking vpc stack creation result, tried: " + tried + '/' + MAX_TRY);
        DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest();
        describeStacksRequest.withStackName(vpcStackName);
        Stack resultStack = client.describeStacks(describeStacksRequest).getStacks().get(0);
        StackStatus stackStatus = StackStatus.valueOf(resultStack.getStackStatus());
        if (FAILED_STATUSES.contains(stackStatus)) {
            LOGGER.error("stack creation failed: {}", stackStatus);
            throw new RuntimeException();
        } else if (CREATE_COMPLETE.equals(stackStatus)) {
            return resultStack.getOutputs();
        }
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            LOGGER.error("thread sleep interrupted", e);
        }
        tried++;
    }
    throw new RuntimeException("vpc creation timed out");
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) StackStatus(com.amazonaws.services.cloudformation.model.StackStatus) Stack(com.amazonaws.services.cloudformation.model.Stack)

Aggregations

DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)8 AmazonServiceException (com.amazonaws.AmazonServiceException)3 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)3 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)3 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)3 Output (com.amazonaws.services.cloudformation.model.Output)2 Stack (com.amazonaws.services.cloudformation.model.Stack)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)1 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)1 AmazonCloudFormationException (com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)1 DeleteChangeSetRequest (com.amazonaws.services.cloudformation.model.DeleteChangeSetRequest)1 DeleteStackRequest (com.amazonaws.services.cloudformation.model.DeleteStackRequest)1 DescribeStacksResult (com.amazonaws.services.cloudformation.model.DescribeStacksResult)1 ExecuteChangeSetRequest (com.amazonaws.services.cloudformation.model.ExecuteChangeSetRequest)1 StackStatus (com.amazonaws.services.cloudformation.model.StackStatus)1 WaiterHandler (com.amazonaws.waiters.WaiterHandler)1 ModelContext (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.ModelContext)1 AwsInstanceProfileView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceProfileView)1