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

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

Introduction

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

Prototype

UpdateEnvironmentRequest

Source Link

Usage

From source file:br.com.ingenieux.jenkins.plugins.awsebdeployment.Deployer.java

License:Apache License

private void updateEnvironments() throws Exception {
    DescribeEnvironmentsResult environments = awseb.describeEnvironments(new DescribeEnvironmentsRequest()
            .withApplicationName(applicationName).withEnvironmentNames(environmentName));

    boolean found = (1 == environments.getEnvironments().size());

    if (found) {//from w w w .  j  a v  a  2 s.  c o m
        for (int nAttempt = 1; nAttempt <= MAX_ATTEMPTS; nAttempt++) {
            String environmentId = environments.getEnvironments().get(0).getEnvironmentId();

            log("Attempt %d/%s", nAttempt, MAX_ATTEMPTS);

            log("Environment found (environment id=%s). Attempting to update environment to version label %s",
                    environmentId, versionLabel);

            UpdateEnvironmentRequest uavReq = new UpdateEnvironmentRequest()
                    .withEnvironmentName(environmentName).withVersionLabel(versionLabel);

            try {
                awseb.updateEnvironment(uavReq);

                log("q'Apla!");

                return;
            } catch (Exception exc) {
                log("Problem: " + exc.getMessage());

                if (nAttempt == MAX_ATTEMPTS) {
                    log("Giving it up");

                    throw exc;
                }

                log("Reattempting in 90s, up to %d", MAX_ATTEMPTS);

                Thread.sleep(TimeUnit.SECONDS.toMillis(90));
            }
        }
    } else {
        log("Environment not found. Continuing");
    }
}

From source file:br.com.ingenieux.mojo.beanstalk.cmd.env.update.UpdateEnvironmentCommand.java

License:Apache License

@Override
protected UpdateEnvironmentResult executeInternal(UpdateEnvironmentContext context) throws Exception {
    UpdateEnvironmentRequest req = new UpdateEnvironmentRequest();

    if (null != context.environmentDescription) {
        req.setDescription(context.environmentDescription);
    }// w  w w.  ja  v  a  2  s  .c  o m

    if (null != context.environmentName) {
        req.setEnvironmentName(context.environmentName);
    } else if (null != context.environmentId) {
        req.setEnvironmentId(context.environmentId);
    }

    if (null != context.getEnvironmentTierName()) {
        String envTierType = "Standard";
        String envTierVersion = "1.0";

        if ("Worker".equals(context.getEnvironmentTierName())) {
            envTierType = "SQS/JSON";
        }

        req.setTier(new EnvironmentTier().withName(context.getEnvironmentTierName()).withType(envTierType)
                .withVersion(envTierVersion));
    }

    if (null != context.optionSettings && 0 != context.optionSettings.length) {
        req.setOptionSettings(Arrays.asList(context.optionSettings));
    }
    if (null != context.optionsToRemove && 0 != context.optionsToRemove.length) {
        req.setOptionsToRemove(Arrays.asList(context.optionsToRemove));
    }

    if (isNotBlank(context.versionLabel)) {
        info("Calling update-environment, and using versionLabel: " + context.versionLabel);

        req.setVersionLabel(context.versionLabel);
    } else if (isNotBlank(context.templateName)) {
        info("Calling update-environment, and using templateName: " + context.templateName);

        req.setTemplateName(context.templateName);
    }

    return service.updateEnvironment(req);
}

From source file:br.com.ingenieux.mojo.beanstalk.env.SetPropertyMojo.java

License:Apache License

protected Object executeInternal() throws Exception {
    waitForNotUpdating();/*  w ww.j a va  2 s .  com*/

    UpdateEnvironmentRequest req = new UpdateEnvironmentRequest().withEnvironmentId(curEnv.getEnvironmentId());

    req.setOptionSettings(Arrays.asList(
            new ConfigurationOptionSetting().withNamespace("aws:elasticbeanstalk:application:environment")
                    .withOptionName(envName).withValue(envValue)));

    UpdateEnvironmentResult result = getService().updateEnvironment(req);

    return result;
}

From source file:br.com.ingenieux.mojo.beanstalk.env.UpdateEnvironmentOptionsMojo.java

License:Apache License

protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
    UpdateEnvironmentRequest req = new UpdateEnvironmentRequest();

    req.setEnvironmentId(curEnv.getEnvironmentId());
    req.setEnvironmentName(curEnv.getEnvironmentName());

    if (WhatToSet.versionLabel.equals(whatToSet)) {
        req.setVersionLabel(versionLabel);
    } else if (WhatToSet.description.equals(whatToSet)) {
        req.setDescription(environmentDescription);
    } else if (WhatToSet.optionSettings.equals(whatToSet)) {
        req.setOptionSettings(getOptionSettings(optionSettings));
    } else if (WhatToSet.templateName.equals(whatToSet)) {
        req.setTemplateName(lookupTemplateName(applicationName, templateName));
    } else if (WhatToSet.optionsToRemove.equals(whatToSet)) {
        req.setOptionsToRemove(getOptionsToRemove(optionsToRemove));
    }//from   www . j  a v a  2 s .com

    return getService().updateEnvironment(req);
}

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  v  a  2s . c  om*/

    return getService().updateEnvironment(request);
}

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

License:Open Source License

protected void updateEnvironmentVersion(String environmentName, String versionLabel) {
    final UpdateEnvironmentRequest envRequest = new UpdateEnvironmentRequest()
            .withEnvironmentName(environmentName).withVersionLabel(versionLabel);

    final UpdateEnvironmentResult envResult = getBeanstalkClient().updateEnvironment(envRequest);

    System.out.println(String.format(
            "Updated environment [%s] with new version of %s (%s). Health: %s, status: %s, Endpoint: %s",
            envResult.getEnvironmentName(), envResult.getApplicationName(), versionLabel, envResult.getHealth(),
            envResult.getStatus(), envResult.getEndpointURL()));
}

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

License:Apache License

@SuppressWarnings("ConstantConditions")
private void doUpdateAndWait(@NotNull String environmentName, @NotNull String versionLabel, boolean wait,
        @Nullable Integer waitTimeoutSec, @Nullable Integer waitIntervalSec) {
    try {//from  w  w w . ja v  a2 s .c o  m
        UpdateEnvironmentRequest request = new UpdateEnvironmentRequest().withEnvironmentName(environmentName)
                .withVersionLabel(versionLabel);

        long startTime = System.currentTimeMillis();

        UpdateEnvironmentResult result = myElasticBeanstalkClient.updateEnvironment(request);

        String environmentId = result.getEnvironmentId();

        myListener.deploymentStarted(environmentId, environmentName, versionLabel);

        if (wait) {
            waitForDeployment(environmentId, versionLabel, startTime, waitTimeoutSec, waitIntervalSec);
        }
    } catch (Throwable t) {
        processFailure(t);
    }
}

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

License:Apache License

@TaskAction
public void createEnvironment() { // NOPMD
    // to enable conventionMappings feature
    String appName = getAppName();
    String envName = getEnvName();
    String envDesc = getEnvDesc();
    String cnamePrefix = getCnamePrefix();
    String templateName = getTemplateName();
    String versionLabel = getVersionLabel();
    Tier tier = getTier();/*from w  w  w .  j a  v  a2 s .  c  om*/
    Map<String, String> tags = getTags();

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

    DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest()
            .withApplicationName(appName).withEnvironmentNames(envName).withIncludeDeleted(false));

    List<Tag> ebTags = tags.entrySet().stream().map(entry -> {
        Tag t = new Tag();
        t.setKey(entry.getKey());
        t.setValue(entry.getValue());
        return t;
    }).collect(Collectors.toList());

    if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) {
        CreateEnvironmentRequest req = new CreateEnvironmentRequest().withApplicationName(appName)
                .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName)
                .withVersionLabel(versionLabel);

        if (tier != null) {
            req.withTier(tier.toEnvironmentTier());
            if (tier == Tier.WebServer) {
                req.withCNAMEPrefix(cnamePrefix);
            }
        }

        if (ebTags != null && !ebTags.isEmpty()) {
            req.withTags(ebTags);
        }

        CreateEnvironmentResult result = eb.createEnvironment(req);
        getLogger().info("environment {} @ {} ({}) created", envName, appName, result.getEnvironmentId());
    } else {
        String environmentId = der.getEnvironments().get(0).getEnvironmentId();

        // Only these two values are required to deploy the a application
        UpdateEnvironmentRequest req = new UpdateEnvironmentRequest().withEnvironmentId(environmentId)
                .withVersionLabel(versionLabel);

        // All other variables are optional and refer to the environment
        if (isNotBlank(envName)) {
            req.withEnvironmentName(envName);
        }
        if (isNotBlank(envDesc)) {
            req.withDescription(envDesc);
        }
        if (isNotBlank(templateName)) {
            req.withTemplateName(templateName);
        }

        eb.updateEnvironment(req);

        getLogger().info("environment {} @ {} ({}) updated", envName, appName, environmentId);
    }
}

From source file:org.cloudml.connectors.BeanstalkConnector.java

License:Open Source License

public void uploadWar(String warFile, String versionLabel, String applicationName, String envName,
        int timeout) {

    prepareWar(new File(warFile), versionLabel, applicationName);
    journal.log(Level.INFO, ">> Uploading War file!");
    while (timeout-- > 0) {
        System.out.print("-");
        try {/*from w ww.j  a  v a 2 s. c  o m*/
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            Logger.getLogger(BeanstalkConnector.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            UpdateEnvironmentResult updateEnvironment = beanstalkClient.updateEnvironment(
                    new UpdateEnvironmentRequest().withEnvironmentName(envName).withVersionLabel(versionLabel));
            journal.log(Level.INFO, ">> War uploaded!");
            break;
        } catch (com.amazonaws.AmazonServiceException e) {

        }

    }

}

From source file:org.xmlsh.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCreateEnvironmentTask.java

License:BSD License

@TaskAction
public void createEnvironment() {
    // to enable conventionMappings feature
    String appName = getAppName();
    String envName = getEnvName();
    String envDesc = getEnvDesc();
    String cnamePrefix = getCnamePrefix();
    String templateName = getTemplateName();
    String versionLabel = getVersionLabel();
    Tier tier = getTier();//from w w w .  ja  v a2s . c om

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

    DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest()
            .withApplicationName(appName).withEnvironmentNames(envName).withIncludeDeleted(false));

    if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) {
        CreateEnvironmentRequest req = new CreateEnvironmentRequest().withApplicationName(appName)
                .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName)
                .withVersionLabel(versionLabel).withTier(tier.toEnvironmentTier());
        if (tier == Tier.WebServer) {
            req.withCNAMEPrefix(cnamePrefix);
        }
        CreateEnvironmentResult result = eb.createEnvironment(req);
        getLogger().info(
                "environment " + envName + " @ " + appName + " (" + result.getEnvironmentId() + ") created");
    } else {
        String environmentId = der.getEnvironments().get(0).getEnvironmentId();

        eb.updateEnvironment(new UpdateEnvironmentRequest().withEnvironmentId(environmentId)
                .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName)
                .withVersionLabel(versionLabel).withTier(tier.toEnvironmentTier()));
        getLogger().info("environment " + envName + " @ " + appName + " (" + environmentId + ") updated");
    }
}