mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(emr-serverless): name SparkConnectServers' servers by their kind (#9222)
SparkConnectServers runs a session's server through the shared Spark runner, probes it until it answers, keeps the tokens given for it and routes a call by its token. Nothing in that is Spark Connect's but its probe and the words of its refusals and its log, which name the Spark Connect server and GetSessionEndpoint. EMR on EKS's managed endpoints need the same for the Jupyter Enterprise Gateway they run (REAL-30). - The class is SessionServers, and takes a Kind: what its servers are called, what each serves, and the operation that gives their tokens. Kind.SPARK_CONNECT gives EMR Serverless's and EMR's sessions the same answers and log as before. - The texts a session fails with when its Spark Connect server exits, cannot start, never answers or ends, and the failure() that picks one, move to SparkConnectSessionOwner, the one class that uses them. - probe(SparkConnectProxy) is sparkConnectProbe. No behavior changes.
This commit is contained in:
1 parent
e394329a8b
commit
81b25c66bc
9 files changed
+119
-85
No files matched your search
@@ -8,7 +8,7 @@ import io.floci.aws.core.common.docker.ContainerLifecycleManager;
|
||||
import io.floci.aws.services.ec2.model.Instance;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrStep;
|
||||
import io.floci.aws.services.emrserverless.SparkConnectServers;
|
||||
import io.floci.aws.services.emrserverless.SessionServers;
|
||||
import io.floci.aws.services.emrserverless.SparkJobRunner;
|
||||
import io.floci.aws.services.eventbridge.EventBridgeService;
|
||||
import io.floci.aws.services.iam.IamService;
|
||||
@@ -299,7 +299,7 @@ final class EmrServiceFixture {
|
||||
private final IamService iam;
|
||||
private final int[] durations;
|
||||
// How the docker runner mode's session servers are asked whether they answer; null for no session servers.
|
||||
private final SparkConnectServers.Probe sessionProbe;
|
||||
private final SessionServers.Probe sessionProbe;
|
||||
|
||||
/** The service as configured by default, every duration 0. */
|
||||
EmrServiceFixture() {
|
||||
@@ -331,7 +331,7 @@ final class EmrServiceFixture {
|
||||
* As {@link #docker(SparkJobRunner, IamService)}, its sessions' Spark Connect servers run by {@code runner} too,
|
||||
* each on a thread of its own, and asked whether they answer by {@code probe}.
|
||||
*/
|
||||
static EmrServiceFixture dockerSessions(SparkJobRunner runner, IamService iam, SparkConnectServers.Probe probe) {
|
||||
static EmrServiceFixture dockerSessions(SparkJobRunner runner, IamService iam, SessionServers.Probe probe) {
|
||||
return new EmrServiceFixture(new InMemoryStorageFactory(ACCOUNT), new MutableClock(), runner, null,
|
||||
new RecordingStorage(), new RecordingReleaseImages(), iam, probe, 0, 0, 0);
|
||||
}
|
||||
@@ -339,7 +339,7 @@ final class EmrServiceFixture {
|
||||
private EmrServiceFixture(InMemoryStorageFactory storage, MutableClock clock, SparkJobRunner runner,
|
||||
BootstrapRunner bootstrap, RecordingStorage clusterStorage,
|
||||
RecordingReleaseImages releaseImages, IamService iam,
|
||||
SparkConnectServers.Probe sessionProbe, int... durations) {
|
||||
SessionServers.Probe sessionProbe, int... durations) {
|
||||
this.sessionProbe = sessionProbe;
|
||||
this.storage = storage;
|
||||
this.clock = clock;
|
||||
@@ -379,8 +379,8 @@ final class EmrServiceFixture {
|
||||
clusterStorage, releaseImages, this::handToThread, iam)
|
||||
: new EmrService(storage, config(false), regionResolver, publisher, clock, recorded, runner, bootstrap,
|
||||
clusterStorage, releaseImages, this::handToThread, iam,
|
||||
new SparkConnectServers(runner, task -> Thread.ofPlatform().daemon().start(task), null,
|
||||
sessionProbe, clock));
|
||||
new SessionServers(SessionServers.Kind.SPARK_CONNECT, runner,
|
||||
task -> Thread.ofPlatform().daemon().start(task), null, sessionProbe, clock));
|
||||
}
|
||||
|
||||
/** A new service on the same storage and clock, as after a restart of Floci with persistent storage. */
|
||||
|
||||
@@ -4,7 +4,8 @@ import io.floci.aws.core.common.SparkConnectEndpoint;
|
||||
import io.floci.aws.core.common.SparkConnectTargets;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrSession;
|
||||
import io.floci.aws.services.emrserverless.SparkConnectServers;
|
||||
import io.floci.aws.services.emrserverless.SessionServers;
|
||||
import io.floci.aws.services.emrserverless.SparkConnectSessionOwner;
|
||||
import io.floci.aws.services.emrserverless.SparkJobRunner;
|
||||
import io.floci.aws.services.iam.IamService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -43,7 +44,7 @@ class EmrSessionServerTest {
|
||||
|
||||
private final FakeServerRunner runner = new FakeServerRunner();
|
||||
private final AtomicBoolean answering = new AtomicBoolean(true);
|
||||
private final SparkConnectServers.Probe probe = (host, port) ->
|
||||
private final SessionServers.Probe probe = (host, port) ->
|
||||
answering.get() && SERVER_HOST.equals(host) && port == SERVER_PORT ? null : "Connection refused";
|
||||
private final EmrServiceFixture fixture = EmrServiceFixture.dockerSessions(runner, mock(IamService.class), probe);
|
||||
private final EmrService service = fixture.service;
|
||||
@@ -136,7 +137,7 @@ class EmrSessionServerTest {
|
||||
runner.end(sessionId).complete(SparkJobRunner.Outcome.exitedWith(1));
|
||||
EmrSession failed = awaitState(clusterId, sessionId, "FAILED");
|
||||
|
||||
assertEquals(String.format(SparkConnectServers.SERVER_EXITED, 1), failed.getStateChangeReason());
|
||||
assertEquals(String.format(SparkConnectSessionOwner.SERVER_EXITED, 1), failed.getStateChangeReason());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -171,7 +171,7 @@ class EmrServerlessSessionServerTest {
|
||||
|
||||
Session failed = awaitState(applicationId, sessionId, "FAILED");
|
||||
|
||||
assertEquals(String.format(SparkConnectServers.SERVER_NOT_STARTED, "java.lang.IllegalStateException"),
|
||||
assertEquals(String.format(SparkConnectSessionOwner.SERVER_NOT_STARTED, "java.lang.IllegalStateException"),
|
||||
failed.getStateDetails());
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ class EmrServerlessSessionServerTest {
|
||||
runner.end(sessionId).complete(SparkJobRunner.Outcome.exitedWith(1));
|
||||
Session failed = awaitState(applicationId, sessionId, "FAILED");
|
||||
|
||||
assertEquals(String.format(SparkConnectServers.SERVER_EXITED, 1), failed.getStateDetails());
|
||||
assertEquals(String.format(SparkConnectSessionOwner.SERVER_EXITED, 1), failed.getStateDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@ class EmrServerlessSessionServiceTest {
|
||||
assertEquals(String.format(EmrServerlessSessionService.NO_SERVER, sessionId), route.refusal());
|
||||
assertTrue(sessions.route("not-a-token").isEmpty());
|
||||
clock.advance(EmrServerlessSessionService.TOKEN_VALIDITY);
|
||||
assertEquals(SparkConnectServers.TOKEN_EXPIRED, sessions.route(token).orElseThrow().refusal());
|
||||
assertEquals(SessionServers.Kind.SPARK_CONNECT.tokenExpired(), sessions.route(token).orElseThrow().refusal());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+13
-5
@@ -24,16 +24,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* The servers {@link SparkConnectServers} runs, read from its owner's side: what reaches the owner, in what order, and
|
||||
* The servers {@link SessionServers} runs, read from its owner's side: what reaches the owner, in what order, and
|
||||
* what a call is answered, as servers start, take calls and stop.
|
||||
*/
|
||||
class SparkConnectServersTest {
|
||||
class SessionServersTest {
|
||||
|
||||
private static final String SESSION = "session-1";
|
||||
private static final String TOKEN = "a-token";
|
||||
|
||||
private final ServerRunner runner = new ServerRunner();
|
||||
private final SparkConnectServers servers = new SparkConnectServers(runner,
|
||||
private final SessionServers servers = new SessionServers(SessionServers.Kind.SPARK_CONNECT, runner,
|
||||
task -> Thread.ofPlatform().daemon().start(task), null, (host, port) -> null, Clock.systemUTC());
|
||||
private final RecordingOwner owner = new RecordingOwner();
|
||||
|
||||
@@ -49,7 +49,15 @@ class SparkConnectServersTest {
|
||||
Route route = servers.route(TOKEN, owner).orElseThrow();
|
||||
|
||||
assertEquals(Route.UNAVAILABLE, route.status());
|
||||
assertEquals(String.format(SparkConnectServers.NO_RUNNING_SERVER, SESSION), route.refusal());
|
||||
assertEquals(SessionServers.Kind.SPARK_CONNECT.noRunningServer(SESSION), route.refusal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sparkConnectServersRefuseACallInTheWordsTheyAlwaysHad() {
|
||||
assertEquals("The authentication token has expired. Call GetSessionEndpoint for a new one.",
|
||||
SessionServers.Kind.SPARK_CONNECT.tokenExpired());
|
||||
assertEquals("Session " + SESSION + " has no Spark Connect server running.",
|
||||
SessionServers.Kind.SPARK_CONNECT.noRunningServer(SESSION));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +124,7 @@ class SparkConnectServersTest {
|
||||
}
|
||||
|
||||
/** An owner that records what reaches it, the idle as it ends, and answers as the test sets it to. */
|
||||
private static final class RecordingOwner implements SparkConnectServers.Owner {
|
||||
private static final class RecordingOwner implements SessionServers.Owner {
|
||||
final List<String> events = new CopyOnWriteArrayList<>();
|
||||
volatile Supplier<String> refusal = () -> null;
|
||||
volatile Runnable idleWait = () -> { };
|
||||
Reference in new issue
Block a user