Example usage for com.amazonaws.services.elasticbeanstalk AWSElasticBeanstalk describeApplicationVersions

List of usage examples for com.amazonaws.services.elasticbeanstalk AWSElasticBeanstalk describeApplicationVersions

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticbeanstalk AWSElasticBeanstalk describeApplicationVersions.

Prototype

DescribeApplicationVersionsResult describeApplicationVersions(
        DescribeApplicationVersionsRequest describeApplicationVersionsRequest);

Source Link

Document

Retrieve a list of application versions.

Usage

From source file:jp.classmethod.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCleanupApplicationVersionTask.java

License:Apache License

@TaskAction
public void deleteVersion() {
    // to enable conventionMappings feature
    String appName = getAppName();
    boolean deleteSourceBundle = isDeleteSourceBundle();

    AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class);
    AWSElasticBeanstalk eb = ext.getClient();

    DescribeEnvironmentsResult der = eb//w  w w.  j av  a 2s  . c  o m
            .describeEnvironments(new DescribeEnvironmentsRequest().withApplicationName(appName));
    List<String> usingVersions = der.getEnvironments().stream().map(ed -> ed.getVersionLabel())
            .collect(Collectors.toList());

    DescribeApplicationVersionsResult davr = eb
            .describeApplicationVersions(new DescribeApplicationVersionsRequest().withApplicationName(appName));
    List<String> versionLabelsToDelete = davr.getApplicationVersions().stream()
            .filter(avd -> usingVersions.contains(avd.getVersionLabel()) == false
                    && avd.getVersionLabel().contains("-SNAPSHOT-"))
            .map(avd -> avd.getVersionLabel()).collect(Collectors.toList());

    versionLabelsToDelete.forEach(versionLabel -> {
        getLogger().info("version " + versionLabel + " deleted");
        eb.deleteApplicationVersion(new DeleteApplicationVersionRequest().withApplicationName(appName)
                .withVersionLabel(versionLabel).withDeleteSourceBundle(deleteSourceBundle));
    });
}