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

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

Introduction

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

Prototype


public String getVersionLabel() 

Source Link

Document

A unique identifier for the application version.

Usage

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 w  w.j a  v 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.CleanPreviousVersionsMojo.java

License:Apache License

void deleteVersion(ApplicationVersionDescription versionToRemove) {
    getLog().info("Must delete version: " + versionToRemove.getVersionLabel());

    DeleteApplicationVersionRequest req = new DeleteApplicationVersionRequest()
            .withApplicationName(versionToRemove.getApplicationName())//
            .withDeleteSourceBundle(deleteSourceBundle)//
            .withVersionLabel(versionToRemove.getVersionLabel());

    if (!dryRun) {
        getService().deleteApplicationVersion(req);
        deletedVersionsCount++;//w  w  w.ja  va 2  s .co m
    }
}

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");
    }/* w w  w  .  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:br.com.ingenieux.mojo.beanstalk.version.RollbackVersionMojo.java

License:Apache License

Object changeToVersion(EnvironmentDescription d, ApplicationVersionDescription latestVersionDescription) {
    String curVersionLabel = d.getVersionLabel();
    String versionLabel = latestVersionDescription.getVersionLabel();

    UpdateEnvironmentRequest request = new UpdateEnvironmentRequest().withEnvironmentId(d.getEnvironmentId())
            .withVersionLabel(versionLabel);

    getLog().info("Changing versionLabel for Environment[name=" + curEnv.getEnvironmentName()
            + "; environmentId=" + curEnv.getEnvironmentId() + "] from version " + curVersionLabel
            + " to version " + latestVersionDescription.getVersionLabel());

    if (dryRun) {
        return null;
    }//from   w w w. j a  va 2  s . com

    return getService().updateEnvironment(request);
}

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

License:Open Source License

public void execute() throws MojoExecutionException, MojoFailureException {
    final Date now = new Date();

    if (!project.getPackaging().equalsIgnoreCase("war")
            && !project.getPackaging().equalsIgnoreCase("uberwar")) {
        throw new MojoExecutionException(
                "Only WAR projects can be deployed to Amazon Beanstalk. Not " + project.getPackaging());
    }/*  w  w  w . j a va 2 s.  c  o m*/

    System.out.println("Existing versions:");
    for (ApplicationVersionDescription version : getVersions()) {
        if (version.getApplicationName().equals(applicationName)) {
            System.out.println(String.format("App Name: %25s, version: %20s, S3: %s/%s",
                    version.getApplicationName(), version.getVersionLabel(),
                    version.getSourceBundle().getS3Bucket(), version.getSourceBundle().getS3Key()));
        }
    }

    final Build build = project.getBuild();

    // It would be much better to use project.getPackaging() instead of hardcoding "war". But
    // the Mojo we use to combine multiple WAR files has a package of 'uberwar'.
    String artifactPath = String.format("%s/%s.%s", build.getDirectory(), build.getFinalName(), "war");

    // Need to push the artifact to S3. Place in the s3Bucket using the s3Key. If the key is
    // not specified, it is generated by using the applicationName and appending a timestamp.
    if (s3Key == null) {
        s3Key = applicationName + '-' + DF.format(now);
    }
    try {
        copyFileToS3(s3Bucket, s3Key, new File(artifactPath));
    } catch (IOException e) {
        throw new MojoFailureException("Failed to copy file to Amazon S3", e);
    }

    // If a version label has not been set, we will use the applicationKey and timestamp.
    if (versionLabel == null) {
        versionLabel = applicationName + '-' + DF.format(now);
    }

    // Create the new version of the application.
    createApplicationVersion(applicationName, versionLabel, s3Bucket, s3Key);

    updateEnvironmentVersion(environmentName, versionLabel);
}

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

License:Open Source License

public void execute() throws MojoExecutionException, MojoFailureException {
    System.out.println("Existing versions:");
    final List<ApplicationVersionDescription> versions = getVersions();
    for (ApplicationVersionDescription version : versions) {
        if (version.getApplicationName().equals(this.applicationName)) {
            System.out.println(String.format("App Name: %s,    version: %s,    S3: %s/%s",
                    version.getApplicationName(), version.getVersionLabel(),
                    version.getSourceBundle().getS3Bucket(), version.getSourceBundle().getS3Key()));
        }/*from  w  w w.j a v  a2  s  . c o m*/
    }
    if (versions.size() == 0) {
        System.out.println("None found.");
    }
}

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

License:Open Source License

public void execute() throws MojoExecutionException, MojoFailureException {
    final Date now = new Date();

    // Version label is required
    if (versionLabel == null) {
        throw new IllegalArgumentException("VersionLabel is a required parameter for this goal.");
    }/*from   www .  j  a  va2 s  .co  m*/

    System.out.println("Existing versions:");
    for (ApplicationVersionDescription version : getVersions()) {
        if (version.getApplicationName().equals(applicationName)) {
            System.out.println(String.format("App Name: %s,    version: %s,    S3: %s/%s",
                    version.getApplicationName(), version.getVersionLabel(),
                    version.getSourceBundle().getS3Bucket(), version.getSourceBundle().getS3Key()));
        }
    }

    // Restoring a previously uploaded version
    updateEnvironmentVersion(environmentName, versionLabel);
}

From source file:fr.xebia.workshop.caching.CreateTomcat.java

License:Apache License

public void createServers() {

    String applicationName = "xfr-cocktail";

    // CREATE APPLICATION
    AmazonAwsUtils.deleteBeanstalkApplicationIfExists(applicationName, beanstalk);
    CreateApplicationRequest createApplicationRequest = new CreateApplicationRequest()
            .withApplicationName(applicationName)
            .withDescription("xfr-cocktail app created at " + new DateTime());

    ApplicationDescription applicationDescription = beanstalk.createApplication(createApplicationRequest)
            .getApplication();// ww  w .  j a v  a 2 s. co m
    logger.debug("Application {} created", applicationDescription.getApplicationName());

    // CREATE APPLICATION VERSION
    CreateApplicationVersionRequest createApplicationVersion1Request = new CreateApplicationVersionRequest()
            .withApplicationName(applicationDescription.getApplicationName()).withVersionLabel("1.0.0")
            .withSourceBundle(new S3Location("xfr-workshop-caching", "cocktail-app-1.0.0-SNAPSHOT.war"));
    ApplicationVersionDescription applicationVersion1Description = beanstalk
            .createApplicationVersion(createApplicationVersion1Request).getApplicationVersion();
    logger.debug("Application version {}:{} created", applicationVersion1Description.getApplicationName(),
            applicationVersion1Description.getVersionLabel());
    CreateApplicationVersionRequest createApplicationVersion11Request = new CreateApplicationVersionRequest()
            .withApplicationName(applicationDescription.getApplicationName()).withVersionLabel("1.1.0")
            .withSourceBundle(new S3Location("xfr-workshop-caching", "cocktail-app-1.1.0-SNAPSHOT.war"));
    ApplicationVersionDescription applicationVersion11Description = beanstalk
            .createApplicationVersion(createApplicationVersion11Request).getApplicationVersion();
    logger.debug("Application version {}:{} created", applicationVersion11Description.getApplicationName(),
            applicationVersion11Description.getVersionLabel());
    CreateApplicationVersionRequest createApplicationVersion12Request = new CreateApplicationVersionRequest()
            .withApplicationName(applicationDescription.getApplicationName()).withVersionLabel("1.2.0")
            .withSourceBundle(new S3Location("xfr-workshop-caching", "cocktail-app-1.2.0-SNAPSHOT.war"));
    ApplicationVersionDescription applicationVersion12Description = beanstalk
            .createApplicationVersion(createApplicationVersion12Request).getApplicationVersion();
    logger.debug("Application version {}:{} created", applicationVersion12Description.getApplicationName(),
            applicationVersion12Description.getVersionLabel());

    // CREATE CONFIGURATION TEMPLATE
    CreateConfigurationTemplateRequest createConfigurationTemplateRequest = new CreateConfigurationTemplateRequest()
            .withApplicationName(applicationDescription.getApplicationName())
            .withTemplateName(applicationDescription.getApplicationName() + "-base-configuration")
            .withSolutionStackName("32bit Amazon Linux running Tomcat 7").withOptionSettings(
                    new ConfigurationOptionSetting("aws:autoscaling:launchconfiguration", "InstanceType",
                            "t1.micro"),
                    new ConfigurationOptionSetting("aws:autoscaling:launchconfiguration", "EC2KeyName",
                            workshopInfrastructure.getKeyPairName()),

                    new ConfigurationOptionSetting("aws:elasticbeanstalk:sns:topics", "Notification Endpoint",
                            workshopInfrastructure.getBeanstalkNotificationEmail()),

                    new ConfigurationOptionSetting("aws:elasticbeanstalk:application:environment",
                            "AWS_ACCESS_KEY_ID", workshopInfrastructure.getAwsAccessKeyId()),
                    new ConfigurationOptionSetting("aws:elasticbeanstalk:application:environment",
                            "AWS_SECRET_KEY", workshopInfrastructure.getAwsSecretKey()));
    CreateConfigurationTemplateResult configurationTemplateResult = beanstalk
            .createConfigurationTemplate(createConfigurationTemplateRequest);
    logger.debug("Configuration {}:{} created", configurationTemplateResult.getApplicationName(),
            configurationTemplateResult.getTemplateName(), configurationTemplateResult);

    for (String teamIdentifier : workshopInfrastructure.getTeamIdentifiers()) {
        // CREATE ENVIRONMENT
        CreateEnvironmentRequest createEnvironmentRequest = new CreateEnvironmentRequest()
                .withEnvironmentName(applicationDescription.getApplicationName() + "-" + teamIdentifier)
                .withApplicationName(applicationDescription.getApplicationName())
                .withVersionLabel(applicationVersion1Description.getVersionLabel())
                .withCNAMEPrefix(applicationDescription.getApplicationName() + "-" + teamIdentifier)
                .withTemplateName(configurationTemplateResult.getTemplateName());

        CreateEnvironmentResult createEnvironmentResult = beanstalk.createEnvironment(createEnvironmentRequest);

        logger.info("Environment {}:{}:{} created at {}", createEnvironmentResult.getApplicationName(),
                createEnvironmentResult.getVersionLabel(), createEnvironmentResult.getEnvironmentName(),
                Strings.nullToEmpty(createEnvironmentResult.getEndpointURL()));

    }
}

From source file:fr.xebia.workshop.nginx.CreateTomcat.java

License:Apache License

public void createServers() {

    String applicationName = "xfr-cocktail-nginx";

    // CREATE APPLICATION
    AmazonAwsUtils.deleteBeanstalkApplicationIfExists(applicationName, beanstalk);
    CreateApplicationRequest createApplicationRequest = new CreateApplicationRequest()
            .withApplicationName(applicationName).withDescription("xfr-cocktail-nginx app");

    ApplicationDescription applicationDescription = beanstalk.createApplication(createApplicationRequest)
            .getApplication();//from ww  w  .j  a v  a 2  s  .  com
    logger.debug("Application {} created", applicationDescription.getApplicationName());

    // CREATE APPLICATION VERSION
    CreateApplicationVersionRequest createApplicationVersion1Request = new CreateApplicationVersionRequest()
            .withApplicationName(applicationDescription.getApplicationName()).withVersionLabel("1.0.0")
            .withSourceBundle(new S3Location("xfr-workshop-caching", "cocktail-app-1.0.0-SNAPSHOT.war"));
    ApplicationVersionDescription applicationVersion1Description = beanstalk
            .createApplicationVersion(createApplicationVersion1Request).getApplicationVersion();
    logger.debug("Application version {}:{} created", applicationVersion1Description.getApplicationName(),
            applicationVersion1Description.getVersionLabel());
    /*CreateApplicationVersionRequest createApplicationVersion11Request = new CreateApplicationVersionRequest()
        .withApplicationName(applicationDescription.getApplicationName())
        .withVersionLabel("1.1.0")
        .withSourceBundle(new S3Location(XFR_WORKSHOP_NGINX, "cocktail-app-1.1.0-SNAPSHOT.war"));
    ApplicationVersionDescription applicationVersion11Description = beanstalk.createApplicationVersion(createApplicationVersion11Request).getApplicationVersion();
    logger.debug("Application version {}:{} created", applicationVersion11Description.getApplicationName(), applicationVersion11Description.getVersionLabel());
    */
    // CREATE CONFIGURATION TEMPLATE
    CreateConfigurationTemplateRequest createConfigurationTemplateRequest = new CreateConfigurationTemplateRequest()
            .withApplicationName(applicationDescription.getApplicationName())
            .withTemplateName(applicationDescription.getApplicationName() + "-base-configuration")
            .withSolutionStackName("32bit Amazon Linux running Tomcat 7").withOptionSettings(
                    new ConfigurationOptionSetting("aws:autoscaling:launchconfiguration", "InstanceType",
                            "t1.micro"),
                    new ConfigurationOptionSetting("aws:autoscaling:launchconfiguration", "EC2KeyName",
                            workshopInfrastructure.getKeyPairName()),

                    new ConfigurationOptionSetting("aws:elasticbeanstalk:sns:topics", "Notification Endpoint",
                            workshopInfrastructure.getBeanstalkNotificationEmail()),

                    new ConfigurationOptionSetting("aws:elasticbeanstalk:application:environment",
                            "AWS_ACCESS_KEY_ID", workshopInfrastructure.getAwsAccessKeyId()),
                    new ConfigurationOptionSetting("aws:elasticbeanstalk:application:environment",
                            "AWS_SECRET_KEY", workshopInfrastructure.getAwsSecretKey()));
    CreateConfigurationTemplateResult configurationTemplateResult = beanstalk
            .createConfigurationTemplate(createConfigurationTemplateRequest);
    logger.debug("Configuration {}:{} created", new Object[] { configurationTemplateResult.getApplicationName(),
            configurationTemplateResult.getTemplateName(), configurationTemplateResult });

    for (String teamIdentifier : workshopInfrastructure.getTeamIdentifiers()) {
        for (int id = 0; id < 2; id++) {
            // CREATE ENVIRONMENT
            CreateEnvironmentRequest createEnvironmentRequest = new CreateEnvironmentRequest()
                    .withEnvironmentName(
                            applicationDescription.getApplicationName() + "-" + teamIdentifier + "-" + id)
                    .withApplicationName(applicationDescription.getApplicationName())
                    .withVersionLabel(applicationVersion1Description.getVersionLabel())
                    .withCNAMEPrefix(
                            applicationDescription.getApplicationName() + "-" + teamIdentifier + "-" + id)
                    .withTemplateName(configurationTemplateResult.getTemplateName());

            CreateEnvironmentResult createEnvironmentResult = beanstalk
                    .createEnvironment(createEnvironmentRequest);

            logger.info("Environment {}:{}:{} created at {}", new Object[] {
                    createEnvironmentResult.getApplicationName(), createEnvironmentResult.getVersionLabel(),
                    createEnvironmentResult.getEnvironmentName(), createEnvironmentResult.getEndpointURL() });
        }

    }
}