List of usage examples for com.amazonaws.services.elasticbeanstalk.model DescribeEventsRequest DescribeEventsRequest
DescribeEventsRequest
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 {//w w w. java 2 s . 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:jetbrains.buildServer.runner.elasticbeanstalk.AWSClient.java
License:Apache License
private List<EventDescription> getErrorEvents(@NotNull String environmentId, String versionLabel) { return myElasticBeanstalkClient.describeEvents(new DescribeEventsRequest().withEnvironmentId(environmentId) .withMaxRecords(10).withVersionLabel(versionLabel).withSeverity(EventSeverity.ERROR)).getEvents(); }
From source file:jetbrains.buildServer.runner.elasticbeanstalk.AWSClient.java
License:Apache License
private List<EventDescription> getNewEvents(@NotNull String environmentId, @NotNull Date startTime) { List<EventDescription> events = myElasticBeanstalkClient.describeEvents(new DescribeEventsRequest() .withEnvironmentId(environmentId).withStartTime(startTime).withMaxRecords(20)).getEvents(); List<EventDescription> newEvents = new ArrayList<>(); for (EventDescription event : events) { if (!pastEvents.containsKey(event.hashCode())) { newEvents.add(event);//from www .ja v a 2 s . co m pastEvents.put(event.hashCode(), event); } } return newEvents; }