From 370c2fefbea50a51ff6ad3982d8afa0466edc48d Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Tue, 27 Apr 2021 10:46:46 -0400 Subject: [PATCH 01/12] wip --- .../singularity/SingularityMainModule.java | 12 +-- .../singularity/SingularityServiceModule.java | 24 ++++- .../singularity/hooks/LoadBalancerClient.java | 1 + .../hooks/LoadBalancerClientImpl.java | 4 + .../hooks/NoOpLoadBalancerClient.java | 90 +++++++++++++++++++ 5 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java diff --git a/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java b/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java index 68fb88ef4c..c22603f180 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java @@ -113,9 +113,14 @@ public class SingularityMainModule implements Module { "singularity.last.mesos.master.heartbeat.time"; private final SingularityConfiguration configuration; + private final Class lbClientClass; - public SingularityMainModule(final SingularityConfiguration configuration) { + public SingularityMainModule( + final SingularityConfiguration configuration, + Class lbClientClass + ) { this.configuration = configuration; + this.lbClientClass = lbClientClass; } @Override @@ -150,10 +155,7 @@ public void configure(Binder binder) { binder.bind(SingularitySmtpSender.class).in(Scopes.SINGLETON); binder.bind(MailTemplateHelpers.class).in(Scopes.SINGLETON); binder.bind(SingularityExceptionNotifier.class).in(Scopes.SINGLETON); - binder - .bind(LoadBalancerClient.class) - .to(LoadBalancerClientImpl.class) - .in(Scopes.SINGLETON); + binder.bind(LoadBalancerClient.class).to(lbClientClass).in(Scopes.SINGLETON); binder.bind(SingularityMailRecordCleaner.class).in(Scopes.SINGLETON); binder.bind(StatusUpdateQueue.class).in(Scopes.SINGLETON); binder.bind(SingularityWebhookPoller.class).in(Scopes.SINGLETON); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java b/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java index 4b2e1f0d57..950cca33a4 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java @@ -19,15 +19,20 @@ import com.hubspot.singularity.data.transcoders.SingularityTranscoderModule; import com.hubspot.singularity.data.zkmigrations.SingularityZkMigrationsModule; import com.hubspot.singularity.event.SingularityEventModule; +import com.hubspot.singularity.hooks.LoadBalancerClient; +import com.hubspot.singularity.hooks.LoadBalancerClientImpl; +import com.hubspot.singularity.hooks.NoOpLoadBalancerClient; import com.hubspot.singularity.jersey.SingularityJerseyModule; import com.hubspot.singularity.mesos.SingularityMesosModule; import com.hubspot.singularity.resources.SingularityOpenApiResource; import com.hubspot.singularity.resources.SingularityResourceModule; import com.hubspot.singularity.scheduler.SingularitySchedulerModule; +import java.util.Optional; public class SingularityServiceModule extends DropwizardAwareModule { private final Function dbModuleProvider; + private Optional> lbClientClass = Optional.empty(); public SingularityServiceModule() { this.dbModuleProvider = SingularityDbModule::new; @@ -39,9 +44,26 @@ public SingularityServiceModule( this.dbModuleProvider = dbModuleProvider; } + public void setLoadBalancerClientClass( + Class lbClientClass + ) { + this.lbClientClass = Optional.of(lbClientClass); + } + @Override public void configure(Binder binder) { - binder.install(new SingularityMainModule(getConfiguration())); + SingularityConfiguration configuration = getConfiguration(); + binder.install( + new SingularityMainModule( + getConfiguration(), + lbClientClass.orElseGet( + () -> + configuration.getLoadBalancerUri() != null + ? LoadBalancerClientImpl.class + : NoOpLoadBalancerClient.class + ) + ) + ); binder.install(new SingularityDataModule(getConfiguration())); binder.install(new SingularitySchedulerModule()); binder.install( diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java index c66b3e2d05..5a0182a8e1 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java @@ -15,6 +15,7 @@ import java.util.concurrent.TimeoutException; public interface LoadBalancerClient { + boolean isEnabled(); SingularityLoadBalancerUpdate enqueue( LoadBalancerRequestId loadBalancerRequestId, SingularityRequest request, diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClientImpl.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClientImpl.java index f9396fb3df..ed11dfe350 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClientImpl.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClientImpl.java @@ -81,6 +81,10 @@ public LoadBalancerClientImpl( this.mesosProtosUtils = mesosProtosUtils; } + public boolean isEnabled() { + return true; + } + private String getStateUriFromRequestUri() { return loadBalancerUri.replace("request", "state"); } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java new file mode 100644 index 0000000000..c7c1b82bd1 --- /dev/null +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java @@ -0,0 +1,90 @@ +package com.hubspot.singularity.hooks; + +import com.google.inject.Inject; +import com.hubspot.baragon.models.UpstreamInfo; +import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; +import com.hubspot.singularity.SingularityCheckingUpstreamsUpdate; +import com.hubspot.singularity.SingularityDeploy; +import com.hubspot.singularity.SingularityLoadBalancerUpdate; +import com.hubspot.singularity.SingularityRequest; +import com.hubspot.singularity.SingularityTask; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +public class NoOpLoadBalancerClient implements LoadBalancerClient { + + @Inject + public NoOpLoadBalancerClient() {} + + @Override + public boolean isEnabled() { + return false; + } + + @Override + public SingularityLoadBalancerUpdate enqueue( + LoadBalancerRequestId loadBalancerRequestId, + SingularityRequest request, + SingularityDeploy deploy, + List add, + List remove + ) { + return null; + } + + @Override + public SingularityLoadBalancerUpdate getState( + LoadBalancerRequestId loadBalancerRequestId + ) { + return null; + } + + @Override + public SingularityLoadBalancerUpdate cancel( + LoadBalancerRequestId loadBalancerRequestId + ) { + return null; + } + + @Override + public SingularityLoadBalancerUpdate delete( + LoadBalancerRequestId loadBalancerRequestId, + String requestId, + Set loadBalancerGroups, + String serviceBasePath + ) { + return null; + } + + @Override + public SingularityCheckingUpstreamsUpdate getLoadBalancerServiceStateForRequest( + String singularityRequestId + ) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + return null; + } + + @Override + public List getUpstreamsForTasks( + List tasks, + String requestId, + Optional loadBalancerUpstreamGroup + ) { + return null; + } + + @Override + public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( + LoadBalancerRequestId loadBalancerRequestId, + List addUpstreams, + List removeUpstreams, + SingularityDeploy deploy, + SingularityRequest request + ) { + return null; + } +} From 5e6c51ee8ee8231fb6e6cac74a0905768197d5d4 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Tue, 27 Apr 2021 15:00:55 -0400 Subject: [PATCH 02/12] big 'ol refactor --- .../singularity/LoadBalancerRequestState.java | 46 +++++++++ .../singularity/LoadBalancerUpstream.java | 72 ++++++++++++++ .../SingularityCheckingUpstreamsUpdate.java | 37 ------- .../SingularityLoadBalancerUpdate.java | 9 +- .../singularity/SingularityMainModule.java | 1 - .../singularity/SingularityServiceModule.java | 11 ++- ...ava => BaragonLoadBalancerClientImpl.java} | 97 +++++++++++-------- .../singularity/hooks/LoadBalancerClient.java | 13 +-- .../hooks/NoOpLoadBalancerClient.java | 69 +++++++++---- .../scheduler/SingularityCleaner.java | 13 ++- .../scheduler/SingularityDeployChecker.java | 22 +---- .../scheduler/SingularityNewTaskChecker.java | 14 +-- .../scheduler/SingularityUpstreamChecker.java | 97 ++++++------------- .../SingularityDeployAcceptanceTest.java | 10 +- .../scheduler/SingularityDeploysTest.java | 10 +- .../scheduler/SingularitySchedulerTest.java | 41 ++++---- .../SingularitySchedulerTestBase.java | 4 +- .../scheduler/SingularityTestModule.java | 4 +- .../scheduler/TestingLoadBalancerClient.java | 32 +++--- 19 files changed, 340 insertions(+), 262 deletions(-) create mode 100644 SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerRequestState.java create mode 100644 SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java delete mode 100644 SingularityBase/src/main/java/com/hubspot/singularity/SingularityCheckingUpstreamsUpdate.java rename SingularityService/src/main/java/com/hubspot/singularity/hooks/{LoadBalancerClientImpl.java => BaragonLoadBalancerClientImpl.java} (86%) diff --git a/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerRequestState.java b/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerRequestState.java new file mode 100644 index 0000000000..6605677238 --- /dev/null +++ b/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerRequestState.java @@ -0,0 +1,46 @@ +package com.hubspot.singularity; + +import com.hubspot.baragon.models.BaragonRequestState; + +public enum LoadBalancerRequestState { + UNKNOWN(false), + FAILED(false), + WAITING(true), + SUCCESS(false), + CANCELING(true), + CANCELED(false), + INVALID_REQUEST_NOOP(false); + + private final boolean inProgress; + + LoadBalancerRequestState(boolean inProgress) { + this.inProgress = inProgress; + } + + public boolean isInProgress() { + return inProgress; + } + + public static LoadBalancerRequestState fromBaragonRequestState( + BaragonRequestState baragonRequestState + ) { + switch (baragonRequestState) { + case WAITING: + return WAITING; + case SUCCESS: + return SUCCESS; + case UNKNOWN: + return UNKNOWN; + case FAILED: + return FAILED; + case CANCELED: + return CANCELED; + case CANCELING: + return CANCELING; + case INVALID_REQUEST_NOOP: + return INVALID_REQUEST_NOOP; + default: + return null; + } + } +} diff --git a/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java b/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java new file mode 100644 index 0000000000..a2d82386ba --- /dev/null +++ b/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java @@ -0,0 +1,72 @@ +package com.hubspot.singularity; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.MoreObjects; +import com.hubspot.baragon.models.UpstreamInfo; +import java.util.Objects; +import java.util.Optional; + +public class LoadBalancerUpstream { + private final String upstream; + private final String group; + private final Optional rackId; + + @JsonCreator + public LoadBalancerUpstream( + @JsonProperty("upstream") String upstream, + @JsonProperty("group") String group, + @JsonProperty("rackId") Optional rackId + ) { + this.upstream = upstream; + this.group = group; + this.rackId = rackId; + } + + public static LoadBalancerUpstream fromBaragonUpstream(UpstreamInfo upstreamInfo) { + return new LoadBalancerUpstream( + upstreamInfo.getUpstream(), + upstreamInfo.getGroup(), + upstreamInfo.getRackId().toJavaUtil() + ); + } + + public String getUpstream() { + return upstream; + } + + public String getGroup() { + return group; + } + + public Optional getRackId() { + return rackId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LoadBalancerUpstream that = (LoadBalancerUpstream) o; + return ( + Objects.equals(upstream, that.upstream) && + Objects.equals(group, that.group) && + Objects.equals(rackId, that.rackId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(upstream, group, rackId); + } + + @Override + public String toString() { + return MoreObjects + .toStringHelper(this) + .add("upstream", upstream) + .add("group", group) + .add("rackId", rackId) + .toString(); + } +} diff --git a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityCheckingUpstreamsUpdate.java b/SingularityBase/src/main/java/com/hubspot/singularity/SingularityCheckingUpstreamsUpdate.java deleted file mode 100644 index b155009d64..0000000000 --- a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityCheckingUpstreamsUpdate.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.hubspot.singularity; - -import com.hubspot.baragon.models.BaragonServiceState; -import java.util.Optional; - -public class SingularityCheckingUpstreamsUpdate { - private final Optional baragonServiceState; - private final String singularityRequestId; - - public SingularityCheckingUpstreamsUpdate( - Optional baragonServiceState, - String singularityRequest - ) { - this.baragonServiceState = baragonServiceState; - this.singularityRequestId = singularityRequest; - } - - public String getSingularityRequestId() { - return singularityRequestId; - } - - public Optional getBaragonServiceState() { - return baragonServiceState; - } - - @Override - public String toString() { - return ( - "SingularityCheckingUpstreamsUpdate{" + - " baragonServiceState=" + - baragonServiceState + - ", singularityRequestId=" + - singularityRequestId + - '}' - ); - } -} diff --git a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityLoadBalancerUpdate.java b/SingularityBase/src/main/java/com/hubspot/singularity/SingularityLoadBalancerUpdate.java index 5b465241cd..c4bd1ee076 100644 --- a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityLoadBalancerUpdate.java +++ b/SingularityBase/src/main/java/com/hubspot/singularity/SingularityLoadBalancerUpdate.java @@ -2,14 +2,13 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.hubspot.baragon.models.BaragonRequestState; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import io.swagger.v3.oas.annotations.media.Schema; import java.util.Optional; @Schema(description = "An updated to load balancer configuration") public class SingularityLoadBalancerUpdate { - private final BaragonRequestState loadBalancerState; + private final LoadBalancerRequestState loadBalancerState; private final Optional message; private final long timestamp; private final Optional uri; @@ -27,7 +26,7 @@ public enum LoadBalancerMethod { @JsonCreator public SingularityLoadBalancerUpdate( - @JsonProperty("state") BaragonRequestState loadBalancerState, + @JsonProperty("state") LoadBalancerRequestState loadBalancerState, @JsonProperty("loadBalancerRequestId") LoadBalancerRequestId loadBalancerRequestId, @JsonProperty("message") Optional message, @JsonProperty("timestamp") long timestamp, @@ -45,7 +44,7 @@ public SingularityLoadBalancerUpdate( @Schema( description = "The current state of the request to update load balancer configuration" ) - public BaragonRequestState getLoadBalancerState() { + public LoadBalancerRequestState getLoadBalancerState() { return loadBalancerState; } @@ -78,7 +77,7 @@ public static SingularityLoadBalancerUpdate preEnqueue( LoadBalancerRequestId lbRequestId ) { return new SingularityLoadBalancerUpdate( - BaragonRequestState.UNKNOWN, + LoadBalancerRequestState.UNKNOWN, lbRequestId, Optional.empty(), System.currentTimeMillis(), diff --git a/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java b/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java index c22603f180..76a0096ead 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/SingularityMainModule.java @@ -39,7 +39,6 @@ import com.hubspot.singularity.helpers.SingularityS3Services; import com.hubspot.singularity.hooks.AbstractWebhookChecker; import com.hubspot.singularity.hooks.LoadBalancerClient; -import com.hubspot.singularity.hooks.LoadBalancerClientImpl; import com.hubspot.singularity.hooks.SingularityWebhookPoller; import com.hubspot.singularity.hooks.SingularityWebhookSender; import com.hubspot.singularity.hooks.SnsWebhookManager; diff --git a/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java b/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java index 950cca33a4..5567c0fa14 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/SingularityServiceModule.java @@ -1,7 +1,6 @@ package com.hubspot.singularity; import com.google.common.base.Function; -import com.google.common.base.Strings; import com.google.inject.Binder; import com.google.inject.Module; import com.google.inject.Provides; @@ -19,8 +18,8 @@ import com.hubspot.singularity.data.transcoders.SingularityTranscoderModule; import com.hubspot.singularity.data.zkmigrations.SingularityZkMigrationsModule; import com.hubspot.singularity.event.SingularityEventModule; +import com.hubspot.singularity.hooks.BaragonLoadBalancerClientImpl; import com.hubspot.singularity.hooks.LoadBalancerClient; -import com.hubspot.singularity.hooks.LoadBalancerClientImpl; import com.hubspot.singularity.hooks.NoOpLoadBalancerClient; import com.hubspot.singularity.jersey.SingularityJerseyModule; import com.hubspot.singularity.mesos.SingularityMesosModule; @@ -59,7 +58,7 @@ public void configure(Binder binder) { lbClientClass.orElseGet( () -> configuration.getLoadBalancerUri() != null - ? LoadBalancerClientImpl.class + ? BaragonLoadBalancerClientImpl.class : NoOpLoadBalancerClient.class ) ) @@ -103,7 +102,9 @@ public void configure(Binder binder) { @Provides @Singleton - public IndexViewConfiguration provideIndexViewConfiguration() { + public IndexViewConfiguration provideIndexViewConfiguration( + LoadBalancerClient loadBalancerClient + ) { SingularityConfiguration configuration = getConfiguration(); return new IndexViewConfiguration( configuration.getUiConfiguration(), @@ -117,7 +118,7 @@ public IndexViewConfiguration provideIndexViewConfiguration() { configuration.getHealthcheckTimeoutSeconds(), configuration.getHealthcheckMaxRetries(), configuration.getStartupTimeoutSeconds(), - !Strings.isNullOrEmpty(configuration.getLoadBalancerUri()), + loadBalancerClient.isEnabled(), configuration.getCommonHostnameSuffixToOmit(), configuration.getWarnIfScheduledJobIsRunningPastNextRunPct(), configuration.getAuthConfiguration().isEnabled() && diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClientImpl.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java similarity index 86% rename from SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClientImpl.java rename to SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java index ed11dfe350..f17ae00f78 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClientImpl.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java @@ -12,9 +12,10 @@ import com.hubspot.baragon.models.UpstreamInfo; import com.hubspot.mesos.JavaUtils; import com.hubspot.mesos.protos.MesosParameter; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; +import com.hubspot.singularity.LoadBalancerUpstream; import com.hubspot.singularity.Singularity; -import com.hubspot.singularity.SingularityCheckingUpstreamsUpdate; import com.hubspot.singularity.SingularityDeploy; import com.hubspot.singularity.SingularityLoadBalancerUpdate; import com.hubspot.singularity.SingularityLoadBalancerUpdate.LoadBalancerMethod; @@ -37,10 +38,11 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class LoadBalancerClientImpl implements LoadBalancerClient { +public class BaragonLoadBalancerClientImpl implements LoadBalancerClient { private static final Logger LOG = LoggerFactory.getLogger(LoadBalancerClient.class); private static final String CONTENT_TYPE_JSON = "application/json"; @@ -62,7 +64,7 @@ public class LoadBalancerClientImpl implements LoadBalancerClient { private static final String OPERATION_URI = "%s/%s"; @Inject - public LoadBalancerClientImpl( + public BaragonLoadBalancerClientImpl( SingularityConfiguration configuration, @Singularity ObjectMapper objectMapper, AsyncHttpClient httpClient, @@ -97,9 +99,7 @@ private String getLoadBalancerStateUri(String singularityRequestId) { ); } - public SingularityCheckingUpstreamsUpdate getLoadBalancerServiceStateForRequest( - String singularityRequestId - ) + public List getUpstreamsForRequest(String singularityRequestId) throws IOException, InterruptedException, ExecutionException, TimeoutException { final String loadBalancerStateUri = getLoadBalancerStateUri(singularityRequestId); final BoundRequestBuilder requestBuilder = httpClient.prepareGet( @@ -123,10 +123,12 @@ public SingularityCheckingUpstreamsUpdate getLoadBalancerServiceStateForRequest( Optional maybeBaragonServiceState = Optional.ofNullable( objectMapper.readValue(response.getResponseBodyAsBytes(), BaragonServiceState.class) ); - return new SingularityCheckingUpstreamsUpdate( - maybeBaragonServiceState, - singularityRequestId - ); + return maybeBaragonServiceState + .map(BaragonServiceState::getUpstreams) + .orElse(Collections.emptyList()) + .stream() + .map(LoadBalancerUpstream::fromBaragonUpstream) + .collect(Collectors.toList()); } private String getLoadBalancerUri(LoadBalancerRequestId loadBalancerRequestId) { @@ -150,9 +152,9 @@ public SingularityLoadBalancerUpdate getState( final BoundRequestBuilder requestBuilder = httpClient.prepareGet(uri); - if (loadBalancerQueryParams.isPresent()) { - addAllQueryParams(requestBuilder, loadBalancerQueryParams.get()); - } + loadBalancerQueryParams.ifPresent( + stringStringMap -> addAllQueryParams(requestBuilder, stringStringMap) + ); return sendRequestWrapper( loadBalancerRequestId, @@ -214,7 +216,7 @@ private SingularityLoadBalancerUpdate sendRequestWrapper( JavaUtils.duration(start) ); return new SingularityLoadBalancerUpdate( - result.state, + LoadBalancerRequestState.fromBaragonRequestState(result.state), loadBalancerRequestId, result.message, start, @@ -251,9 +253,9 @@ private SingularityLoadBalancerUpdate sendLoadBalancerRequest( .addHeader(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON) .setBody(objectMapper.writeValueAsBytes(loadBalancerRequest)); - if (loadBalancerQueryParams.isPresent()) { - addAllQueryParams(requestBuilder, loadBalancerQueryParams.get()); - } + loadBalancerQueryParams.ifPresent( + stringStringMap -> addAllQueryParams(requestBuilder, stringStringMap) + ); return sendRequestWrapper( loadBalancerRequestId, @@ -263,7 +265,7 @@ private SingularityLoadBalancerUpdate sendLoadBalancerRequest( ); } catch (IOException e) { return new SingularityLoadBalancerUpdate( - BaragonRequestState.UNKNOWN, + LoadBalancerRequestState.UNKNOWN, loadBalancerRequestId, Optional.of(e.getMessage()), System.currentTimeMillis(), @@ -372,12 +374,12 @@ public SingularityLoadBalancerUpdate enqueue( List add, List remove ) { - final List addUpstreams = getUpstreamsForTasks( + final List addUpstreams = getUpstreamsForTasks( add, loadBalancerRequestId.toString(), deploy.getLoadBalancerUpstreamGroup() ); - final List removeUpstreams = getUpstreamsForTasks( + final List removeUpstreams = getUpstreamsForTasks( remove, loadBalancerRequestId.toString(), deploy.getLoadBalancerUpstreamGroup() @@ -395,17 +397,17 @@ public SingularityLoadBalancerUpdate enqueue( @Override public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( LoadBalancerRequestId loadBalancerRequestId, - List addUpstreams, - List removeUpstreams, + List addUpstreams, + List removeUpstreams, SingularityDeploy deploy, SingularityRequest request ) { final List serviceOwners = request .getOwners() - .orElse(Collections.emptyList()); + .orElse(Collections.emptyList()); final Set loadBalancerGroups = deploy .getLoadBalancerGroups() - .orElse(Collections.emptySet()); + .orElse(Collections.emptySet()); boolean enableDNSPreResolution; if (skipDNSPreResolutionForRequests.contains(request.getId())) { @@ -430,10 +432,16 @@ public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( final BaragonRequest loadBalancerRequest = new BaragonRequest( loadBalancerRequestId.toString(), lbService, - addUpstreams, - removeUpstreams, - Collections.emptyList(), - com.google.common.base.Optional.absent(), + addUpstreams + .stream() + .map(u -> singularityToBaragonUpstream(u, loadBalancerRequestId.toString())) + .collect(Collectors.toList()), + removeUpstreams + .stream() + .map(u -> singularityToBaragonUpstream(u, loadBalancerRequestId.toString())) + .collect(Collectors.toList()), + Collections.emptyList(), + com.google.common.base.Optional.absent(), com.google.common.base.Optional.of(RequestAction.UPDATE), false, false, @@ -447,12 +455,27 @@ public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( ); } - public List getUpstreamsForTasks( + private UpstreamInfo singularityToBaragonUpstream( + LoadBalancerUpstream loadBalancerUpstream, + String loadBalancerRequestId + ) { + return new UpstreamInfo( + loadBalancerUpstream.getUpstream(), + com.google.common.base.Optional.of(loadBalancerRequestId), + com.google.common.base.Optional.fromJavaUtil(loadBalancerUpstream.getRackId()), + com.google.common.base.Optional.absent(), + com.google.common.base.Optional.of(loadBalancerUpstream.getGroup()) + ); + } + + public List getUpstreamsForTasks( List tasks, String requestId, Optional loadBalancerUpstreamGroup ) { - final List upstreams = Lists.newArrayListWithCapacity(tasks.size()); + final List upstreams = Lists.newArrayListWithCapacity( + tasks.size() + ); for (SingularityTask task : tasks) { final Optional maybeLoadBalancerPort = MesosUtils.getPortByIndex( @@ -482,13 +505,7 @@ public List getUpstreamsForTasks( } upstreams.add( - new UpstreamInfo( - upstream, - com.google.common.base.Optional.of(requestId), - com.google.common.base.Optional.fromJavaUtil(task.getRackId()), - com.google.common.base.Optional.absent(), - com.google.common.base.Optional.fromJavaUtil(group) - ) + new LoadBalancerUpstream(upstream, group.orElse("default"), task.getRackId()) ); } else { LOG.warn( @@ -510,9 +527,9 @@ public SingularityLoadBalancerUpdate cancel( final BoundRequestBuilder requestBuilder = httpClient.prepareDelete(uri); - if (loadBalancerQueryParams.isPresent()) { - addAllQueryParams(requestBuilder, loadBalancerQueryParams.get()); - } + loadBalancerQueryParams.ifPresent( + stringStringMap -> addAllQueryParams(requestBuilder, stringStringMap) + ); return sendRequestWrapper( loadBalancerRequestId, diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java index 5a0182a8e1..351505bfe3 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java @@ -1,8 +1,7 @@ package com.hubspot.singularity.hooks; -import com.hubspot.baragon.models.UpstreamInfo; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; -import com.hubspot.singularity.SingularityCheckingUpstreamsUpdate; +import com.hubspot.singularity.LoadBalancerUpstream; import com.hubspot.singularity.SingularityDeploy; import com.hubspot.singularity.SingularityLoadBalancerUpdate; import com.hubspot.singularity.SingularityRequest; @@ -35,12 +34,10 @@ SingularityLoadBalancerUpdate delete( String serviceBasePath ); - SingularityCheckingUpstreamsUpdate getLoadBalancerServiceStateForRequest( - String singularityRequestId - ) + List getUpstreamsForRequest(String singularityRequestId) throws IOException, InterruptedException, ExecutionException, TimeoutException; - List getUpstreamsForTasks( + List getUpstreamsForTasks( List tasks, String requestId, Optional loadBalancerUpstreamGroup @@ -48,8 +45,8 @@ List getUpstreamsForTasks( SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( LoadBalancerRequestId loadBalancerRequestId, - List addUpstreams, - List removeUpstreams, + List addUpstreams, + List removeUpstreams, SingularityDeploy deploy, SingularityRequest request ); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java index c7c1b82bd1..41bcf3d473 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java @@ -1,19 +1,18 @@ package com.hubspot.singularity.hooks; import com.google.inject.Inject; -import com.hubspot.baragon.models.UpstreamInfo; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; -import com.hubspot.singularity.SingularityCheckingUpstreamsUpdate; +import com.hubspot.singularity.LoadBalancerUpstream; import com.hubspot.singularity.SingularityDeploy; import com.hubspot.singularity.SingularityLoadBalancerUpdate; +import com.hubspot.singularity.SingularityLoadBalancerUpdate.LoadBalancerMethod; import com.hubspot.singularity.SingularityRequest; import com.hubspot.singularity.SingularityTask; -import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; public class NoOpLoadBalancerClient implements LoadBalancerClient { @@ -33,21 +32,42 @@ public SingularityLoadBalancerUpdate enqueue( List add, List remove ) { - return null; + return new SingularityLoadBalancerUpdate( + LoadBalancerRequestState.SUCCESS, + loadBalancerRequestId, + Optional.empty(), + System.currentTimeMillis(), + LoadBalancerMethod.ENQUEUE, + Optional.empty() + ); } @Override public SingularityLoadBalancerUpdate getState( LoadBalancerRequestId loadBalancerRequestId ) { - return null; + return new SingularityLoadBalancerUpdate( + LoadBalancerRequestState.SUCCESS, + loadBalancerRequestId, + Optional.empty(), + System.currentTimeMillis(), + LoadBalancerMethod.CHECK_STATE, + Optional.empty() + ); } @Override public SingularityLoadBalancerUpdate cancel( LoadBalancerRequestId loadBalancerRequestId ) { - return null; + return new SingularityLoadBalancerUpdate( + LoadBalancerRequestState.SUCCESS, + loadBalancerRequestId, + Optional.empty(), + System.currentTimeMillis(), + LoadBalancerMethod.CANCEL, + Optional.empty() + ); } @Override @@ -57,34 +77,45 @@ public SingularityLoadBalancerUpdate delete( Set loadBalancerGroups, String serviceBasePath ) { - return null; + return new SingularityLoadBalancerUpdate( + LoadBalancerRequestState.SUCCESS, + loadBalancerRequestId, + Optional.empty(), + System.currentTimeMillis(), + LoadBalancerMethod.DELETE, + Optional.empty() + ); } @Override - public SingularityCheckingUpstreamsUpdate getLoadBalancerServiceStateForRequest( - String singularityRequestId - ) - throws IOException, InterruptedException, ExecutionException, TimeoutException { - return null; + public List getUpstreamsForRequest(String singularityRequestId) { + return Collections.emptyList(); } @Override - public List getUpstreamsForTasks( + public List getUpstreamsForTasks( List tasks, String requestId, Optional loadBalancerUpstreamGroup ) { - return null; + return Collections.emptyList(); } @Override public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( LoadBalancerRequestId loadBalancerRequestId, - List addUpstreams, - List removeUpstreams, + List addUpstreams, + List removeUpstreams, SingularityDeploy deploy, SingularityRequest request ) { - return null; + return new SingularityLoadBalancerUpdate( + LoadBalancerRequestState.SUCCESS, + loadBalancerRequestId, + Optional.empty(), + System.currentTimeMillis(), + LoadBalancerMethod.CHECK_STATE, + Optional.empty() + ); } } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleaner.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleaner.java index 3c1689db6f..b67dd27ea7 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleaner.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityCleaner.java @@ -5,8 +5,8 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Multiset; import com.google.inject.Inject; -import com.hubspot.baragon.models.BaragonRequestState; import com.hubspot.mesos.JavaUtils; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.RequestCleanupType; @@ -1317,8 +1317,10 @@ private CheckLBState checkLbState(SingularityTaskId taskId) { lbRemoveUpdate ); } else if ( - maybeLbRemoveUpdate.get().getLoadBalancerState() == BaragonRequestState.WAITING || - maybeLbRemoveUpdate.get().getLoadBalancerState() == BaragonRequestState.CANCELING + maybeLbRemoveUpdate.get().getLoadBalancerState() == + LoadBalancerRequestState.WAITING || + maybeLbRemoveUpdate.get().getLoadBalancerState() == + LoadBalancerRequestState.CANCELING ) { lbRemoveUpdate = lbClient.getState(loadBalancerRequestId); @@ -1608,8 +1610,9 @@ private CheckLBState checkRequestLbState( cleanup.setLoadBalancerUpdate(Optional.of(lbDeleteUpdate)); requestManager.saveLbCleanupRequest(cleanup); } else if ( - maybeDeleteUpdate.get().getLoadBalancerState() == BaragonRequestState.WAITING || - maybeDeleteUpdate.get().getLoadBalancerState() == BaragonRequestState.CANCELING + maybeDeleteUpdate.get().getLoadBalancerState() == + LoadBalancerRequestState.WAITING || + maybeDeleteUpdate.get().getLoadBalancerState() == LoadBalancerRequestState.CANCELING ) { lbDeleteUpdate = lbClient.getState(loadBalancerRequestId); cleanup.setLoadBalancerUpdate(Optional.of(lbDeleteUpdate)); diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployChecker.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployChecker.java index 31ceebbfbf..f67c974d38 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployChecker.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityDeployChecker.java @@ -2,11 +2,11 @@ import com.google.common.collect.Iterables; import com.google.inject.Inject; -import com.hubspot.baragon.models.BaragonRequestState; import com.hubspot.mesos.JavaUtils; import com.hubspot.singularity.DeployAcceptanceResult; import com.hubspot.singularity.DeployProgressLbUpdateHolder; import com.hubspot.singularity.DeployState; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.RequestState; @@ -1051,19 +1051,6 @@ private SingularityDeployResult checkDeployProgress( return new SingularityDeployResult(DeployState.WAITING); } - if (configuration.getLoadBalancerUri() == null) { - LOG.warn( - "Deploy {} required a load balancer URI but it wasn't set", - pendingDeploy - ); - return new SingularityDeployResult( - DeployState.FAILED, - Optional.of("No valid load balancer URI was present"), - Collections.emptyList(), - System.currentTimeMillis() - ); - } - for (SingularityTaskId activeTaskId : deployActiveTasks) { taskManager.markHealthchecksFinished(activeTaskId); taskManager.clearStartupHealthchecks(activeTaskId); @@ -1220,9 +1207,7 @@ private SingularityDeployResult checkAcceptanceOfDeployStep( acceptanceHookDeployState, updatedProgress ); - if ( - request.isLoadBalanced() && configuration.getLoadBalancerUri() != null - ) { + if (request.isLoadBalanced() && lbClient.isEnabled()) { // Add previous tasks back to load balancer, since we previously took them out if (updatedProgress.getPendingLbUpdate().isPresent()) { return checkLbRevertToActiveTasks( @@ -1515,7 +1500,8 @@ private SingularityDeployResult enqueueAndProcessLbRequest( if ( maybeAddUpdate.isPresent() && ( - maybeAddUpdate.get().getLoadBalancerState() == BaragonRequestState.SUCCESS || + maybeAddUpdate.get().getLoadBalancerState() == + LoadBalancerRequestState.SUCCESS || maybeAddUpdate.get().getLoadBalancerState().isInProgress() ) ) { diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityNewTaskChecker.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityNewTaskChecker.java index 1abaffb600..e130bf7c8c 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityNewTaskChecker.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityNewTaskChecker.java @@ -5,9 +5,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.inject.Inject; -import com.hubspot.baragon.models.BaragonRequestState; import com.hubspot.mesos.JavaUtils; import com.hubspot.singularity.ExtendedTaskState; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.SingularityAbort; @@ -540,7 +540,7 @@ CheckTaskState getTaskState( task.getTaskId(), LoadBalancerRequestType.ADD, new SingularityLoadBalancerUpdate( - BaragonRequestState.UNKNOWN, + LoadBalancerRequestState.UNKNOWN, loadBalancerRequestId, Optional.empty(), System.currentTimeMillis(), @@ -579,14 +579,10 @@ CheckTaskState getTaskState( newLbUpdate.getLoadBalancerState() ); - if (maybeCheckTaskState.isPresent()) { - return maybeCheckTaskState.get(); - } - - return CheckTaskState.LB_IN_PROGRESS_CHECK_AGAIN; + return maybeCheckTaskState.orElse(CheckTaskState.LB_IN_PROGRESS_CHECK_AGAIN); } - private Optional checkLbState(BaragonRequestState lbState) { + private Optional checkLbState(LoadBalancerRequestState lbState) { switch (lbState) { case SUCCESS: return Optional.of(CheckTaskState.HEALTHY); @@ -665,7 +661,7 @@ private long getTaskRunningStartTime(SingularityTaskId task) { private boolean unknownNotRemoving(SingularityLoadBalancerUpdate update) { return ( - update.getLoadBalancerState() == BaragonRequestState.UNKNOWN && + update.getLoadBalancerState() == LoadBalancerRequestState.UNKNOWN && update.getLoadBalancerRequestId().getRequestType() != LoadBalancerRequestType.REMOVE ); } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityUpstreamChecker.java b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityUpstreamChecker.java index d093c8c148..e765acb78a 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityUpstreamChecker.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/scheduler/SingularityUpstreamChecker.java @@ -3,13 +3,10 @@ import com.github.rholder.retry.Retryer; import com.github.rholder.retry.RetryerBuilder; import com.github.rholder.retry.WaitStrategies; -import com.google.common.base.Predicate; -import com.hubspot.baragon.models.BaragonRequestState; -import com.hubspot.baragon.models.BaragonServiceState; -import com.hubspot.baragon.models.UpstreamInfo; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; -import com.hubspot.singularity.SingularityCheckingUpstreamsUpdate; +import com.hubspot.singularity.LoadBalancerUpstream; import com.hubspot.singularity.SingularityDeploy; import com.hubspot.singularity.SingularityLoadBalancerUpdate; import com.hubspot.singularity.SingularityRequest; @@ -30,6 +27,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; import java.util.stream.Collectors; import javax.inject.Inject; import javax.inject.Singleton; @@ -42,7 +40,8 @@ public class SingularityUpstreamChecker { SingularityUpstreamChecker.class ); private static final Predicate IS_WAITING_STATE = singularityLoadBalancerUpdate -> - singularityLoadBalancerUpdate.getLoadBalancerState() == BaragonRequestState.WAITING; + singularityLoadBalancerUpdate.getLoadBalancerState() == + LoadBalancerRequestState.WAITING; private final LoadBalancerClient lbClient; private final TaskManager taskManager; @@ -98,7 +97,7 @@ private List getActiveHealthyAndCleaningTasksForService( throw new TaskIdNotFoundException("TaskId not found"); } - private Collection getUpstreamsFromActiveHealthyAndCleaningTasksForService( + private Collection getUpstreamsFromActiveHealthyAndCleaningTasksForService( String singularityRequestId, Optional loadBalancerUpstreamGroup ) @@ -117,25 +116,22 @@ private Collection getUpstreamsFromActiveHealthyAndCleaningTasksFo * @return a collection of upstreams in the upstreams param that match with the upstream param on upstream and group. * We expect that the collection will have a maximum of one match, but we will keep it as a collection just in case. */ - private Collection getEqualUpstreams( - UpstreamInfo upstream, - Collection upstreams + private Collection getEqualUpstreams( + LoadBalancerUpstream upstream, + Collection upstreams ) { - return upstreams - .stream() - .filter(candidate -> UpstreamInfo.upstreamAndGroupMatches(candidate, upstream)) - .collect(Collectors.toList()); + return upstreams.stream().filter(upstream::equals).collect(Collectors.toList()); } - private List getExtraUpstreamsInLoadBalancer( - Collection upstreamsInLoadBalancerForService, - Collection upstreamsInSingularityForService + private List getExtraUpstreamsInLoadBalancer( + Collection upstreamsInLoadBalancerForService, + Collection upstreamsInSingularityForService ) { - List extraUpstreams = new ArrayList<>( + List extraUpstreams = new ArrayList<>( upstreamsInLoadBalancerForService ); - for (UpstreamInfo upstreamInSingularity : upstreamsInSingularityForService) { - final Collection matches = getEqualUpstreams( + for (LoadBalancerUpstream upstreamInSingularity : upstreamsInSingularityForService) { + final Collection matches = getEqualUpstreams( upstreamInSingularity, upstreamsInLoadBalancerForService ); @@ -144,35 +140,7 @@ private List getExtraUpstreamsInLoadBalancer( return extraUpstreams; } - private Collection getLoadBalancerUpstreamsForServiceHelper( - SingularityCheckingUpstreamsUpdate singularityCheckingUpstreamsUpdate, - Optional loadBalancerUpstreamGroup - ) { - if (singularityCheckingUpstreamsUpdate.getBaragonServiceState().isPresent()) { - LOG.debug( - "Baragon service state for service {} is present.", - singularityCheckingUpstreamsUpdate.getSingularityRequestId() - ); - final BaragonServiceState baragonServiceState = singularityCheckingUpstreamsUpdate - .getBaragonServiceState() - .get(); - return baragonServiceState - .getUpstreams() - .stream() - .filter( - upstream -> - upstream.getGroup().equals(loadBalancerUpstreamGroup.orElse("default")) - ) - .collect(Collectors.toList()); - } - LOG.debug( - "Baragon service state for service {} is absent.", - singularityCheckingUpstreamsUpdate.getSingularityRequestId() - ); - return Collections.emptyList(); - } - - private Collection getLoadBalancerUpstreamsForService( + private Collection getLoadBalancerUpstreamsForService( String singularityRequestId, Optional loadBalancerServiceIdOverride, Optional loadBalancerUpstreamGroup @@ -186,19 +154,14 @@ private Collection getLoadBalancerUpstreamsForService( singularityRequestId, loadBalancerServiceId ); - final SingularityCheckingUpstreamsUpdate checkUpstreamsState = lbClient.getLoadBalancerServiceStateForRequest( - loadBalancerServiceId - ); - LOG.trace( - "Succeeded getting load balancer upstreams for singularity request {} with loadBalancerServiceId {}. State is {}.", - singularityRequestId, - loadBalancerServiceId, - checkUpstreamsState.toString() - ); - return getLoadBalancerUpstreamsForServiceHelper( - checkUpstreamsState, - loadBalancerUpstreamGroup - ); + return lbClient + .getUpstreamsForRequest(loadBalancerServiceId) + .stream() + .filter( + upstream -> + upstream.getGroup().equals(loadBalancerUpstreamGroup.orElse("default")) + ) + .collect(Collectors.toList()); } catch (Exception e) { LOG.error( "Failed getting load balancer upstreams for singularity request {} with loadBalancerServiceId {}. ", @@ -220,7 +183,7 @@ private Optional syncUpstreamsForServiceHelper( "Checking load balancer upstreams for service {}.", singularityRequest.getId() ); - Collection upstreamsInLoadBalancerForService = getLoadBalancerUpstreamsForService( + Collection upstreamsInLoadBalancerForService = getLoadBalancerUpstreamsForService( singularityRequest.getId(), deploy.getLoadBalancerServiceIdOverride(), loadBalancerUpstreamGroup @@ -230,7 +193,7 @@ private Optional syncUpstreamsForServiceHelper( singularityRequest.getId(), upstreamsInLoadBalancerForService ); - Collection upstreamsInSingularityForService = getUpstreamsFromActiveHealthyAndCleaningTasksForService( + Collection upstreamsInSingularityForService = getUpstreamsFromActiveHealthyAndCleaningTasksForService( singularityRequest.getId(), loadBalancerUpstreamGroup ); @@ -239,7 +202,7 @@ private Optional syncUpstreamsForServiceHelper( singularityRequest.getId(), upstreamsInSingularityForService ); - final List extraUpstreams = getExtraUpstreamsInLoadBalancer( + final List extraUpstreams = getExtraUpstreamsInLoadBalancer( upstreamsInLoadBalancerForService, upstreamsInSingularityForService ); @@ -354,7 +317,7 @@ private void checkSyncUpstreamsState( .newBuilder() .retryIfException() .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS)) - .retryIfResult(IS_WAITING_STATE) + .retryIfResult(IS_WAITING_STATE::test) .build(); try { LOG.debug( @@ -364,7 +327,7 @@ private void checkSyncUpstreamsState( SingularityLoadBalancerUpdate syncUpstreamsState = syncingRetryer.call( () -> lbClient.getState(loadBalancerRequestId) ); - if (syncUpstreamsState.getLoadBalancerState() == BaragonRequestState.SUCCESS) { + if (syncUpstreamsState.getLoadBalancerState() == LoadBalancerRequestState.SUCCESS) { LOG.debug( "Syncing upstreams for singularity request {} is {}.", singularityRequestId, diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeployAcceptanceTest.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeployAcceptanceTest.java index 3f00979c1f..f415cd06db 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeployAcceptanceTest.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeployAcceptanceTest.java @@ -1,13 +1,13 @@ package com.hubspot.singularity.scheduler; import com.google.inject.Inject; -import com.hubspot.baragon.models.BaragonRequestState; import com.hubspot.singularity.CanaryDeploySettings; import com.hubspot.singularity.DeployAcceptanceMode; import com.hubspot.singularity.DeployAcceptanceResult; import com.hubspot.singularity.DeployAcceptanceState; import com.hubspot.singularity.DeployProgressLbUpdateHolder; import com.hubspot.singularity.DeployState; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.SingularityDeployBuilder; import com.hubspot.singularity.SingularityDeployProgress; import com.hubspot.singularity.SingularityDeployResult; @@ -334,18 +334,18 @@ public void testLbRevertsAfterFailedAcceptanceStepOnNonCanary() { .getPendingDeploy(requestId) .get(); Assertions.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState()); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); deployChecker.checkDeploys(); pendingDeploy = deployManager.getPendingDeploy(requestId).get(); Assertions.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState()); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS); + testingLbClient.setNextRequestState(LoadBalancerRequestState.SUCCESS); deployChecker.checkDeploys(); // Acceptance checks fail - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); deployChecker.checkDeploys(); pendingDeploy = deployManager.getPendingDeploy(requestId).get(); Assertions.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState()); @@ -368,7 +368,7 @@ public void testLbRevertsAfterFailedAcceptanceStepOnNonCanary() { Assertions.assertTrue(lbUpdateHolder.getAdded().contains(firstTask.getTaskId())); Assertions.assertTrue(lbUpdateHolder.getRemoved().contains(firstNewTaskId)); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS); + testingLbClient.setNextRequestState(LoadBalancerRequestState.SUCCESS); deployChecker.checkDeploys(); SingularityDeployResult deployResult = deployManager .getDeployResult(requestId, secondDeployId) diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeploysTest.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeploysTest.java index c9d38a2458..99b9b4f641 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeploysTest.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityDeploysTest.java @@ -1,7 +1,7 @@ package com.hubspot.singularity.scheduler; -import com.hubspot.baragon.models.BaragonRequestState; import com.hubspot.singularity.DeployState; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType; import com.hubspot.singularity.RequestState; import com.hubspot.singularity.RequestType; @@ -1006,13 +1006,13 @@ public void testLbUpdatesAfterEachDeployStep() { .get(); Assertions.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState()); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); deployChecker.checkDeploys(); pendingDeploy = deployManager.getPendingDeploy(requestId).get(); Assertions.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState()); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS); + testingLbClient.setNextRequestState(LoadBalancerRequestState.SUCCESS); deployChecker.checkDeploys(); deployChecker.checkDeploys(); @@ -1026,7 +1026,7 @@ public void testLbUpdatesAfterEachDeployStep() { cleaner.drainCleanupQueue(); statusUpdate(firstTask, TaskState.TASK_KILLED); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); deployChecker.checkDeploys(); @@ -1062,7 +1062,7 @@ public void testLbUpdatesAfterEachDeployStep() { pendingDeploy = deployManager.getPendingDeploy(requestId).get(); Assertions.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState()); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS); + testingLbClient.setNextRequestState(LoadBalancerRequestState.SUCCESS); deployChecker.checkDeploys(); deployChecker.checkDeploys(); diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTest.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTest.java index b2f83cf1b2..90628bc013 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTest.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTest.java @@ -16,6 +16,7 @@ import com.hubspot.singularity.AgentPlacement; import com.hubspot.singularity.DeployState; import com.hubspot.singularity.ExtendedTaskState; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.MachineState; @@ -389,7 +390,7 @@ public void testBounceWithLoadBalancer() { SingularityTask taskOne = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING); saveLoadBalancerState( - BaragonRequestState.SUCCESS, + LoadBalancerRequestState.SUCCESS, taskOne.getTaskId(), LoadBalancerRequestType.ADD ); @@ -418,7 +419,7 @@ public void testBounceWithLoadBalancer() { // add to LB: saveLoadBalancerState( - BaragonRequestState.SUCCESS, + LoadBalancerRequestState.SUCCESS, taskTwo, LoadBalancerRequestType.ADD ); @@ -429,7 +430,7 @@ public void testBounceWithLoadBalancer() { Assertions.assertEquals(2, taskManager.getNumActiveTasks()); saveLoadBalancerState( - BaragonRequestState.SUCCESS, + LoadBalancerRequestState.SUCCESS, taskOne.getTaskId(), LoadBalancerRequestType.REMOVE ); @@ -1313,7 +1314,7 @@ public void testLBCleanup() { SingularityTask task = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING); saveLoadBalancerState( - BaragonRequestState.SUCCESS, + LoadBalancerRequestState.SUCCESS, task.getTaskId(), LoadBalancerRequestType.ADD ); @@ -1322,7 +1323,7 @@ public void testLBCleanup() { Assertions.assertTrue(!taskManager.getLBCleanupTasks().isEmpty()); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); cleaner.drainCleanupQueue(); Assertions.assertTrue(!taskManager.getLBCleanupTasks().isEmpty()); @@ -1334,10 +1335,10 @@ public void testLBCleanup() { Assertions.assertTrue(lbUpdate.isPresent()); Assertions.assertTrue( - lbUpdate.get().getLoadBalancerState() == BaragonRequestState.WAITING + lbUpdate.get().getLoadBalancerState() == LoadBalancerRequestState.WAITING ); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.FAILED); + testingLbClient.setNextRequestState(LoadBalancerRequestState.FAILED); cleaner.drainCleanupQueue(); Assertions.assertTrue(!taskManager.getLBCleanupTasks().isEmpty()); @@ -1347,10 +1348,10 @@ public void testLBCleanup() { Assertions.assertTrue(lbUpdate.isPresent()); Assertions.assertTrue( - lbUpdate.get().getLoadBalancerState() == BaragonRequestState.FAILED + lbUpdate.get().getLoadBalancerState() == LoadBalancerRequestState.FAILED ); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS); + testingLbClient.setNextRequestState(LoadBalancerRequestState.SUCCESS); cleaner.drainCleanupQueue(); @@ -1365,7 +1366,7 @@ public void testLBCleanup() { Assertions.assertTrue(lbUpdate.isPresent()); Assertions.assertTrue( - lbUpdate.get().getLoadBalancerState() == BaragonRequestState.SUCCESS + lbUpdate.get().getLoadBalancerState() == LoadBalancerRequestState.SUCCESS ); Assertions.assertTrue( lbUpdate.get().getLoadBalancerRequestId().getAttemptNumber() == 2 @@ -1385,7 +1386,7 @@ public void testLbCleanupDoesNotRemoveBeforeAdd() { 1, TaskState.TASK_RUNNING ); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); deployChecker.checkDeploys(); // First task from old deploy is still starting, never got added to LB so it should not have a removal request @@ -1407,7 +1408,7 @@ public void testLbCleanupDoesNotRemoveBeforeAdd() { .isPresent() ); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS); + testingLbClient.setNextRequestState(LoadBalancerRequestState.SUCCESS); deployChecker.checkDeploys(); deployChecker.checkDeploys(); @@ -1565,7 +1566,7 @@ public void testLbCleanupSkippedOnSkipRemoveFlag() { requestResource.deleteRequest(requestId, Optional.of(deleteRequest), singularityUser); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); Assertions.assertFalse( requestManager.getCleanupRequests().isEmpty(), @@ -1595,7 +1596,7 @@ public void testLbCleanupOccursOnRequestDelete() { requestResource.deleteRequest(requestId, Optional.empty(), singularityUser); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); Assertions.assertFalse( requestManager.getCleanupRequests().isEmpty(), @@ -1811,7 +1812,7 @@ public void testPauseLbCleanup() { Optional.empty() ); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING); + testingLbClient.setNextRequestState(LoadBalancerRequestState.WAITING); cleaner.drainCleanupQueue(); Assertions.assertTrue(!requestManager.getLbCleanupRequestIds().isEmpty()); @@ -1823,10 +1824,10 @@ public void testPauseLbCleanup() { Assertions.assertTrue(lbUpdate.isPresent()); Assertions.assertTrue( - lbUpdate.get().getLoadBalancerState() == BaragonRequestState.WAITING + lbUpdate.get().getLoadBalancerState() == LoadBalancerRequestState.WAITING ); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.FAILED); + testingLbClient.setNextRequestState(LoadBalancerRequestState.FAILED); cleaner.drainCleanupQueue(); Assertions.assertTrue(!requestManager.getLbCleanupRequestIds().isEmpty()); @@ -1836,10 +1837,10 @@ public void testPauseLbCleanup() { Assertions.assertTrue(lbUpdate.isPresent()); Assertions.assertTrue( - lbUpdate.get().getLoadBalancerState() == BaragonRequestState.FAILED + lbUpdate.get().getLoadBalancerState() == LoadBalancerRequestState.FAILED ); - testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS); + testingLbClient.setNextRequestState(LoadBalancerRequestState.SUCCESS); cleaner.drainCleanupQueue(); Assertions.assertTrue(requestManager.getLbCleanupRequestIds().isEmpty()); @@ -4497,7 +4498,7 @@ public void testRecoveredTaskIsRecoveredIfLoadBalancerRemoveIsStarted() { taskId, LoadBalancerRequestType.REMOVE, new SingularityLoadBalancerUpdate( - BaragonRequestState.UNKNOWN, + LoadBalancerRequestState.UNKNOWN, new LoadBalancerRequestId( taskId.getId(), LoadBalancerRequestType.REMOVE, diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTestBase.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTestBase.java index 6d10e946c0..60ccd01823 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTestBase.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularitySchedulerTestBase.java @@ -2,7 +2,6 @@ import com.google.inject.Inject; import com.google.inject.name.Named; -import com.hubspot.baragon.models.BaragonRequestState; import com.hubspot.deploy.HealthcheckOptionsBuilder; import com.hubspot.mesos.Resources; import com.hubspot.mesos.json.MesosTaskMonitorObject; @@ -10,6 +9,7 @@ import com.hubspot.mesos.protos.MesosTaskStatusObject; import com.hubspot.singularity.AgentPlacement; import com.hubspot.singularity.DeployState; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.RequestType; @@ -1194,7 +1194,7 @@ protected void saveAndSchedule(SingularityRequestBuilder bldr) { } protected void saveLoadBalancerState( - BaragonRequestState brs, + LoadBalancerRequestState brs, SingularityTaskId taskId, LoadBalancerRequestType lbrt ) { diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java index 9bc0c80e08..570d433fbb 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java @@ -170,7 +170,9 @@ public void configure(Binder mainBinder) { mainBinder.install( Modules - .override(new SingularityMainModule(configuration)) + .override( + new SingularityMainModule(configuration, TestingLoadBalancerClient.class) + ) .with( new Module() { diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java index 936787f668..6c725bceb1 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java @@ -1,9 +1,8 @@ package com.hubspot.singularity.scheduler; -import com.hubspot.baragon.models.BaragonRequestState; -import com.hubspot.baragon.models.UpstreamInfo; +import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; -import com.hubspot.singularity.SingularityCheckingUpstreamsUpdate; +import com.hubspot.singularity.LoadBalancerUpstream; import com.hubspot.singularity.SingularityDeploy; import com.hubspot.singularity.SingularityLoadBalancerUpdate; import com.hubspot.singularity.SingularityLoadBalancerUpdate.LoadBalancerMethod; @@ -19,16 +18,21 @@ import java.util.concurrent.TimeoutException; public class TestingLoadBalancerClient implements LoadBalancerClient { - private BaragonRequestState requestState; + private LoadBalancerRequestState requestState; public TestingLoadBalancerClient() { - requestState = BaragonRequestState.WAITING; + requestState = LoadBalancerRequestState.WAITING; } - public void setNextBaragonRequestState(BaragonRequestState nextState) { + public void setNextRequestState(LoadBalancerRequestState nextState) { this.requestState = nextState; } + @Override + public boolean isEnabled() { + return true; + } + private SingularityLoadBalancerUpdate getReturnValue( LoadBalancerRequestId loadBalancerRequestId, LoadBalancerMethod method @@ -36,10 +40,10 @@ private SingularityLoadBalancerUpdate getReturnValue( return new SingularityLoadBalancerUpdate( requestState, loadBalancerRequestId, - Optional.empty(), + Optional.empty(), System.currentTimeMillis(), method, - Optional.empty() + Optional.empty() ); } @@ -79,15 +83,13 @@ public SingularityLoadBalancerUpdate delete( } @Override - public SingularityCheckingUpstreamsUpdate getLoadBalancerServiceStateForRequest( - String singularityRequestId - ) + public List getUpstreamsForRequest(String singularityRequestId) throws IOException, InterruptedException, ExecutionException, TimeoutException { - return new SingularityCheckingUpstreamsUpdate(Optional.empty(), singularityRequestId); + return Collections.emptyList(); } @Override - public List getUpstreamsForTasks( + public List getUpstreamsForTasks( List tasks, String requestId, Optional loadBalancerUpstreamGroup @@ -98,8 +100,8 @@ public List getUpstreamsForTasks( @Override public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( LoadBalancerRequestId loadBalancerRequestId, - List addUpstreams, - List removeUpstreams, + List addUpstreams, + List removeUpstreams, SingularityDeploy deploy, SingularityRequest request ) { From 72f2fd81dd4d8ab7621b19631b0db5901d13f7ae Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Tue, 27 Apr 2021 15:19:18 -0400 Subject: [PATCH 03/12] build? --- .../com/hubspot/singularity/LoadBalancerUpstream.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java b/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java index a2d82386ba..1bdd326064 100644 --- a/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java +++ b/SingularityBase/src/main/java/com/hubspot/singularity/LoadBalancerUpstream.java @@ -45,8 +45,12 @@ public Optional getRackId() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } LoadBalancerUpstream that = (LoadBalancerUpstream) o; return ( Objects.equals(upstream, that.upstream) && From c983ba3f1aff0e89c7c4dbad9a7ef135cb1b58e2 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Tue, 27 Apr 2021 15:58:18 -0400 Subject: [PATCH 04/12] Move validation to lb client implementation --- .../singularity/data/SingularityValidator.java | 18 +++++++----------- .../hooks/BaragonLoadBalancerClientImpl.java | 14 ++++++++++++++ .../singularity/hooks/LoadBalancerClient.java | 2 ++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/data/SingularityValidator.java b/SingularityService/src/main/java/com/hubspot/singularity/data/SingularityValidator.java index 5e88b2d8bf..f1c9b731ad 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/data/SingularityValidator.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/data/SingularityValidator.java @@ -51,6 +51,7 @@ import com.hubspot.singularity.data.history.DeployHistoryHelper; import com.hubspot.singularity.expiring.SingularityExpiringMachineState; import com.hubspot.singularity.helpers.ImageName; +import com.hubspot.singularity.hooks.LoadBalancerClient; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.net.URI; import java.net.URISyntaxException; @@ -116,6 +117,7 @@ public class SingularityValidator { private final PriorityManager priorityManager; private final DisasterManager disasterManager; private final AgentManager agentManager; + private final LoadBalancerClient loadBalancerClient; @Inject public SingularityValidator( @@ -124,7 +126,8 @@ public SingularityValidator( PriorityManager priorityManager, DisasterManager disasterManager, AgentManager agentManager, - UIConfiguration uiConfiguration + UIConfiguration uiConfiguration, + LoadBalancerClient loadBalancerClient ) { this.maxDeployIdSize = configuration.getMaxDeployIdSize(); this.maxRequestIdSize = configuration.getMaxRequestIdSize(); @@ -183,6 +186,7 @@ public SingularityValidator( this.disasterManager = disasterManager; this.agentManager = agentManager; + this.loadBalancerClient = loadBalancerClient; } public SingularityRequest checkSingularityRequest( @@ -420,16 +424,8 @@ public SingularityDeploy checkDeploy( "Deploy id must match request id" ); - if (request.isLoadBalanced()) { - checkBadRequest( - deploy.getServiceBasePath().isPresent(), - "Deploy for loadBalanced request must include serviceBasePath" - ); - checkBadRequest( - deploy.getLoadBalancerGroups().isPresent() && - !deploy.getLoadBalancerGroups().get().isEmpty(), - "Deploy for a loadBalanced request must include at least one load balacner group" - ); + if (request.isLoadBalanced() && loadBalancerClient.isEnabled()) { + loadBalancerClient.validateDeploy(deploy); } if (deploy.getEnv().isPresent()) { diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java index f17ae00f78..67990dfeeb 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java @@ -1,5 +1,7 @@ package com.hubspot.singularity.hooks; +import static com.hubspot.singularity.WebExceptions.checkBadRequest; + import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; import com.google.inject.Inject; @@ -569,4 +571,16 @@ public SingularityLoadBalancerUpdate delete( LoadBalancerMethod.DELETE ); } + + public void validateDeploy(SingularityDeploy deploy) { + checkBadRequest( + deploy.getServiceBasePath().isPresent(), + "Deploy for loadBalanced request must include serviceBasePath" + ); + checkBadRequest( + deploy.getLoadBalancerGroups().isPresent() && + !deploy.getLoadBalancerGroups().get().isEmpty(), + "Deploy for a loadBalanced request must include at least one load balancer group" + ); + } } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java index 351505bfe3..dc200ab0d9 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java @@ -50,4 +50,6 @@ SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( SingularityDeploy deploy, SingularityRequest request ); + + void validateDeploy(SingularityDeploy deploy); } From a5103b325ddc01067b4c252b391a8eedaff8eef9 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Tue, 27 Apr 2021 16:21:46 -0400 Subject: [PATCH 05/12] move more to abstract class --- .../hooks/BaragonLoadBalancerClientImpl.java | 105 +------------- .../singularity/hooks/LoadBalancerClient.java | 128 ++++++++++++++++-- .../hooks/NoOpLoadBalancerClient.java | 39 ++---- .../singularity/data/ValidatorTest.java | 3 +- .../scheduler/TestingLoadBalancerClient.java | 11 +- 5 files changed, 138 insertions(+), 148 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java index 67990dfeeb..32d368f34b 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/BaragonLoadBalancerClientImpl.java @@ -1,9 +1,6 @@ package com.hubspot.singularity.hooks; -import static com.hubspot.singularity.WebExceptions.checkBadRequest; - import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Lists; import com.google.inject.Inject; import com.hubspot.baragon.models.BaragonRequest; import com.hubspot.baragon.models.BaragonRequestState; @@ -13,7 +10,6 @@ import com.hubspot.baragon.models.RequestAction; import com.hubspot.baragon.models.UpstreamInfo; import com.hubspot.mesos.JavaUtils; -import com.hubspot.mesos.protos.MesosParameter; import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.LoadBalancerUpstream; @@ -22,10 +18,8 @@ import com.hubspot.singularity.SingularityLoadBalancerUpdate; import com.hubspot.singularity.SingularityLoadBalancerUpdate.LoadBalancerMethod; import com.hubspot.singularity.SingularityRequest; -import com.hubspot.singularity.SingularityTask; import com.hubspot.singularity.config.SingularityConfiguration; import com.hubspot.singularity.helpers.MesosProtosUtils; -import com.hubspot.singularity.helpers.MesosUtils; import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; import com.ning.http.client.ListenableFuture; @@ -44,7 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BaragonLoadBalancerClientImpl implements LoadBalancerClient { +public class BaragonLoadBalancerClientImpl extends LoadBalancerClient { private static final Logger LOG = LoggerFactory.getLogger(LoadBalancerClient.class); private static final String CONTENT_TYPE_JSON = "application/json"; @@ -58,10 +52,8 @@ public class BaragonLoadBalancerClientImpl implements LoadBalancerClient { private final AsyncHttpClient httpClient; private final ObjectMapper objectMapper; - private final Optional taskLabelForLoadBalancerUpstreamGroup; private final boolean preResolveUpstreamDNS; private final Set skipDNSPreResolutionForRequests; - private final MesosProtosUtils mesosProtosUtils; private static final String OPERATION_URI = "%s/%s"; @@ -72,17 +64,15 @@ public BaragonLoadBalancerClientImpl( AsyncHttpClient httpClient, MesosProtosUtils mesosProtosUtils ) { + super(configuration, mesosProtosUtils); this.httpClient = httpClient; this.objectMapper = objectMapper; this.loadBalancerUri = configuration.getLoadBalancerUri(); this.loadBalancerTimeoutMillis = configuration.getLoadBalancerRequestTimeoutMillis(); this.loadBalancerQueryParams = configuration.getLoadBalancerQueryParams(); - this.taskLabelForLoadBalancerUpstreamGroup = - configuration.getTaskLabelForLoadBalancerUpstreamGroup(); this.skipDNSPreResolutionForRequests = configuration.getSkipDNSPreResolutionForRequests(); this.preResolveUpstreamDNS = configuration.isPreResolveUpstreamDNS(); - this.mesosProtosUtils = mesosProtosUtils; } public boolean isEnabled() { @@ -368,34 +358,6 @@ private LoadBalancerUpdateHolder sendRequest( } } - @Override - public SingularityLoadBalancerUpdate enqueue( - LoadBalancerRequestId loadBalancerRequestId, - SingularityRequest request, - SingularityDeploy deploy, - List add, - List remove - ) { - final List addUpstreams = getUpstreamsForTasks( - add, - loadBalancerRequestId.toString(), - deploy.getLoadBalancerUpstreamGroup() - ); - final List removeUpstreams = getUpstreamsForTasks( - remove, - loadBalancerRequestId.toString(), - deploy.getLoadBalancerUpstreamGroup() - ); - - return makeAndSendLoadBalancerRequest( - loadBalancerRequestId, - addUpstreams, - removeUpstreams, - deploy, - request - ); - } - @Override public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( LoadBalancerRequestId loadBalancerRequestId, @@ -470,57 +432,6 @@ private UpstreamInfo singularityToBaragonUpstream( ); } - public List getUpstreamsForTasks( - List tasks, - String requestId, - Optional loadBalancerUpstreamGroup - ) { - final List upstreams = Lists.newArrayListWithCapacity( - tasks.size() - ); - - for (SingularityTask task : tasks) { - final Optional maybeLoadBalancerPort = MesosUtils.getPortByIndex( - mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), - task.getTaskRequest().getDeploy().getLoadBalancerPortIndex().orElse(0) - ); - - if (maybeLoadBalancerPort.isPresent()) { - String upstream = String.format( - "%s:%d", - task.getHostname(), - maybeLoadBalancerPort.get() - ); - Optional group = loadBalancerUpstreamGroup; - - if (taskLabelForLoadBalancerUpstreamGroup.isPresent()) { - for (MesosParameter label : task.getMesosTask().getLabels().getLabels()) { - if ( - label.hasKey() && - label.getKey().equals(taskLabelForLoadBalancerUpstreamGroup.get()) && - label.hasValue() - ) { - group = Optional.of(label.getValue()); - break; - } - } - } - - upstreams.add( - new LoadBalancerUpstream(upstream, group.orElse("default"), task.getRackId()) - ); - } else { - LOG.warn( - "Task {} is missing port but is being passed to LB ({})", - task.getTaskId(), - task - ); - } - } - - return upstreams; - } - @Override public SingularityLoadBalancerUpdate cancel( LoadBalancerRequestId loadBalancerRequestId @@ -571,16 +482,4 @@ public SingularityLoadBalancerUpdate delete( LoadBalancerMethod.DELETE ); } - - public void validateDeploy(SingularityDeploy deploy) { - checkBadRequest( - deploy.getServiceBasePath().isPresent(), - "Deploy for loadBalanced request must include serviceBasePath" - ); - checkBadRequest( - deploy.getLoadBalancerGroups().isPresent() && - !deploy.getLoadBalancerGroups().get().isEmpty(), - "Deploy for a loadBalanced request must include at least one load balancer group" - ); - } } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java index dc200ab0d9..2b7a1deb09 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/LoadBalancerClient.java @@ -1,49 +1,143 @@ package com.hubspot.singularity.hooks; +import static com.hubspot.singularity.WebExceptions.checkBadRequest; + +import com.google.common.collect.Lists; +import com.hubspot.mesos.protos.MesosParameter; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.LoadBalancerUpstream; import com.hubspot.singularity.SingularityDeploy; import com.hubspot.singularity.SingularityLoadBalancerUpdate; import com.hubspot.singularity.SingularityRequest; import com.hubspot.singularity.SingularityTask; +import com.hubspot.singularity.config.SingularityConfiguration; +import com.hubspot.singularity.helpers.MesosProtosUtils; +import com.hubspot.singularity.helpers.MesosUtils; import java.io.IOException; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class LoadBalancerClient { + private static final Logger LOG = LoggerFactory.getLogger(LoadBalancerClient.class); + + private final Optional taskLabelForLoadBalancerUpstreamGroup; + private final MesosProtosUtils mesosProtosUtils; + + public LoadBalancerClient( + SingularityConfiguration configuration, + MesosProtosUtils mesosProtosUtils + ) { + this.taskLabelForLoadBalancerUpstreamGroup = + configuration.getTaskLabelForLoadBalancerUpstreamGroup(); + this.mesosProtosUtils = mesosProtosUtils; + } -public interface LoadBalancerClient { - boolean isEnabled(); - SingularityLoadBalancerUpdate enqueue( + public abstract boolean isEnabled(); + + public SingularityLoadBalancerUpdate enqueue( LoadBalancerRequestId loadBalancerRequestId, SingularityRequest request, SingularityDeploy deploy, List add, List remove - ); + ) { + final List addUpstreams = getUpstreamsForTasks( + add, + loadBalancerRequestId.toString(), + deploy.getLoadBalancerUpstreamGroup() + ); + final List removeUpstreams = getUpstreamsForTasks( + remove, + loadBalancerRequestId.toString(), + deploy.getLoadBalancerUpstreamGroup() + ); - SingularityLoadBalancerUpdate getState(LoadBalancerRequestId loadBalancerRequestId); + return makeAndSendLoadBalancerRequest( + loadBalancerRequestId, + addUpstreams, + removeUpstreams, + deploy, + request + ); + } - SingularityLoadBalancerUpdate cancel(LoadBalancerRequestId loadBalancerRequestId); + public abstract SingularityLoadBalancerUpdate getState( + LoadBalancerRequestId loadBalancerRequestId + ); - SingularityLoadBalancerUpdate delete( + public abstract SingularityLoadBalancerUpdate cancel( + LoadBalancerRequestId loadBalancerRequestId + ); + + public abstract SingularityLoadBalancerUpdate delete( LoadBalancerRequestId loadBalancerRequestId, String requestId, Set loadBalancerGroups, String serviceBasePath ); - List getUpstreamsForRequest(String singularityRequestId) + public abstract List getUpstreamsForRequest( + String singularityRequestId + ) throws IOException, InterruptedException, ExecutionException, TimeoutException; - List getUpstreamsForTasks( + public List getUpstreamsForTasks( List tasks, String requestId, Optional loadBalancerUpstreamGroup - ); + ) { + final List upstreams = Lists.newArrayListWithCapacity( + tasks.size() + ); + + for (SingularityTask task : tasks) { + final Optional maybeLoadBalancerPort = MesosUtils.getPortByIndex( + mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), + task.getTaskRequest().getDeploy().getLoadBalancerPortIndex().orElse(0) + ); + + if (maybeLoadBalancerPort.isPresent()) { + String upstream = String.format( + "%s:%d", + task.getHostname(), + maybeLoadBalancerPort.get() + ); + Optional group = loadBalancerUpstreamGroup; + + if (taskLabelForLoadBalancerUpstreamGroup.isPresent()) { + for (MesosParameter label : task.getMesosTask().getLabels().getLabels()) { + if ( + label.hasKey() && + label.getKey().equals(taskLabelForLoadBalancerUpstreamGroup.get()) && + label.hasValue() + ) { + group = Optional.of(label.getValue()); + break; + } + } + } + + upstreams.add( + new LoadBalancerUpstream(upstream, group.orElse("default"), task.getRackId()) + ); + } else { + LOG.warn( + "Task {} is missing port but is being passed to LB ({})", + task.getTaskId(), + task + ); + } + } + + return upstreams; + } - SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( + public abstract SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( LoadBalancerRequestId loadBalancerRequestId, List addUpstreams, List removeUpstreams, @@ -51,5 +145,15 @@ SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( SingularityRequest request ); - void validateDeploy(SingularityDeploy deploy); + public void validateDeploy(SingularityDeploy deploy) { + checkBadRequest( + deploy.getServiceBasePath().isPresent(), + "Deploy for loadBalanced request must include serviceBasePath" + ); + checkBadRequest( + deploy.getLoadBalancerGroups().isPresent() && + !deploy.getLoadBalancerGroups().get().isEmpty(), + "Deploy for a loadBalanced request must include at least one load balancer group" + ); + } } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java b/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java index 41bcf3d473..b44c33b151 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/hooks/NoOpLoadBalancerClient.java @@ -8,40 +8,28 @@ import com.hubspot.singularity.SingularityLoadBalancerUpdate; import com.hubspot.singularity.SingularityLoadBalancerUpdate.LoadBalancerMethod; import com.hubspot.singularity.SingularityRequest; -import com.hubspot.singularity.SingularityTask; +import com.hubspot.singularity.config.SingularityConfiguration; +import com.hubspot.singularity.helpers.MesosProtosUtils; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; -public class NoOpLoadBalancerClient implements LoadBalancerClient { +public class NoOpLoadBalancerClient extends LoadBalancerClient { @Inject - public NoOpLoadBalancerClient() {} + public NoOpLoadBalancerClient( + SingularityConfiguration configuration, + MesosProtosUtils mesosProtosUtils + ) { + super(configuration, mesosProtosUtils); + } @Override public boolean isEnabled() { return false; } - @Override - public SingularityLoadBalancerUpdate enqueue( - LoadBalancerRequestId loadBalancerRequestId, - SingularityRequest request, - SingularityDeploy deploy, - List add, - List remove - ) { - return new SingularityLoadBalancerUpdate( - LoadBalancerRequestState.SUCCESS, - loadBalancerRequestId, - Optional.empty(), - System.currentTimeMillis(), - LoadBalancerMethod.ENQUEUE, - Optional.empty() - ); - } - @Override public SingularityLoadBalancerUpdate getState( LoadBalancerRequestId loadBalancerRequestId @@ -92,15 +80,6 @@ public List getUpstreamsForRequest(String singularityReque return Collections.emptyList(); } - @Override - public List getUpstreamsForTasks( - List tasks, - String requestId, - Optional loadBalancerUpstreamGroup - ) { - return Collections.emptyList(); - } - @Override public SingularityLoadBalancerUpdate makeAndSendLoadBalancerRequest( LoadBalancerRequestId loadBalancerRequestId, diff --git a/SingularityService/src/test/java/com/hubspot/singularity/data/ValidatorTest.java b/SingularityService/src/test/java/com/hubspot/singularity/data/ValidatorTest.java index 4a140f092d..ef1b254f0f 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/data/ValidatorTest.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/data/ValidatorTest.java @@ -56,7 +56,8 @@ public void createValidator() { priorityManager, disasterManager, agentManager, - uiConfiguration + uiConfiguration, + testingLbClient ); } diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java index 6c725bceb1..8ea4a95503 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/TestingLoadBalancerClient.java @@ -1,5 +1,6 @@ package com.hubspot.singularity.scheduler; +import com.fasterxml.jackson.databind.ObjectMapper; import com.hubspot.singularity.LoadBalancerRequestState; import com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId; import com.hubspot.singularity.LoadBalancerUpstream; @@ -8,6 +9,8 @@ import com.hubspot.singularity.SingularityLoadBalancerUpdate.LoadBalancerMethod; import com.hubspot.singularity.SingularityRequest; import com.hubspot.singularity.SingularityTask; +import com.hubspot.singularity.config.SingularityConfiguration; +import com.hubspot.singularity.helpers.MesosProtosUtils; import com.hubspot.singularity.hooks.LoadBalancerClient; import java.io.IOException; import java.util.Collections; @@ -17,10 +20,14 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -public class TestingLoadBalancerClient implements LoadBalancerClient { +public class TestingLoadBalancerClient extends LoadBalancerClient { private LoadBalancerRequestState requestState; - public TestingLoadBalancerClient() { + public TestingLoadBalancerClient( + SingularityConfiguration configuration, + ObjectMapper objectMapper + ) { + super(configuration, new MesosProtosUtils(objectMapper)); requestState = LoadBalancerRequestState.WAITING; } From c1153fc8f2799fefba95ab6f0afc95e8b818b354 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Tue, 27 Apr 2021 16:23:54 -0400 Subject: [PATCH 06/12] fix test --- .../hubspot/singularity/scheduler/SingularityTestModule.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java index 570d433fbb..208c94c53d 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java @@ -188,7 +188,10 @@ public void configure(Binder binder) { binder.bind(SingularityMailer.class).toInstance(mailer); binder.bind(SingularityAbort.class).toInstance(abort); - TestingLoadBalancerClient tlbc = new TestingLoadBalancerClient(); + TestingLoadBalancerClient tlbc = new TestingLoadBalancerClient( + configuration, + om + ); binder.bind(LoadBalancerClient.class).toInstance(tlbc); binder.bind(TestingLoadBalancerClient.class).toInstance(tlbc); if (configuration.isCacheOffers()) { From cdca236ef983894e958e3d6f16c0eaf704a35038 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Wed, 28 Apr 2021 10:06:21 -0400 Subject: [PATCH 07/12] build settings --- SingularityService/.blazar.yaml | 2 +- .../hubspot/singularity/scheduler/SingularityTestModule.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SingularityService/.blazar.yaml b/SingularityService/.blazar.yaml index 4b59aa68ee..dd6b861a2c 100644 --- a/SingularityService/.blazar.yaml +++ b/SingularityService/.blazar.yaml @@ -1,5 +1,5 @@ env: - MAVEN_ARGS: "-T 8 -Dsingularity.jar.name.format=\\${project.artifactId} -Dgpg.skip=true -DforkCount=2C" + MAVEN_ARGS: "-Dsingularity.jar.name.format=\\${project.artifactId} -Dgpg.skip=true" SET_VERSION_OVERRIDE: "1.5.0-$GIT_BRANCH-SNAPSHOT" buildResources: diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java index 208c94c53d..e6736a17cc 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java @@ -112,7 +112,7 @@ public SingularityTestModule( Logger hsLogger = context.getLogger("com.hubspot"); hsLogger.setLevel( Level.toLevel( - System.getProperty("singularity.test.log.level.for.com.hubspot", "DEBUG") + System.getProperty("singularity.test.log.level.for.com.hubspot", "WARN") ) ); From 6fe7c2f7c47cb246ae8223ffc49647c416b5fddc Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Wed, 28 Apr 2021 10:21:02 -0400 Subject: [PATCH 08/12] forks --- SingularityService/pom.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SingularityService/pom.xml b/SingularityService/pom.xml index d6738c4cdf..c69d65be02 100644 --- a/SingularityService/pom.xml +++ b/SingularityService/pom.xml @@ -518,7 +518,9 @@ maven-surefire-plugin - 300 + 8 + true + 600 From ae7a908f985177443ea0561949b52c4b5b82c6ea Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Wed, 28 Apr 2021 10:29:20 -0400 Subject: [PATCH 09/12] More thoughts on test fixes --- SingularityService/pom.xml | 2 +- .../com/hubspot/singularity/SingularityCuratorTestBase.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SingularityService/pom.xml b/SingularityService/pom.xml index c69d65be02..e96da06d10 100644 --- a/SingularityService/pom.xml +++ b/SingularityService/pom.xml @@ -519,7 +519,7 @@ maven-surefire-plugin 8 - true + false 600 diff --git a/SingularityService/src/test/java/com/hubspot/singularity/SingularityCuratorTestBase.java b/SingularityService/src/test/java/com/hubspot/singularity/SingularityCuratorTestBase.java index 664b38c19e..520e242f39 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/SingularityCuratorTestBase.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/SingularityCuratorTestBase.java @@ -81,7 +81,7 @@ public class SingularityCuratorTestBase { ); @AfterEach - public void clearData() { + public synchronized void clearData() { try { // clean up most data for (String parent : cf.getChildren().forPath("/")) { @@ -129,7 +129,7 @@ public void clearData() { } @BeforeAll - public void setup() throws Exception { + public synchronized void setup() throws Exception { JerseyGuiceUtils.reset(); singularityTestModule = new SingularityTestModule(useDBTests, customConfigSetup); @@ -172,7 +172,7 @@ public SingularityCuratorTestBase( } @AfterAll - public void teardown() throws Exception { + public synchronized void teardown() throws Exception { if (singularityTestModule != null) { singularityTestModule.stop(); } From 012dd743618a8386e6b5fafa9cd35891661609e7 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Wed, 28 Apr 2021 10:45:48 -0400 Subject: [PATCH 10/12] more forks --- SingularityService/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SingularityService/pom.xml b/SingularityService/pom.xml index e96da06d10..fd1db64dc6 100644 --- a/SingularityService/pom.xml +++ b/SingularityService/pom.xml @@ -518,7 +518,7 @@ maven-surefire-plugin - 8 + 1 false 600 From c490baf547aa631bf2ee78f1af0a0c57608e2220 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Wed, 28 Apr 2021 10:51:13 -0400 Subject: [PATCH 11/12] Use for number as namespace --- SingularityService/pom.xml | 5 ++++- .../hubspot/singularity/scheduler/SingularityTestModule.java | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/SingularityService/pom.xml b/SingularityService/pom.xml index fd1db64dc6..00ca8a1033 100644 --- a/SingularityService/pom.xml +++ b/SingularityService/pom.xml @@ -518,9 +518,12 @@ maven-surefire-plugin - 1 + 8 false 600 + + sy_${surefire.forkNumber} + diff --git a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java index e6736a17cc..148d3e049d 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/scheduler/SingularityTestModule.java @@ -324,6 +324,9 @@ private static SingularityConfiguration getSingularityConfigurationForTestingSer config.setSmtpConfiguration(new SMTPConfiguration()); ZooKeeperConfiguration zookeeperConfiguration = new ZooKeeperConfiguration(); + zookeeperConfiguration.setZkNamespace( + Optional.ofNullable(System.getProperty("zkNamespace")).orElse("sy") + ); zookeeperConfiguration.setQuorum(ts.getConnectString()); config.setZooKeeperConfiguration(zookeeperConfiguration); From 5117b3804ad96a9b773561cb6eed0628d986bfdc Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Wed, 28 Apr 2021 10:55:53 -0400 Subject: [PATCH 12/12] reuse forks to maybe speed up --- SingularityService/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SingularityService/pom.xml b/SingularityService/pom.xml index 00ca8a1033..19c624f1e7 100644 --- a/SingularityService/pom.xml +++ b/SingularityService/pom.xml @@ -518,8 +518,8 @@ maven-surefire-plugin - 8 - false + 2 + true 600 sy_${surefire.forkNumber}