feat(emr-serverless): report the image digest each job run attempt resolved (#8307)

GetJobRun now carries the job run's imageConfiguration and
workerTypeSpecifications. Each attempt copies its application's image
configurations as they stand when the attempt is made. The configuration
the driver takes its image from, its worker type's or else the
application's, gets the resolvedImageDigest of the image the attempt
pulled for the driver: the manifest digest the Docker runner's pull
already returned. The executors' configuration gets theirs, or keeps the
driver's where the two share one. "To identify which image version each
job is running, the GetJobRun API response returns the resolvedImageDigest
for that specific job."

A retried attempt resolves its images again ("New job attempts will pick
new images") and keeps its own digests; earlier attempts keep theirs. A
configuration no worker type ran gets no digest, even one naming the same
image, nor does an image built locally under that URI, nor any outside
the docker runner mode. The application's own resolvedImageDigest, which
AWS fixes at its start for 7.13 and earlier, is not part of this change.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-14 10:59:40 -04:00
1 parent c407c82f8f
commit ddc844b48e
9 files changed
+375 -12

No files matched your search

+10 -2
View File
@@ -228,7 +228,15 @@ worker of its own on EMR Serverless (see **Executors** below).
a `repositoryUri` from Floci's ECR, is in another Region, both with `ValidationException` in Floci's own
wording. An update that leaves `imageUri` out removes that image configuration. Without a custom image,
`image-template` names another image than the release's, such as a mirror or a dated tag of it:
`registry.internal/emr-serverless/spark/%s:20250425`.
`registry.internal/emr-serverless/spark/%s:20250425`. `GetJobRun` reports the image configurations each attempt
applies, as its application had them when the attempt was made: its `imageConfiguration`, and its worker types'
in `workerTypeSpecifications`, as AWS's do when digests are resolved for each run ("To identify which image
version each job is running, the GetJobRun API response returns the resolvedImageDigest for that specific job").
The driver's configuration, its worker type's or else the application's, has the `resolvedImageDigest` of the
image the attempt pulled for the driver, its manifest digest in Floci's ECR; the executors' has theirs, or the
driver's where the two share one. No other has a digest, even one naming the same image, such as the `Executor`
image while local mode runs the executors in the driver's container, or a Hive run's `TezTask` image. Nor does
one built locally under that URI, nor any without the `docker` runner mode, which pulls no image.
* **Architecture**: a run's containers, its driver's and its executors', run on the Docker host's own platform by
default. With `honour-architectures` on (`FLOCI_SERVICES_EMRSERVERLESS_HONOUR_ARCHITECTURES=true`) they run the
image for its application's `architecture`, `linux/amd64` for `X86_64` and `linux/arm64` for `ARM64`, the
@@ -281,7 +289,7 @@ application's `imageConfiguration`; a `TezTask` image is not used, as Tez's task
* **Archives**: only the archives of `spark.archives` that are in S3 are unpacked into the driver's working
directory; Spark alone unpacks the others, into its own files folder. Floci reads an archive itself,
whatever the execution role may read, though Spark's own read of it uses the role's credentials.
* **Custom images**: Floci does not check an `imageUri` against the model's pattern, which would refuse the repository URIs Floci's own ECR hands out, nor that the image was built from its release's base image (AWS refuses one that was not from `emr-7.14.0` and `emr-spark-8.1.0` on), nor the image's size. An image that cannot be pulled fails the run, not the request that names it. Every run resolves its image again, as releases from 7.14 do and earlier ones with `applicationLevelDigestResolution` false: Floci keeps no digest from the application's start, and reports no `resolvedImageDigest`, on the application or on a job run.
* **Custom images**: Floci does not check an `imageUri` against the model's pattern, which would refuse the repository URIs Floci's own ECR hands out, nor that the image was built from its release's base image (AWS refuses one that was not from `emr-7.14.0` and `emr-spark-8.1.0` on), nor the image's size. An image that cannot be pulled fails the run, not the request that names it. Every run resolves its image again, as releases from 7.14 do and earlier ones with `applicationLevelDigestResolution` false: Floci keeps no digest from the application's start, and reports no `resolvedImageDigest` on the application; a job run's comes from its attempt's own pull (see **Image** above), and its image configurations carry no `applicationLevelDigestResolution`.
* **Not emulated**: the "EMR Serverless Job Run Retry" event, as Floci sends no EMR Serverless events, queuing (`QUEUED`), `totalResourceUtilization` and `billedResourceUtilization`, and `shutdownGracePeriodInSeconds` (accepted and ignored: a cancelled run's driver is stopped at once).
* **Instant Start/Stop**: Floci marks the application `STARTED` or `STOPPED` immediately without provisioning actual compute capacity in the background.
* **Data Plane**: Floci does not implement the data-plane API, such as interactive sessions.
@@ -19,6 +19,7 @@ import io.floci.aws.core.common.docker.DockerPlatforms;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.emrserverless.model.Application;
import io.floci.aws.services.emrserverless.model.ImageConfiguration;
import io.floci.aws.services.emrserverless.model.JobDriver;
import io.floci.aws.services.emrserverless.model.JobRun;
import io.floci.aws.services.emrserverless.model.JobRunAttemptSummary;
@@ -521,6 +522,7 @@ public class EmrServerlessJobRunService implements Resettable {
run.setAttempt(FIRST_ATTEMPT);
run.setAttemptCreatedAt(now);
run.setAttemptUpdatedAt(now);
applyImages(run, app);
if (sparkRunner == null) {
run.setStartedAt(now);
}
@@ -600,7 +602,53 @@ public class EmrServerlessJobRunService implements Resettable {
* {@code TezTask} image is not used; a Spark run's executors have their own, {@link #executors}.
*/
static String customImage(Application app) {
return workerImage(app, HIVE_TYPE.equalsIgnoreCase(app.getType()) ? HIVE_DRIVER_WORKER_TYPE : DRIVER_WORKER_TYPE);
return workerImage(app, driverWorkerType(app.getType()));
}
private static String driverWorkerType(String applicationType) {
return HIVE_TYPE.equalsIgnoreCase(applicationType) ? HIVE_DRIVER_WORKER_TYPE : DRIVER_WORKER_TYPE;
}
/**
* The image configurations an attempt of a run applies: its application's, and its worker types', as they stand
* when the attempt is made. Floci resolves a custom image for each attempt, as "EMR 7.14 and later" do ("New
* custom images take effect for new workloads immediately") and "New job attempts will pick new images", so the
* run's {@code workerTypeSpecifications} hold the attempt's own, as AWS's do "when the
* applicationLevelDigestResolution is false for the application". Each is a copy holding the image's URI, with no
* digest until the attempt's runner resolves that image, {@link #imageDigestResolved}.
*/
private static void applyImages(JobRun run, Application app) {
run.setImageConfiguration(appliedImage(app.getImageConfiguration()));
Map<String, WorkerTypeSpecification> workerTypes = new LinkedHashMap<>();
if (app.getWorkerTypeSpecifications() != null) {
app.getWorkerTypeSpecifications().forEach((workerType, specification) -> {
ImageConfiguration image = specification != null
? appliedImage(specification.getImageConfiguration()) : null;
if (image != null) {
WorkerTypeSpecification applied = new WorkerTypeSpecification();
applied.setImageConfiguration(image);
workerTypes.put(workerType, applied);
}
});
}
run.setWorkerTypeSpecifications(workerTypes.isEmpty() ? null : workerTypes);
}
private static ImageConfiguration appliedImage(ImageConfiguration image) {
if (image == null || image.getImageUri() == null) {
return null;
}
ImageConfiguration applied = new ImageConfiguration();
applied.setImageUri(image.getImageUri());
return applied;
}
// The image configuration an attempt applies to a worker type: the worker type's own, else the run's, as
// workerImage chose its image.
private static ImageConfiguration appliedImage(JobRun run, String workerType) {
WorkerTypeSpecification worker = run.getWorkerTypeSpecifications() != null
? run.getWorkerTypeSpecifications().get(workerType) : null;
return worker != null ? worker.getImageConfiguration() : run.getImageConfiguration();
}
// A worker type's custom image, else the application's, else null for the release's.
@@ -780,6 +828,32 @@ public class EmrServerlessJobRunService implements Resettable {
});
}
/**
* The run's latest attempt resolved its {@code workerType}'s custom image to the image whose manifest digest is
* {@code digest}: the image configuration that worker type took its image from, its own or the run's, both copied
* from the application the attempt's job was made from, gets it as its {@code resolvedImageDigest}. Another naming
* the same image does not: its image may not run, as an {@code Executor} image while the executors run in the
* driver's container, or was pulled apart, maybe after a push. One the driver and the executors both take their
* image from holds the driver's.
*/
private synchronized void imageDigestResolved(String jobRunId, SparkJobRunner.WorkerType workerType, String digest,
long launchedIn) {
if (launchedIn != generation) {
return;
}
store.get(jobRunId).ifPresent(record -> {
JobRun run = record.getJobRun();
ImageConfiguration driver = appliedImage(run, driverWorkerType(record.getApplicationType()));
ImageConfiguration applied = workerType == SparkJobRunner.WorkerType.DRIVER
? driver : appliedImage(run, EXECUTOR_WORKER_TYPE);
if (applied == null || (workerType == SparkJobRunner.WorkerType.EXECUTOR && applied == driver)) {
return;
}
applied.setResolvedImageDigest(digest);
store.put(jobRunId, record);
});
}
// A run past its timeout is CANCELLING while its driver is stopped: "the job run has timed out".
private synchronized void driverTimedOut(String jobRunId, long launchedIn) {
if (launchedIn != generation) {
@@ -884,6 +958,7 @@ public class EmrServerlessJobRunService implements Resettable {
run.setStartedAt(null);
run.setEndedAt(null);
run.setTotalExecutionDurationSeconds(null);
applyImages(run, app);
store.put(run.getJobRunId(), record);
LOG.infov("EMR Serverless job run {0} failed its attempt {1}; attempt {2} starts", run.getJobRunId(),
failed.getAttempt(), run.getAttempt());
@@ -1293,6 +1368,12 @@ public class EmrServerlessJobRunService implements Resettable {
RequestScopes.runAs(job.accountId(), job.region(), () -> driverStarted(job.runId(), launchedIn));
}
@Override
public void imageResolved(SparkJobRunner.WorkerType workerType, String digest) {
RequestScopes.runAs(job.accountId(), job.region(),
() -> imageDigestResolved(job.runId(), workerType, digest, launchedIn));
}
@Override
public void timedOut() {
RequestScopes.runAs(job.accountId(), job.region(), () -> driverTimedOut(job.runId(), launchedIn));
@@ -24,6 +24,7 @@ import io.floci.aws.core.common.docker.LaunchedContainerAwsEnv;
import io.floci.aws.core.common.docker.RetryingTarCopier;
import io.floci.aws.services.ecr.registry.EcrRegistryManager;
import io.floci.aws.services.iam.model.SessionCreds;
import io.floci.aws.services.lambda.launcher.ImageCacheService.LaunchImage;
import io.floci.aws.services.lambda.launcher.LambdaExecutionRoleCredentials;
import io.floci.aws.services.s3.S3Service;
import jakarta.enterprise.context.ApplicationScoped;
@@ -432,9 +433,9 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
List<String> awsEnvironment = awsEnv.sdkBaselineEnv(job.region(), Optional.empty(), credentials,
job.accountId());
// Pulled, when it is not the driver's, before the driver starts rather than while it waits for executors.
String executorImage = job.executors() != null ? executorImage(job) : null;
String executorImage = job.executors() != null ? executorImage(job, progress) : null;
String secret = job.executors() != null ? newSecret() : null;
ContainerBuilder.Builder container = containerBuilder.newContainer(launchImage(job))
ContainerBuilder.Builder container = containerBuilder.newContainer(launchImage(job, progress))
.withName(ContainerStorageHelper.dockerName(config, job.service() + "-" + job.runId()))
.withEnv(environment(awsEnvironment, job.environment()));
// bash -c's script gets "floci" as its $0, and what runs after it as its arguments, "$@".
@@ -810,13 +811,12 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
// The image a job's executors run in: the application's for its executors, pulled for every run as the driver's
// custom image is, else the release's, pulled when missing, as a driver with a custom image does not pull it.
private String executorImage(Job job) {
private String executorImage(Job job, Progress progress) {
if (job.executors().image() == null) {
return lifecycleManager.resolveImageForLaunch(image(job.imageTemplate(), job.releaseLabel(), Engine.SPARK),
ImagePullBehavior.PREFER_CACHED, job.platform()).imageId();
}
String image = containerBuilder.resolveImage(ecrRegistryManager.rewriteImageUri(job.executors().image()));
return lifecycleManager.resolveImageForLaunch(image, ImagePullBehavior.DEFAULT, job.platform()).imageId();
return customImageForLaunch(job, WorkerType.EXECUTOR, job.executors().image(), progress);
}
/**
@@ -885,12 +885,26 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
* starts from the image id that pull resolved, which a later push cannot move. Either is pulled for the run's
* platform, its application's architecture.
*/
private String launchImage(Job job) {
private String launchImage(Job job, Progress progress) {
if (job.customImage() == null) {
return image(job.imageTemplate(), job.releaseLabel(), job.engine());
}
String image = containerBuilder.resolveImage(ecrRegistryManager.rewriteImageUri(job.customImage()));
return lifecycleManager.resolveImageForLaunch(image, ImagePullBehavior.DEFAULT, job.platform()).imageId();
return customImageForLaunch(job, WorkerType.DRIVER, job.customImage(), progress);
}
/**
* The image id a custom image resolves to for this run's {@code workerType}, pulled from Floci's own registry for
* the run's platform, {@code progress} told its manifest digest, which GetJobRun reports: "To identify which image
* version each job is running, the GetJobRun API response returns the resolvedImageDigest for that specific job".
* An image the registry holds no digest for, one never pulled from or pushed to it, reports none.
*/
private String customImageForLaunch(Job job, WorkerType workerType, String customImage, Progress progress) {
String image = containerBuilder.resolveImage(ecrRegistryManager.rewriteImageUri(customImage));
LaunchImage launched = lifecycleManager.resolveImageForLaunch(image, ImagePullBehavior.DEFAULT, job.platform());
if (launched.manifestDigest() != null) {
progress.imageResolved(workerType, launched.manifestDigest());
}
return launched.imageId();
}
/**
@@ -37,6 +37,14 @@ public interface SparkJobRunner {
/** The run's Spark driver runs. */
void started();
/**
* The run resolved the custom image its job names for {@code workerType} ({@link Job#customImage} for its
* driver, {@link Executors#image} for its executors) to the image whose manifest digest is {@code digest}, and
* runs that image as that worker type.
*/
default void imageResolved(WorkerType workerType, String digest) {
}
/** The run has passed its timeout, and its driver is about to be stopped. */
void timedOut();
@@ -47,6 +55,12 @@ public interface SparkJobRunner {
boolean cancelled();
}
/** What a run's container runs as: its driver, or one of its executors. */
enum WorkerType {
DRIVER,
EXECUTOR
}
/** What a run's driver runs: Spark's {@code spark-submit}, or Hive's {@code hive}. */
enum Engine {
SPARK,
@@ -1,8 +1,10 @@
package io.floci.aws.services.emrserverless.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ImageConfiguration {
private String imageUri;
private String resolvedImageDigest;
@@ -42,6 +42,8 @@ public class JobRun {
private Instant startedAt;
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
private Instant endedAt;
private ImageConfiguration imageConfiguration;
private Map<String, WorkerTypeSpecification> workerTypeSpecifications;
public String getApplicationId() { return applicationId; }
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
@@ -93,4 +95,8 @@ public class JobRun {
public void setStartedAt(Instant startedAt) { this.startedAt = startedAt; }
public Instant getEndedAt() { return endedAt; }
public void setEndedAt(Instant endedAt) { this.endedAt = endedAt; }
public ImageConfiguration getImageConfiguration() { return imageConfiguration; }
public void setImageConfiguration(ImageConfiguration imageConfiguration) { this.imageConfiguration = imageConfiguration; }
public Map<String, WorkerTypeSpecification> getWorkerTypeSpecifications() { return workerTypeSpecifications; }
public void setWorkerTypeSpecifications(Map<String, WorkerTypeSpecification> workerTypeSpecifications) { this.workerTypeSpecifications = workerTypeSpecifications; }
}
@@ -18,6 +18,7 @@ import java.math.BigDecimal;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.hamcrest.Matchers.*;
@@ -123,7 +124,27 @@ class EmrServerlessJobRunIntegrationTest {
.body("jobRun.attempt", equalTo(1))
.body("jobRun.attemptCreatedAt", instanceOf(Number.class))
.body("jobRun.attemptUpdatedAt", instanceOf(Number.class))
.body("jobRun", not(hasKey("hive")));
.body("jobRun", not(hasKey("hive")))
.body("jobRun", not(hasKey("imageConfiguration")))
.body("jobRun", not(hasKey("workerTypeSpecifications")));
}
@Test
void getJobRunReportsTheImageConfigurationsTheRunApplies() {
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String driverImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/driver:7.5.0";
String applicationId = createApplication("""
, "imageConfiguration": {"imageUri": "%s", "applicationLevelDigestResolution": false},
"workerTypeSpecifications": {"Driver": {"imageConfiguration": {"imageUri": "%s"}}}"""
.formatted(applicationImage, driverImage));
String jobRunId = startedRunId(applicationId, sparkRun(UUID.randomUUID().toString(), ""));
// Without the docker runner mode no image is pulled, so neither has a digest.
givenReq().when().get("/applications/" + applicationId + "/jobruns/" + jobRunId)
.then().statusCode(200)
.body("jobRun.imageConfiguration", equalTo(Map.of("imageUri", applicationImage)))
.body("jobRun.workerTypeSpecifications",
equalTo(Map.of("Driver", Map.of("imageConfiguration", Map.of("imageUri", driverImage)))));
}
@Test
@@ -9,6 +9,7 @@ import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.emrserverless.model.Application;
import io.floci.aws.services.emrserverless.model.CreateApplicationRequest;
import io.floci.aws.services.emrserverless.model.ImageConfiguration;
import io.floci.aws.services.emrserverless.model.JobDriver;
import io.floci.aws.services.emrserverless.model.JobRun;
import io.floci.aws.services.emrserverless.model.JobRunAttemptSummary;
@@ -26,12 +27,14 @@ import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -52,6 +55,8 @@ class EmrServerlessJobRunServiceTest {
private static final String REGION = "us-east-1";
private static final String ACCOUNT_ID = "000000000000";
private static final String ROLE = "arn:aws:iam::000000000000:role/emr-serverless-job";
private static final String DIGEST = "sha256:" + "a".repeat(64);
private static final String OTHER_DIGEST = "sha256:" + "b".repeat(64);
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
private EmrServerlessService applications;
@@ -318,6 +323,170 @@ class EmrServerlessJobRunServiceTest {
assertNull(runner.jobs.get(2).customImage());
}
@Test
void aRunReportsTheImageConfigurationsItAppliesEachWithTheDigestOfTheImageItsRunnerResolvedForIt() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner, 2);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String driverImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/driver:7.5.0";
String executorImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/executor:7.5.0";
CreateApplicationRequest custom = applicationRequest("custom", "emr-7.5.0", "SPARK");
custom.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
custom.getImageConfiguration().setApplicationLevelDigestResolution(false);
custom.setWorkerTypeSpecifications(Map.of("Driver", EmrServerlessServiceTest.workerType(driverImage),
"Executor", EmrServerlessServiceTest.workerType(executorImage)));
String customId = applications.createApplication(custom).getApplicationId();
String jobRunId = service.startJobRun(customId, request(null, null)).getJobRunId();
String plain = service.startJobRun(applicationId, request(null, null)).getJobRunId();
runner.digests.put(driverImage, DIGEST);
runner.digests.put(executorImage, OTHER_DIGEST);
JobRun submitted = service.getJobRun(customId, jobRunId, null);
runNext();
runNext();
assertEquals(List.of("application " + applicationImage + " null", "Driver " + driverImage + " null",
"Executor " + executorImage + " null"), images(submitted));
// The driver and the executors each run their worker type's image, so the application's runs on none.
JobRun ran = service.getJobRun(customId, jobRunId, null);
assertEquals(List.of("application " + applicationImage + " null", "Driver " + driverImage + " " + DIGEST,
"Executor " + executorImage + " " + OTHER_DIGEST), images(ran));
assertNull(ran.getImageConfiguration().getApplicationLevelDigestResolution());
// The application's own stay as it gave them.
Application app = applications.getApplication(customId);
assertNull(app.getImageConfiguration().getResolvedImageDigest());
assertNull(app.getWorkerTypeSpecifications().get("Driver").getImageConfiguration().getResolvedImageDigest());
JobRun withoutImages = service.getJobRun(applicationId, plain, null);
assertNull(withoutImages.getImageConfiguration());
assertNull(withoutImages.getWorkerTypeSpecifications());
}
@Test
void aDigestGoesOnlyToTheConfigurationItsWorkerTypeTookItsImageFromNotToAnotherNamingThatImage() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String hiveDriverImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/hive/driver:7.5.0";
CreateApplicationRequest spark = applicationRequest("local-executors", "emr-7.5.0", "SPARK");
spark.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
spark.setWorkerTypeSpecifications(Map.of("Executor", EmrServerlessServiceTest.workerType(applicationImage)));
CreateApplicationRequest hive = applicationRequest("tez-tasks", "emr-7.5.0", "HIVE");
hive.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
hive.setWorkerTypeSpecifications(Map.of("HiveDriver", EmrServerlessServiceTest.workerType(hiveDriverImage),
"TezTask", EmrServerlessServiceTest.workerType(hiveDriverImage)));
String sparkId = applications.createApplication(spark).getApplicationId();
String hiveId = applications.createApplication(hive).getApplicationId();
String sparkRun = service.startJobRun(sparkId, request(null, null)).getJobRunId();
String hiveRun = service.startJobRun(hiveId, hiveRequest("s3://bucket/queries/report.sql", null, null))
.getJobRunId();
runner.digests.put(applicationImage, DIGEST);
runner.digests.put(hiveDriverImage, OTHER_DIGEST);
runNext();
runNext();
// Local mode runs the executors in the driver's container, and Tez a Hive run's tasks, so neither image runs.
assertEquals(List.of("application " + applicationImage + " " + DIGEST,
"Executor " + applicationImage + " null"), images(service.getJobRun(sparkId, sparkRun, null)));
assertEquals(List.of("application " + applicationImage + " null",
"HiveDriver " + hiveDriverImage + " " + OTHER_DIGEST, "TezTask " + hiveDriverImage + " null"),
images(service.getJobRun(hiveId, hiveRun, null)));
}
@Test
void eachWorkerTypeKeepsTheDigestOfItsOwnPullAndAConfigurationTheyShareHoldsTheDrivers() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner, 2);
String sameTag = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String shared = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/shared:7.5.0";
CreateApplicationRequest apart = applicationRequest("apart", "emr-7.5.0", "SPARK");
apart.setWorkerTypeSpecifications(Map.of("Driver", EmrServerlessServiceTest.workerType(sameTag),
"Executor", EmrServerlessServiceTest.workerType(sameTag)));
CreateApplicationRequest together = applicationRequest("together", "emr-7.5.0", "SPARK");
together.setImageConfiguration(EmrServerlessServiceTest.image(shared));
String apartId = applications.createApplication(apart).getApplicationId();
String togetherId = applications.createApplication(together).getApplicationId();
String apartRun = service.startJobRun(apartId, request(null, null)).getJobRunId();
String togetherRun = service.startJobRun(togetherId, request(null, null)).getJobRunId();
// The tag pushed again between the driver's pull and the executors'.
runner.digests.put(sameTag, DIGEST);
runner.executorDigests.put(sameTag, OTHER_DIGEST);
runner.digests.put(shared, DIGEST);
runner.executorDigests.put(shared, OTHER_DIGEST);
runNext();
runNext();
assertEquals(List.of("Driver " + sameTag + " " + DIGEST, "Executor " + sameTag + " " + OTHER_DIGEST),
images(service.getJobRun(apartId, apartRun, null)));
assertEquals(List.of("application " + shared + " " + DIGEST),
images(service.getJobRun(togetherId, togetherRun, null)));
}
@Test
void eachAttemptAppliesItsApplicationsImageAgainAndKeepsTheDigestItsOwnPullResolved() {
FakeRunner runner = new FakeRunner();
runner.outcome = SparkJobRunner.Outcome.exitedWith(1);
EmrServerlessJobRunService service = dockerService(runner);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
CreateApplicationRequest custom = applicationRequest("retagged", "emr-7.5.0", "SPARK");
custom.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
String customId = applications.createApplication(custom).getApplicationId();
StartJobRunRequest resilient = request(null, null);
resilient.setRetryPolicy(Map.of("maxAttempts", 2));
String jobRunId = service.startJobRun(customId, resilient).getJobRunId();
runner.digests.put(applicationImage, DIGEST);
runNext();
JobRun secondScheduled = service.getJobRun(customId, jobRunId, null);
// The tag pushed again: "either by retagging an image in Amazon ECR or by updating the imageConfiguration".
runner.digests.put(applicationImage, OTHER_DIGEST);
runner.outcome = SparkJobRunner.Outcome.exitedWith(0);
runNext();
assertEquals(List.of("application " + applicationImage + " null"), images(secondScheduled));
assertEquals(List.of("application " + applicationImage + " " + OTHER_DIGEST),
images(service.getJobRun(customId, jobRunId, null)));
assertEquals(List.of("application " + applicationImage + " " + DIGEST),
images(service.getJobRun(customId, jobRunId, 1)));
}
@Test
void aDigestResolvedOnceAResetHasBegunIsNotWritten() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
CreateApplicationRequest custom = applicationRequest("reset", "emr-7.5.0", "SPARK");
custom.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
String customId = applications.createApplication(custom).getApplicationId();
String jobRunId = service.startJobRun(customId, request(null, null)).getJobRunId();
runner.digests.put(applicationImage, DIGEST);
runner.whileResolving = service::beforeReset;
runNext();
assertEquals(List.of("application " + applicationImage + " null"),
images(store.get(jobRunId).orElseThrow().getJobRun()));
}
// A run's image configurations, each "<whose> <imageUri> <resolvedImageDigest>": its own, then its worker types'
// by name.
private static List<String> images(JobRun run) {
List<String> images = new ArrayList<>();
if (run.getImageConfiguration() != null) {
images.add(described("application", run.getImageConfiguration()));
}
if (run.getWorkerTypeSpecifications() != null) {
new TreeMap<>(run.getWorkerTypeSpecifications()).forEach((workerType, specification) ->
images.add(described(workerType, specification.getImageConfiguration())));
}
return images;
}
private static String described(String whose, ImageConfiguration image) {
return whose + " " + image.getImageUri() + " " + image.getResolvedImageDigest();
}
@Test
void aRunsContainersRunForItsApplicationsArchitectureElseTheDockerHostsOwn() {
FakeRunner runner = new FakeRunner();
@@ -1198,6 +1367,11 @@ class EmrServerlessJobRunServiceTest {
Outcome outcome = Outcome.exitedWith(0);
Runnable whileRunning = () -> { };
Runnable whileTimingOut = () -> { };
// The manifest digest each custom image resolves to, told before the driver starts as the Docker runner does,
// and the executors' where their pull resolves another, as a push between the two pulls gives.
final Map<String, String> digests = new HashMap<>();
final Map<String, String> executorDigests = new HashMap<>();
Runnable whileResolving = () -> { };
@Override
public Outcome run(Job job, Progress progress) {
@@ -1206,6 +1380,13 @@ class EmrServerlessJobRunServiceTest {
if (progress.cancelled()) {
return Outcome.halted();
}
// The driver's first, so an executors' digest written over it shows.
resolved(progress, WorkerType.DRIVER, job.customImage(), digests);
if (job.executors() != null) {
Map<String, String> executorsResolve = new HashMap<>(digests);
executorsResolve.putAll(executorDigests);
resolved(progress, WorkerType.EXECUTOR, job.executors().image(), executorsResolve);
}
driversStarted.add(job.runId());
progress.started();
cancelledAsRunning.add(progress.cancelled());
@@ -1218,6 +1399,13 @@ class EmrServerlessJobRunServiceTest {
return stopped.contains(job.runId()) ? Outcome.halted() : outcome;
}
private void resolved(Progress progress, WorkerType workerType, String image, Map<String, String> resolve) {
if (image != null && resolve.containsKey(image)) {
whileResolving.run();
progress.imageResolved(workerType, resolve.get(image));
}
}
@Override
public void stop(String runId) {
stopped.add(runId);
@@ -696,6 +696,35 @@ class EmrServerlessSparkRunnerTest {
verify(builder, never()).newContainer(custom);
}
@Test
void aRunIsToldTheManifestDigestEachWorkerTypesCustomImageResolvedToAndNoneForAnImageWithout() {
ContainerBuilder builder = mock(ContainerBuilder.class);
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
String driverImage = "123456789012.dkr.ecr.eu-west-1.amazonaws.com/spark/driver:7.5.0";
String executorImage = "123456789012.dkr.ecr.eu-west-1.amazonaws.com/spark/executor:7.5.0";
String builtLocally = "123456789012.dkr.ecr.eu-west-1.amazonaws.com/spark/local:7.5.0";
when(builder.newContainer(anyString())).thenReturn(spec);
when(builder.resolveImage(anyString())).thenAnswer(resolve -> resolve.getArgument(0));
when(ecr.rewriteImageUri(anyString())).thenAnswer(rewrite -> "localhost:5100/" + rewrite.getArgument(0));
when(lifecycle.resolveImageForLaunch("localhost:5100/" + driverImage, ImagePullBehavior.DEFAULT, null))
.thenReturn(new LaunchImage("sha256:" + "1".repeat(64), "sha256:" + "a".repeat(64)));
when(lifecycle.resolveImageForLaunch("localhost:5100/" + executorImage, ImagePullBehavior.DEFAULT, null))
.thenReturn(new LaunchImage("sha256:" + "2".repeat(64), "sha256:" + "b".repeat(64)));
when(lifecycle.resolveImageForLaunch("localhost:5100/" + builtLocally, ImagePullBehavior.DEFAULT, null))
.thenReturn(new LaunchImage("sha256:" + "3".repeat(64), null));
EmrServerlessSparkRunner runner = runner(builder);
ContainerExecStubs.completeEveryExec(docker, "driver", 7L, "", "");
runner.run(customImageJob(driverImage)
.withExecutors(new SparkJobRunner.Executors(2, executorImage, 0, 0, 0, null)), progress);
runner.run(customImageJob(builtLocally), progress);
// Each for the worker type that runs it.
verify(progress).imageResolved(SparkJobRunner.WorkerType.DRIVER, "sha256:" + "a".repeat(64));
verify(progress).imageResolved(SparkJobRunner.WorkerType.EXECUTOR, "sha256:" + "b".repeat(64));
verify(progress, times(2)).imageResolved(any(), any());
}
@Test
void aCommandRunsThroughFlocisWrapperWithTheJobsSparkSettingsInItsEnvironment() {
ContainerBuilder builder = mock(ContainerBuilder.class);