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

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

Introduction

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

Prototype

DescribeEnvironmentsRequest

Source Link

Usage

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

License:Apache License

private void terminateEnvironment(String environmentId) {
    final DescribeEnvironmentsResult result = getAwseb().describeEnvironments(
            new DescribeEnvironmentsRequest().withEnvironmentIds(environmentId).withIncludeDeleted(false));

    if (result.getEnvironments().isEmpty()) {
        log("Environment environmentId '%s' was already finished.");
        return;//  ww w .ja  v a2s. c om
    }

    log("Terminating environment %s", environmentId);

    TerminateEnvironmentRequest request = new TerminateEnvironmentRequest().withEnvironmentId(environmentId);

    getAwseb().terminateEnvironment(request);
}

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

License:Apache License

private EnvironmentDescription lookupEnvironmentIds(List<String> environmentNames)
        throws InvalidEnvironmentsSizeException, InvalidDeploymentTypeException {
    DescribeEnvironmentsResult environments = getAwseb().describeEnvironments(new DescribeEnvironmentsRequest()
            .withApplicationName(getApplicationName()).withIncludeDeleted(false));

    for (EnvironmentDescription env : environments.getEnvironments()) {
        if (environmentNames.contains(env.getEnvironmentName())) {
            if (WORKER_ENVIRONMENT_TYPE.equals(env.getTier().getName())) {
                throw new InvalidDeploymentTypeException();
            }//from w  w w.jav a2 s. co m

            return env;
        }
    }

    throw new InvalidEnvironmentsSizeException(getApplicationName(), environmentNames.get(0),
            environments.getEnvironments().size());
}

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 av  a 2s  . 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.AbstractNeedsEnvironmentMojo.java

License:Apache License

/**
 * Returns a list of environments for applicationName
 *
 * @param applicationName applicationName
 * @return environments/*from www.j  a  v  a2  s. com*/
 */
protected Collection<EnvironmentDescription> getEnvironmentsFor(String applicationName) {
    /*
     * Requests
    */
    DescribeEnvironmentsRequest req = new DescribeEnvironmentsRequest().withApplicationName(applicationName)
            .withIncludeDeleted(false);

    return getService().describeEnvironments(req).getEnvironments();
}

From source file:br.com.ingenieux.mojo.beanstalk.cmd.env.waitfor.WaitForEnvironmentCommand.java

License:Apache License

public Collection<EnvironmentDescription> lookupInternal(WaitForEnvironmentContext context) {
    List<Predicate<EnvironmentDescription>> envPredicates = getEnvironmentDescriptionPredicate(context);

    DescribeEnvironmentsRequest req = new DescribeEnvironmentsRequest()
            .withApplicationName(context.getApplicationName()).withIncludeDeleted(true);

    final List<EnvironmentDescription> envs = parentMojo.getService().describeEnvironments(req)
            .getEnvironments();//from  w  w w . ja va 2 s . c  om

    return Collections2.filter(envs, Predicates.and(envPredicates));
}

From source file:br.com.ingenieux.mojo.beanstalk.cmd.env.waitfor.WaitForEnvironmentCommand.java

License:Apache License

public EnvironmentDescription executeInternal(WaitForEnvironmentContext context) throws Exception {
    // Those are invariants
    long timeoutMins = context.getTimeoutMins();

    Date expiresAt = new Date(System.currentTimeMillis() + MINS_TO_MSEC * timeoutMins);
    Date lastMessageRecord = new Date();

    info("Environment Lookup");

    List<Predicate<EnvironmentDescription>> envPredicates = getEnvironmentDescriptionPredicate(context);
    Predicate<EnvironmentDescription> corePredicate = envPredicates.get(0);
    Predicate<EnvironmentDescription> fullPredicate = Predicates.and(envPredicates);

    do {/*from   w w w .j  a va 2s  .c o  m*/
        DescribeEnvironmentsRequest req = new DescribeEnvironmentsRequest()
                .withApplicationName(context.getApplicationName()).withIncludeDeleted(true);

        final List<EnvironmentDescription> envs = parentMojo.getService().describeEnvironments(req)
                .getEnvironments();

        Collection<EnvironmentDescription> validEnvironments = Collections2.filter(envs, fullPredicate);

        debug("There are %d environments", validEnvironments.size());

        if (1 == validEnvironments.size()) {
            EnvironmentDescription foundEnvironment = validEnvironments.iterator().next();

            debug("Found environment %s", foundEnvironment);

            return foundEnvironment;
        } else {
            debug("Found %d environments. No good. Ignoring.", validEnvironments.size());

            for (EnvironmentDescription d : validEnvironments) {
                debug(" ... %s", d);
            }

            // ... but have we've got any closer match? If so, dump recent events

            Collection<EnvironmentDescription> foundEnvironments = Collections2.filter(envs, corePredicate);

            if (1 == foundEnvironments.size()) {
                EnvironmentDescription foundEnvironment = foundEnvironments.iterator().next();

                DescribeEventsResult events = service.describeEvents(
                        new DescribeEventsRequest().withApplicationName(foundEnvironment.getApplicationName())
                                .withStartTime(new Date(1000 + lastMessageRecord.getTime()))
                                .withEnvironmentId(foundEnvironment.getEnvironmentId()).withSeverity("TRACE"));

                Set<EventDescription> eventList = new TreeSet<EventDescription>(
                        new EventDescriptionComparator());

                eventList.addAll(events.getEvents());

                for (EventDescription d : eventList) {
                    info(String.format("%s %s %s", d.getSeverity(), d.getEventDate(), d.getMessage()));

                    if (d.getSeverity().equals(("ERROR"))) {
                        throw new MojoExecutionException(
                                "Something went wrong in while waiting for the environment setup to complete : "
                                        + d.getMessage());
                    }
                    lastMessageRecord = d.getEventDate();
                }
            }
        }

        sleepInterval(POLL_INTERVAL);
    } while (!timedOutP(expiresAt));

    throw new MojoExecutionException("Timed out");
}

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

License:Apache License

@Override
protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
    DescribeEnvironmentsRequest req = new DescribeEnvironmentsRequest();

    req.setApplicationName(applicationName);
    req.setIncludeDeleted(includeDeleted);

    // TODO add environmentNames / environmentIds / includeDeletedBackTo

    DescribeEnvironmentsResult result = getService().describeEnvironments(req);

    if (null != outputFile) {
        getLog().info("Writing results into " + outputFile.getName());

        try {//w w w .  j a  v a 2 s.  com
            ObjectMapper objectMapper = new ObjectMapper();

            ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();

            writer.writeValue(outputFile, result.getEnvironments());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return null;
    }

    return result;
}

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  w  w.  j  ava2s.c  o 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:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java

License:Apache License

public static void synchronousTerminateEnvironments(@Nonnull String applicationName,
        @Nonnull AWSElasticBeanstalk beanstalk) {
    Set<String> statusToTerminate = Sets.newHashSet("Launching", "Updating", "Ready");
    Set<String> statusTerminating = Sets.newHashSet("Terminating");

    List<EnvironmentDescription> environments = beanstalk
            .describeEnvironments(new DescribeEnvironmentsRequest().withApplicationName(applicationName))
            .getEnvironments();/*from w w w  . j  ava  2  s .c  o  m*/
    List<EnvironmentDescription> environmentsToWaitFor = Collections.emptyList();

    int counter = 0;
    while (counter < 1 * 60) {
        environmentsToWaitFor = Lists.newArrayList();
        for (EnvironmentDescription environment : environments) {
            if (statusToTerminate.contains(environment.getStatus())) {
                TerminateEnvironmentResult terminateEnvironmentResult = beanstalk.terminateEnvironment(
                        new TerminateEnvironmentRequest().withEnvironmentId(environment.getEnvironmentId()));
                logger.debug("Terminate environment {}, status:{} - ",
                        new Object[] { environment.getEnvironmentName(), environment.getStatus(),
                                terminateEnvironmentResult });
                environmentsToWaitFor.add(environment);
            } else if (statusTerminating.contains(environment.getStatus())) {
                environmentsToWaitFor.add(environment);
                logger.debug("Skip termination of not running environment {}", environment);
            } else {
                logger.trace("skip terminated environment {}", environment);
            }
        }
        if (environmentsToWaitFor.isEmpty()) {
            break;
        } else {
            try {
                Thread.sleep(500);
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
            environments = beanstalk
                    .describeEnvironments(
                            new DescribeEnvironmentsRequest().withApplicationName(applicationName))
                    .getEnvironments();
        }
    }

    if (!environmentsToWaitFor.isEmpty()) {
        logger.warn("Failure to terminate {}", environmentsToWaitFor);
    }
}

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

License:Apache License

private EnvironmentDescription getEnvironment(@NotNull String environmentId) {
    return myElasticBeanstalkClient
            .describeEnvironments(new DescribeEnvironmentsRequest().withEnvironmentIds(environmentId))
            .getEnvironments().get(0);/*from   w  w  w . ja v a  2s  . co m*/
}