Example usage for com.amazonaws.services.elasticbeanstalk.model DescribeApplicationVersionsRequest DescribeApplicationVersionsRequest

List of usage examples for com.amazonaws.services.elasticbeanstalk.model DescribeApplicationVersionsRequest DescribeApplicationVersionsRequest

Introduction

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

Prototype

DescribeApplicationVersionsRequest

Source Link

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/*from ww  w  .j  a  va2s .c  o m*/
            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!");
    }/*from   w  ww  .j a  v  a  2s  .  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 .  ja v a  2s. 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.DescribeApplicationVersionsMojo.java

License:Apache License

protected Object executeInternal() throws MojoExecutionException {
    DescribeApplicationVersionsRequest describeApplicationVersionsRequest = new DescribeApplicationVersionsRequest();

    describeApplicationVersionsRequest.setApplicationName(applicationName);

    return getService().describeApplicationVersions(describeApplicationVersionsRequest);
}

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  ww.  j a  va  2 s .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: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();//from w  w  w  .j av  a  2  s  .com

    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//from  ww  w. ja  v a2s. 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));
    });
}