From b26a28cadfe7e9c49e5d8eef6e8cccd005254146 Mon Sep 17 00:00:00 2001 From: Whitney Sorenson Date: Mon, 15 Dec 2014 17:39:26 +0000 Subject: [PATCH 1/3] move webhook processing to leader only - also move locks into constructor rather than protected, non-final access - change enabled / abort to use methods --- .../hubspot/singularity/SingularityAbort.java | 2 + .../SingularityDeployHistoryPersister.java | 10 ++-- .../history/SingularityHistoryPersister.java | 52 +++++-------------- .../SingularityRequestHistoryPersister.java | 10 ++-- .../SingularityTaskHistoryPersister.java | 10 ++-- .../hooks/SingularityWebhookPoller.java | 47 ++++------------- .../scheduler/SingularityCleanupPoller.java | 3 +- .../scheduler/SingularityCooldownPoller.java | 3 +- .../scheduler/SingularityDeployPoller.java | 3 +- .../SingularityLeaderOnlyPoller.java | 38 +++++++++----- .../scheduler/SingularitySchedulerPoller.java | 6 +-- 11 files changed, 76 insertions(+), 108 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/SingularityAbort.java b/SingularityService/src/main/java/com/hubspot/singularity/SingularityAbort.java index 07dcd29168..7df061e82c 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/SingularityAbort.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/SingularityAbort.java @@ -92,6 +92,8 @@ private void exit() { private void sendAbortNotification(AbortReason abortReason) { final String message = String.format("Singularity on %s is aborting due to %s", hostAndPort.getHostText(), abortReason); + LOG.error(message); + sendAbortMail(message); exceptionNotifier.notify(message); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityDeployHistoryPersister.java b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityDeployHistoryPersister.java index cc1e212071..b3d567ecbd 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityDeployHistoryPersister.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityDeployHistoryPersister.java @@ -14,10 +14,11 @@ import com.hubspot.singularity.SingularityDeployHistory; import com.hubspot.singularity.SingularityDeployKey; import com.hubspot.singularity.SingularityRequestDeployState; +import com.hubspot.singularity.config.SingularityConfiguration; import com.hubspot.singularity.data.DeployManager; @Singleton -public class SingularityDeployHistoryPersister { +public class SingularityDeployHistoryPersister extends SingularityHistoryPersister { private static final Logger LOG = LoggerFactory.getLogger(SingularityDeployHistoryPersister.class); @@ -25,12 +26,15 @@ public class SingularityDeployHistoryPersister { private final HistoryManager historyManager; @Inject - public SingularityDeployHistoryPersister(DeployManager deployManager, HistoryManager historyManager) { + public SingularityDeployHistoryPersister(SingularityConfiguration configuration, DeployManager deployManager, HistoryManager historyManager) { + super(configuration); + this.deployManager = deployManager; this.historyManager = historyManager; } - public void checkInactiveDeploys() { + @Override + public void runActionOnPoll() { LOG.info("Checking inactive deploys for deploy history persistance"); final long start = System.currentTimeMillis(); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java index ff0449f4ef..e823fd1cfa 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java @@ -1,59 +1,31 @@ package com.hubspot.singularity.data.history; -import io.dropwizard.lifecycle.Managed; - import java.util.concurrent.TimeUnit; import javax.inject.Singleton; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.inject.Inject; import com.hubspot.singularity.config.SingularityConfiguration; import com.hubspot.singularity.scheduler.SingularityLeaderOnlyPoller; -import com.hubspot.singularity.sentry.SingularityExceptionNotifier; @Singleton -public class SingularityHistoryPersister extends SingularityLeaderOnlyPoller implements Managed { +public abstract class SingularityHistoryPersister extends SingularityLeaderOnlyPoller { - private static final Logger LOG = LoggerFactory.getLogger(SingularityHistoryPersister.class); + private final SingularityConfiguration configuration; - private final SingularityTaskHistoryPersister taskPersister; - private final SingularityDeployHistoryPersister deployPersister; - private final SingularityRequestHistoryPersister requestHistoryPersister; - private final SingularityExceptionNotifier exceptionNotifier; + public SingularityHistoryPersister(SingularityConfiguration configuration) { + super(configuration.getPersistHistoryEverySeconds(), TimeUnit.SECONDS); - @Inject - public SingularityHistoryPersister(SingularityExceptionNotifier exceptionNotifier, SingularityTaskHistoryPersister taskPersister, - SingularityRequestHistoryPersister requestHistoryPersister, SingularityDeployHistoryPersister deployPersister, SingularityConfiguration configuration) { - super(configuration.getPersistHistoryEverySeconds(), TimeUnit.SECONDS, configuration.getDatabaseConfiguration().isPresent()); + this.configuration = configuration; + } - this.taskPersister = taskPersister; - this.deployPersister = deployPersister; - this.exceptionNotifier = exceptionNotifier; - this.requestHistoryPersister = requestHistoryPersister; + @Override + protected boolean abortsOnError() { + return false; } @Override - public void runActionOnPoll() { - try { - taskPersister.checkInactiveTaskIds(); - } catch (Throwable t) { - exceptionNotifier.notify(t); - LOG.error("While persisting task history", t); - } - try { - deployPersister.checkInactiveDeploys(); - } catch (Throwable t) { - exceptionNotifier.notify(t); - LOG.error("While persisting deploy history", t); - } - try { - requestHistoryPersister.checkRequestHistory(); - } catch (Throwable t) { - exceptionNotifier.notify(t); - LOG.error("While persisting request history", t); - } + protected boolean isEnabled() { + return configuration.getDatabaseConfiguration().isPresent(); } + } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityRequestHistoryPersister.java b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityRequestHistoryPersister.java index c9373c63e8..53f9017095 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityRequestHistoryPersister.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityRequestHistoryPersister.java @@ -12,10 +12,11 @@ import com.google.inject.Inject; import com.hubspot.mesos.JavaUtils; import com.hubspot.singularity.SingularityRequestHistory; +import com.hubspot.singularity.config.SingularityConfiguration; import com.hubspot.singularity.data.RequestManager; @Singleton -public class SingularityRequestHistoryPersister { +public class SingularityRequestHistoryPersister extends SingularityHistoryPersister { private static final Logger LOG = LoggerFactory.getLogger(SingularityRequestHistoryPersister.class); @@ -23,12 +24,15 @@ public class SingularityRequestHistoryPersister { private final HistoryManager historyManager; @Inject - public SingularityRequestHistoryPersister(RequestManager requestManager, HistoryManager historyManager) { + public SingularityRequestHistoryPersister(SingularityConfiguration configuration, RequestManager requestManager, HistoryManager historyManager) { + super(configuration); + this.requestManager = requestManager; this.historyManager = historyManager; } - public void checkRequestHistory() { + @Override + public void runActionOnPoll() { LOG.info("Checking request history for persistence"); final long start = System.currentTimeMillis(); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityTaskHistoryPersister.java b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityTaskHistoryPersister.java index 577490e265..25e8ff965a 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityTaskHistoryPersister.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityTaskHistoryPersister.java @@ -16,11 +16,12 @@ import com.hubspot.singularity.SingularityPendingDeploy; import com.hubspot.singularity.SingularityTaskHistory; import com.hubspot.singularity.SingularityTaskId; +import com.hubspot.singularity.config.SingularityConfiguration; import com.hubspot.singularity.data.DeployManager; import com.hubspot.singularity.data.TaskManager; @Singleton -public class SingularityTaskHistoryPersister { +public class SingularityTaskHistoryPersister extends SingularityHistoryPersister { private static final Logger LOG = LoggerFactory.getLogger(SingularityTaskHistoryPersister.class); @@ -29,13 +30,16 @@ public class SingularityTaskHistoryPersister { private final HistoryManager historyManager; @Inject - public SingularityTaskHistoryPersister(TaskManager taskManager, DeployManager deployManager, HistoryManager historyManager) { + public SingularityTaskHistoryPersister(SingularityConfiguration configuration, TaskManager taskManager, DeployManager deployManager, HistoryManager historyManager) { + super(configuration); + this.taskManager = taskManager; this.historyManager = historyManager; this.deployManager = deployManager; } - public void checkInactiveTaskIds() { + @Override + public void runActionOnPoll() { LOG.info("Checking inactive task ids for task history persistance"); final long start = System.currentTimeMillis(); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/SingularityWebhookPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/SingularityWebhookPoller.java index 1e6d4bac8f..0f5e530ed7 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/SingularityWebhookPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/SingularityWebhookPoller.java @@ -1,62 +1,35 @@ package com.hubspot.singularity.hooks; -import io.dropwizard.lifecycle.Managed; - -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import javax.inject.Singleton; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.util.concurrent.MoreExecutors; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.inject.Inject; -import com.hubspot.mesos.JavaUtils; import com.hubspot.singularity.config.SingularityConfiguration; +import com.hubspot.singularity.scheduler.SingularityLeaderOnlyPoller; import com.hubspot.singularity.sentry.SingularityExceptionNotifier; @Singleton -public class SingularityWebhookPoller implements Managed { - - private static final Logger LOG = LoggerFactory.getLogger(SingularityWebhookPoller.class); +public class SingularityWebhookPoller extends SingularityLeaderOnlyPoller { private final SingularityWebhookSender webhookSender; - private final SingularityExceptionNotifier exceptionNotifier; - private final SingularityConfiguration configuration; - private final ScheduledExecutorService executorService; @Inject public SingularityWebhookPoller(SingularityWebhookSender webhookSender, SingularityExceptionNotifier exceptionNotifier, SingularityConfiguration configuration) { - this.webhookSender = webhookSender; - this.configuration = configuration; - this.exceptionNotifier = exceptionNotifier; + super(configuration.getCheckWebhooksEveryMillis(), TimeUnit.MILLISECONDS); - this.executorService = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("SingularityWebhookSender-%d").build()); + this.webhookSender = webhookSender; } @Override - public void start() { - LOG.info("Starting a webhookPoller that executes webhooks every {}", JavaUtils.durationFromMillis(configuration.getCheckWebhooksEveryMillis())); - - executorService.scheduleAtFixedRate(new Runnable() { - - @Override - public void run() { - try { - webhookSender.checkWebhooks(); - } catch (Throwable t) { - LOG.error("Caught an unexpected exception while checking webhooks", t); - exceptionNotifier.notify(t); - } - } - }, configuration.getCheckWebhooksEveryMillis(), configuration.getCheckWebhooksEveryMillis(), TimeUnit.MILLISECONDS); + public void runActionOnPoll() { + webhookSender.checkWebhooks(); } @Override - public void stop() { - MoreExecutors.shutdownAndAwaitTermination(executorService, 1, TimeUnit.SECONDS); + protected boolean abortsOnError() { + return false; } + + } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java index 8c09ea5d5d..bc138e9daa 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java @@ -18,10 +18,9 @@ public class SingularityCleanupPoller extends SingularityLeaderOnlyPoller { @Inject SingularityCleanupPoller(SingularityConfiguration configuration, SingularityCleaner cleaner, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(configuration.getCleanupEverySeconds(), TimeUnit.SECONDS); + super(configuration.getCleanupEverySeconds(), TimeUnit.SECONDS, Optional.of(lock)); this.cleaner = cleaner; - this.lockHolder = Optional.of(lock); } @Override diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java index 20d345bf51..e069d13202 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java @@ -18,10 +18,9 @@ public class SingularityCooldownPoller extends SingularityLeaderOnlyPoller { @Inject SingularityCooldownPoller(SingularityConfiguration configuration, SingularityCooldownChecker checker, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(TimeUnit.MINUTES.toMillis(configuration.getCooldownExpiresAfterMinutes()) / 2, TimeUnit.MILLISECONDS); + super(TimeUnit.MINUTES.toMillis(configuration.getCooldownExpiresAfterMinutes()) / 2, TimeUnit.MILLISECONDS, Optional.of(lock)); this.checker = checker; - this.lockHolder = Optional.of(lock); } @Override diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java index abda60a93d..addd7e0afe 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java @@ -24,10 +24,9 @@ public class SingularityDeployPoller extends SingularityLeaderOnlyPoller { @Inject SingularityDeployPoller(SingularityDeployChecker deployChecker, SingularityConfiguration configuration, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(configuration.getCheckDeploysEverySeconds(), TimeUnit.SECONDS); + super(configuration.getCheckDeploysEverySeconds(), TimeUnit.SECONDS, Optional.of(lock)); this.deployChecker = deployChecker; - this.lockHolder = Optional.of(lock); } @Override diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java index 52ce2f9bf4..f05ec2303d 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java @@ -1,7 +1,6 @@ package com.hubspot.singularity.scheduler; import static com.google.common.base.Preconditions.checkNotNull; - import io.dropwizard.lifecycle.Managed; import java.util.concurrent.Executors; @@ -30,23 +29,21 @@ public abstract class SingularityLeaderOnlyPoller implements Managed { private final ScheduledExecutorService executorService; private final long pollDelay; private final TimeUnit pollTimeUnit; - private final boolean enabled; + private final Optional lockHolder; private LeaderLatch leaderLatch; private SingularityExceptionNotifier exceptionNotifier; private SingularityAbort abort; private SingularityMesosSchedulerDelegator mesosScheduler; - protected Optional lockHolder = Optional.absent(); - protected SingularityLeaderOnlyPoller(long pollDelay, TimeUnit pollTimeUnit) { - this(pollDelay, pollTimeUnit, true); + this(pollDelay, pollTimeUnit, Optional. absent()); } - protected SingularityLeaderOnlyPoller(long pollDelay, TimeUnit pollTimeUnit, boolean enabled) { + protected SingularityLeaderOnlyPoller(long pollDelay, TimeUnit pollTimeUnit, Optional lockHolder) { this.pollDelay = pollDelay; this.pollTimeUnit = pollTimeUnit; - this.enabled = enabled; + this.lockHolder = lockHolder; this.executorService = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat(getClass().getSimpleName() + "-%d").build()); } @@ -64,8 +61,8 @@ void injectPollerDependencies(LeaderLatch leaderLatch, @Override public void start() { - if (!enabled) { - LOG.info("{} is not enabled, skipping.", getClass().getSimpleName()); + if (!isEnabled()) { + LOG.info("{} is not enabled, not starting.", getClass().getSimpleName()); return; } @@ -90,13 +87,16 @@ private void runActionIfLeaderAndMesosIsRunning() { final boolean leadership = leaderLatch.hasLeadership(); final boolean schedulerRunning = mesosScheduler.isRunning(); - if (!leadership || !schedulerRunning) { - LOG.trace("Skipping {} (period: {}) (leadership: {}, mesos running: {})", getClass().getSimpleName(), JavaUtils.durationFromMillis(pollTimeUnit.toMillis(pollDelay)), leadership, schedulerRunning); + if (!leadership || !schedulerRunning || !isEnabled()) { + LOG.trace("Skipping {} (period: {}) (leadership: {}, mesos running: {}, enabled: {})", getClass().getSimpleName(), JavaUtils.durationFromMillis(pollTimeUnit.toMillis(pollDelay)), leadership, + schedulerRunning, isEnabled()); return; } LOG.trace("Running {} (period: {})", getClass().getSimpleName(), JavaUtils.durationFromMillis(pollTimeUnit.toMillis(pollDelay))); + final long start = System.currentTimeMillis(); + if (lockHolder.isPresent()) { lockHolder.get().lock(); } @@ -104,16 +104,28 @@ private void runActionIfLeaderAndMesosIsRunning() { try { runActionOnPoll(); } catch (Throwable t) { - LOG.error("Caught an exception while running {} -- aborting", getClass().getSimpleName(), t); + LOG.error("Caught an exception while running {}", getClass().getSimpleName(), t); exceptionNotifier.notify(t); - abort.abort(AbortReason.UNRECOVERABLE_ERROR); + if (abortsOnError()) { + abort.abort(AbortReason.UNRECOVERABLE_ERROR); + } } finally { if (lockHolder.isPresent()) { lockHolder.get().unlock(); } + + LOG.debug("Ran {} in {}", getClass().getSimpleName(), JavaUtils.duration(start)); } } + protected boolean isEnabled() { + return true; + } + + protected boolean abortsOnError() { + return true; + } + public abstract void runActionOnPoll(); @Override diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java index f203e310a8..62aaf399ee 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java @@ -27,11 +27,10 @@ public class SingularitySchedulerPoller extends SingularityLeaderOnlyPoller { @Inject SingularitySchedulerPoller(Provider stateCacheProvider, SingularityScheduler scheduler, SingularityConfiguration configuration, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(configuration.getCheckSchedulerEverySeconds(), TimeUnit.SECONDS); + super(configuration.getCheckSchedulerEverySeconds(), TimeUnit.SECONDS, Optional.of(lock)); this.stateCacheProvider = stateCacheProvider; this.scheduler = scheduler; - this.lockHolder = Optional.of(lock); } @Override @@ -43,6 +42,7 @@ public void runActionOnPoll() { scheduler.checkForDecomissions(stateCache); scheduler.drainPendingQueue(stateCache); - LOG.info("Processed decomissions and pending queue in {}", JavaUtils.duration(start)); + LOG.debug("Processed decomissions and pending queue in {}", JavaUtils.duration(start)); } + } From ec1dcac234695ac4fa3635fd31f9e40e5da26725 Mon Sep 17 00:00:00 2001 From: Whitney Sorenson Date: Wed, 17 Dec 2014 14:25:13 +0000 Subject: [PATCH 2/3] don't bind / annotate abstract class --- .../singularity/data/history/SingularityHistoryModule.java | 1 - .../singularity/data/history/SingularityHistoryPersister.java | 3 --- 2 files changed, 4 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryModule.java b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryModule.java index c317c6a48f..f4501eff7e 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryModule.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryModule.java @@ -50,7 +50,6 @@ public void configure() { resultSetMappers.addBinding().to(SingularityMappers.SingularityTaskIdHistoryMapper.class).in(Scopes.SINGLETON); resultSetMappers.addBinding().to(SingularityMappers.SingularityDeployHistoryLiteMapper.class).in(Scopes.SINGLETON); - bind(SingularityHistoryPersister.class).in(Scopes.SINGLETON); bind(TaskHistoryHelper.class).in(Scopes.SINGLETON); bind(RequestHistoryHelper.class).in(Scopes.SINGLETON); bind(DeployHistoryHelper.class).in(Scopes.SINGLETON); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java index e823fd1cfa..97c249206c 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java @@ -2,12 +2,9 @@ import java.util.concurrent.TimeUnit; -import javax.inject.Singleton; - import com.hubspot.singularity.config.SingularityConfiguration; import com.hubspot.singularity.scheduler.SingularityLeaderOnlyPoller; -@Singleton public abstract class SingularityHistoryPersister extends SingularityLeaderOnlyPoller { private final SingularityConfiguration configuration; From ad415f69a9a52ede3a029cc708b3fca24bae56c4 Mon Sep 17 00:00:00 2001 From: Whitney Sorenson Date: Tue, 6 Jan 2015 14:49:59 +0000 Subject: [PATCH 3/3] add constructor --- .../singularity/scheduler/SingularityCleanupPoller.java | 3 +-- .../singularity/scheduler/SingularityCooldownPoller.java | 3 +-- .../singularity/scheduler/SingularityDeployPoller.java | 3 +-- .../singularity/scheduler/SingularityLeaderOnlyPoller.java | 6 +++++- .../singularity/scheduler/SingularitySchedulerPoller.java | 3 +-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java index bc138e9daa..63a489449b 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleanupPoller.java @@ -5,7 +5,6 @@ import javax.inject.Singleton; -import com.google.common.base.Optional; import com.google.inject.Inject; import com.google.inject.name.Named; import com.hubspot.singularity.config.SingularityConfiguration; @@ -18,7 +17,7 @@ public class SingularityCleanupPoller extends SingularityLeaderOnlyPoller { @Inject SingularityCleanupPoller(SingularityConfiguration configuration, SingularityCleaner cleaner, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(configuration.getCleanupEverySeconds(), TimeUnit.SECONDS, Optional.of(lock)); + super(configuration.getCleanupEverySeconds(), TimeUnit.SECONDS, lock); this.cleaner = cleaner; } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java index e069d13202..a463e41710 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCooldownPoller.java @@ -5,7 +5,6 @@ import javax.inject.Singleton; -import com.google.common.base.Optional; import com.google.inject.Inject; import com.google.inject.name.Named; import com.hubspot.singularity.config.SingularityConfiguration; @@ -18,7 +17,7 @@ public class SingularityCooldownPoller extends SingularityLeaderOnlyPoller { @Inject SingularityCooldownPoller(SingularityConfiguration configuration, SingularityCooldownChecker checker, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(TimeUnit.MINUTES.toMillis(configuration.getCooldownExpiresAfterMinutes()) / 2, TimeUnit.MILLISECONDS, Optional.of(lock)); + super(TimeUnit.MINUTES.toMillis(configuration.getCooldownExpiresAfterMinutes()) / 2, TimeUnit.MILLISECONDS, lock); this.checker = checker; } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java index addd7e0afe..65bbebcec4 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployPoller.java @@ -8,7 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; import com.google.inject.Inject; import com.google.inject.name.Named; import com.hubspot.mesos.JavaUtils; @@ -24,7 +23,7 @@ public class SingularityDeployPoller extends SingularityLeaderOnlyPoller { @Inject SingularityDeployPoller(SingularityDeployChecker deployChecker, SingularityConfiguration configuration, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(configuration.getCheckDeploysEverySeconds(), TimeUnit.SECONDS, Optional.of(lock)); + super(configuration.getCheckDeploysEverySeconds(), TimeUnit.SECONDS, lock); this.deployChecker = deployChecker; } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java index f05ec2303d..ea28fdded3 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityLeaderOnlyPoller.java @@ -40,7 +40,11 @@ protected SingularityLeaderOnlyPoller(long pollDelay, TimeUnit pollTimeUnit) { this(pollDelay, pollTimeUnit, Optional. absent()); } - protected SingularityLeaderOnlyPoller(long pollDelay, TimeUnit pollTimeUnit, Optional lockHolder) { + protected SingularityLeaderOnlyPoller(long pollDelay, TimeUnit pollTimeUnit, Lock lock) { + this(pollDelay, pollTimeUnit, Optional.of(lock)); + } + + private SingularityLeaderOnlyPoller(long pollDelay, TimeUnit pollTimeUnit, Optional lockHolder) { this.pollDelay = pollDelay; this.pollTimeUnit = pollTimeUnit; this.lockHolder = lockHolder; diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java index 62aaf399ee..7352b6154f 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularitySchedulerPoller.java @@ -8,7 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.name.Named; @@ -27,7 +26,7 @@ public class SingularitySchedulerPoller extends SingularityLeaderOnlyPoller { @Inject SingularitySchedulerPoller(Provider stateCacheProvider, SingularityScheduler scheduler, SingularityConfiguration configuration, @Named(SingularityMesosModule.SCHEDULER_LOCK_NAME) final Lock lock) { - super(configuration.getCheckSchedulerEverySeconds(), TimeUnit.SECONDS, Optional.of(lock)); + super(configuration.getCheckSchedulerEverySeconds(), TimeUnit.SECONDS, lock); this.stateCacheProvider = stateCacheProvider; this.scheduler = scheduler;