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

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

Introduction

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

Prototype

DescribeApplicationsResult describeApplications(DescribeApplicationsRequest describeApplicationsRequest);

Source Link

Document

Returns the descriptions of existing applications.

Usage

From source file:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java

License:Apache License

/**
 * Delete given application and wait for its removal.
 *
 * @param applicationName//  w w w.  j a  v  a2s .  c  o m
 * @param beanstalk
 */
public static void deleteBeanstalkApplicationIfExists(@Nonnull String applicationName,
        @Nonnull AWSElasticBeanstalk beanstalk) {
    ApplicationDescription application = Iterables.getFirst(beanstalk
            .describeApplications(new DescribeApplicationsRequest().withApplicationNames(applicationName))
            .getApplications(), null);
    if (application == null) {
        logger.debug("No application named '{}' found", applicationName);
        return;
    }

    synchronousTerminateEnvironments(applicationName, beanstalk);

    beanstalk.deleteApplication(new DeleteApplicationRequest().withApplicationName(applicationName));
    logger.info("Existing application {} deleted", applicationName);

    int counter = 0;
    while (application != null && counter < 1 * 60) {
        logger.debug("Wait for deletion of application {}", application);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw Throwables.propagate(e);
        }
        application = Iterables.getFirst(beanstalk
                .describeApplications(new DescribeApplicationsRequest().withApplicationNames(applicationName))
                .getApplications(), null);
    }
    if (application == null) {
        logger.info("Application {} successfully deleted", applicationName);
    } else {
        logger.warn("Failure to delete application {}", applicationName);
    }
}

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

License:Apache License

@TaskAction
public void createApplication() {
    // to enable conventionMappings feature
    String appName = getAppName();
    String appDesc = getAppDesc();

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

    DescribeApplicationsResult existingApps = eb
            .describeApplications(new DescribeApplicationsRequest().withApplicationNames(appName));
    if (existingApps.getApplications().isEmpty()) {
        eb.createApplication(// w w  w.  j ava  2s  .c o m
                new CreateApplicationRequest().withApplicationName(appName).withDescription(appDesc));
        getLogger().info("application " + appName + " (" + appDesc + ") created");
    } else {
        eb.updateApplication(
                new UpdateApplicationRequest().withApplicationName(appName).withDescription(appDesc));
        getLogger().info("application " + appName + " (" + appDesc + ") updated");
    }
}

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

License:Apache License

@TaskAction
public void createTemplate() {
    // to enable conventionMappings feature
    String appName = getAppName();

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

    configurationTemplates.forEach(config -> {
        String templateName = config.getName();
        String templateDesc = config.getDesc();
        String solutionStackName = config.getSolutionStackName() != null ? config.getSolutionStackName()
                : getDefaultSolutionStackName();
        boolean deleteTemplateIfExists = config.isRecreate();

        try {/*from   ww  w . j av  a2  s  . c o m*/
            List<ConfigurationOptionSetting> optionSettings = loadConfigurationOptions(
                    config.getOptionSettings());
            List<ApplicationDescription> existingApps = eb
                    .describeApplications(new DescribeApplicationsRequest().withApplicationNames(appName))
                    .getApplications();
            if (existingApps.isEmpty()) {
                throw new IllegalArgumentException("App with name '" + appName + "' does not exist");
            }

            if (existingApps.get(0).getConfigurationTemplates().contains(templateName)) {
                if (deleteTemplateIfExists) {
                    eb.deleteConfigurationTemplate(new DeleteConfigurationTemplateRequest()
                            .withApplicationName(appName).withTemplateName(templateName));
                    getLogger().info("configuration template {} @ {} deleted", templateName, appName);
                } else {
                    eb.updateConfigurationTemplate(new UpdateConfigurationTemplateRequest()
                            .withApplicationName(appName).withTemplateName(templateName)
                            .withDescription(templateDesc).withOptionSettings(optionSettings));
                    getLogger().info("configuration template {} @ {} updated", templateName, appName);
                    return;
                }
            }

            eb.createConfigurationTemplate(new CreateConfigurationTemplateRequest().withApplicationName(appName)
                    .withTemplateName(templateName).withDescription(templateDesc)
                    .withSolutionStackName(solutionStackName).withOptionSettings(optionSettings));
            getLogger().info("configuration template {} @ {} created", templateName, appName);
        } catch (IOException e) {
            getLogger().error("IOException", e);
        }
    });
}