mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 23:59:27 -05:00
feat(emr-containers): emulate the EMR on EKS control plane (#8543)
Floci had no emr-containers service, so Airflow's EmrContainerOperator, the
aws emr-containers CLI and the SDKs had nothing to call. This adds its 25
operations: virtual clusters, job runs, job templates, managed endpoints,
security configurations and tags.
Job runs follow the job run states without running Spark on Kubernetes: a
run completes as soon as it is submitted, or after
floci.services.emrcontainers.job-run-duration-seconds. When Floci's EKS has
no cluster of the virtual cluster's container provider id, the run is FAILED
with "Cluster <id> does not exist." and CLUSTER_UNAVAILABLE, as AWS's "Common
errors when running jobs" page gives it; that page also gives the wording for
a job run on a missing or non-RUNNING virtual cluster. A job template's
${name} placeholders are filled from jobTemplateParameters or the parameter's
default. Deleting a virtual cluster clears its tags, as the development guide
says, only resources in an active state of the request's Region take tags,
and a job run's template and request tags together keep the 50-tag limit. A
virtual cluster created on an EKS cluster whose authenticationMode admits
access entries is access entry integrated, which ListVirtualClusters'
eksAccessEntryIntegrated filters on.
Every request is checked against botocore's emr-containers constraints,
vendored by tools/aws/regen_emr_containers_shapes.py and gated by make
aws-data-check. Routes sit under a signed-service prefix, so a path-style S3
request for a bucket named virtualclusters still reaches S3. The routes are
added to IAM's REST route table, and emr-containers to the IAM generators'
namespaces, so each operation is checked on the resource its path names,
StartJobRun and CreateManagedEndpoint need iam:PassRole on their
executionRoleArn, and the create operations need emr-containers:TagResource
for their tags, all from AWS's Service Reference.
This commit is contained in:
1 parent
039d4fbb26
commit
9eda97cf84
33 files changed
+3623
-17
No files matched your search
@@ -66,6 +66,7 @@ import software.amazon.awssdk.services.elasticache.ElastiCacheClient;
|
||||
import software.amazon.awssdk.services.elasticbeanstalk.ElasticBeanstalkClient;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client;
|
||||
import software.amazon.awssdk.services.emr.EmrClient;
|
||||
import software.amazon.awssdk.services.emrcontainers.EmrContainersClient;
|
||||
import software.amazon.awssdk.services.emrserverless.EmrServerlessClient;
|
||||
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
|
||||
import software.amazon.awssdk.services.eventbridgev2.EventBridgeV2Client;
|
||||
@@ -1272,6 +1273,14 @@ public final class TestFixtures {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static EmrContainersClient emrContainersClient() {
|
||||
return EmrContainersClient.builder()
|
||||
.endpointOverride(ENDPOINT)
|
||||
.region(REGION)
|
||||
.credentialsProvider(CREDENTIALS)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static EmrServerlessClient emrServerlessClient() {
|
||||
return EmrServerlessClient.builder()
|
||||
.endpointOverride(ENDPOINT)
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.emrcontainers.EmrContainersClient;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.ContainerProviderType;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.CreateVirtualClusterResponse;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.FailureReason;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.JobRun;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.JobRunState;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.ResourceNotFoundException;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.TemplateParameterConfiguration;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.TemplateParameterDataType;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.VirtualCluster;
|
||||
import software.amazon.awssdk.services.emrcontainers.model.VirtualClusterState;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.within;
|
||||
|
||||
@DisplayName("EMR on EKS")
|
||||
class EmrContainersTest {
|
||||
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/emr-job";
|
||||
private static final String RELEASE = "emr-7.5.0-latest";
|
||||
// No EKS cluster of this name exists, so a job run fails the way AWS documents it.
|
||||
private static final String EKS_CLUSTER = "no-such-eks-cluster";
|
||||
|
||||
private static EmrContainersClient emr;
|
||||
private static String virtualClusterId;
|
||||
private static String virtualClusterArn;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
emr = TestFixtures.emrContainersClient();
|
||||
CreateVirtualClusterResponse created = emr.createVirtualCluster(r -> r
|
||||
.name(TestFixtures.uniqueName("vc"))
|
||||
.clientToken(UUID.randomUUID().toString())
|
||||
.containerProvider(p -> p.type(ContainerProviderType.EKS).id(EKS_CLUSTER)
|
||||
.info(i -> i.eksInfo(e -> e.namespace("spark"))))
|
||||
.tags(Map.of("team", "data")));
|
||||
virtualClusterId = created.id();
|
||||
virtualClusterArn = created.arn();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (emr == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
emr.deleteVirtualCluster(r -> r.id(virtualClusterId));
|
||||
}
|
||||
finally {
|
||||
emr.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("A virtual cluster is RUNNING and its timestamps parse")
|
||||
void describeVirtualCluster() {
|
||||
VirtualCluster cluster = emr.describeVirtualCluster(r -> r.id(virtualClusterId)).virtualCluster();
|
||||
|
||||
assertThat(cluster.state()).isEqualTo(VirtualClusterState.RUNNING);
|
||||
assertThat(cluster.arn()).isEqualTo(virtualClusterArn).contains(":/virtualclusters/" + virtualClusterId);
|
||||
assertThat(cluster.containerProvider().info().eksInfo().namespace()).isEqualTo("spark");
|
||||
assertThat(cluster.createdAt()).isCloseTo(Instant.now(), within(1, ChronoUnit.HOURS));
|
||||
assertThat(emr.listVirtualClusters(r -> r.states(VirtualClusterState.RUNNING)).virtualClusters())
|
||||
.extracting(VirtualCluster::id).contains(virtualClusterId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("A job run on an EKS cluster that does not exist FAILS with CLUSTER_UNAVAILABLE")
|
||||
void jobRunOnMissingEksCluster() {
|
||||
String runId = emr.startJobRun(r -> r
|
||||
.virtualClusterId(virtualClusterId)
|
||||
.name("pi")
|
||||
.clientToken(UUID.randomUUID().toString())
|
||||
.executionRoleArn(ROLE)
|
||||
.releaseLabel(RELEASE)
|
||||
.jobDriver(d -> d.sparkSubmitJobDriver(s -> s.entryPoint("s3://bucket/pi.py")))).id();
|
||||
|
||||
JobRun run = emr.describeJobRun(r -> r.virtualClusterId(virtualClusterId).id(runId)).jobRun();
|
||||
|
||||
assertThat(run.state()).isEqualTo(JobRunState.FAILED);
|
||||
assertThat(run.failureReason()).isEqualTo(FailureReason.CLUSTER_UNAVAILABLE);
|
||||
assertThat(run.stateDetails()).isEqualTo("Cluster " + EKS_CLUSTER + " does not exist.");
|
||||
assertThat(run.finishedAt()).isNotNull();
|
||||
assertThat(emr.listJobRuns(r -> r.virtualClusterId(virtualClusterId).states(JobRunState.FAILED)).jobRuns())
|
||||
.extracting(JobRun::id).contains(runId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("A job template's parameters are filled in on StartJobRun")
|
||||
void jobTemplate() {
|
||||
String templateId = emr.createJobTemplate(r -> r
|
||||
.name(TestFixtures.uniqueName("template"))
|
||||
.clientToken(UUID.randomUUID().toString())
|
||||
.jobTemplateData(d -> d
|
||||
.executionRoleArn(ROLE)
|
||||
.releaseLabel(RELEASE)
|
||||
.jobDriver(j -> j.sparkSubmitJobDriver(s -> s.entryPoint("${EntryPoint}")))
|
||||
.parameterConfiguration(Map.of("EntryPoint",
|
||||
TemplateParameterConfiguration.builder()
|
||||
.type(TemplateParameterDataType.STRING).build())))).id();
|
||||
try {
|
||||
String runId = emr.startJobRun(r -> r
|
||||
.virtualClusterId(virtualClusterId)
|
||||
.clientToken(UUID.randomUUID().toString())
|
||||
.jobTemplateId(templateId)
|
||||
.jobTemplateParameters(Map.of("EntryPoint", "s3://bucket/job.py"))).id();
|
||||
|
||||
JobRun run = emr.describeJobRun(r -> r.virtualClusterId(virtualClusterId).id(runId)).jobRun();
|
||||
assertThat(run.jobDriver().sparkSubmitJobDriver().entryPoint()).isEqualTo("s3://bucket/job.py");
|
||||
assertThat(run.executionRoleArn()).isEqualTo(ROLE);
|
||||
}
|
||||
finally {
|
||||
emr.deleteJobTemplate(r -> r.id(templateId));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("TagResource, UntagResource and ListTagsForResource round trip on the virtual cluster ARN")
|
||||
void tags() {
|
||||
emr.tagResource(r -> r.resourceArn(virtualClusterArn).tags(Map.of("env", "dev")));
|
||||
assertThat(emr.listTagsForResource(r -> r.resourceArn(virtualClusterArn)).tags())
|
||||
.containsOnly(Map.entry("team", "data"), Map.entry("env", "dev"));
|
||||
|
||||
emr.untagResource(r -> r.resourceArn(virtualClusterArn).tagKeys("env"));
|
||||
assertThat(emr.listTagsForResource(r -> r.resourceArn(virtualClusterArn)).tags())
|
||||
.containsOnly(Map.entry("team", "data"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("An unknown virtual cluster is ResourceNotFoundException")
|
||||
void unknownVirtualCluster() {
|
||||
assertThatThrownBy(() -> emr.describeVirtualCluster(r -> r.id("nosuchcluster")))
|
||||
.isInstanceOf(ResourceNotFoundException.class)
|
||||
.hasMessageContaining("Virtual cluster nosuchcluster doesn't exist.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user