mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(glue): jobs and crawlers (#2591)
* feat(glue): implement CRUD operations for Jobs and Crawlers * fix(glue): resolve edge cases in jobs, crawlers, and tagging implementation - Fix DynamoDBTarget ScanAll/ScanRate JsonProperty casing - Support MaxResults and NextToken pagination in GetJobs and GetCrawlers - Throw EntityNotFoundException for unknown Job/Crawler deletions - Retain existing configuration values during Crawler updates - Use centralized ResourceGroupsTaggingService for non-schema TagResource/UntagResource/GetTags actions * test(glue): add CRUD, pagination, and tagging tests for Jobs and Crawlers * fix(glue): validate pagination limits and ARN existence for tagging * fix(glue): enforce AWS-compliant validation, semantics, and responses - Add required field validation to Job and Crawler CRUD operations. - Persist SourceControlDetails and ProfileName across Job updates. - Set default State (READY) and Version for Crawlers on creation. - Standardize empty-body responses to bare Response.ok() per AWS specs. - Add handler-level integration tests for request payload parsing. - Refactor GlueServiceTest to use valid mock objects and standard imports. * fix(glue): add missing ARN validation for databases, tables, and UDFs - Restore EntityNotFoundException when attempting to tag nonexistent Databases, Tables, or UserDefinedFunctions. - Expand tagging tests to verify behavior for these resources. * chore(glue): apply AWS defaults for Job creation and remove unused Crawler DTOs - Apply default GlueVersion (5.1) and Timeout (480/2880 based on version) for newly created Jobs. - Remove empty Create/Update/DeleteCrawlerResponse models since they are unused. * fix(glue): throw EntityNotFoundException for unmodeled resource ARNs - Prevent validateResourceExists from silently passing when an ARN type isn't supported (e.g. connections). - Any ARN not matching jobs, crawlers, databases, tables, or UDFs now throws.
This commit is contained in:
1 parent
146753b094
commit
de6bf8f599
44 files changed
+2484
-28
No files matched your search
+1
-11
@@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Verifies the wire-accurate empty-list responses for the read-only Glue actions on resources
|
||||
* the emulator does not model (GetJobs, GetCrawlers, ListDataQualityRulesets, GetSecurityConfigurations).
|
||||
* the emulator does not model (ListDataQualityRulesets, GetSecurityConfigurations).
|
||||
* Each must return HTTP 200, an empty list under its result key, and omit NextToken.
|
||||
*/
|
||||
class GlueJsonHandlerEmptyListTest {
|
||||
@@ -45,16 +45,6 @@ class GlueJsonHandlerEmptyListTest {
|
||||
handler = new GlueJsonHandler(glueService, schemaRegistryService, mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getJobsReturnsEmptyJobsList() throws Exception {
|
||||
assertEmptyList("GetJobs", "Jobs");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getCrawlersReturnsEmptyCrawlersList() throws Exception {
|
||||
assertEmptyList("GetCrawlers", "Crawlers");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDataQualityRulesetsReturnsEmptyRulesetsList() throws Exception {
|
||||
assertEmptyList("ListDataQualityRulesets", "Rulesets");
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package io.github.hectorvent.floci.services.glue;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.glue.schemaregistry.GlueSchemaRegistryService;
|
||||
import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsTaggingService;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class GlueJsonHandlerTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT_ID = "000000000000";
|
||||
|
||||
private GlueJsonHandler handler;
|
||||
private ObjectMapper mapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
|
||||
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT_ID);
|
||||
StorageFactory storageFactory = new InMemoryStorageFactory();
|
||||
GlueSchemaRegistryService schemaRegistryService =
|
||||
new GlueSchemaRegistryService(storageFactory, regionResolver);
|
||||
GlueService glueService = new GlueService(
|
||||
storageFactory, schemaRegistryService, regionResolver, new ResourceGroupsTaggingService(storageFactory));
|
||||
handler = new GlueJsonHandler(glueService, schemaRegistryService, mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createCrawlerWithScheduleSucceeds() throws Exception {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("Name", "test-crawler");
|
||||
request.put("Role", "arn:aws:iam::000000000000:role/role");
|
||||
request.put("Schedule", "cron(15 12 * * ? *)");
|
||||
|
||||
ObjectNode targets = request.putObject("Targets");
|
||||
targets.putArray("S3Targets").addObject().put("Path", "s3://bucket/path/");
|
||||
|
||||
Response response = handler.handle("CreateCrawler", request, REGION);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
JsonNode body = mapper.valueToTree(response.getEntity());
|
||||
assertNotNull(body);
|
||||
|
||||
Response getResponse = handler.handle("GetCrawler", mapper.createObjectNode().put("Name", "test-crawler"), REGION);
|
||||
assertEquals(200, getResponse.getStatus());
|
||||
JsonNode getBody = mapper.valueToTree(getResponse.getEntity());
|
||||
assertTrue(getBody.has("Crawler"));
|
||||
JsonNode crawler = getBody.get("Crawler");
|
||||
assertEquals("test-crawler", crawler.get("Name").asText());
|
||||
assertEquals("READY", crawler.get("State").asText());
|
||||
assertEquals(1, crawler.get("Version").asInt());
|
||||
assertTrue(crawler.has("Schedule"));
|
||||
assertEquals("cron(15 12 * * ? *)", crawler.get("Schedule").get("ScheduleExpression").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateCrawlerWithScheduleSucceeds() throws Exception {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("Name", "test-crawler-update");
|
||||
request.put("Role", "arn:aws:iam::000000000000:role/role");
|
||||
|
||||
ObjectNode targets = request.putObject("Targets");
|
||||
targets.putArray("S3Targets").addObject().put("Path", "s3://bucket/path/");
|
||||
|
||||
assertEquals(200, handler.handle("CreateCrawler", request, REGION).getStatus());
|
||||
|
||||
ObjectNode updateRequest = mapper.createObjectNode();
|
||||
updateRequest.put("Name", "test-crawler-update");
|
||||
updateRequest.put("Schedule", "cron(0 0 * * ? *)");
|
||||
|
||||
Response response = handler.handle("UpdateCrawler", updateRequest, REGION);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
Response getResponse = handler.handle("GetCrawler", mapper.createObjectNode().put("Name", "test-crawler-update"), REGION);
|
||||
assertEquals(200, getResponse.getStatus());
|
||||
JsonNode getBody = mapper.valueToTree(getResponse.getEntity());
|
||||
JsonNode crawler = getBody.get("Crawler");
|
||||
assertEquals("test-crawler-update", crawler.get("Name").asText());
|
||||
assertEquals(2, crawler.get("Version").asInt());
|
||||
assertTrue(crawler.has("Schedule"));
|
||||
assertEquals("cron(0 0 * * ? *)", crawler.get("Schedule").get("ScheduleExpression").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createJobSucceeds() throws Exception {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("Name", "test-job");
|
||||
request.put("Role", "arn:aws:iam::000000000000:role/role");
|
||||
|
||||
ObjectNode command = request.putObject("Command");
|
||||
command.put("Name", "glueetl");
|
||||
command.put("ScriptLocation", "s3://bucket/script.py");
|
||||
|
||||
Response response = handler.handle("CreateJob", request, REGION);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
Response getResponse = handler.handle("GetJob", mapper.createObjectNode().put("JobName", "test-job"), REGION);
|
||||
assertEquals(200, getResponse.getStatus());
|
||||
JsonNode getBody = mapper.valueToTree(getResponse.getEntity());
|
||||
assertTrue(getBody.has("Job"));
|
||||
JsonNode job = getBody.get("Job");
|
||||
assertEquals("test-job", job.get("Name").asText());
|
||||
assertEquals("glueetl", job.get("Command").get("Name").asText());
|
||||
}
|
||||
|
||||
private static final class InMemoryStorageFactory extends StorageFactory {
|
||||
private InMemoryStorageFactory() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName,
|
||||
String fileName,
|
||||
TypeReference<Map<String, V>> typeReference) {
|
||||
return AccountAwareStorageBackend.inMemory("000000000000");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,13 @@ import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.glue.model.Column;
|
||||
import io.github.hectorvent.floci.services.glue.model.Database;
|
||||
import io.github.hectorvent.floci.services.glue.model.Crawler;
|
||||
import io.github.hectorvent.floci.services.glue.model.CrawlerTargets;
|
||||
import io.github.hectorvent.floci.services.glue.model.Job;
|
||||
import io.github.hectorvent.floci.services.glue.model.JobCommand;
|
||||
import io.github.hectorvent.floci.services.glue.model.JobUpdate;
|
||||
import io.github.hectorvent.floci.services.glue.model.Partition;
|
||||
import io.github.hectorvent.floci.services.glue.model.S3Target;
|
||||
import io.github.hectorvent.floci.services.glue.model.SchemaReference;
|
||||
import io.github.hectorvent.floci.services.glue.model.StorageDescriptor;
|
||||
import io.github.hectorvent.floci.services.glue.model.Table;
|
||||
@@ -70,6 +76,8 @@ class GlueServiceTest {
|
||||
partitionStore,
|
||||
new InMemoryStorage<String, Map<String, Object>>(),
|
||||
new InMemoryStorage<String, UserDefinedFunction>(),
|
||||
new InMemoryStorage<String, Job>(),
|
||||
new InMemoryStorage<String, Crawler>(),
|
||||
schemaRegistryService, regionResolver, new ResourceGroupsTaggingService(null));
|
||||
glueService.createDatabase(new Database("db1"));
|
||||
}
|
||||
@@ -1039,4 +1047,195 @@ class GlueServiceTest {
|
||||
return AccountAwareStorageBackend.inMemory("000000000000");
|
||||
}
|
||||
}
|
||||
|
||||
private Job createValidJob(String name) {
|
||||
Job job = new Job();
|
||||
job.setName(name);
|
||||
job.setRole("arn:aws:iam::000000000000:role/my-role");
|
||||
job.setCommand(new JobCommand());
|
||||
return job;
|
||||
}
|
||||
|
||||
private Crawler createValidCrawler(String name) {
|
||||
Crawler crawler = new Crawler();
|
||||
crawler.setName(name);
|
||||
crawler.setRole("arn:aws:iam::000000000000:role/my-role");
|
||||
CrawlerTargets targets = new CrawlerTargets();
|
||||
targets.setS3Targets(java.util.List.of(new S3Target()));
|
||||
crawler.setTargets(targets);
|
||||
return crawler;
|
||||
}
|
||||
|
||||
@Test
|
||||
void jobCanBeCreatedFetchedUpdatedAndDeleted() {
|
||||
Job job = createValidJob("my-job");
|
||||
job.setDescription("Original description");
|
||||
|
||||
glueService.createJob(job);
|
||||
|
||||
Job fetched = glueService.getJob("my-job");
|
||||
assertEquals("my-job", fetched.getName());
|
||||
assertEquals("Original description", fetched.getDescription());
|
||||
assertNotNull(fetched.getCreatedOn());
|
||||
assertEquals(fetched.getCreatedOn(), fetched.getLastModifiedOn());
|
||||
|
||||
assertEquals(1, glueService.getJobs().size());
|
||||
assertEquals(1, glueService.getJobs(10, null).items().size());
|
||||
|
||||
JobUpdate update = new JobUpdate();
|
||||
update.setDescription("Updated description");
|
||||
update.setRole("arn:aws:iam::000000000000:role/new-role");
|
||||
|
||||
glueService.updateJob("my-job", update);
|
||||
|
||||
Job updated = glueService.getJob("my-job");
|
||||
assertEquals("Updated description", updated.getDescription());
|
||||
assertEquals("arn:aws:iam::000000000000:role/new-role", updated.getRole());
|
||||
assertTrue(updated.getLastModifiedOn().isAfter(fetched.getCreatedOn()) || updated.getLastModifiedOn().equals(fetched.getCreatedOn()));
|
||||
|
||||
glueService.deleteJob("my-job", REGION);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> glueService.getJob("my-job"));
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
assertTrue(glueService.getJobs().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void crawlerCanBeCreatedFetchedUpdatedAndDeleted() {
|
||||
Crawler crawler = createValidCrawler("my-crawler");
|
||||
crawler.setDescription("Original crawler");
|
||||
crawler.setDatabaseName("db1");
|
||||
|
||||
glueService.createCrawler(crawler);
|
||||
|
||||
Crawler fetched = glueService.getCrawler("my-crawler");
|
||||
assertEquals("my-crawler", fetched.getName());
|
||||
assertEquals("Original crawler", fetched.getDescription());
|
||||
assertEquals("db1", fetched.getDatabaseName());
|
||||
assertNotNull(fetched.getCreationTime());
|
||||
assertEquals(fetched.getCreationTime(), fetched.getLastUpdated());
|
||||
|
||||
assertEquals(1, glueService.getCrawlers().size());
|
||||
assertEquals(1, glueService.getCrawlers(10, null).items().size());
|
||||
|
||||
Crawler update = new Crawler();
|
||||
update.setName("my-crawler");
|
||||
update.setDescription("Updated crawler");
|
||||
update.setDatabaseName("db2");
|
||||
|
||||
glueService.updateCrawler(update);
|
||||
|
||||
Crawler updated = glueService.getCrawler("my-crawler");
|
||||
assertEquals("Updated crawler", updated.getDescription());
|
||||
assertEquals("db2", updated.getDatabaseName());
|
||||
assertTrue(updated.getLastUpdated().isAfter(fetched.getCreationTime()) || updated.getLastUpdated().equals(fetched.getCreationTime()));
|
||||
|
||||
glueService.deleteCrawler("my-crawler", REGION);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> glueService.getCrawler("my-crawler"));
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
assertTrue(glueService.getCrawlers().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceTaggingWorksForJobsAndCrawlers() {
|
||||
Job job = createValidJob("tagged-job");
|
||||
glueService.createJob(job, Map.of("key1", "value1"), REGION);
|
||||
|
||||
String jobArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":job/tagged-job";
|
||||
Map<String, String> tags = glueService.getTags(jobArn, REGION);
|
||||
assertEquals("value1", tags.get("key1"));
|
||||
|
||||
glueService.tagResource(jobArn, Map.of("key2", "value2"), REGION);
|
||||
Map<String, String> updatedTags = glueService.getTags(jobArn, REGION);
|
||||
assertEquals("value1", updatedTags.get("key1"));
|
||||
assertEquals("value2", updatedTags.get("key2"));
|
||||
|
||||
glueService.untagResource(jobArn, List.of("key1"), REGION);
|
||||
Map<String, String> finalTags = glueService.getTags(jobArn, REGION);
|
||||
assertNull(finalTags.get("key1"));
|
||||
assertEquals("value2", finalTags.get("key2"));
|
||||
|
||||
Crawler crawler = createValidCrawler("tagged-crawler");
|
||||
glueService.createCrawler(crawler, Map.of("env", "prod"), REGION);
|
||||
|
||||
String crawlerArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":crawler/tagged-crawler";
|
||||
Map<String, String> crawlerTags = glueService.getTags(crawlerArn, REGION);
|
||||
assertEquals("prod", crawlerTags.get("env"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void jobAndCrawlerRejectsDuplicateCreation() {
|
||||
Job job = createValidJob("dup-job");
|
||||
glueService.createJob(job);
|
||||
|
||||
AwsException jobEx = assertThrows(AwsException.class, () -> glueService.createJob(job));
|
||||
assertEquals("AlreadyExistsException", jobEx.getErrorCode());
|
||||
|
||||
Crawler crawler = createValidCrawler("dup-crawler");
|
||||
glueService.createCrawler(crawler);
|
||||
|
||||
AwsException crawlerEx = assertThrows(AwsException.class, () -> glueService.createCrawler(crawler));
|
||||
assertEquals("AlreadyExistsException", crawlerEx.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getJobsAndCrawlersPagination() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Job job = createValidJob("job-" + i);
|
||||
glueService.createJob(job);
|
||||
|
||||
Crawler crawler = createValidCrawler("crawler-" + i);
|
||||
glueService.createCrawler(crawler);
|
||||
}
|
||||
|
||||
GlueService.Page<Job> jobsPage = glueService.getJobs(2, null);
|
||||
assertEquals(2, jobsPage.items().size());
|
||||
assertNotNull(jobsPage.nextToken());
|
||||
|
||||
GlueService.Page<Job> jobsNextPage = glueService.getJobs(10, jobsPage.nextToken());
|
||||
assertEquals(3, jobsNextPage.items().size());
|
||||
assertNull(jobsNextPage.nextToken());
|
||||
|
||||
GlueService.Page<Crawler> crawlersPage = glueService.getCrawlers(3, null);
|
||||
assertEquals(3, crawlersPage.items().size());
|
||||
assertNotNull(crawlersPage.nextToken());
|
||||
|
||||
GlueService.Page<Crawler> crawlersNextPage = glueService.getCrawlers(10, crawlersPage.nextToken());
|
||||
assertEquals(2, crawlersNextPage.items().size());
|
||||
assertNull(crawlersNextPage.nextToken());
|
||||
|
||||
AwsException negativeMaxResultsJobs = assertThrows(AwsException.class, () -> glueService.getJobs(-1, null));
|
||||
assertEquals("InvalidInputException", negativeMaxResultsJobs.getErrorCode());
|
||||
|
||||
AwsException zeroMaxResultsCrawlers = assertThrows(AwsException.class, () -> glueService.getCrawlers(0, null));
|
||||
assertEquals("InvalidInputException", zeroMaxResultsCrawlers.getErrorCode());
|
||||
|
||||
AwsException hugeMaxResultsJobs = assertThrows(AwsException.class, () -> glueService.getJobs(1001, null));
|
||||
assertEquals("InvalidInputException", hugeMaxResultsJobs.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void taggingNonExistentResourceThrows() {
|
||||
String fakeJobArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":job/fake-job";
|
||||
String fakeCrawlerArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":crawler/fake-crawler";
|
||||
String fakeDbArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":database/fake-db";
|
||||
String fakeTableArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":table/fake-db/fake-table";
|
||||
String fakeUdfArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":userDefinedFunction/fake-db/fake-udf";
|
||||
|
||||
AwsException jobTagEx = assertThrows(AwsException.class, () -> glueService.tagResource(fakeJobArn, Map.of("k", "v"), REGION));
|
||||
assertEquals("EntityNotFoundException", jobTagEx.getErrorCode());
|
||||
|
||||
AwsException crawlerGetTagsEx = assertThrows(AwsException.class, () -> glueService.getTags(fakeCrawlerArn, REGION));
|
||||
assertEquals("EntityNotFoundException", crawlerGetTagsEx.getErrorCode());
|
||||
|
||||
AwsException dbTagEx = assertThrows(AwsException.class, () -> glueService.tagResource(fakeDbArn, Map.of("k", "v"), REGION));
|
||||
assertEquals("EntityNotFoundException", dbTagEx.getErrorCode());
|
||||
|
||||
AwsException tableTagEx = assertThrows(AwsException.class, () -> glueService.tagResource(fakeTableArn, Map.of("k", "v"), REGION));
|
||||
assertEquals("EntityNotFoundException", tableTagEx.getErrorCode());
|
||||
|
||||
AwsException udfTagEx = assertThrows(AwsException.class, () -> glueService.tagResource(fakeUdfArn, Map.of("k", "v"), REGION));
|
||||
assertEquals("EntityNotFoundException", udfTagEx.getErrorCode());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user