Example usage for com.amazonaws.services.elasticbeanstalk.model ApplicationVersionDescription getDateUpdated

List of usage examples for com.amazonaws.services.elasticbeanstalk.model ApplicationVersionDescription getDateUpdated

Introduction

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

Prototype


public java.util.Date getDateUpdated() 

Source Link

Document

The last modified date of the application version.

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.  ja  va  2s. 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  va 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.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");
    }// ww w . j a v  a2 s  .c  om

    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);
}