List of usage examples for java.util Deque getLast
E getLast();
From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSService.java
/** * Looks whether the latest task definition matches the desired one. If yes, returns the ARN of the existing one. * If no, register a new task definition with desired parameters and return the new ARN. *//* www. j a va 2 s . co m*/ String registerTemplate(final ECSCloud cloud, final ECSTaskTemplate template, String clusterArn) { final AmazonECSClient client = getAmazonECSClient(); String familyName = fullQualifiedTemplateName(cloud, template); final ContainerDefinition def = new ContainerDefinition().withName(familyName) .withImage(template.getImage()).withEnvironment(template.getEnvironmentKeyValuePairs()) .withExtraHosts(template.getExtraHostEntries()).withMountPoints(template.getMountPointEntries()) .withCpu(template.getCpu()).withPrivileged(template.getPrivileged()).withEssential(true); /* at least one of memory or memoryReservation has to be set the form validation will highlight if the settings are inappropriate */ if (template.getMemoryReservation() > 0) /* this is the soft limit */ def.withMemoryReservation(template.getMemoryReservation()); if (template.getMemory() > 0) /* this is the hard limit */ def.withMemory(template.getMemory()); if (template.getEntrypoint() != null) def.withEntryPoint(StringUtils.split(template.getEntrypoint())); if (template.getJvmArgs() != null) def.withEnvironment(new KeyValuePair().withName("JAVA_OPTS").withValue(template.getJvmArgs())) .withEssential(true); if (template.getLogDriver() != null) { LogConfiguration logConfig = new LogConfiguration(); logConfig.setLogDriver(template.getLogDriver()); logConfig.setOptions(template.getLogDriverOptionsMap()); def.withLogConfiguration(logConfig); } String lastToken = null; Deque<String> taskDefinitions = new LinkedList<String>(); do { ListTaskDefinitionsResult listTaskDefinitions = client .listTaskDefinitions(new ListTaskDefinitionsRequest().withFamilyPrefix(familyName) .withMaxResults(100).withNextToken(lastToken)); taskDefinitions.addAll(listTaskDefinitions.getTaskDefinitionArns()); lastToken = listTaskDefinitions.getNextToken(); } while (lastToken != null); boolean templateMatchesExistingContainerDefinition = false; boolean templateMatchesExistingVolumes = false; boolean templateMatchesExistingTaskRole = false; DescribeTaskDefinitionResult describeTaskDefinition = null; if (taskDefinitions.size() > 0) { describeTaskDefinition = client.describeTaskDefinition( new DescribeTaskDefinitionRequest().withTaskDefinition(taskDefinitions.getLast())); templateMatchesExistingContainerDefinition = def .equals(describeTaskDefinition.getTaskDefinition().getContainerDefinitions().get(0)); LOGGER.log(Level.INFO, "Match on container defintion: {0}", new Object[] { templateMatchesExistingContainerDefinition }); LOGGER.log(Level.FINE, "Match on container defintion: {0}; template={1}; last={2}", new Object[] { templateMatchesExistingContainerDefinition, def, describeTaskDefinition.getTaskDefinition().getContainerDefinitions().get(0) }); templateMatchesExistingVolumes = ObjectUtils.equals(template.getVolumeEntries(), describeTaskDefinition.getTaskDefinition().getVolumes()); LOGGER.log(Level.INFO, "Match on volumes: {0}", new Object[] { templateMatchesExistingVolumes }); LOGGER.log(Level.FINE, "Match on volumes: {0}; template={1}; last={2}", new Object[] { templateMatchesExistingVolumes, template.getVolumeEntries(), describeTaskDefinition.getTaskDefinition().getVolumes() }); templateMatchesExistingTaskRole = template.getTaskrole() == null || template.getTaskrole().equals(describeTaskDefinition.getTaskDefinition().getTaskRoleArn()); LOGGER.log(Level.INFO, "Match on task role: {0}", new Object[] { templateMatchesExistingTaskRole }); LOGGER.log(Level.FINE, "Match on task role: {0}; template={1}; last={2}", new Object[] { templateMatchesExistingTaskRole, template.getTaskrole(), describeTaskDefinition.getTaskDefinition().getTaskRoleArn() }); } if (templateMatchesExistingContainerDefinition && templateMatchesExistingVolumes && templateMatchesExistingTaskRole) { LOGGER.log(Level.FINE, "Task Definition already exists: {0}", new Object[] { describeTaskDefinition.getTaskDefinition().getTaskDefinitionArn() }); return describeTaskDefinition.getTaskDefinition().getTaskDefinitionArn(); } else { final RegisterTaskDefinitionRequest request = new RegisterTaskDefinitionRequest().withFamily(familyName) .withVolumes(template.getVolumeEntries()).withContainerDefinitions(def); if (template.getTaskrole() != null) { request.withTaskRoleArn(template.getTaskrole()); } final RegisterTaskDefinitionResult result = client.registerTaskDefinition(request); String taskDefinitionArn = result.getTaskDefinition().getTaskDefinitionArn(); LOGGER.log(Level.FINE, "Created Task Definition {0}: {1}", new Object[] { taskDefinitionArn, request }); LOGGER.log(Level.INFO, "Created Task Definition: {0}", new Object[] { taskDefinitionArn }); return taskDefinitionArn; } }
From source file:org.ciasaboark.tacere.service.EventSilencerService.java
private void checkForActiveEventsAndSilence() { Log.d(TAG, "checking for events to silence"); Deque<EventInstance> events = databaseInterface.getAllActiveEvents(); boolean foundEvent = false; for (EventInstance event : events) { if (shouldEventSilence(event)) { Log.d(TAG, "found event to silence for: " + event.toString()); foundEvent = true;//from w w w . j a v a 2 s . com silenceForEventAndShowNotification(event); break; } } if (!foundEvent) { Log.d(TAG, "did not find an event to silence for"); //if we couldn't find any events, then do some cleanup and schedule the service to be //restarted when the last active checked event ends. If there were no active events, //then we need to sleep until the next event in the database starts. If there are no //events in the database either, then just sleep for 24 hours. if (stateManager.isEventActive()) { Log.d(TAG, "event previously active, but non active now, restoring volumes"); vibrate(); stateManager.resetServiceState(); notificationManager.cancelAllNotifications(); volumesManager.restoreVolumes(); ringerStateManager.restorePhoneRinger(); notifyCursorAdapterDataChanged(); } long wakeAt; if (!events.isEmpty()) { EventInstance lastActiveEvent = events.getLast(); wakeAt = lastActiveEvent.getOriginalEnd(); Log.d(TAG, "sleeping until last known event ends at " + wakeAt); } else { EventInstance nextInactiveEvent = databaseInterface.nextEvent(); if (nextInactiveEvent != null) { wakeAt = nextInactiveEvent.getBegin() - (EventInstance.MILLISECONDS_IN_MINUTE * prefs.getBufferMinutes()); Log.d(TAG, "sleeping until next known event starts at " + wakeAt); } else { Log.d(TAG, "sleeping for 24 hrs"); wakeAt = System.currentTimeMillis() + EventInstance.MILLISECONDS_IN_DAY; } } alarmManager.scheduleNormalWakeAt(wakeAt); } }