Search in sources :

Example 1 with Output

use of com.amazonaws.services.cloudformation.model.Output 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 Output

use of com.amazonaws.services.cloudformation.model.Output 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 3 with Output

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

the class AwsCreateVpcNetworkTest method createNetwork.

@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "vpcStackName", "vpcName", "existingSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-stack") String vpcStackName, @Optional("it-vpc") String vpcName, boolean existingSubnet) {
    AmazonCloudFormationClient client = new AmazonCloudFormationClient();
    client.setRegion(RegionUtils.getRegion(regionName));
    Map<String, Object> networkMap = new HashMap<>();
    String vpcCreationJson = existingSubnet ? "public_vpc_with_subnet.json" : "public_vpc_wihout_subnet.json";
    try (InputStream vpcJsonInputStream = getClass().getResourceAsStream("/cloudformation/" + vpcCreationJson)) {
        String vpcCFTemplateString = IOUtils.toString(vpcJsonInputStream);
        CreateStackRequest stackRequest = createStackRequest(vpcStackName, vpcName, vpcCFTemplateString);
        client.createStack(stackRequest);
        List<Output> outputForRequest = getOutputForRequest(vpcStackName, client);
        if (existingSubnet) {
            networkMap.put("vpcId", outputForRequest.get(0).getOutputValue());
            networkMap.put("subnetId", outputForRequest.get(1).getOutputValue());
        } else {
            networkMap.put("vpcId", outputForRequest.get(1).getOutputValue());
            networkMap.put("internetGatewayId", outputForRequest.get(0).getOutputValue());
        }
    } catch (IOException e) {
        LOGGER.error("can't read vpc cloudformation template file");
        throw new RuntimeException(e);
    }
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setName(networkName);
    networkRequest.setDescription(description);
    networkRequest.setParameters(networkMap);
    if (!existingSubnet) {
        networkRequest.setSubnetCIDR("10.0.0.0/24");
    }
    networkRequest.setCloudPlatform("AWS");
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) Output(com.amazonaws.services.cloudformation.model.Output) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) IOException(java.io.IOException) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

Output (com.amazonaws.services.cloudformation.model.Output)3 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)2 HashMap (java.util.HashMap)2 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)1 CreateStackRequest (com.amazonaws.services.cloudformation.model.CreateStackRequest)1 DescribeStacksResult (com.amazonaws.services.cloudformation.model.DescribeStacksResult)1 Stack (com.amazonaws.services.cloudformation.model.Stack)1 NetworkRequest (com.sequenceiq.cloudbreak.api.model.NetworkRequest)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1