mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
c407c82f8f
commit
ddc844b48e
9 files changed
+375
-12
No files matched your search
@@ -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; }
|
||||
}
|
||||
Reference in new issue
Block a user