mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(kinesisanalytics): add Managed Service for Apache Flink (Kinesis Analytics V2) (#1914)
* feat(kinesisanalytics): add Managed Service for Apache Flink (Kinesis Analytics V2)
Adds the kinesisanalyticsv2 service (X-Amz-Target KinesisAnalytics_20180523.*):
a control-plane state machine plus a real Apache Flink JobManager container spun up
as a sidecar on StartApplication, modeled on the AmazonMQ->RabbitMQ pattern.
- CreateApplication -> READY, StartApplication -> STARTING -> RUNNING via a readiness
poller, StopApplication -> READY, DeleteApplication -> removed
- Container image chosen from the requested RuntimeEnvironment (FLINK-1_15..1_20 ->
apache/flink:1.x) via KinesisAnalyticsRuntimes, with an optional operator override;
unsupported runtimes (SQL / Zeppelin) rejected with InvalidArgumentException
- Container naming via ContainerStorageHelper.resourceName (floci-kinesisanalytics-<name>)
- Registered in ResolvedServiceCatalog, dispatched by AwsJson11Controller; container
teardown wired into EmulatorLifecycle.onStop
- Tests: service + handler unit tests, @QuarkusTest integration, Java SDK compatibility test
- Docs: service page, services index, README, environment-variable reference
* fix(kinesisanalytics): enforce delete/update state and version/timestamp guards
Addresses review feedback (self-review + Greptile) on the Managed Flink service:
- DeleteApplication rejects a non-READY (RUNNING/STARTING) application with
ResourceInUseException; the caller must StopApplication first (Greptile P1)
- DeleteApplication validates the required CreateTimestamp against the stored value
- UpdateApplication validates CurrentApplicationVersionId (ConcurrentModificationException
on mismatch, InvalidArgumentException when absent)
- StopApplication error message reads 'RUNNING or STARTING' to match the guard
- Readiness poller @PreDestroy awaits termination (bounded) before returning so a
mid-flight write cannot race the shutdown storage flush
- Drop the unused Tags field from FlinkApplication (full tag support tracked as a follow-up)
- Compat test @AfterAll logs tolerated teardown failures (AGENTS.md) and stops before delete
Tests updated accordingly and verified live against the packaged jar.
* feat(kinesisanalytics): deploy and run the application JAR on the Flink cluster
Implements real job submission for Managed Service for Apache Flink, so the AWS
'deploy a JAR' flow actually runs the job (previously only a bare JobManager reached RUNNING):
- CreateApplication parses and stores ApplicationConfiguration (ApplicationCodeConfiguration
S3ContentLocation + ParallelismConfiguration); DescribeApplication echoes it back as
ApplicationConfigurationDescription
- StartApplication reads the JAR from Floci's local S3 (via S3Service), starts a JobManager plus a
TaskManager (sharing the JobManager network namespace for localhost RPC), then uploads and runs the
JAR via the Flink REST API (new FlinkRestClient); the app reaches RUNNING when the Flink job is RUNNING
- StopApplication cancels the job and tears down both containers
- Applications created without code still come up as a bare cluster
- Docs + README updated; unit tests for config round-trip; verified live end-to-end against the
packaged jar (S3 JAR -> RUNNING Flink job -> stop/delete cleanup)
Not yet emulated: EnvironmentProperties injection, snapshots/savepoints, in-place code updates.
* fix(kinesisanalytics): align Flink runtimes with AWS and add the 2.x line
The runtime map now mirrors the runtimes AWS Managed Service for Apache Flink actually offers:
- Add FLINK-2_0 / 2_1 / 2_2 / 2_3 -> apache/flink:2.0/2.1/2.2/2.3 (the Flink 2.x line; FLINK-2_2 is in
the AWS SDK RuntimeEnvironment enum and the whole 2.x line has published apache/flink images)
- Remove FLINK-1_16 / FLINK-1_17 -> AWS does not offer these runtimes, so Floci should reject them too
rather than accept versions real AWS refuses
Supported set: FLINK-1_15, 1_18, 1_19, 1_20, 2_0, 2_1, 2_2, 2_3. Tests + docs + README updated.
* test(kinesisanalytics): cover both Flink 1.18 and 2.3 in the SDK compat test
Refactor the single-runtime compat test into an abstract ordered lifecycle run against two
runtimes, so the suite guards both the Flink 1.x and 2.x lines (Flink 2.0 changed the config
system and boots slower):
- AbstractKinesisAnalyticsV2LifecycleTest: PER_CLASS instance state + the create->start->RUNNING->
list->stop->unsupported->delete lifecycle, parameterized on an abstract runtime()
- KinesisAnalyticsV2Flink118Test (FLINK-1_18) and KinesisAnalyticsV2Flink23Test (FLINK-2_3)
- FLINK-2_3 is passed as a string (newer than the pinned SDK 2.44.14 enum) and asserted via
runtimeEnvironmentAsString(); RUNNING wait bumped to 300s for Flink 2.x's slower boot
Verified live: both subclasses boot real apache/flink:1.18 and :2.3 clusters and reach RUNNING
(0 skipped). CI now exercises two clusters; both skip gracefully when Docker is unavailable.
* fix(kinesisanalytics): preserve AwsException from a bad application-code S3 location
StartApplication's catch(RuntimeException) wrapped every failure from startCluster into
InternalFailureException (HTTP 500) — including the AwsException that readJar throws when the
application-code S3 object is missing/empty/unreadable. A client's bad S3 code location therefore
surfaced as a 500 server error instead of the intended InvalidArgumentException (400).
Now AwsException propagates as-is (preserving its error code and message); only unexpected
RuntimeExceptions (e.g. Docker unavailable) become InternalFailureException. Addresses Greptile P1.
* feat(kinesisanalytics): add resource tagging (TagResource/UntagResource/ListTagsForResource)
Adds Tags support to CreateApplication plus TagResource, UntagResource, and
ListTagsForResource, dispatched as regular JSON1.1 actions under the same
KinesisAnalytics_20180523 target prefix as every other action — verified
against the real botocore kinesisanalyticsv2 model that this API has no
separate REST tagging endpoint (protocol is pure "json"/1.1 with all
operations on POST /), unlike REST-JSON services (EKS, MWAA) that use the
shared /tags/{arn} controller.
Tags is a list of {Key, Value} objects on the wire (not a map), same shape
MemoryDB's handler already uses for its own tagging actions; mirrored that
parse/build pattern rather than the map-shaped TagHandler interface. Tags
are stored on FlinkApplication but, matching the real API, never echoed in
ApplicationDetail (CreateApplication/DescribeApplication) — only
ListTagsForResource returns them. TagResource enforces AWS's 50
user-defined-tag ceiling (TooManyTagsException) on both CreateApplication
and TagResource.
docs/services/kinesisanalytics.md's action table is auto-generated from the
handler source (tools/docs/regen_action_docs.py) — regenerated it and filled
in the three new rows' hand-written descriptions.
* feat(kinesisanalytics): inject EnvironmentProperties into the Flink cluster
CreateApplication now accepts ApplicationConfiguration.EnvironmentProperties
.PropertyGroups and writes them to /etc/flink/application_properties.json in
both the JobManager and TaskManager containers before the job runs — the
same well-known path and JSON shape (a list of {PropertyGroupId, PropertyMap}
objects, matching the AWS API's own PropertyGroups shape) real Managed
Service for Apache Flink uses, so a JAR written against
KinesisAnalyticsRuntime.getApplicationProperties() picks them up unmodified
against Floci. DescribeApplication echoes them back under
ApplicationConfigurationDescription.EnvironmentPropertyDescriptions
.PropertyGroupDescriptions.
/etc/flink does not exist in the stock apache/flink image, and the
container's non-root "flink" user (uid 9999) can't create it directly under
/etc (confirmed live: mkdir -p /etc/flink fails with permission denied as
that user). The fix, also verified live: name the tar entry
"flink/application_properties.json" and extract into the existing /etc
rather than targeting /etc/flink directly — the daemon-level copy API can
create the missing subdirectory as part of unpacking the archive even
though the in-container user couldn't, landing as root:root 775 (so it's
still world-readable by the flink user). A real apache/flink:1.18 container
was used to verify both the failure mode and the fix before writing the
Java implementation.
* feat(kinesisanalytics): add application snapshot (savepoint) support
Adds CreateApplicationSnapshot/DescribeApplicationSnapshot/ListApplicationSnapshots/
DeleteApplicationSnapshot. Triggers a real Flink savepoint of the running job and
polls it to completion the same way StartApplication polls job readiness. Snapshot
files land on a persistent named Docker volume mounted at /opt/flink/savepoints in
the JobManager container, so they survive a Stop/Start cycle; the volume is only
removed on DeleteApplication.
* feat(kinesisanalytics): support in-place application code updates
UpdateApplication with a new ApplicationCodeConfigurationUpdate (or
ParallelismConfigurationUpdate) now redeploys onto an already-running application
without tearing down its JobManager/TaskManager containers: the current job is
cancelled and the new JAR is uploaded and run on the same cluster, transitioning
RUNNING -> STARTING -> RUNNING the same way StartApplication submits a fresh job.
Updating a READY application just stores the new code location for the next
StartApplication. Attaching code to a running bare cluster for the first time is
not yet supported and is rejected with InvalidRequestException.
* fix(kinesisanalytics): use AWS's documented generic InternalFailure code
startApplication and updateApplication's redeploy-code path threw an invented
"InternalFailureException" for unexpected Docker provisioning failures — not a
shape kinesisanalyticsv2's model declares (no operation in this API declares any
5xx shape at all). AWS documents "InternalFailure" (no "Exception" suffix, HTTP
500) as the generic error common to every service's API; it's also already the
default used elsewhere in this codebase (JsonErrorResponseUtils, KMS, Pricing,
SES, CloudControl, EventBridge, and others).
* feat(kinesisanalytics): add CreateApplicationPresignedUrl and SnapshotsEnabled
CreateApplicationPresignedUrl returns a URL to the running application's Flink
Dashboard (UrlType: FLINK_DASHBOARD_URL only; Zeppelin/Studio isn't supported).
Floci has no real session/proxy layer for this, so it returns the JobManager
container's own REST/dashboard URL directly, while still validating UrlType and
SessionExpirationDurationInSeconds against AWS's documented constraints.
ApplicationSnapshotConfiguration.SnapshotsEnabled (default true, matching real
AWS) is now honored on CreateApplication and toggleable via UpdateApplication's
ApplicationSnapshotConfigurationUpdate; CreateApplicationSnapshot rejects the
request with InvalidRequestException while disabled.
* fix(kinesisanalytics): persist flinkJobId as soon as the job is submitted
The readiness poller only called putApplication when advanceToRunning reported
RUNNING, not when it merely assigned flinkJobId after submitting the job (which
returns false until the job state catches up). pendingJars — a separate,
in-process-only cache — is already cleared by that point, so an emulator
restart between job submission and reaching RUNNING would leave the
application stuck: no persisted flinkJobId to resume polling, and no cached
JAR left to resubmit.
This commit is contained in:
1 parent
3b760bd8e5
commit
d78520d5cb
33 files changed
+4250
-4
No files matched your search
@@ -69,6 +69,7 @@ class EmulatorLifecycleTest {
|
||||
@Mock private NeptuneContainerManager neptuneContainerManager;
|
||||
@Mock private NeptuneProxyManager neptuneProxyManager;
|
||||
@Mock private io.github.hectorvent.floci.services.amazonmq.container.RabbitMqManager rabbitMqManager;
|
||||
@Mock private io.github.hectorvent.floci.services.kinesisanalytics.container.FlinkContainerManager flinkContainerManager;
|
||||
@Mock private RdsService rdsService;
|
||||
@Mock private io.github.hectorvent.floci.services.elbv2.ElbV2Service elbV2Service;
|
||||
@Mock private InitializationHooksRunner initializationHooksRunner;
|
||||
@@ -103,7 +104,7 @@ class EmulatorLifecycleTest {
|
||||
elastiCacheProxyManager, rdsContainerManager, rdsProxyManager,
|
||||
memoryDbContainerManager, memoryDbProxyManager,
|
||||
docDbContainerManager, neptuneContainerManager, neptuneProxyManager,
|
||||
rabbitMqManager, rdsService, elbV2Service,
|
||||
rabbitMqManager, flinkContainerManager, rdsService, elbV2Service,
|
||||
initializationHooksRunner, sqsPoller, kinesisPoller, dynamodbStreamsPoller,
|
||||
pipesService, ec2MetadataServer, ecrRegistryManager, flociUiManager, initLifecycleState,
|
||||
schemaCreationWorker, containerTeardowns, persistentPathValidator);
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package io.github.hectorvent.floci.services.kinesisanalytics;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class KinesisAnalyticsRuntimesTest {
|
||||
|
||||
@Test
|
||||
void imageForMapsRuntimeToFlinkTag() {
|
||||
assertEquals("apache/flink:1.18", KinesisAnalyticsRuntimes.imageFor("FLINK-1_18"));
|
||||
assertEquals("apache/flink:1.19", KinesisAnalyticsRuntimes.imageFor("FLINK-1_19"));
|
||||
assertEquals("apache/flink:1.20", KinesisAnalyticsRuntimes.imageFor("FLINK-1_20"));
|
||||
// Flink 2.x line
|
||||
assertEquals("apache/flink:2.0", KinesisAnalyticsRuntimes.imageFor("FLINK-2_0"));
|
||||
assertEquals("apache/flink:2.2", KinesisAnalyticsRuntimes.imageFor("FLINK-2_2"));
|
||||
assertEquals("apache/flink:2.3", KinesisAnalyticsRuntimes.imageFor("FLINK-2_3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void imageForFallsBackToDefaultWhenBlank() {
|
||||
assertEquals(KinesisAnalyticsRuntimes.imageFor(KinesisAnalyticsRuntimes.DEFAULT_RUNTIME),
|
||||
KinesisAnalyticsRuntimes.imageFor(null));
|
||||
assertEquals(KinesisAnalyticsRuntimes.imageFor(KinesisAnalyticsRuntimes.DEFAULT_RUNTIME),
|
||||
KinesisAnalyticsRuntimes.imageFor(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void imageForRejectsUnsupportedRuntime() {
|
||||
// SQL / ZEPPELIN studio runtimes and bogus values have no plain Flink image.
|
||||
assertThrows(AwsException.class, () -> KinesisAnalyticsRuntimes.imageFor("SQL-1_0"));
|
||||
assertThrows(AwsException.class, () -> KinesisAnalyticsRuntimes.imageFor("FLINK-9_9"));
|
||||
// AWS does not offer 1.16 / 1.17, so Floci rejects them too.
|
||||
assertThrows(AwsException.class, () -> KinesisAnalyticsRuntimes.imageFor("FLINK-1_16"));
|
||||
assertThrows(AwsException.class, () -> KinesisAnalyticsRuntimes.imageFor("FLINK-1_17"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateAllowsSupportedAndBlankButRejectsUnknown() {
|
||||
KinesisAnalyticsRuntimes.validate("FLINK-1_20");
|
||||
KinesisAnalyticsRuntimes.validate(null);
|
||||
assertThrows(AwsException.class, () -> KinesisAnalyticsRuntimes.validate("ZEPPELIN-FLINK-3_0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveImageHonoursOperatorOverride() {
|
||||
// A configured override wins regardless of the requested runtime.
|
||||
assertEquals("registry.example.com/flink:pinned",
|
||||
KinesisAnalyticsRuntimes.resolveImage(
|
||||
Optional.of("registry.example.com/flink:pinned"), "FLINK-1_18"));
|
||||
// Blank/absent override falls back to the runtime map.
|
||||
assertEquals("apache/flink:1.19",
|
||||
KinesisAnalyticsRuntimes.resolveImage(Optional.empty(), "FLINK-1_19"));
|
||||
assertEquals("apache/flink:1.19",
|
||||
KinesisAnalyticsRuntimes.resolveImage(Optional.of(" "), "FLINK-1_19"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportedRuntimesListsFlinkVersions() {
|
||||
assertTrue(KinesisAnalyticsRuntimes.supportedRuntimes().contains("FLINK-1_18"));
|
||||
}
|
||||
}
|
||||
+399
@@ -0,0 +1,399 @@
|
||||
package io.github.hectorvent.floci.services.kinesisanalytics;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.json.config.JsonPathConfig;
|
||||
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.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* Drives the full JSON-1.1 dispatch path (AwsJson11Controller → ResolvedServiceCatalog →
|
||||
* KinesisAnalyticsV2JsonHandler) via the {@code KinesisAnalytics_20180523.} target prefix.
|
||||
* Runs with {@code kinesis-analytics.mock=true} (see src/test/resources/application.yml), so no
|
||||
* Docker daemon is needed — StartApplication comes up RUNNING immediately.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class KinesisAnalyticsV2IntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/x";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private void createApplication(String name) {
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "%s", "RuntimeEnvironment": "FLINK-1_18",
|
||||
"ServiceExecutionRole": "%s"}
|
||||
""".formatted(name, ROLE))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ApplicationDetail.ApplicationName", equalTo(name))
|
||||
.body("ApplicationDetail.ApplicationStatus", equalTo("READY"))
|
||||
.body("ApplicationDetail.ApplicationARN", startsWith("arn:aws:kinesisanalytics:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createThenDescribeApplication() {
|
||||
createApplication("it-describe");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.DescribeApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-describe"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ApplicationDetail.ApplicationName", equalTo("it-describe"))
|
||||
.body("ApplicationDetail.RuntimeEnvironment", equalTo("FLINK-1_18"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void startApplicationTransitionsToRunning() {
|
||||
createApplication("it-start");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.StartApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-start", "RunConfiguration": {}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.DescribeApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-start"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
// mock mode: RUNNING immediately
|
||||
.body("ApplicationDetail.ApplicationStatus", equalTo("RUNNING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listApplicationsIncludesCreated() {
|
||||
createApplication("it-list");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.ListApplications")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ApplicationSummaries.ApplicationName", hasItem("it-list"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationSucceeds() {
|
||||
createApplication("it-delete");
|
||||
|
||||
// DeleteApplication validates CreateTimestamp against the stored value — fetch the real one
|
||||
// (epoch seconds). Use BigDecimal number handling: the default float extraction truncates the
|
||||
// ~10-digit epoch to ~7 significant figures, which would shift it by seconds and fail the match.
|
||||
String createTimestamp = given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.DescribeApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-delete"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath(new JsonPathConfig(JsonPathConfig.NumberReturnType.BIG_DECIMAL))
|
||||
.getString("ApplicationDetail.CreateTimestamp");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.DeleteApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{\"ApplicationName\": \"it-delete\", \"CreateTimestamp\": " + createTimestamp + "}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagLifecycleRoundTripsThroughTheWireProtocol() {
|
||||
String arn = given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-tags", "RuntimeEnvironment": "FLINK-1_18",
|
||||
"ServiceExecutionRole": "%s",
|
||||
"Tags": [{"Key": "env", "Value": "dev"}]}
|
||||
""".formatted(ROLE))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
// Tags is a list of {Key, Value} objects on this API, never echoed on ApplicationDetail.
|
||||
.body("ApplicationDetail.Tags", equalTo(null))
|
||||
.extract().path("ApplicationDetail.ApplicationARN");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.ListTagsForResource")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{\"ResourceARN\": \"" + arn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.Key", hasItem("env"))
|
||||
.body("Tags.Value", hasItem("dev"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.TagResource")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{\"ResourceARN\": \"" + arn + "\", \"Tags\": [{\"Key\": \"team\", \"Value\": \"platform\"}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.UntagResource")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{\"ResourceARN\": \"" + arn + "\", \"TagKeys\": [\"env\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.ListTagsForResource")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{\"ResourceARN\": \"" + arn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.Key", hasItem("team"))
|
||||
.body("Tags.Key", not(hasItem("env")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationWithNewCodeLocationRoundTripsThroughTheWireProtocol() {
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-update-code", "RuntimeEnvironment": "FLINK-1_18",
|
||||
"ServiceExecutionRole": "%s",
|
||||
"ApplicationConfiguration": {"ApplicationCodeConfiguration": {
|
||||
"CodeContent": {"S3ContentLocation": {
|
||||
"BucketARN": "arn:aws:s3:::flink-code", "FileKey": "app.jar"}},
|
||||
"CodeContentType": "ZIPFILE"}}}
|
||||
""".formatted(ROLE))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.UpdateApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-update-code", "CurrentApplicationVersionId": 1,
|
||||
"ApplicationConfigurationUpdate": {"ApplicationCodeConfigurationUpdate": {
|
||||
"CodeContentUpdate": {"S3ContentLocationUpdate": {
|
||||
"BucketARNUpdate": "arn:aws:s3:::flink-code-v2",
|
||||
"FileKeyUpdate": "app-v2.jar"}}}}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ApplicationDetail.ApplicationVersionId", equalTo(2))
|
||||
.body("ApplicationDetail.ApplicationConfigurationDescription"
|
||||
+ ".ApplicationCodeConfigurationDescription.CodeContentDescription"
|
||||
+ ".S3ApplicationCodeLocationDescription.BucketARN", equalTo("arn:aws:s3:::flink-code-v2"))
|
||||
.body("ApplicationDetail.ApplicationConfigurationDescription"
|
||||
+ ".ApplicationCodeConfigurationDescription.CodeContentDescription"
|
||||
+ ".S3ApplicationCodeLocationDescription.FileKey", equalTo("app-v2.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void snapshotLifecycleRoundTripsThroughTheWireProtocol() {
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-snapshot", "RuntimeEnvironment": "FLINK-1_18",
|
||||
"ServiceExecutionRole": "%s",
|
||||
"ApplicationConfiguration": {"ApplicationCodeConfiguration": {
|
||||
"CodeContent": {"S3ContentLocation": {
|
||||
"BucketARN": "arn:aws:s3:::flink-code", "FileKey": "app.jar"}},
|
||||
"CodeContentType": "ZIPFILE"}}}
|
||||
""".formatted(ROLE))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.StartApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-snapshot", "RunConfiguration": {}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplicationSnapshot")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-snapshot", "SnapshotName": "before-upgrade"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String creationTimestamp = given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.DescribeApplicationSnapshot")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-snapshot", "SnapshotName": "before-upgrade"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SnapshotDetails.SnapshotName", equalTo("before-upgrade"))
|
||||
// mock mode: the snapshot completes immediately, same as the application itself.
|
||||
.body("SnapshotDetails.SnapshotStatus", equalTo("READY"))
|
||||
.extract().jsonPath(new JsonPathConfig(JsonPathConfig.NumberReturnType.BIG_DECIMAL))
|
||||
.getString("SnapshotDetails.SnapshotCreationTimestamp");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.ListApplicationSnapshots")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-snapshot"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SnapshotSummaries.SnapshotName", hasItem("before-upgrade"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.DeleteApplicationSnapshot")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{\"ApplicationName\": \"it-snapshot\", \"SnapshotName\": \"before-upgrade\", "
|
||||
+ "\"SnapshotCreationTimestamp\": " + creationTimestamp + "}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.ListApplicationSnapshots")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-snapshot"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SnapshotSummaries", equalTo(java.util.List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationWithSnapshotsDisabledRejectsCreateApplicationSnapshot() {
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-nosnaps", "RuntimeEnvironment": "FLINK-1_18",
|
||||
"ServiceExecutionRole": "%s",
|
||||
"ApplicationConfiguration": {"ApplicationCodeConfiguration": {
|
||||
"CodeContent": {"S3ContentLocation": {
|
||||
"BucketARN": "arn:aws:s3:::flink-code", "FileKey": "app.jar"}},
|
||||
"CodeContentType": "ZIPFILE"},
|
||||
"ApplicationSnapshotConfiguration": {"SnapshotsEnabled": false}}}
|
||||
""".formatted(ROLE))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.StartApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-nosnaps", "RunConfiguration": {}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplicationSnapshot")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-nosnaps", "SnapshotName": "attempt"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlRejectsWhenNotRunning() {
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplication")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-presigned", "RuntimeEnvironment": "FLINK-1_18",
|
||||
"ServiceExecutionRole": "%s"}
|
||||
""".formatted(ROLE))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "KinesisAnalytics_20180523.CreateApplicationPresignedUrl")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ApplicationName": "it-presigned", "UrlType": "FLINK_DASHBOARD_URL"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
+430
@@ -0,0 +1,430 @@
|
||||
package io.github.hectorvent.floci.services.kinesisanalytics;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.kinesisanalytics.container.FlinkContainerManager;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class KinesisAnalyticsV2JsonHandlerTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/x";
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private KinesisAnalyticsV2JsonHandler handler;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
handler = new KinesisAnalyticsV2JsonHandler(mockModeService(), MAPPER);
|
||||
}
|
||||
|
||||
private ObjectNode entity(Response response) {
|
||||
return (ObjectNode) response.getEntity();
|
||||
}
|
||||
|
||||
private void createApplication(String name) {
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", name);
|
||||
req.put("RuntimeEnvironment", "FLINK-1_18");
|
||||
req.put("ServiceExecutionRole", ROLE);
|
||||
assertThat(handler.handle("CreateApplication", req, REGION).getStatus(), is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationReturnsReadyDetail() {
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "demo");
|
||||
req.put("RuntimeEnvironment", "FLINK-1_18");
|
||||
req.put("ServiceExecutionRole", ROLE);
|
||||
|
||||
Response resp = handler.handle("CreateApplication", req, REGION);
|
||||
assertThat(resp.getStatus(), is(200));
|
||||
ObjectNode detail = (ObjectNode) entity(resp).get("ApplicationDetail");
|
||||
assertEquals("demo", detail.get("ApplicationName").asText());
|
||||
assertEquals("READY", detail.get("ApplicationStatus").asText());
|
||||
assertEquals(1, detail.get("ApplicationVersionId").asLong());
|
||||
assertThat(detail.get("ApplicationARN").asText().contains(":kinesisanalytics:"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeApplicationReturnsDetail() {
|
||||
createApplication("demo");
|
||||
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "demo");
|
||||
Response resp = handler.handle("DescribeApplication", req, REGION);
|
||||
assertThat(resp.getStatus(), is(200));
|
||||
ObjectNode detail = (ObjectNode) entity(resp).get("ApplicationDetail");
|
||||
assertEquals("demo", detail.get("ApplicationName").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startThenDescribeShowsRunning() {
|
||||
createApplication("demo");
|
||||
|
||||
ObjectNode start = MAPPER.createObjectNode();
|
||||
start.put("ApplicationName", "demo");
|
||||
assertThat(handler.handle("StartApplication", start, REGION).getStatus(), is(200));
|
||||
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("ApplicationName", "demo");
|
||||
ObjectNode detail = (ObjectNode) entity(handler.handle("DescribeApplication", describe, REGION))
|
||||
.get("ApplicationDetail");
|
||||
// Mock mode: the application comes up RUNNING immediately.
|
||||
assertEquals("RUNNING", detail.get("ApplicationStatus").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listApplicationsIncludesCreated() {
|
||||
createApplication("demo-a");
|
||||
createApplication("demo-b");
|
||||
|
||||
Response resp = handler.handle("ListApplications", MAPPER.createObjectNode(), REGION);
|
||||
assertThat(resp.getStatus(), is(200));
|
||||
var summaries = entity(resp).get("ApplicationSummaries");
|
||||
assertEquals(2, summaries.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationRemovesIt() {
|
||||
createApplication("demo");
|
||||
|
||||
// DeleteApplication requires the app's CreateTimestamp (epoch seconds).
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("ApplicationName", "demo");
|
||||
double createTs = ((ObjectNode) entity(handler.handle("DescribeApplication", describe, REGION))
|
||||
.get("ApplicationDetail")).get("CreateTimestamp").asDouble();
|
||||
|
||||
ObjectNode del = MAPPER.createObjectNode();
|
||||
del.put("ApplicationName", "demo");
|
||||
del.put("CreateTimestamp", createTs);
|
||||
assertThat(handler.handle("DeleteApplication", del, REGION).getStatus(), is(200));
|
||||
|
||||
var summaries = entity(handler.handle("ListApplications", MAPPER.createObjectNode(), REGION))
|
||||
.get("ApplicationSummaries");
|
||||
assertEquals(0, summaries.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithCodeConfigEchoesItOnDescribe() {
|
||||
ObjectNode s3 = MAPPER.createObjectNode();
|
||||
s3.put("BucketARN", "arn:aws:s3:::flink-code");
|
||||
s3.put("FileKey", "app.jar");
|
||||
ObjectNode codeCfg = MAPPER.createObjectNode();
|
||||
codeCfg.set("CodeContent", MAPPER.createObjectNode().set("S3ContentLocation", s3));
|
||||
codeCfg.put("CodeContentType", "ZIPFILE");
|
||||
ObjectNode flinkCfg = MAPPER.createObjectNode();
|
||||
flinkCfg.set("ParallelismConfiguration", MAPPER.createObjectNode().put("Parallelism", 3));
|
||||
ObjectNode appCfg = MAPPER.createObjectNode();
|
||||
appCfg.set("ApplicationCodeConfiguration", codeCfg);
|
||||
appCfg.set("FlinkApplicationConfiguration", flinkCfg);
|
||||
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "coded");
|
||||
req.put("RuntimeEnvironment", "FLINK-1_18");
|
||||
req.put("ServiceExecutionRole", ROLE);
|
||||
req.set("ApplicationConfiguration", appCfg);
|
||||
assertThat(handler.handle("CreateApplication", req, REGION).getStatus(), is(200));
|
||||
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("ApplicationName", "coded");
|
||||
ObjectNode detail = (ObjectNode) entity(handler.handle("DescribeApplication", describe, REGION))
|
||||
.get("ApplicationDetail");
|
||||
var loc = detail.get("ApplicationConfigurationDescription")
|
||||
.get("ApplicationCodeConfigurationDescription")
|
||||
.get("CodeContentDescription").get("S3ApplicationCodeLocationDescription");
|
||||
assertEquals("arn:aws:s3:::flink-code", loc.get("BucketARN").asText());
|
||||
assertEquals("app.jar", loc.get("FileKey").asText());
|
||||
assertEquals(3, detail.get("ApplicationConfigurationDescription")
|
||||
.get("FlinkApplicationConfigurationDescription")
|
||||
.get("ParallelismConfigurationDescription").get("Parallelism").asInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithEnvironmentPropertiesEchoesThemOnDescribe() {
|
||||
ObjectNode s3 = MAPPER.createObjectNode();
|
||||
s3.put("BucketARN", "arn:aws:s3:::flink-code");
|
||||
s3.put("FileKey", "app.jar");
|
||||
ObjectNode codeCfg = MAPPER.createObjectNode();
|
||||
codeCfg.set("CodeContent", MAPPER.createObjectNode().set("S3ContentLocation", s3));
|
||||
ObjectNode propertyGroup = MAPPER.createObjectNode();
|
||||
propertyGroup.put("PropertyGroupId", "ProducerConfigProperties");
|
||||
propertyGroup.set("PropertyMap", MAPPER.createObjectNode().put("aws.region", "us-west-2"));
|
||||
ObjectNode envProps = MAPPER.createObjectNode();
|
||||
envProps.putArray("PropertyGroups").add(propertyGroup);
|
||||
ObjectNode appCfg = MAPPER.createObjectNode();
|
||||
appCfg.set("ApplicationCodeConfiguration", codeCfg);
|
||||
appCfg.set("EnvironmentProperties", envProps);
|
||||
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "envprops");
|
||||
req.put("RuntimeEnvironment", "FLINK-1_18");
|
||||
req.put("ServiceExecutionRole", ROLE);
|
||||
req.set("ApplicationConfiguration", appCfg);
|
||||
assertThat(handler.handle("CreateApplication", req, REGION).getStatus(), is(200));
|
||||
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("ApplicationName", "envprops");
|
||||
ObjectNode detail = (ObjectNode) entity(handler.handle("DescribeApplication", describe, REGION))
|
||||
.get("ApplicationDetail");
|
||||
var groups = detail.get("ApplicationConfigurationDescription")
|
||||
.get("EnvironmentPropertyDescriptions").get("PropertyGroupDescriptions");
|
||||
assertEquals(1, groups.size());
|
||||
assertEquals("ProducerConfigProperties", groups.get(0).get("PropertyGroupId").asText());
|
||||
assertEquals("us-west-2", groups.get(0).get("PropertyMap").get("aws.region").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationDefaultsSnapshotsEnabledToTrueOnDescribe() {
|
||||
createApplication("demo");
|
||||
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("ApplicationName", "demo");
|
||||
ObjectNode detail = (ObjectNode) entity(handler.handle("DescribeApplication", describe, REGION))
|
||||
.get("ApplicationDetail");
|
||||
// No code configured, so ApplicationConfigurationDescription isn't built at all — matches how
|
||||
// EnvironmentPropertyDescriptions is also only ever echoed when the app has code.
|
||||
assertThat(detail.has("ApplicationConfigurationDescription"), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationWithSnapshotsDisabledEchoesItOnDescribe() {
|
||||
ObjectNode s3 = MAPPER.createObjectNode();
|
||||
s3.put("BucketARN", "arn:aws:s3:::flink-code");
|
||||
s3.put("FileKey", "app.jar");
|
||||
ObjectNode codeCfg = MAPPER.createObjectNode();
|
||||
codeCfg.set("CodeContent", MAPPER.createObjectNode().set("S3ContentLocation", s3));
|
||||
ObjectNode appCfg = MAPPER.createObjectNode();
|
||||
appCfg.set("ApplicationCodeConfiguration", codeCfg);
|
||||
appCfg.set("ApplicationSnapshotConfiguration",
|
||||
MAPPER.createObjectNode().put("SnapshotsEnabled", false));
|
||||
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "nosnaps");
|
||||
req.put("RuntimeEnvironment", "FLINK-1_18");
|
||||
req.put("ServiceExecutionRole", ROLE);
|
||||
req.set("ApplicationConfiguration", appCfg);
|
||||
assertThat(handler.handle("CreateApplication", req, REGION).getStatus(), is(200));
|
||||
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("ApplicationName", "nosnaps");
|
||||
ObjectNode detail = (ObjectNode) entity(handler.handle("DescribeApplication", describe, REGION))
|
||||
.get("ApplicationDetail");
|
||||
assertThat(detail.get("ApplicationConfigurationDescription")
|
||||
.get("ApplicationSnapshotConfigurationDescription").get("SnapshotsEnabled").asBoolean(), is(false));
|
||||
|
||||
ObjectNode createSnap = MAPPER.createObjectNode();
|
||||
createSnap.put("ApplicationName", "nosnaps");
|
||||
createSnap.put("SnapshotName", "attempt");
|
||||
assertThrows(AwsException.class, () -> handler.handle("CreateApplicationSnapshot", createSnap, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlRejectsUnsupportedUrlType() {
|
||||
createApplication("demo");
|
||||
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "demo");
|
||||
req.put("UrlType", "ZEPPELIN_UI_URL");
|
||||
assertThrows(AwsException.class, () -> handler.handle("CreateApplicationPresignedUrl", req, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlRejectsWhenNotRunning() {
|
||||
createApplication("demo"); // READY, never started
|
||||
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "demo");
|
||||
req.put("UrlType", "FLINK_DASHBOARD_URL");
|
||||
assertThrows(AwsException.class, () -> handler.handle("CreateApplicationPresignedUrl", req, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationWithNewCodeLocationEchoesItOnDescribe() {
|
||||
createRunningCodedApplication("redeploy-target");
|
||||
|
||||
ObjectNode s3Update = MAPPER.createObjectNode();
|
||||
s3Update.put("BucketARNUpdate", "arn:aws:s3:::flink-code-v2");
|
||||
s3Update.put("FileKeyUpdate", "app-v2.jar");
|
||||
ObjectNode codeCfgUpdate = MAPPER.createObjectNode();
|
||||
codeCfgUpdate.set("CodeContentUpdate", MAPPER.createObjectNode().set("S3ContentLocationUpdate", s3Update));
|
||||
ObjectNode appCfgUpdate = MAPPER.createObjectNode();
|
||||
appCfgUpdate.set("ApplicationCodeConfigurationUpdate", codeCfgUpdate);
|
||||
|
||||
ObjectNode updateReq = MAPPER.createObjectNode();
|
||||
updateReq.put("ApplicationName", "redeploy-target");
|
||||
updateReq.put("CurrentApplicationVersionId", 1L);
|
||||
updateReq.set("ApplicationConfigurationUpdate", appCfgUpdate);
|
||||
Response updated = handler.handle("UpdateApplication", updateReq, REGION);
|
||||
assertThat(updated.getStatus(), is(200));
|
||||
ObjectNode detail = (ObjectNode) entity(updated).get("ApplicationDetail");
|
||||
assertEquals(2L, detail.get("ApplicationVersionId").asLong());
|
||||
|
||||
var loc = detail.get("ApplicationConfigurationDescription")
|
||||
.get("ApplicationCodeConfigurationDescription")
|
||||
.get("CodeContentDescription").get("S3ApplicationCodeLocationDescription");
|
||||
assertEquals("arn:aws:s3:::flink-code-v2", loc.get("BucketARN").asText());
|
||||
assertEquals("app-v2.jar", loc.get("FileKey").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedActionReturns400() {
|
||||
Response resp = handler.handle("BogusAction", MAPPER.createObjectNode(), REGION);
|
||||
assertThat(resp.getStatus(), is(400));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationWithTagsThenListTagsForResourceRoundTrips() {
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", "tagged");
|
||||
req.put("RuntimeEnvironment", "FLINK-1_18");
|
||||
req.put("ServiceExecutionRole", ROLE);
|
||||
req.putArray("Tags")
|
||||
.addObject().put("Key", "env").put("Value", "dev");
|
||||
Response created = handler.handle("CreateApplication", req, REGION);
|
||||
assertThat(created.getStatus(), is(200));
|
||||
// Tags is a list of {Key, Value} objects on this API, never echoed on ApplicationDetail.
|
||||
assertThat(entity(created).get("ApplicationDetail").has("Tags"), is(false));
|
||||
|
||||
String arn = entity(created).get("ApplicationDetail").get("ApplicationARN").asText();
|
||||
ObjectNode listReq = MAPPER.createObjectNode();
|
||||
listReq.put("ResourceARN", arn);
|
||||
Response listed = handler.handle("ListTagsForResource", listReq, REGION);
|
||||
assertThat(listed.getStatus(), is(200));
|
||||
var tags = entity(listed).get("Tags");
|
||||
assertEquals(1, tags.size());
|
||||
assertEquals("env", tags.get(0).get("Key").asText());
|
||||
assertEquals("dev", tags.get(0).get("Value").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceThenUntagResourceRoundTrips() {
|
||||
createApplication("demo");
|
||||
String arn = describeArn("demo");
|
||||
|
||||
ObjectNode tagReq = MAPPER.createObjectNode();
|
||||
tagReq.put("ResourceARN", arn);
|
||||
tagReq.putArray("Tags").addObject().put("Key", "team").put("Value", "platform");
|
||||
assertThat(handler.handle("TagResource", tagReq, REGION).getStatus(), is(200));
|
||||
|
||||
ObjectNode listReq = MAPPER.createObjectNode();
|
||||
listReq.put("ResourceARN", arn);
|
||||
assertEquals(1, entity(handler.handle("ListTagsForResource", listReq, REGION)).get("Tags").size());
|
||||
|
||||
ObjectNode untagReq = MAPPER.createObjectNode();
|
||||
untagReq.put("ResourceARN", arn);
|
||||
untagReq.putArray("TagKeys").add("team");
|
||||
assertThat(handler.handle("UntagResource", untagReq, REGION).getStatus(), is(200));
|
||||
|
||||
assertEquals(0, entity(handler.handle("ListTagsForResource", listReq, REGION)).get("Tags").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotThenDescribeAndListThenDeleteRoundTrips() {
|
||||
createRunningCodedApplication("streaming");
|
||||
|
||||
ObjectNode createSnap = MAPPER.createObjectNode();
|
||||
createSnap.put("ApplicationName", "streaming");
|
||||
createSnap.put("SnapshotName", "before-upgrade");
|
||||
assertThat(handler.handle("CreateApplicationSnapshot", createSnap, REGION).getStatus(), is(200));
|
||||
|
||||
ObjectNode describeSnap = MAPPER.createObjectNode();
|
||||
describeSnap.put("ApplicationName", "streaming");
|
||||
describeSnap.put("SnapshotName", "before-upgrade");
|
||||
Response described = handler.handle("DescribeApplicationSnapshot", describeSnap, REGION);
|
||||
assertThat(described.getStatus(), is(200));
|
||||
ObjectNode details = (ObjectNode) entity(described).get("SnapshotDetails");
|
||||
assertEquals("before-upgrade", details.get("SnapshotName").asText());
|
||||
// Mock mode: the snapshot completes immediately, same as the application itself.
|
||||
assertEquals("READY", details.get("SnapshotStatus").asText());
|
||||
double creationTimestamp = details.get("SnapshotCreationTimestamp").asDouble();
|
||||
|
||||
Response listed = handler.handle("ListApplicationSnapshots",
|
||||
MAPPER.createObjectNode().put("ApplicationName", "streaming"), REGION);
|
||||
assertThat(listed.getStatus(), is(200));
|
||||
var summaries = entity(listed).get("SnapshotSummaries");
|
||||
assertEquals(1, summaries.size());
|
||||
assertEquals("before-upgrade", summaries.get(0).get("SnapshotName").asText());
|
||||
|
||||
ObjectNode deleteSnap = MAPPER.createObjectNode();
|
||||
deleteSnap.put("ApplicationName", "streaming");
|
||||
deleteSnap.put("SnapshotName", "before-upgrade");
|
||||
deleteSnap.put("SnapshotCreationTimestamp", creationTimestamp);
|
||||
assertThat(handler.handle("DeleteApplicationSnapshot", deleteSnap, REGION).getStatus(), is(200));
|
||||
|
||||
var afterDelete = entity(handler.handle("ListApplicationSnapshots",
|
||||
MAPPER.createObjectNode().put("ApplicationName", "streaming"), REGION)).get("SnapshotSummaries");
|
||||
assertEquals(0, afterDelete.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotFailsWhenApplicationNotRunning() {
|
||||
createApplication("demo");
|
||||
|
||||
ObjectNode createSnap = MAPPER.createObjectNode();
|
||||
createSnap.put("ApplicationName", "demo");
|
||||
createSnap.put("SnapshotName", "before-upgrade");
|
||||
assertThrows(AwsException.class, () -> handler.handle("CreateApplicationSnapshot", createSnap, REGION));
|
||||
}
|
||||
|
||||
private void createRunningCodedApplication(String name) {
|
||||
ObjectNode s3 = MAPPER.createObjectNode();
|
||||
s3.put("BucketARN", "arn:aws:s3:::flink-code");
|
||||
s3.put("FileKey", "app.jar");
|
||||
ObjectNode codeCfg = MAPPER.createObjectNode();
|
||||
codeCfg.set("CodeContent", MAPPER.createObjectNode().set("S3ContentLocation", s3));
|
||||
codeCfg.put("CodeContentType", "ZIPFILE");
|
||||
ObjectNode appCfg = MAPPER.createObjectNode();
|
||||
appCfg.set("ApplicationCodeConfiguration", codeCfg);
|
||||
|
||||
ObjectNode req = MAPPER.createObjectNode();
|
||||
req.put("ApplicationName", name);
|
||||
req.put("RuntimeEnvironment", "FLINK-1_18");
|
||||
req.put("ServiceExecutionRole", ROLE);
|
||||
req.set("ApplicationConfiguration", appCfg);
|
||||
assertThat(handler.handle("CreateApplication", req, REGION).getStatus(), is(200));
|
||||
|
||||
ObjectNode start = MAPPER.createObjectNode();
|
||||
start.put("ApplicationName", name);
|
||||
assertThat(handler.handle("StartApplication", start, REGION).getStatus(), is(200));
|
||||
}
|
||||
|
||||
private String describeArn(String name) {
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("ApplicationName", name);
|
||||
return entity(handler.handle("DescribeApplication", describe, REGION))
|
||||
.get("ApplicationDetail").get("ApplicationARN").asText();
|
||||
}
|
||||
|
||||
private KinesisAnalyticsV2Service mockModeService() {
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenReturn(new InMemoryStorage<>());
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
|
||||
var kaConfig = Mockito.mock(EmulatorConfig.KinesisAnalyticsServiceConfig.class);
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.kinesisAnalytics()).thenReturn(kaConfig);
|
||||
when(kaConfig.mock()).thenReturn(true);
|
||||
when(config.defaultRegion()).thenReturn("us-east-1");
|
||||
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
return new KinesisAnalyticsV2Service(storageFactory, config, regionResolver,
|
||||
Mockito.mock(FlinkContainerManager.class));
|
||||
}
|
||||
}
|
||||
+625
@@ -0,0 +1,625 @@
|
||||
package io.github.hectorvent.floci.services.kinesisanalytics;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.kinesisanalytics.container.FlinkContainerManager;
|
||||
import io.github.hectorvent.floci.services.kinesisanalytics.model.ApplicationStatus;
|
||||
import io.github.hectorvent.floci.services.kinesisanalytics.model.FlinkApplication;
|
||||
import io.github.hectorvent.floci.services.kinesisanalytics.model.Snapshot;
|
||||
import io.github.hectorvent.floci.services.kinesisanalytics.model.SnapshotStatus;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class KinesisAnalyticsV2ServiceTest {
|
||||
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/x";
|
||||
|
||||
private KinesisAnalyticsV2Service service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = mockModeService();
|
||||
}
|
||||
|
||||
private FlinkApplication create(String name) {
|
||||
return service.createApplication(name, "FLINK-1_18", ROLE, "desc", "STREAMING");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationLandsInReady() {
|
||||
// AWS-faithful: a freshly created application is READY, not RUNNING.
|
||||
FlinkApplication app = create("demo");
|
||||
assertEquals("demo", app.getApplicationName());
|
||||
assertEquals("FLINK-1_18", app.getRuntimeEnvironment());
|
||||
assertEquals(ApplicationStatus.READY, app.getApplicationStatus());
|
||||
assertEquals(1L, app.getApplicationVersionId());
|
||||
assertTrue(app.getApplicationArn().contains(":kinesisanalytics:"));
|
||||
assertTrue(app.getApplicationArn().contains("application/demo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationRequiresName() {
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.createApplication(" ", "FLINK-1_18", ROLE, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationRequiresRuntimeEnvironment() {
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.createApplication("demo", null, ROLE, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationRequiresServiceExecutionRole() {
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.createApplication("demo", "FLINK-1_18", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationRejectsUnsupportedRuntime() {
|
||||
// SQL/ZEPPELIN studio runtimes and bogus values are not backable with a Flink image.
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.createApplication("demo", "ZEPPELIN-FLINK-3_0", ROLE, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationRejectsDuplicateName() {
|
||||
create("demo");
|
||||
assertThrows(AwsException.class, () -> create("demo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeApplicationThrowsWhenMissing() {
|
||||
assertThrows(AwsException.class, () -> service.describeApplication("nope"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void startApplicationRunsInMockMode() {
|
||||
create("demo");
|
||||
FlinkApplication started = service.startApplication("demo");
|
||||
// In mock mode there is no container: the application comes up RUNNING immediately.
|
||||
assertEquals(ApplicationStatus.RUNNING, started.getApplicationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startApplicationRejectedWhenNotReady() {
|
||||
create("demo");
|
||||
service.startApplication("demo");
|
||||
// Already RUNNING → cannot start again.
|
||||
assertThrows(AwsException.class, () -> service.startApplication("demo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopApplicationReturnsToReady() {
|
||||
create("demo");
|
||||
service.startApplication("demo");
|
||||
FlinkApplication stopped = service.stopApplication("demo");
|
||||
assertEquals(ApplicationStatus.READY, stopped.getApplicationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopApplicationRejectedWhenNotRunning() {
|
||||
create("demo");
|
||||
// Still READY (never started) → cannot stop.
|
||||
assertThrows(AwsException.class, () -> service.stopApplication("demo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationBumpsVersion() {
|
||||
create("demo");
|
||||
FlinkApplication updated = service.updateApplication("demo", 1L, "arn:aws:iam::000000000000:role/y");
|
||||
assertEquals(2L, updated.getApplicationVersionId());
|
||||
assertEquals("arn:aws:iam::000000000000:role/y", updated.getServiceExecutionRole());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationRejectsStaleVersion() {
|
||||
create("demo"); // version 1
|
||||
// Optimistic concurrency: a mismatched CurrentApplicationVersionId is rejected.
|
||||
assertThrows(AwsException.class, () -> service.updateApplication("demo", 5L, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationRemovesIt() {
|
||||
FlinkApplication app = create("demo");
|
||||
service.deleteApplication("demo", app.getCreateTimestamp());
|
||||
assertTrue(service.listApplications().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationRejectsWrongTimestamp() {
|
||||
create("demo");
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.deleteApplication("demo", java.time.Instant.ofEpochSecond(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationRejectedWhileRunning() {
|
||||
FlinkApplication app = create("demo");
|
||||
service.startApplication("demo"); // mock mode → RUNNING
|
||||
// AWS rejects delete of a running application; it must be stopped first.
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.deleteApplication("demo", app.getCreateTimestamp()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void startApplicationWrapsProvisioningFailure() {
|
||||
// Real mode with a container manager that fails: the AWS envelope must not leak the
|
||||
// internal cause, but the operation must throw. "InternalFailure" (no "Exception" suffix) is
|
||||
// AWS's documented generic 500 common to every service's API, not a kinesisanalyticsv2-specific
|
||||
// shape (this service's model declares no 5xx shape at all).
|
||||
KinesisAnalyticsV2Service realMode = realModeServiceWithFailingManager();
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null);
|
||||
AwsException ex = assertThrows(AwsException.class, () -> realMode.startApplication("demo"));
|
||||
assertEquals("InternalFailure", ex.getErrorCode());
|
||||
assertEquals(500, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startApplicationPreservesAwsExceptionFromCodeFetch() {
|
||||
// A bad application-code S3 location makes startCluster throw AwsException(InvalidArgumentException).
|
||||
// It must propagate as-is (400 client error), not be masked as InternalFailure (500).
|
||||
FlinkContainerManager failing = Mockito.mock(FlinkContainerManager.class);
|
||||
Mockito.doThrow(new AwsException("InvalidArgumentException",
|
||||
"Unable to fetch application code from s3://b/missing.jar", 400))
|
||||
.when(failing).startCluster(Mockito.any());
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, failing);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> realMode.startApplication("demo"));
|
||||
assertEquals("InvalidArgumentException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationStoresCodeConfig() {
|
||||
FlinkApplication app = service.createApplication("coded", "FLINK-1_18", ROLE, null, null,
|
||||
"flink-code", "app.jar", "v2", 4);
|
||||
assertTrue(app.hasCode());
|
||||
assertEquals("flink-code", app.getCodeS3Bucket());
|
||||
assertEquals("app.jar", app.getCodeS3Key());
|
||||
assertEquals("v2", app.getCodeS3ObjectVersion());
|
||||
assertEquals(4, app.getParallelism());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationWithoutCodeHasNoCode() {
|
||||
FlinkApplication app = create("bare");
|
||||
assertFalse(app.hasCode());
|
||||
assertEquals(1, app.getParallelism());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationStoresTags() {
|
||||
FlinkApplication app = service.createApplication("tagged", "FLINK-1_18", ROLE, null, null,
|
||||
null, null, null, 1, Map.of("env", "dev"));
|
||||
assertEquals("dev", app.getTags().get("env"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationStoresEnvironmentProperties() {
|
||||
Map<String, Map<String, String>> groups = Map.of(
|
||||
"ProducerConfigProperties", Map.of("aws.region", "us-west-2"));
|
||||
FlinkApplication app = service.createApplication("props", "FLINK-1_18", ROLE, null, null,
|
||||
null, null, null, 1, null, groups);
|
||||
assertEquals("us-west-2",
|
||||
app.getEnvironmentProperties().get("ProducerConfigProperties").get("aws.region"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationDefaultsSnapshotsEnabledToTrue() {
|
||||
FlinkApplication app = create("demo");
|
||||
assertTrue(app.isSnapshotsEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationWithSnapshotsDisabled() {
|
||||
FlinkApplication app = service.createApplication("demo", "FLINK-1_18", ROLE, null, null,
|
||||
null, null, null, 1, null, null, false);
|
||||
assertFalse(app.isSnapshotsEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationRejectsTooManyTags() {
|
||||
Map<String, String> tooMany = new HashMap<>();
|
||||
for (int i = 0; i < 51; i++) {
|
||||
tooMany.put("k" + i, "v");
|
||||
}
|
||||
AwsException ex = assertThrows(AwsException.class, () -> service.createApplication(
|
||||
"tagged", "FLINK-1_18", ROLE, null, null, null, null, null, 1, tooMany));
|
||||
assertEquals("TooManyTagsException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceThenListTagsForResourceRoundTrips() {
|
||||
FlinkApplication app = create("demo");
|
||||
|
||||
Map<String, String> after = service.tagResource(app.getApplicationArn(), Map.of("team", "platform"));
|
||||
assertEquals("platform", after.get("team"));
|
||||
assertEquals("platform", service.listTagsForResource(app.getApplicationArn()).get("team"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void untagResourceRemovesKeys() {
|
||||
FlinkApplication app = create("demo");
|
||||
service.tagResource(app.getApplicationArn(), Map.of("team", "platform", "env", "dev"));
|
||||
|
||||
Map<String, String> after = service.untagResource(app.getApplicationArn(), List.of("team"));
|
||||
assertFalse(after.containsKey("team"));
|
||||
assertEquals("dev", after.get("env"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsUnknownArn() {
|
||||
assertThrows(AwsException.class, () -> service.tagResource(
|
||||
"arn:aws:kinesisanalytics:us-east-1:000000000000:application/nope", Map.of("k", "v")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsExceedingMaxTags() {
|
||||
FlinkApplication app = create("demo");
|
||||
Map<String, String> tooMany = new HashMap<>();
|
||||
for (int i = 0; i < 51; i++) {
|
||||
tooMany.put("k" + i, "v");
|
||||
}
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.tagResource(app.getApplicationArn(), tooMany));
|
||||
assertEquals("TooManyTagsException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
private FlinkApplication createRunningWithCode(String name) {
|
||||
service.createApplication(name, "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
return service.startApplication(name); // mock mode: RUNNING immediately
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotRequiresRunningApplication() {
|
||||
create("demo"); // READY, never started
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.createApplicationSnapshot("demo", "snap1"));
|
||||
assertEquals("InvalidRequestException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotRejectsWhenSnapshotsDisabled() {
|
||||
service.createApplication("demo", "FLINK-1_18", ROLE, null, null,
|
||||
"bucket", "app.jar", null, 1, null, null, false);
|
||||
service.startApplication("demo"); // mock mode: RUNNING immediately
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.createApplicationSnapshot("demo", "snap1"));
|
||||
assertEquals("InvalidRequestException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationTogglesSnapshotsEnabled() {
|
||||
FlinkApplication app = createRunningWithCode("demo");
|
||||
assertTrue(app.isSnapshotsEnabled());
|
||||
|
||||
service.updateApplication("demo", 1L, null, null, null, null, null, false);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.createApplicationSnapshot("demo", "snap1"));
|
||||
assertEquals("InvalidRequestException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotRequiresCode() {
|
||||
create("demo");
|
||||
service.startApplication("demo"); // mock mode: RUNNING even with no code
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.createApplicationSnapshot("demo", "snap1"));
|
||||
assertEquals("InvalidRequestException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotSucceedsInMockMode() {
|
||||
createRunningWithCode("demo");
|
||||
Snapshot snapshot = service.createApplicationSnapshot("demo", "snap1");
|
||||
assertEquals(SnapshotStatus.READY, snapshot.getSnapshotStatus());
|
||||
assertEquals(1L, snapshot.getApplicationVersionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotRejectsDuplicateName() {
|
||||
createRunningWithCode("demo");
|
||||
service.createApplicationSnapshot("demo", "snap1");
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.createApplicationSnapshot("demo", "snap1"));
|
||||
assertEquals("ResourceInUseException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeApplicationSnapshotThrowsWhenMissing() {
|
||||
createRunningWithCode("demo");
|
||||
assertThrows(AwsException.class, () -> service.describeApplicationSnapshot("demo", "nope"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listApplicationSnapshotsIncludesCreated() {
|
||||
createRunningWithCode("demo");
|
||||
service.createApplicationSnapshot("demo", "snap1");
|
||||
service.createApplicationSnapshot("demo", "snap2");
|
||||
assertEquals(2, service.listApplicationSnapshots("demo").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationSnapshotRemovesIt() {
|
||||
createRunningWithCode("demo");
|
||||
Snapshot snapshot = service.createApplicationSnapshot("demo", "snap1");
|
||||
service.deleteApplicationSnapshot("demo", "snap1", snapshot.getSnapshotCreationTimestamp());
|
||||
assertTrue(service.listApplicationSnapshots("demo").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationSnapshotRejectsWrongTimestamp() {
|
||||
createRunningWithCode("demo");
|
||||
service.createApplicationSnapshot("demo", "snap1");
|
||||
assertThrows(AwsException.class, () -> service.deleteApplicationSnapshot(
|
||||
"demo", "snap1", java.time.Instant.ofEpochSecond(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteApplicationSnapshotRejectsWhileStillCreating() {
|
||||
// Real mode, but the mocked FlinkContainerManager.createSnapshot never actually advances the
|
||||
// snapshot to READY/FAILED, so it stays CREATING — matching a real Flink savepoint still
|
||||
// in flight when a delete is attempted.
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
// Real mode's startApplication only marks STARTING; force RUNNING directly to isolate the
|
||||
// snapshot precondition from the readiness-poller mechanics already covered elsewhere.
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
Snapshot snapshot = realMode.createApplicationSnapshot("demo", "snap1");
|
||||
assertEquals(SnapshotStatus.CREATING, snapshot.getSnapshotStatus());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> realMode.deleteApplicationSnapshot(
|
||||
"demo", "snap1", snapshot.getSnapshotCreationTimestamp()));
|
||||
assertEquals("ResourceInUseException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationSnapshotMarksFailedWhenTriggerThrows() {
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
Mockito.doThrow(new RuntimeException("jobmanager unreachable"))
|
||||
.when(manager).createSnapshot(Mockito.any(), Mockito.any());
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
|
||||
// The trigger failure marks the snapshot FAILED rather than failing CreateApplicationSnapshot
|
||||
// itself, the same async-follow-up-failure shape job submission already uses.
|
||||
Snapshot snapshot = realMode.createApplicationSnapshot("demo", "snap1");
|
||||
assertEquals(SnapshotStatus.FAILED, snapshot.getSnapshotStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationWithNewCodeWhileReadyJustUpdatesStoredCode() {
|
||||
service.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
|
||||
FlinkApplication updated = service.updateApplication("demo", 1L, null,
|
||||
"flink-code", "v2.jar", null, null);
|
||||
|
||||
assertEquals("flink-code", updated.getCodeS3Bucket());
|
||||
assertEquals("v2.jar", updated.getCodeS3Key());
|
||||
assertEquals(ApplicationStatus.READY, updated.getApplicationStatus());
|
||||
assertEquals(2L, updated.getApplicationVersionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationUpdatesParallelism() {
|
||||
create("demo");
|
||||
FlinkApplication updated = service.updateApplication("demo", 1L, null, null, null, null, 5);
|
||||
assertEquals(5, updated.getParallelism());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationRedeploysCodeInPlaceWhenRunningInRealMode() {
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
app.setTaskManagerContainerId("tm-1");
|
||||
app.setFlinkJobId("job-1");
|
||||
|
||||
FlinkApplication updated = realMode.updateApplication("demo", 1L, null,
|
||||
"bucket", "v2.jar", null, null);
|
||||
|
||||
Mockito.verify(manager).redeployCode(app);
|
||||
assertEquals("v2.jar", updated.getCodeS3Key());
|
||||
assertEquals(ApplicationStatus.STARTING, updated.getApplicationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationWrapsRedeployFailureAsInternalFailure() {
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
Mockito.doThrow(new RuntimeException("docker unavailable"))
|
||||
.when(manager).redeployCode(Mockito.any());
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
app.setTaskManagerContainerId("tm-1");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> realMode.updateApplication(
|
||||
"demo", 1L, null, "bucket", "v2.jar", null, null));
|
||||
assertEquals("InternalFailure", ex.getErrorCode());
|
||||
assertEquals(500, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationRejectsCodeChangeOnRunningBareCluster() {
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> realMode.updateApplication(
|
||||
"demo", 1L, null, "bucket", "app.jar", null, null));
|
||||
assertEquals("InvalidRequestException", ex.getErrorCode());
|
||||
Mockito.verify(manager, Mockito.never()).redeployCode(Mockito.any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateApplicationWithCodeChangeInMockModeSkipsContainerRedeploy() {
|
||||
service.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
service.startApplication("demo"); // mock mode: RUNNING immediately, no container
|
||||
|
||||
FlinkApplication updated = service.updateApplication("demo", 1L, null,
|
||||
"bucket", "v2.jar", null, null);
|
||||
|
||||
assertEquals("v2.jar", updated.getCodeS3Key());
|
||||
// Mock mode has no container to redeploy against, so the application simply stays RUNNING.
|
||||
assertEquals(ApplicationStatus.RUNNING, updated.getApplicationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlReturnsRestEndpointWhenRunning() {
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
app.setRestEndpoint("http://localhost:41000");
|
||||
|
||||
String url = realMode.createApplicationPresignedUrl("demo", "FLINK_DASHBOARD_URL", 1800L);
|
||||
assertEquals("http://localhost:41000", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlRejectsWhenNotRunning() {
|
||||
create("demo"); // READY, never started
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.createApplicationPresignedUrl("demo", "FLINK_DASHBOARD_URL", null));
|
||||
assertEquals("ResourceInUseException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlRejectsUnsupportedUrlType() {
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
app.setRestEndpoint("http://localhost:41000");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> realMode.createApplicationPresignedUrl("demo", "ZEPPELIN_UI_URL", null));
|
||||
assertEquals("InvalidArgumentException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlRejectsOutOfRangeExpiration() {
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
KinesisAnalyticsV2Service realMode = buildService(false, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.RUNNING);
|
||||
app.setRestEndpoint("http://localhost:41000");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> realMode.createApplicationPresignedUrl("demo", "FLINK_DASHBOARD_URL", 100L));
|
||||
assertEquals("InvalidArgumentException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createApplicationPresignedUrlRejectsUnknownApplication() {
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.createApplicationPresignedUrl("nope", "FLINK_DASHBOARD_URL", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readinessPollerPersistsFlinkJobIdAssignedBeforeReachingRunning() throws InterruptedException {
|
||||
// Regression test: advanceToRunning can assign flinkJobId on a tick where the Flink job has
|
||||
// been submitted but hasn't reached RUNNING yet (it returns false in that case). That
|
||||
// intermediate state must still be persisted — not just the final RUNNING transition — since
|
||||
// pendingJars (a separate in-process-only cache) is already cleared by then; an emulator
|
||||
// restart before the next persist would otherwise leave the application permanently stuck.
|
||||
InMemoryStorage<String, FlinkApplication> backing = Mockito.spy(new InMemoryStorage<>());
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
Mockito.doReturn(backing).when(storageFactory)
|
||||
.create(Mockito.anyString(), Mockito.anyString(), Mockito.any());
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
|
||||
var kaConfig = Mockito.mock(EmulatorConfig.KinesisAnalyticsServiceConfig.class);
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.kinesisAnalytics()).thenReturn(kaConfig);
|
||||
when(kaConfig.mock()).thenReturn(false);
|
||||
when(config.defaultRegion()).thenReturn("us-east-1");
|
||||
|
||||
FlinkContainerManager manager = Mockito.mock(FlinkContainerManager.class);
|
||||
when(manager.advanceToRunning(Mockito.any())).thenAnswer(invocation -> {
|
||||
FlinkApplication app = invocation.getArgument(0);
|
||||
if (app.getFlinkJobId() == null) {
|
||||
app.setFlinkJobId("job-1"); // job just submitted; not yet RUNNING
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
KinesisAnalyticsV2Service realMode =
|
||||
new KinesisAnalyticsV2Service(storageFactory, config, regionResolver, manager);
|
||||
realMode.createApplication("demo", "FLINK-1_18", ROLE, null, null, "bucket", "app.jar", null, 1);
|
||||
FlinkApplication app = realMode.describeApplication("demo");
|
||||
app.setApplicationStatus(ApplicationStatus.STARTING);
|
||||
Mockito.clearInvocations(backing); // ignore createApplication's own put()
|
||||
|
||||
try {
|
||||
// @PostConstruct isn't wired by a plain `new` in this unit test; start the poller manually.
|
||||
realMode.init();
|
||||
// The poller's first tick fires ~1s after scheduling; give it margin.
|
||||
Thread.sleep(1500);
|
||||
|
||||
Mockito.verify(backing, Mockito.atLeastOnce()).put(Mockito.eq("demo"), Mockito.any());
|
||||
assertEquals("job-1", realMode.describeApplication("demo").getFlinkJobId());
|
||||
} finally {
|
||||
realMode.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private KinesisAnalyticsV2Service mockModeService() {
|
||||
return buildService(true, Mockito.mock(FlinkContainerManager.class));
|
||||
}
|
||||
|
||||
private KinesisAnalyticsV2Service realModeServiceWithFailingManager() {
|
||||
FlinkContainerManager failing = Mockito.mock(FlinkContainerManager.class);
|
||||
Mockito.doThrow(new RuntimeException("docker unavailable"))
|
||||
.when(failing).startCluster(Mockito.any());
|
||||
return buildService(false, failing);
|
||||
}
|
||||
|
||||
private KinesisAnalyticsV2Service buildService(boolean mock, FlinkContainerManager manager) {
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenReturn(new InMemoryStorage<>());
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
|
||||
var kaConfig = Mockito.mock(EmulatorConfig.KinesisAnalyticsServiceConfig.class);
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.kinesisAnalytics()).thenReturn(kaConfig);
|
||||
when(kaConfig.mock()).thenReturn(mock);
|
||||
when(config.defaultRegion()).thenReturn("us-east-1");
|
||||
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
return new KinesisAnalyticsV2Service(storageFactory, config, regionResolver, manager);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package io.github.hectorvent.floci.services.kinesisanalytics.container;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
|
||||
import io.github.hectorvent.floci.services.kinesisanalytics.model.FlinkApplication;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit coverage for {@link FlinkContainerManager}'s {@code application_properties.json} construction —
|
||||
* the JSON shape must exactly match real MSF/KDA's runtime file so a real
|
||||
* {@code KinesisAnalyticsRuntime.getApplicationProperties()} call in a user's JAR finds it. The
|
||||
* container-injection path itself (tar-entry-prefix trick to create the non-existent {@code /etc/flink}
|
||||
* directory via the daemon-level copy) was verified live against a real {@code apache/flink} image
|
||||
* rather than re-implemented here with a mocked DockerClient — see the design notes on the injection
|
||||
* call sites for what was checked and why.
|
||||
*/
|
||||
class FlinkContainerManagerTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private FlinkContainerManager manager() {
|
||||
return new FlinkContainerManager(
|
||||
Mockito.mock(ContainerBuilder.class),
|
||||
Mockito.mock(ContainerLifecycleManager.class),
|
||||
Mockito.mock(ContainerLogStreamer.class),
|
||||
Mockito.mock(ContainerDetector.class),
|
||||
Mockito.mock(EmulatorConfig.class),
|
||||
Mockito.mock(RegionResolver.class),
|
||||
Mockito.mock(S3Service.class),
|
||||
Mockito.mock(FlinkRestClient.class),
|
||||
MAPPER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applicationPropertiesJsonMatchesTheRealMsfFileShape() throws Exception {
|
||||
FlinkApplication app = new FlinkApplication("demo", "arn:aws:kinesisanalytics:us-east-1:000000000000:application/demo",
|
||||
"FLINK-1_18", "arn:aws:iam::000000000000:role/x", "STREAMING");
|
||||
Map<String, Map<String, String>> groups = new LinkedHashMap<>();
|
||||
groups.put("ProducerConfigProperties", Map.of("flink.stream.initpos", "LATEST", "aws.region", "us-west-2"));
|
||||
groups.put("ConsumerConfigProperties", Map.of("aws.region", "us-west-2"));
|
||||
app.setEnvironmentProperties(groups);
|
||||
|
||||
byte[] json = manager().applicationPropertiesJson(app);
|
||||
JsonNode root = MAPPER.readTree(json);
|
||||
|
||||
assertTrue(root.isArray());
|
||||
assertEquals(2, root.size());
|
||||
assertEquals("ProducerConfigProperties", root.get(0).get("PropertyGroupId").asText());
|
||||
assertEquals("LATEST", root.get(0).get("PropertyMap").get("flink.stream.initpos").asText());
|
||||
assertEquals("us-west-2", root.get(0).get("PropertyMap").get("aws.region").asText());
|
||||
assertEquals("ConsumerConfigProperties", root.get(1).get("PropertyGroupId").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void applicationPropertiesJsonIsAnEmptyArrayWhenNoPropertiesConfigured() throws Exception {
|
||||
FlinkApplication app = new FlinkApplication("bare", "arn:aws:kinesisanalytics:us-east-1:000000000000:application/bare",
|
||||
"FLINK-1_18", "arn:aws:iam::000000000000:role/x", "STREAMING");
|
||||
|
||||
byte[] json = manager().applicationPropertiesJson(app);
|
||||
JsonNode root = MAPPER.readTree(json);
|
||||
|
||||
// Real MSF always provides the file, even with zero property groups configured, so
|
||||
// KinesisAnalyticsRuntime.getApplicationProperties() never has to handle a missing file.
|
||||
assertTrue(root.isArray());
|
||||
assertEquals(0, root.size());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user