mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(athena): add UpdateWorkGroup support (#3468)
* feat(athena): add UpdateWorkGroup support * fix(athena): validate workgroup configuration updates --------- Co-authored-by: Ovidiu (Ovi) <462561+ovidiubute@users.noreply.github.com>
This commit is contained in:
1 parent
e62e99f060
commit
ea5925f630
9 files changed
+634
-20
No files matched your search
+57
@@ -18,6 +18,7 @@ import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -291,6 +292,62 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest {
|
||||
assertEquals("Athena engine version 3", engineVersion.get("EffectiveEngineVersion"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWorkGroupPersistsMergedState() throws Exception {
|
||||
Files.deleteIfExists(WORKGROUPS_FILE);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Name": "persistent-update",
|
||||
"Configuration": {
|
||||
"EnforceWorkGroupConfiguration": true,
|
||||
"BytesScannedCutoffPerQuery": 10000000
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"WorkGroup": "persistent-update",
|
||||
"Description": "persisted after update",
|
||||
"State": "DISABLED",
|
||||
"ConfigurationUpdates": {
|
||||
"PublishCloudWatchMetricsEnabled": true,
|
||||
"RemoveBytesScannedCutoffPerQuery": true
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
PersistentStorage<String, Map<String, Object>> store = new PersistentStorage<>(
|
||||
WORKGROUPS_FILE,
|
||||
new TypeReference<Map<String, Map<String, Object>>>() {});
|
||||
store.load();
|
||||
|
||||
Map<String, Object> persisted = store.get("000000000000/us-east-1:persistent-update").orElseThrow();
|
||||
assertEquals("persisted after update", persisted.get("Description"));
|
||||
assertEquals("DISABLED", persisted.get("State"));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> configuration = (Map<String, Object>) persisted.get("Configuration");
|
||||
assertEquals(true, configuration.get("EnforceWorkGroupConfiguration"));
|
||||
assertEquals(true, configuration.get("PublishCloudWatchMetricsEnabled"));
|
||||
assertNull(configuration.get("BytesScannedCutoffPerQuery"));
|
||||
}
|
||||
|
||||
public static final class PersistentStorageProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
package io.github.hectorvent.floci.services.athena;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@QuarkusTest
|
||||
class AthenaUpdateWorkGroupIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWorkGroupMergesDescriptionStateAndConfiguration() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Name": "analytics-update",
|
||||
"Description": "before",
|
||||
"Configuration": {
|
||||
"ResultConfiguration": {
|
||||
"OutputLocation": "s3://before/results/"
|
||||
},
|
||||
"EnforceWorkGroupConfiguration": true,
|
||||
"PublishCloudWatchMetricsEnabled": false,
|
||||
"RequesterPaysEnabled": false,
|
||||
"BytesScannedCutoffPerQuery": 10000000
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String responseBody = given()
|
||||
.header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"WorkGroup": "analytics-update",
|
||||
"Description": "after",
|
||||
"State": "DISABLED",
|
||||
"ConfigurationUpdates": {
|
||||
"ResultConfigurationUpdates": {
|
||||
"OutputLocation": "s3://after/results/"
|
||||
},
|
||||
"EnforceWorkGroupConfiguration": false,
|
||||
"PublishCloudWatchMetricsEnabled": true,
|
||||
"RequesterPaysEnabled": true,
|
||||
"BytesScannedCutoffPerQuery": 20000000,
|
||||
"EngineVersion": {
|
||||
"SelectedEngineVersion": "AUTO"
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().asString();
|
||||
|
||||
assertEquals("{}", responseBody);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.GetWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{ \"WorkGroup\": \"analytics-update\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("WorkGroup.Description", equalTo("after"))
|
||||
.body("WorkGroup.State", equalTo("DISABLED"))
|
||||
.body("WorkGroup.Configuration.ResultConfiguration.OutputLocation",
|
||||
equalTo("s3://after/results/"))
|
||||
.body("WorkGroup.Configuration.EnforceWorkGroupConfiguration", equalTo(false))
|
||||
.body("WorkGroup.Configuration.PublishCloudWatchMetricsEnabled", equalTo(true))
|
||||
.body("WorkGroup.Configuration.RequesterPaysEnabled", equalTo(true))
|
||||
.body("WorkGroup.Configuration.BytesScannedCutoffPerQuery", equalTo(20000000))
|
||||
.body("WorkGroup.Configuration.EngineVersion.SelectedEngineVersion", equalTo("AUTO"))
|
||||
.body("WorkGroup.Configuration.EngineVersion.EffectiveEngineVersion",
|
||||
equalTo("Athena engine version 3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWorkGroupPreservesOmittedSettingsAndAppliesRemovalFlags() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Name": "analytics-partial-update",
|
||||
"Configuration": {
|
||||
"ResultConfiguration": {
|
||||
"OutputLocation": "s3://before/results/"
|
||||
},
|
||||
"EnforceWorkGroupConfiguration": true,
|
||||
"BytesScannedCutoffPerQuery": 10000000
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"WorkGroup": "analytics-partial-update",
|
||||
"ConfigurationUpdates": {
|
||||
"ResultConfigurationUpdates": {
|
||||
"RemoveOutputLocation": true
|
||||
},
|
||||
"RemoveBytesScannedCutoffPerQuery": true
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.GetWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{ \"WorkGroup\": \"analytics-partial-update\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("WorkGroup.State", equalTo("ENABLED"))
|
||||
.body("WorkGroup.Configuration.EnforceWorkGroupConfiguration", equalTo(true))
|
||||
.body("WorkGroup.Configuration.ResultConfiguration", nullValue())
|
||||
.body("WorkGroup.Configuration.BytesScannedCutoffPerQuery", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWorkGroupRejectsMissingWorkGroup() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{ \"WorkGroup\": \"missing-update-workgroup\", \"Description\": \"after\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"))
|
||||
.body("message", equalTo("WorkGroup missing-update-workgroup is not found."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWorkGroupRejectsInvalidState() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{ \"Name\": \"analytics-invalid-state\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{ \"WorkGroup\": \"analytics-invalid-state\", \"State\": \"UNKNOWN\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWorkGroupRejectsBytesScannedCutoffBelowMinimumWithoutApplyingOtherChanges() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Name": "analytics-invalid-cutoff",
|
||||
"Description": "before",
|
||||
"Configuration": {
|
||||
"BytesScannedCutoffPerQuery": 20000000
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"WorkGroup": "analytics-invalid-cutoff",
|
||||
"Description": "after",
|
||||
"ConfigurationUpdates": {
|
||||
"BytesScannedCutoffPerQuery": 9999999
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.GetWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{ \"WorkGroup\": \"analytics-invalid-cutoff\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("WorkGroup.Description", equalTo("before"))
|
||||
.body("WorkGroup.Configuration.BytesScannedCutoffPerQuery", equalTo(20000000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWorkGroupRejectsEmptySelectedEngineVersionWithoutApplyingOtherChanges() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Name": "analytics-invalid-engine",
|
||||
"Description": "before"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"WorkGroup": "analytics-invalid-engine",
|
||||
"Description": "after",
|
||||
"ConfigurationUpdates": {
|
||||
"EngineVersion": {
|
||||
"SelectedEngineVersion": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonAthena.GetWorkGroup")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{ \"WorkGroup\": \"analytics-invalid-engine\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("WorkGroup.Description", equalTo("before"))
|
||||
.body("WorkGroup.Configuration.EngineVersion.SelectedEngineVersion",
|
||||
equalTo("Athena engine version 3"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user