With TLS on, every container Floci launches gets the CA bundle and the
SSL_CERT_FILE family of variables, but the JVM reads none of them. So
in the docker runner mode a Spark job's own SDK clients that ignore
AWS_ENDPOINT_URL, the AWS SDK for Java 1.x's or an older 2.x's,
failed with "PKIX path building failed" against Floci's HTTPS, even
with FLOCI_DNS_SPOOF_AWS_ENDPOINTS sending AWS's endpoint names to
Floci. A job could only reach Floci over its HTTP endpoint.
Floci now also writes the bundle's certificates as a PKCS12 trust
store at boot, floci-ca-bundle.p12 beside the bundle. A launcher whose
workload is Java can copy it into a container before the container
starts (ContainerLifecycleManager.copyJavaTrustStore) and point the
container's JVMs at it through JAVA_TOOL_OPTIONS, with a shell line
that does so only when the file is there. The store has no password
and the line gives only its path, so a trust store a job or an image
names itself replaces Floci's, with that store's own type and
password. EMR Serverless job runs and EMR steps copy it into the
driver's container ahead of spark-submit or the step's command, and
the bootstrap actions' container gets it for its actions, then drops
it before the image is kept. Other services' containers are unchanged.
JAVA_TOOL_OPTIONS rather than spark.driver.extraJavaOptions, since
setting that key would replace what the image's spark-defaults.conf
gives it, and a job's own value would drop Floci's. Each JVM prints
"Picked up JAVA_TOOL_OPTIONS: ..." on its standard error, as the docs
now say.
In the docker runner mode a job run's retryPolicy was stored and
returned, but a run whose driver failed was never tried again: every
run was its one attempt. Now, on release 7.1.0 or later, "EMR
Serverless releases 7.1.0 and higher include support for job
resiliency", a run whose driver fails is tried again as the user
guide's "Job resiliency" gives it:
- a BATCH run until it has made maxAttempts attempts, "The default is
1, which means to not rerun the job";
- a STREAMING run, which "EMR Serverless indefinitely retries", until
it has failed maxFailedAttemptsPerHour times within an hour, "The
default is five".
The failed attempt ends FAILED with its stateDetails, and the next is
SCHEDULED again and runs its driver from the beginning, "its own set
of logs" under attempts/<n>/ in S3 and CloudWatch Logs. A cancelled
run, one past its timeout ("Cancelling: ... or the job run has timed
out"), one Floci's own shutdown stopped and one whose application is
gone are not tried again; a retry is admitted while its application
cannot be deleted, as the first attempt is.
GetJobRun without attempt returns "the latest attempt", and with one
an earlier attempt as it ended; ListJobRunAttempts lists them all,
oldest first, each with its own createdAt and updatedAt. No source says
whether a run's timeout spans its attempts; Floci applies it to each.
Floci sends no EMR Serverless events, so the job run retry event is
not sent.
StartJobRun holds retryPolicy to "Accepted values are 1 to 10,
inclusive" for both members: outside that range is a
ValidationException in the model's constraint form, and a member that
is not an integer a SerializationException, as Smithy's restJson1
malformed-request tests have it.
With CloudWatch logging enabled on a job run in the docker runner mode,
its Spark driver's standard output and error now go line by line, while
it runs, to Floci's CloudWatch Logs, as well as to Floci's log.
- Which configuration: the run's cloudWatchLoggingConfiguration, or
else the application's; the user guide merges them by configuration
type, and "enabled": false at the run removes it.
- Where: the log group logGroupName, /aws/emr-serverless by default,
and the log streams <logStreamNamePrefix>/applications/<applicationId>
/jobs/<jobRunId>/SPARK_DRIVER/stdout and .../stderr, with attempts/1/
before SPARK_DRIVER for a retried run on 7.1.0 or later, as for S3.
The guide gives the default group and the stream up to its worker
type; the stdout and stderr streams under it are as Dagster's EMR
Serverless client reads them, and Airflow's operator builds the same
prefix. Group and streams are created as needed, in the run's account
and Region.
- What: the driver's stdout and stderr, "By default, EMR Serverless
publishes only the driver stdout and stderr logs". A logTypes that
names some types sends only the driver's it names, so none of them
when it names only SPARK_EXECUTOR: the API reference's logTypes is
"The types of logs that you want to publish to CloudWatch".
ContainerLogStreamer gets attachByStreamForAccount, which sends a
container's standard output and error to log streams of their own; its
reassembly callback now keeps the stream each line came from. The
shared Spark runner uses it when a job carries a CloudWatch destination.
In the docker runner mode a Spark driver's output went only to Floci's
log. Once a driver ends, the shared runner now reads its standard output
and error from Docker and puts them, gzipped, into Floci's S3 as
stdout.gz and stderr.gz in the run's log folder, while the container is
still the run's. A driver a cancel or its timeout ended is stopped
first, through a new ContainerLifecycleManager.stop that leaves the
container in place, so it changes nothing more while its output is read
and the logs hold all it wrote; a driver Floci's teardown took writes
nothing. Logs that cannot be written leave the run as it ended.
- EMR steps: under the cluster's LogUri, at
<LogUri>/<cluster-id>/steps/<step-id>/ (Management Guide, "Log
locations"); without a LogUri "logs are not created". An s3n:// or
s3a:// LogUri names the same bucket.
- EMR Serverless job runs: under the run's s3MonitoringConfiguration
logUri, or else the application's (the user guide merges them by
configuration type, and an empty one at the run removes it), at
applications/<applicationId>/jobs/<jobRunId>/SPARK_DRIVER/, with
attempts/1/ before SPARK_DRIVER/ for a STREAMING run or a BATCH run
whose retry policy allows more than one attempt, on 7.1.0 or later.
FailureDetails gets no LogFile: the Management Guide ties it to a root
cause EMR identifies, and Floci's Reason is always "Unknown Error".
core.common.S3Uri splits the folder's s3:// URI into bucket and key.
ImageCacheService gave each attempt at pulling an image a hard-coded
five minutes, and a pull three attempts. An EMR Serverless runtime is
3.5 to 4.3 GB, so on an ordinary connection the first run of a release
Docker did not have yet failed with "Could not pull image" before the
pull could finish.
floci.docker.image-pull-timeout-seconds, or
FLOCI_DOCKER_IMAGE_PULL_TIMEOUT_SECONDS, now sets the limit for each
attempt. Its default, 300, keeps today's five minutes, and it must be
at least 1, checked with the other Docker timeouts in
DockerClientProducer.
Follow-up to #6469.
A new runner mode, floci.services.emrserverless.runner-mode=docker,
runs each Spark job run. Floci starts one container per run from the
release's EMR Serverless base image on Amazon ECR Public, and starts
spark-submit in local mode in it itself, since the image's own
entrypoint hands over to a script only EMR Serverless supplies. The
default, immediate, keeps today's behaviour.
A docker run is SCHEDULED while its image is pulled and its container
starts, RUNNING once the Spark driver runs, then SUCCESS when it exits
0 and FAILED otherwise, with the exit code in stateDetails, as the
user guide's job run states describe. CancelJobRun, or a BATCH run
passing its executionTimeoutMinutes, makes it CANCELLING until the
driver is stopped, then CANCELLED. A run left by a Floci restart is
FAILED once read.
Floci's shutdown and a state reset stop every driver, one whose image
is still being pulled as soon as its container is up, and a reset
raises a generation the runs' threads check, so none writes its run
back after the storage wipe. A driver a hard stop left running is
removed before this process starts one: driver containers carry the
deployment's owner label, as EC2's and ECS's do, and
reconcile-containers-on-startup turns the removal off, as theirs does,
for two Flocis sharing a daemon. A stop that comes after its run has
ended is dropped, and a cancel before a run starts is read from the
run's state. A driver is watched with a look at its container every
250 ms, as Batch's runner watches its jobs, so a run holds no Docker
connection while its driver runs; a run past its timeout is
CANCELLING while its driver is stopped.
spark-submit gets the entry point, its arguments and the
sparkSubmitParameters (split as a POSIX shell would), after the
spark-defaults of the application's runtimeConfiguration, or the
run's own in its applicationConfiguration, which replace the
application's whole classification ("Only the properties included in
StartJobRun is considered for this classification"); from
emr-spark-8.1.0 the two merge by property, the run's winning, as its
release notes say. S3A takes s3:// and s3a:// paths to Floci's S3 on
every release, with in-memory commit tracking, without which EMR's
committer loses every write; the Glue Data Catalog client goes to
Floci's Glue. The container gets a session for the run's execution
role and AWS_ENDPOINT_URL, as the other containers Floci launches do.
The image is public.ecr.aws/emr-serverless/spark/<release>:latest, or
spark4/ in place of spark/ for an emr-spark-* release, where ECR
Public keeps the AWS runtime for Apache Spark images. image-template
names another image, and docker-network the network.
Docker answers a stop of a container that has already exited with
HTTP 304, which ContainerLifecycleManager logged as a failed stop
after every run that ended by itself. It now counts as stopped, as a
304 on start already counts as started, and so does the runner's stop
for a cancel that finds the driver already exited.
A Hive run fails without running. Log destinations, retries and the
cancellation grace period are not emulated; the driver's output goes
to Floci's log.
Part of #6046 (REAL-2).
A Task can now use the six optimized EMR Serverless integrations the
Step Functions guide lists: createApplication, startApplication,
stopApplication, deleteApplication, startJobRun and cancelJobRun, each
request-response and .sync. Each calls Floci's EMR Serverless in the
state machine's Region. They failed with "Unsupported resource" before.
A Task names the API's members in PascalCase where the API writes them
in camelCase, so a request and a response are mapped against botocore's
EMR Serverless model, now vendored as aws/emr-serverless-shapes.json by
tools/aws/regen_emr_serverless_shapes.py: a structure's members are
renamed, a map keeps the keys the state machine wrote (tags,
InitialCapacity's DRIVER, a configuration's Properties such as
spark.executor.memory), and a member the model does not have is
dropped. A member, ApplicationId and JobRunId included, may be written
in either case. One the model has and Floci's request class lacks is
refused rather than dropped, and a test holds the classes to the model.
request_shapes.py can now keep output shapes for it. A request
without ClientToken gets a random one, as the SDK fills an idempotency
token in; the guide's examples leave it out.
The result is the API's response in PascalCase, or {"ApplicationId"}
where the API answers nothing, as the guide's table says. The guide
finds no difference between a .sync response and the API's, so a .sync
result is the starting call's own: state machines read a
createApplication.sync result's ApplicationId and a startJobRun.sync
result's JobRunId. A .sync Task records TaskSubmitted and polls
GetApplication or GetJobRun until the state the guide names, as the
elasticmapreduce ones do; a run that ends FAILED or CANCELLED, or an
application that can no longer get there, fails the Task with
States.TaskFailed and the describe response as the cause. A wait that
ends early cancels the run of a startJobRun.sync, stops the application
of a startApplication.sync and deletes the one a createApplication.sync
made, the call each integration's IAM policy grants beyond its own and
its read. EMR Serverless answering that the application or run is gone
or past undoing is logged and leaves the Task ending as it was; any
other failure is raised.
An EMR Serverless error keeps its code under EmrServerless., the
exception prefix the guide gives the service; no record shows the
optimized integration's. A Task without the ApplicationId, or a
cancelJobRun without the JobRunId, it acts on fails with
States.TaskFailed before EMR Serverless sees it.
CreateApplication now stores the configurations UpdateApplication
already did (runtime, monitoring, scheduler, disk encryption,
interactive, Identity Center and job-level cost allocation), and
ImageConfiguration keeps applicationLevelDigestResolution. Both were
dropped, from a Task and from the API alike. A runtime configuration
kept only its properties, lifted out of their member: Jackson bound the
properties member to the field of that name holding every member read.
It keeps its classification and properties now, on update as well.
GetApplication no longer returns the application's clientToken, which
its Application has no member for and which the .sync waits read. The
token stays with the stored application, which CreateApplication's
retries are matched on.
The .sync wait loop the elasticmapreduce integrations had is now shared
by both, as are their request and failure helpers, and the two EMR
Step Functions tests share their state machine helpers.
Part of #6046 (part 11).
TagResource, UntagResource and ListTagsForResource now take job run ARNs
(.../applications/<id>/jobruns/<id>), which the model's ResourceArn
allows ("the supported resources are Amazon EMR Serverless applications
and job runs"). They work on the tags StartJobRun stores, so GetJobRun
reports the current set, under the same rules as an application's: at
most 50 tags, no "aws:" prefix. An ARN must be the run's own, so one of
another application or account names nothing, and once an application
is deleted its runs' ARNs name nothing, as its own ARN already does. A
session ARN, which the pattern also allows, now answers
ResourceNotFoundException rather than ValidationException, as sessions
are not emulated.
ListJobRunAttempts (GET .../jobruns/{jobRunId}/attempts) and GetJobRun's
attempt parameter report attempts. Nothing runs, so no run fails and
none is retried: every run is one attempt, number 1, created and updated
with the run. GetJobRun, ListJobRuns and ListJobRunAttempts carry it.
GetJobRun with attempt 1 or none returns the run; another attempt
answers ResourceNotFoundException, in Floci's words, as no source shows
AWS's answer for an attempt a run never made, and leaves the run as it
was.
Also from the #6202 review:
- From release emr-7.11.0 a BATCH run's executionTimeoutMinutes must be
1 to 10080. The model: "the maximum value is 10080 minutes (7 days)
starting with Amazon EMR release 7.11. Setting a value of 0 to disable
the timeout is no longer supported for BATCH mode job runs." Earlier
releases and STREAMING runs keep 0 to 1,000,000. No source gives the
error; ValidationException, in Floci's words. The check runs before
auto-start, under the application's lock, so a refused run leaves the
application as it was.
- ListJobRuns refuses a state or mode that does not exist and more than
8 states, and ListApplications a state that does not exist and more
than 7, with the framework ValidationException. A typo listed nothing
before. ListApplications' maxResults outside 1 to 50 now answers the
same framework message, joined with any states violation.
- EmrServerlessRegionIntegrationTest uses EmrServerlessRequests, which
gains tagsPath, and pins a job run ARN across Regions;
EmrServerlessTagIntegrationTest moves onto the same helpers.
The enum and range violations are now SmithyValidationErrors.notInEnum,
notAllInEnum and outOfRange, which EMR Serverless uses.
Part of #6046 (part 9).
Adds StartJobRun, GetJobRun, ListJobRuns and CancelJobRun under
/applications/{applicationId}/jobruns. Job runs are metadata only, like
Glue's: a run is RUNNING from submission and settles when read. With the
new floci.services.emrserverless.job-run-duration-seconds at its default
of 0, a BATCH run is SUCCESS as soon as it starts; a positive duration
keeps it RUNNING that long, and a run that would outlast its
executionTimeoutMinutes (720 when not given) is CANCELLED at the
timeout. A STREAMING run stays RUNNING until it is cancelled.
A run on a CREATED or STOPPED application starts it, as auto-start
defaults to on; with auto-start off the run is refused. clientToken is
the idempotency token: a retry returns the original run, and the same
token with another request answers ConflictException "Request did not
match the original". CancelJobRun on a finished run answers
ValidationException "Job run is not in a cancellable state". ListJobRuns
returns the newest runs first, filtered by states, creation time and
mode, and its nextToken resumes only the listing it came from. A run
needs a jobDriver that sets exactly one of sparkSubmit and hive, as
GetJobRun's JobRun always carries one, and tags are checked before
auto-start, so a refused run leaves the application as it was.
createdBy is the caller's ARN.
Application createdAt and updatedAt now go out as epoch seconds, the
restJson1 default for the model's Date shape, as job runs do. They were
epoch milliseconds, which the Java SDK reads as the year 58774 and
botocore refuses as out of range. Auto-start rewrites updatedAt, so a
run's own submission reached the bug. Applications persisted with
millisecond timestamps read back at the same instant.
Part of #6046 (part 8).
EMR Serverless had no tagging API: no TagHandler was registered for the
emr-serverless ARN service, so TagResource, UntagResource and
ListTagsForResource could not be routed, and a tagged
aws_emrserverless_application could not be planned.
Register an emr-serverless handler with the shared /tags dispatcher,
answering 200 as the model does, over the tags already stored on the
application. Validate keys and values, the user guide's 50 tag limit
and its reserved aws: prefix, refuse job run ARNs as not found, and
synchronize the application mutators so a tag write cannot lose a
concurrent update.
Closes#4662
* feat(emrserverless): add EMR Serverless application management emulator
This adds a full emulator for the EMR Serverless Application management plane,
allowing tools like Terraform to provision and manage EmrServerless applications.
Includes full CRUD operations, route collision handling, and integration tests.
* fix(emrserverless): disambiguate local endpoint routing using SigV4 auth header
* fix(emrserverless): resolve bot feedback on ARNs, idempotency, updates, and list controls
* fix(emrserverless): resolve bot feedback on idempotency races and dropped update fields
* fix(emrserverless): add jobLevelCostAllocationConfiguration to updates
* fix(emrserverless): retain nested configuration fields using dynamic properties
* fix(emrserverless): add required field validation and correct 404 status code
* docs(emrserverless): document unsupported tagging APIs
* fix(emrserverless): increase ListApplications maxResults limit to 100
* test(emrserverless): fix integration test assertions to align with required field validations and correct 404 status code
* fix(emrserverless): revert ListApplications maxResults limit to 50 to match AWS limits
* test(emrserverless): add validation tests for CreateApplication required fields