Example usage for com.amazonaws.services.elasticbeanstalk.model DescribeApplicationVersionsResult getApplicationVersions

List of usage examples for com.amazonaws.services.elasticbeanstalk.model DescribeApplicationVersionsResult getApplicationVersions

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticbeanstalk.model DescribeApplicationVersionsResult getApplicationVersions.

Prototype


public java.util.List<ApplicationVersionDescription> getApplicationVersions() 

Source Link

Document

List of ApplicationVersionDescription objects sorted in order of creation.

Usage

From source file:br.com.ingenieux.mojo.beanstalk.AbstractNeedsEnvironmentMojo.java

License:Apache License

protected String lookupVersionLabel(String appName, String versionLabel) {
    if (StringUtils.isBlank(versionLabel)) {
        DescribeApplicationVersionsResult appVersionsResult = getService().describeApplicationVersions(
                new DescribeApplicationVersionsRequest().withApplicationName(appName));

        List<ApplicationVersionDescription> appVersionList = new ArrayList<ApplicationVersionDescription>(
                appVersionsResult.getApplicationVersions());

        Collections.sort(appVersionList, new Comparator<ApplicationVersionDescription>() {
            @Override//ww w. j a v a 2s. c  om
            public int compare(ApplicationVersionDescription o1, ApplicationVersionDescription o2) {
                return new CompareToBuilder().append(o2.getDateUpdated(), o1.getDateUpdated())
                        .append(o2.getDateCreated(), o1.getDateUpdated()).toComparison();
            }
        });

        if (appVersionList.isEmpty()) {
            String message = "No version label supplied **AND** no app versions available.";

            getLog().info(message);

            throw new IllegalStateException(message);
        } else {
            versionLabel = appVersionList.get(0).getVersionLabel();

            getLog().info("Using latest available application version " + versionLabel);
        }
    }

    return versionLabel;
}

From source file:br.com.ingenieux.mojo.beanstalk.version.CleanPreviousVersionsMojo.java

License:Apache License

@Override
protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
    boolean bVersionsToKeepDefined = (null != versionsToKeep);
    boolean bDaysToKeepDefined = (null != daysToKeep);

    if (!(bVersionsToKeepDefined ^ bDaysToKeepDefined)) {
        throw new MojoFailureException("Declare either versionsToKeep or daysToKeep, but not both nor none!");
    }// w  ww . j  av  a 2  s  .  c  o m

    DescribeApplicationVersionsRequest describeApplicationVersionsRequest = new DescribeApplicationVersionsRequest()
            .withApplicationName(applicationName);

    DescribeApplicationVersionsResult appVersions = getService()
            .describeApplicationVersions(describeApplicationVersionsRequest);

    DescribeEnvironmentsResult environments = getService().describeEnvironments();

    List<ApplicationVersionDescription> appVersionList = new ArrayList<ApplicationVersionDescription>(
            appVersions.getApplicationVersions());

    deletedVersionsCount = 0;

    for (EnvironmentDescription d : environments.getEnvironments()) {
        boolean bActiveEnvironment = (d.getStatus().equals("Running") || d.getStatus().equals("Launching")
                || d.getStatus().equals("Ready"));

        for (ListIterator<ApplicationVersionDescription> appVersionIterator = appVersionList
                .listIterator(); appVersionIterator.hasNext();) {
            ApplicationVersionDescription appVersion = appVersionIterator.next();

            boolean bMatchesVersion = appVersion.getVersionLabel().equals(d.getVersionLabel());

            if (bActiveEnvironment && bMatchesVersion) {
                getLog().info("VersionLabel " + appVersion.getVersionLabel() + " is bound to environment "
                        + d.getEnvironmentName() + " - Skipping it");

                appVersionIterator.remove();
            }
        }
    }

    filterAppVersionListByVersionLabelPattern(appVersionList, cleanFilter);

    Collections.sort(appVersionList, new Comparator<ApplicationVersionDescription>() {
        @Override
        public int compare(ApplicationVersionDescription o1, ApplicationVersionDescription o2) {
            return new CompareToBuilder().append(o1.getDateUpdated(), o2.getDateUpdated()).toComparison();
        }
    });

    if (bDaysToKeepDefined) {
        Date now = new Date();

        for (ApplicationVersionDescription d : appVersionList) {
            long delta = now.getTime() - d.getDateUpdated().getTime();

            delta /= 1000;
            delta /= 86400;

            boolean shouldDeleteP = (delta > daysToKeep);

            if (getLog().isDebugEnabled()) {
                getLog().debug("Version " + d.getVersionLabel() + " was from " + delta
                        + " days ago. Should we delete? " + shouldDeleteP);
            }

            if (shouldDeleteP) {
                deleteVersion(d);
            }
        }
    } else {
        while (appVersionList.size() > versionsToKeep) {
            deleteVersion(appVersionList.remove(0));
        }
    }

    getLog().info("Deleted " + deletedVersionsCount + " versions.");

    return null;
}

From source file:br.com.ingenieux.mojo.beanstalk.version.CreateApplicationVersionMojo.java

License:Apache License

private boolean versionLabelExists() {
    /*//w  w w  .j  av a 2 s  .c om
    * Builds a request for this very specific version label
    */
    DescribeApplicationVersionsRequest davRequest = new DescribeApplicationVersionsRequest()
            .withApplicationName(applicationName).withVersionLabels(versionLabel);

    /*
     * Sends the request
     */
    DescribeApplicationVersionsResult result = getService().describeApplicationVersions(davRequest);

    /*
     * Non-empty means the application version label *DOES* exist.
     */
    return !result.getApplicationVersions().isEmpty();
}

From source file:br.com.ingenieux.mojo.beanstalk.version.RollbackVersionMojo.java

License:Apache License

@Override
protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
    // TODO: Deal with withVersionLabels
    DescribeApplicationVersionsRequest describeApplicationVersionsRequest = new DescribeApplicationVersionsRequest()
            .withApplicationName(applicationName);

    DescribeApplicationVersionsResult appVersions = getService()
            .describeApplicationVersions(describeApplicationVersionsRequest);

    DescribeEnvironmentsRequest describeEnvironmentsRequest = new DescribeEnvironmentsRequest()
            .withApplicationName(applicationName).withEnvironmentIds(curEnv.getEnvironmentId())
            .withEnvironmentNames(curEnv.getEnvironmentName()).withIncludeDeleted(false);

    DescribeEnvironmentsResult environments = getService().describeEnvironments(describeEnvironmentsRequest);

    List<ApplicationVersionDescription> appVersionList = new ArrayList<ApplicationVersionDescription>(
            appVersions.getApplicationVersions());

    List<EnvironmentDescription> environmentList = environments.getEnvironments();

    if (environmentList.isEmpty()) {
        throw new MojoFailureException("No environments were found");
    }/*from   w  w w .  j  a v a 2s.co m*/

    EnvironmentDescription d = environmentList.get(0);

    Collections.sort(appVersionList, new Comparator<ApplicationVersionDescription>() {
        @Override
        public int compare(ApplicationVersionDescription o1, ApplicationVersionDescription o2) {
            return new CompareToBuilder().append(o1.getDateUpdated(), o2.getDateUpdated()).toComparison();
        }
    });

    Collections.reverse(appVersionList);

    if (latestVersionInstead) {
        ApplicationVersionDescription latestVersionDescription = appVersionList.get(0);

        return changeToVersion(d, latestVersionDescription);
    }

    ListIterator<ApplicationVersionDescription> versionIterator = appVersionList.listIterator();

    String curVersionLabel = d.getVersionLabel();

    while (versionIterator.hasNext()) {
        ApplicationVersionDescription versionDescription = versionIterator.next();

        String versionLabel = versionDescription.getVersionLabel();

        if (curVersionLabel.equals(versionLabel) && versionIterator.hasNext()) {
            return changeToVersion(d, versionIterator.next());
        }
    }

    throw new MojoFailureException("No previous version was found (current version: " + curVersionLabel);
}

From source file:com.tracermedia.maven.plugins.CreateVersionMojo.java

License:Open Source License

protected List<ApplicationVersionDescription> getVersions() {
    final DescribeApplicationVersionsResult versionsResult = getBeanstalkClient().describeApplicationVersions();

    return versionsResult.getApplicationVersions();
}

From source file:jetbrains.buildServer.runner.elasticbeanstalk.AWSClient.java

License:Apache License

private boolean doesApplicationVersionExist(@NotNull String applicationName, @NotNull String versionLabel) {
    DescribeApplicationVersionsRequest request = new DescribeApplicationVersionsRequest()
            .withApplicationName(applicationName).withVersionLabels(versionLabel);

    DescribeApplicationVersionsResult describeApplicationVersionsResult = myElasticBeanstalkClient
            .describeApplicationVersions(request);

    List<ApplicationVersionDescription> applicationVersions = describeApplicationVersionsResult
            .getApplicationVersions();// ww  w.  j a  va  2  s .co m

    return applicationVersions != null && applicationVersions.size() > 0;
}

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// ww  w.j ava 2  s  .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));
    });
}