Example usage for com.amazonaws.services.elasticbeanstalk.model DescribeEventsResult getEvents

List of usage examples for com.amazonaws.services.elasticbeanstalk.model DescribeEventsResult getEvents

Introduction

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

Prototype


public java.util.List<EventDescription> getEvents() 

Source Link

Document

A list of EventDescription.

Usage

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   ww w . j a v a  2s.co  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");
}