mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
feat(emr-serverless): tag, untag and list tags for applications (#4667)
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
This commit is contained in:
1 parent
48214e04e0
commit
5aad012e78
8 files changed
+510
-6
No files matched your search
+73
@@ -0,0 +1,73 @@
|
||||
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.emrserverless.EmrServerlessClient;
|
||||
import software.amazon.awssdk.services.emrserverless.model.CreateApplicationResponse;
|
||||
import software.amazon.awssdk.services.emrserverless.model.ResourceNotFoundException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@DisplayName("EMR Serverless tags")
|
||||
class EmrServerlessTagTest {
|
||||
|
||||
private static EmrServerlessClient emr;
|
||||
private static String applicationId;
|
||||
private static String arn;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
emr = TestFixtures.emrServerlessClient();
|
||||
CreateApplicationResponse created = emr.createApplication(r -> r
|
||||
.name(TestFixtures.uniqueName("tagged-app"))
|
||||
.releaseLabel("emr-7.5.0")
|
||||
.type("SPARK")
|
||||
.clientToken(UUID.randomUUID().toString())
|
||||
.tags(Map.of("team", "data")));
|
||||
applicationId = created.applicationId();
|
||||
arn = created.arn();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (emr == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
emr.deleteApplication(r -> r.applicationId(applicationId));
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
// Cleanup is best effort: the application is unique to this run and the emulator is disposable.
|
||||
}
|
||||
emr.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("TagResource, UntagResource and ListTagsForResource round trip on the application ARN")
|
||||
void tagRoundTrip() {
|
||||
assertThat(emr.listTagsForResource(r -> r.resourceArn(arn)).tags()).containsExactly(Map.entry("team", "data"));
|
||||
|
||||
emr.tagResource(r -> r.resourceArn(arn).tags(Map.of("env", "dev", "team", "platform")));
|
||||
assertThat(emr.listTagsForResource(r -> r.resourceArn(arn)).tags())
|
||||
.containsOnly(Map.entry("team", "platform"), Map.entry("env", "dev"));
|
||||
assertThat(emr.getApplication(r -> r.applicationId(applicationId)).application().tags())
|
||||
.containsEntry("env", "dev");
|
||||
|
||||
emr.untagResource(r -> r.resourceArn(arn).tagKeys("env"));
|
||||
assertThat(emr.listTagsForResource(r -> r.resourceArn(arn)).tags()).containsOnly(Map.entry("team", "platform"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("An unknown application is ResourceNotFoundException")
|
||||
void unknownApplication() {
|
||||
String missing = arn.substring(0, arn.lastIndexOf('/') + 1) + "00missing00";
|
||||
assertThatThrownBy(() -> emr.listTagsForResource(r -> r.resourceArn(missing)))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user