From c2482e28440aea69b294437beaf0571b74ffc6ec Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:44:29 -0500 Subject: [PATCH] fix(appconfig): list deployments with the settings they started with (#6759) ListDeployments built each deployment's summary from the deployment strategy as it is now: once a strategy that one of an environment's deployments used was deleted, ListDeployments on that environment answered 404 "Deployment strategy not found", while GetDeployment still returned the deployment. The summary also took the profile's current name over the one the deployment recorded. AWS documents these values as the deployment's own (GetDeployment's DeploymentDurationInMinutes is "Total amount of time the deployment lasted"), and DeleteDeploymentStrategy, unlike DeleteEnvironment and DeleteConfigurationProfile, has no ConflictException for a resource in use. - StartDeployment records the strategy's DeploymentDurationInMinutes, FinalBakeTimeInMinutes, GrowthFactor and GrowthType on the deployment, and StartDeployment and GetDeployment return them, as AWS documents for both. - ListDeployments reports the recorded profile name and strategy settings, so deleting the strategy leaves earlier deployments as they started. Floci serves no UpdateDeploymentStrategy or UpdateConfigurationProfile yet; the recorded values also keep earlier deployments as they were once anything changes a strategy or renames a profile in place. - Deployments stored by earlier builds load unchanged: GetDeployment still omits the settings they never recorded, and ListDeployments reads them from the strategy while it exists and reports them as null once it is gone, instead of failing. Type is unchanged: it is still read from the profile. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> --- .../java/com/floci/test/AppConfigTest.java | 69 +++++++++++ docs/services/appconfig.md | 5 + .../services/appconfig/AppConfigService.java | 45 ++++++-- .../services/appconfig/model/Deployment.java | 26 +++++ ...ppConfigResourceFieldsIntegrationTest.java | 95 ++++++++++++++++ .../AppConfigServicePersistenceTest.java | 43 ++++++- .../appconfig/AppConfigServiceTest.java | 107 ++++++++++++++++++ 7 files changed, 379 insertions(+), 11 deletions(-) diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java index 240b29826b..a2c5c845ce 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AppConfigTest.java @@ -678,4 +678,73 @@ class AppConfigTest { } } } + + @Test + @Order(58) + @DisplayName("Deployments report the strategy settings they started with, also once the strategy is deleted") + void deploymentsKeepTheirStrategySettings() { + String historyAppId = appConfig.createApplication(CreateApplicationRequest.builder() + .name(TestFixtures.uniqueName("history-app")).build()).id(); + try { + String historyEnvId = appConfig.createEnvironment(CreateEnvironmentRequest.builder() + .applicationId(historyAppId).name("history").build()).id(); + String profileId = appConfig.createConfigurationProfile(CreateConfigurationProfileRequest.builder() + .applicationId(historyAppId).name("history-settings").locationUri("hosted").build()).id(); + appConfig.createHostedConfigurationVersion(CreateHostedConfigurationVersionRequest.builder() + .applicationId(historyAppId) + .configurationProfileId(profileId) + .content(SdkBytes.fromString("{\"key\": \"value\"}", StandardCharsets.UTF_8)) + .contentType("application/json") + .build()); + String strategyId = appConfig.createDeploymentStrategy(CreateDeploymentStrategyRequest.builder() + .name(TestFixtures.uniqueName("gradual")) + .deploymentDurationInMinutes(15) + .finalBakeTimeInMinutes(5) + .growthFactor(25.0f) + .growthType(GrowthType.LINEAR) + .replicateTo(ReplicateTo.NONE) + .build()).id(); + StartDeploymentResponse started = appConfig.startDeployment(StartDeploymentRequest.builder() + .applicationId(historyAppId) + .environmentId(historyEnvId) + .configurationProfileId(profileId) + .configurationVersion("1") + .deploymentStrategyId(strategyId) + .build()); + + appConfig.deleteDeploymentStrategy(DeleteDeploymentStrategyRequest.builder() + .deploymentStrategyId(strategyId).build()); + + ListDeploymentsResponse listed = appConfig.listDeployments(ListDeploymentsRequest.builder() + .applicationId(historyAppId).environmentId(historyEnvId).build()); + assertThat(listed.items()).hasSize(1); + DeploymentSummary summary = listed.items().get(0); + assertThat(summary.deploymentNumber()).isEqualTo(started.deploymentNumber()); + assertThat(summary.configurationName()).isEqualTo("history-settings"); + assertThat(summary.deploymentDurationInMinutes()).isEqualTo(15); + assertThat(summary.finalBakeTimeInMinutes()).isEqualTo(5); + assertThat(summary.growthFactor()).isEqualTo(25.0f); + assertThat(summary.growthType()).isEqualTo(GrowthType.LINEAR); + + GetDeploymentResponse deployment = appConfig.getDeployment(GetDeploymentRequest.builder() + .applicationId(historyAppId) + .environmentId(historyEnvId) + .deploymentNumber(started.deploymentNumber()) + .build()); + assertThat(deployment.deploymentDurationInMinutes()).isEqualTo(15); + assertThat(deployment.finalBakeTimeInMinutes()).isEqualTo(5); + assertThat(deployment.growthFactor()).isEqualTo(25.0f); + assertThat(deployment.growthType()).isEqualTo(GrowthType.LINEAR); + assertThat(started.deploymentDurationInMinutes()).isEqualTo(15); + assertThat(started.finalBakeTimeInMinutes()).isEqualTo(5); + assertThat(started.growthFactor()).isEqualTo(25.0f); + assertThat(started.growthType()).isEqualTo(GrowthType.LINEAR); + } finally { + try { + appConfig.deleteApplication(DeleteApplicationRequest.builder().applicationId(historyAppId).build()); + } catch (Exception ignored) { + // Best-effort cleanup: the application name is unique, so a leftover cannot affect other tests. + } + } + } } diff --git a/docs/services/appconfig.md b/docs/services/appconfig.md index 32fc2e6232..76a41c1376 100644 --- a/docs/services/appconfig.md +++ b/docs/services/appconfig.md @@ -48,6 +48,11 @@ that is not an IAM role ARN, returns `BadRequestException`. `StartDeployment` and `GetDeployment` return the deployed profile's name and location URI as `ConfigurationName` and `ConfigurationLocationUri`. Deployments stored by earlier Floci versions did not record them, so on those neither is set. +They also return the deployment strategy's `DeploymentDurationInMinutes`, `FinalBakeTimeInMinutes`, +`GrowthFactor` and `GrowthType` as the deployment started with them, and `ListDeployments` reports each +deployment with the profile name and strategy settings it recorded, also once its strategy is deleted. +A deployment stored by an earlier Floci version returns no strategy settings from `GetDeployment`, and +`ListDeployments` reports the strategy's current settings while the strategy exists. A configuration profile created without `Type` reports no type, as AWS documents no default. ## Data Plane (AppConfigData) {#data-plane} diff --git a/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigService.java b/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigService.java index da6d8a6827..e9f108d2a1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigService.java +++ b/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigService.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; @@ -308,10 +309,14 @@ public class AppConfigService { } public DeploymentStrategy getDeploymentStrategy(String id) { - // AWS predefined built-in strategies + return findDeploymentStrategy(id) + .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Deployment strategy not found", 404)); + } + + /** The predefined or stored deployment strategy whose ID is {@code id}. */ + private Optional findDeploymentStrategy(String id) { DeploymentStrategy builtin = builtinStrategy(id); - if (builtin != null) return builtin; - return strategyStore.get(id).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Deployment strategy not found", 404)); + return builtin != null ? Optional.of(builtin) : strategyStore.get(id); } public List listDeploymentStrategies() { @@ -384,7 +389,7 @@ public class AppConfigService { String version = (String) request.get("ConfigurationVersion"); String strategyId = (String) request.get("DeploymentStrategyId"); - getDeploymentStrategy(strategyId); + DeploymentStrategy strategy = getDeploymentStrategy(strategyId); Deployment deployment = new Deployment(); deployment.setApplicationId(appId); @@ -394,6 +399,10 @@ public class AppConfigService { deployment.setConfigurationLocationUri(profile.getLocationUri()); deployment.setConfigurationVersion(version); deployment.setDeploymentStrategyId(strategyId); + deployment.setDeploymentDurationInMinutes(strategy.getDeploymentDurationInMinutes()); + deployment.setFinalBakeTimeInMinutes(strategy.getFinalBakeTimeInMinutes()); + deployment.setGrowthFactor(strategy.getGrowthFactor()); + deployment.setGrowthType(strategy.getGrowthType()); int nextDeploymentNumber = deploymentStore.scan(key -> true).stream() .mapToInt(Deployment::getDeploymentNumber) .max() @@ -469,6 +478,12 @@ public class AppConfigService { return new DeploymentPage(items, resultToken); } + /** + * The deployment with the profile name and strategy settings it recorded when it started, so changing + * the profile or the strategy, or deleting the strategy, leaves them as they were. A deployment stored + * before Floci recorded them reads them from the profile and the strategy while those exist. The type + * is read from the profile. + */ private DeploymentSummary toDeploymentSummary(Deployment deployment) { DeploymentSummary summary = new DeploymentSummary(); summary.setConfigurationProfileId(deployment.getConfigurationProfileId()); @@ -478,14 +493,24 @@ public class AppConfigService { summary.setConfigurationName(deployment.getConfigurationName()); ConfigurationProfile profile = profileStore.get(deployment.getConfigurationProfileId()).orElse(null); if (profile != null) { - summary.setConfigurationName(profile.getName()); + if (deployment.getConfigurationName() == null) { + summary.setConfigurationName(profile.getName()); + } summary.setType(profile.getType()); } - DeploymentStrategy strategy = getDeploymentStrategy(deployment.getDeploymentStrategyId()); - summary.setDeploymentDurationInMinutes(strategy.getDeploymentDurationInMinutes()); - summary.setFinalBakeTimeInMinutes(strategy.getFinalBakeTimeInMinutes()); - summary.setGrowthFactor(strategy.getGrowthFactor()); - summary.setGrowthType(strategy.getGrowthType()); + if (deployment.getDeploymentDurationInMinutes() != null) { + summary.setDeploymentDurationInMinutes(deployment.getDeploymentDurationInMinutes()); + summary.setFinalBakeTimeInMinutes(deployment.getFinalBakeTimeInMinutes()); + summary.setGrowthFactor(deployment.getGrowthFactor()); + summary.setGrowthType(deployment.getGrowthType()); + } else { + findDeploymentStrategy(deployment.getDeploymentStrategyId()).ifPresent(strategy -> { + summary.setDeploymentDurationInMinutes(strategy.getDeploymentDurationInMinutes()); + summary.setFinalBakeTimeInMinutes(strategy.getFinalBakeTimeInMinutes()); + summary.setGrowthFactor(strategy.getGrowthFactor()); + summary.setGrowthType(strategy.getGrowthType()); + }); + } summary.setPercentageComplete("COMPLETE".equals(deployment.getState()) ? 100.0f : 0.0f); return summary; } diff --git a/src/main/java/io/github/hectorvent/floci/services/appconfig/model/Deployment.java b/src/main/java/io/github/hectorvent/floci/services/appconfig/model/Deployment.java index 8239436a68..db751bde0b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/appconfig/model/Deployment.java +++ b/src/main/java/io/github/hectorvent/floci/services/appconfig/model/Deployment.java @@ -26,6 +26,20 @@ public class Deployment { private String configurationVersion; @JsonProperty("DeploymentStrategyId") private String deploymentStrategyId; + // The strategy's settings as the deployment started with them, so changing or deleting the strategy + // leaves them as they were. Omitted on deployments stored before they were recorded. + @JsonProperty("DeploymentDurationInMinutes") + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer deploymentDurationInMinutes; + @JsonProperty("FinalBakeTimeInMinutes") + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer finalBakeTimeInMinutes; + @JsonProperty("GrowthFactor") + @JsonInclude(JsonInclude.Include.NON_NULL) + private Float growthFactor; + @JsonProperty("GrowthType") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String growthType; @JsonProperty("State") private String state; // BAKING, VALIDATING, DEPLOYING, COMPLETE, ROLLING_BACK, ROLLED_BACK @JsonProperty("Description") @@ -57,6 +71,18 @@ public class Deployment { public String getDeploymentStrategyId() { return deploymentStrategyId; } public void setDeploymentStrategyId(String deploymentStrategyId) { this.deploymentStrategyId = deploymentStrategyId; } + public Integer getDeploymentDurationInMinutes() { return deploymentDurationInMinutes; } + public void setDeploymentDurationInMinutes(Integer deploymentDurationInMinutes) { this.deploymentDurationInMinutes = deploymentDurationInMinutes; } + + public Integer getFinalBakeTimeInMinutes() { return finalBakeTimeInMinutes; } + public void setFinalBakeTimeInMinutes(Integer finalBakeTimeInMinutes) { this.finalBakeTimeInMinutes = finalBakeTimeInMinutes; } + + public Float getGrowthFactor() { return growthFactor; } + public void setGrowthFactor(Float growthFactor) { this.growthFactor = growthFactor; } + + public String getGrowthType() { return growthType; } + public void setGrowthType(String growthType) { this.growthType = growthType; } + public String getState() { return state; } public void setState(String state) { this.state = state; } diff --git a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigResourceFieldsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigResourceFieldsIntegrationTest.java index 74f2a81346..d61341faae 100644 --- a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigResourceFieldsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigResourceFieldsIntegrationTest.java @@ -143,6 +143,66 @@ class AppConfigResourceFieldsIntegrationTest { .body("ConfigurationLocationUri", equalTo("ssm-parameter://service-settings")); } + @Test + void deploymentReturnsTheStrategySettingsItStartedWith() { + String applicationId = createApplication("deployment-strategy-app"); + String deployments = newEnvironmentDeployments(applicationId, "deployment-strategy-env"); + String profileId = createProfile(applicationId, "strategy-settings"); + String strategyId = createGradualStrategy(); + + int deploymentNumber = given() + .contentType(ContentType.JSON) + .body(startDeploymentBody(profileId, strategyId)) + .when().post(deployments) + .then().statusCode(201) + .body("DeploymentDurationInMinutes", equalTo(15)) + .body("FinalBakeTimeInMinutes", equalTo(5)) + .body("GrowthFactor", equalTo(25.0f)) + .body("GrowthType", equalTo("LINEAR")) + .extract().path("DeploymentNumber"); + + given() + .when().get(deployments + "/" + deploymentNumber) + .then().statusCode(200) + .body("DeploymentDurationInMinutes", equalTo(15)) + .body("FinalBakeTimeInMinutes", equalTo(5)) + .body("GrowthFactor", equalTo(25.0f)) + .body("GrowthType", equalTo("LINEAR")); + } + + @Test + void listDeploymentsStillReportsADeploymentWhoseStrategyWasDeleted() { + String applicationId = createApplication("deleted-strategy-app"); + String deployments = newEnvironmentDeployments(applicationId, "deleted-strategy-env"); + String profileId = createProfile(applicationId, "deleted-strategy-settings"); + String strategyId = createGradualStrategy(); + int deploymentNumber = given() + .contentType(ContentType.JSON) + .body(startDeploymentBody(profileId, strategyId)) + .when().post(deployments) + .then().statusCode(201) + .extract().path("DeploymentNumber"); + + given() + .when().delete("/deployementstrategies/" + strategyId) + .then().statusCode(204); + + given() + .when().get(deployments) + .then().statusCode(200) + .body("Items.size()", equalTo(1)) + .body("Items[0].DeploymentNumber", equalTo(deploymentNumber)) + .body("Items[0].ConfigurationName", equalTo("deleted-strategy-settings")) + .body("Items[0].DeploymentDurationInMinutes", equalTo(15)) + .body("Items[0].FinalBakeTimeInMinutes", equalTo(5)) + .body("Items[0].GrowthFactor", equalTo(25.0f)) + .body("Items[0].GrowthType", equalTo("LINEAR")); + given() + .when().get(deployments + "/" + deploymentNumber) + .then().statusCode(200) + .body("DeploymentStrategyId", equalTo(strategyId)); + } + @Test void profileCreatedWithoutTypeReturnsNoType() { String applicationId = createApplication("untyped-profile-app"); @@ -168,4 +228,39 @@ class AppConfigResourceFieldsIntegrationTest { .then().statusCode(201) .extract().path("Id"); } + + /** Creates an environment and returns the path of its deployments. */ + private static String newEnvironmentDeployments(String applicationId, String environmentName) { + String environmentId = given() + .contentType(ContentType.JSON) + .body("{\"Name\":\"" + environmentName + "\"}") + .when().post("/applications/" + applicationId + "/environments") + .then().statusCode(201) + .extract().path("Id"); + return "/applications/" + applicationId + "/environments/" + environmentId + "/deployments"; + } + + private static String createProfile(String applicationId, String name) { + return given() + .contentType(ContentType.JSON) + .body("{\"Name\":\"" + name + "\",\"LocationUri\":\"hosted\",\"Type\":\"AWS.Freeform\"}") + .when().post("/applications/" + applicationId + "/configurationprofiles") + .then().statusCode(201) + .extract().path("Id"); + } + + private static String createGradualStrategy() { + return given() + .contentType(ContentType.JSON) + .body("{\"Name\":\"gradual\",\"DeploymentDurationInMinutes\":15,\"FinalBakeTimeInMinutes\":5," + + "\"GrowthFactor\":25,\"GrowthType\":\"LINEAR\",\"ReplicateTo\":\"NONE\"}") + .when().post("/deploymentstrategies") + .then().statusCode(201) + .extract().path("Id"); + } + + private static String startDeploymentBody(String profileId, String strategyId) { + return "{\"ConfigurationProfileId\":\"" + profileId + "\",\"ConfigurationVersion\":\"1\"," + + "\"DeploymentStrategyId\":\"" + strategyId + "\"}"; + } } diff --git a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServicePersistenceTest.java b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServicePersistenceTest.java index 1927b440dc..e1cee7e7c4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServicePersistenceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServicePersistenceTest.java @@ -1,10 +1,12 @@ package io.github.hectorvent.floci.services.appconfig; +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.ServiceConfigAccess; import io.github.hectorvent.floci.core.storage.StorageFactory; import io.github.hectorvent.floci.services.appconfig.model.Deployment; +import io.github.hectorvent.floci.services.appconfig.model.DeploymentSummary; import io.github.hectorvent.floci.services.appconfig.model.Environment; import io.github.hectorvent.floci.services.appconfig.model.Monitor; import org.junit.jupiter.api.Test; @@ -66,11 +68,50 @@ class AppConfigServicePersistenceTest { assertEquals("prof1", deployment.getConfigurationProfileId()); assertEquals("COMPLETE", deployment.getState()); assertNull(deployment.getConfigurationLocationUri()); - assertFalse(MAPPER.valueToTree(deployment).has("ConfigurationLocationUri")); + JsonNode deploymentJson = MAPPER.valueToTree(deployment); + for (String unrecorded : List.of("ConfigurationLocationUri", "DeploymentDurationInMinutes", + "FinalBakeTimeInMinutes", "GrowthFactor", "GrowthType")) { + assertFalse(deploymentJson.has(unrecorded), unrecorded); + } + + DeploymentSummary summary = service.listDeployments("app1", "env1", null, null).items().get(0); + assertEquals("stored-profile", summary.getConfigurationName()); + assertEquals(0, summary.getDeploymentDurationInMinutes()); + assertEquals(10, summary.getFinalBakeTimeInMinutes()); + assertEquals(100f, summary.getGrowthFactor()); + assertEquals("LINEAR", summary.getGrowthType()); assertNull(service.getConfigurationProfile("app1", "prof1").getType()); } + @Test + void deploymentStrategySettingsSurviveARestart() { + StorageFactory first = newFactory(); + AppConfigService service = new AppConfigService(first, mock(EmulatorConfig.class)); + String appId = service.createApplication(Map.of("Name", "restarted-app")).getId(); + String environmentId = service.createEnvironment(appId, Map.of("Name", "restarted-env")).getId(); + String profileId = service.createConfigurationProfile(appId, Map.of( + "Name", "service-settings", "LocationUri", "hosted")).getId(); + String strategyId = service.createDeploymentStrategy(Map.of( + "Name", "gradual", "DeploymentDurationInMinutes", 15, "FinalBakeTimeInMinutes", 5, + "GrowthFactor", 25, "GrowthType", "EXPONENTIAL")).getId(); + service.startDeployment(appId, environmentId, Map.of( + "ConfigurationProfileId", profileId, + "ConfigurationVersion", "1", + "DeploymentStrategyId", strategyId)); + first.shutdownAll(); + + AppConfigService restarted = new AppConfigService(newFactory(), mock(EmulatorConfig.class)); + // With the strategy gone, the settings can only come from the stored deployment. + restarted.deleteDeploymentStrategy(strategyId); + + DeploymentSummary summary = restarted.listDeployments(appId, environmentId, null, null).items().get(0); + assertEquals(15, summary.getDeploymentDurationInMinutes()); + assertEquals(5, summary.getFinalBakeTimeInMinutes()); + assertEquals(25f, summary.getGrowthFactor()); + assertEquals("EXPONENTIAL", summary.getGrowthType()); + } + @Test void monitorsAndDeploymentLocationsSurviveARestart() { StorageFactory first = newFactory(); diff --git a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServiceTest.java index 2c1b1ee1c2..942828a5d4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/appconfig/AppConfigServiceTest.java @@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.storage.StorageFactory; import io.github.hectorvent.floci.services.appconfig.model.Application; import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile; import io.github.hectorvent.floci.services.appconfig.model.Deployment; +import io.github.hectorvent.floci.services.appconfig.model.DeploymentStrategy; import io.github.hectorvent.floci.services.appconfig.model.DeploymentSummary; import io.github.hectorvent.floci.services.appconfig.model.Environment; import io.github.hectorvent.floci.services.appconfig.model.Monitor; @@ -68,12 +69,23 @@ class AppConfigServiceTest { when(deploymentStore.keys()).thenAnswer(invocation -> Set.copyOf(deployments.keySet())); doAnswer(invocation -> deployments.remove(invocation.getArgument(0, String.class))) .when(deploymentStore).delete(anyString()); + AccountAwareStorageBackend strategyStore = mock(AccountAwareStorageBackend.class); + Map strategies = new HashMap<>(); + doAnswer(invocation -> { + strategies.put(invocation.getArgument(0, String.class), invocation.getArgument(1, DeploymentStrategy.class)); + return null; + }).when(strategyStore).put(anyString(), any(DeploymentStrategy.class)); + when(strategyStore.get(anyString())) + .thenAnswer(invocation -> Optional.ofNullable(strategies.get(invocation.getArgument(0, String.class)))); + doAnswer(invocation -> strategies.remove(invocation.getArgument(0, String.class))) + .when(strategyStore).delete(anyString()); when(activeConfigStore.keys()).thenReturn(Set.of()); StorageFactory storageFactory = mock(StorageFactory.class); doAnswer(invocation -> switch (invocation.getArgument(1, String.class)) { case "appconfig-applications.json" -> applicationStore; case "appconfig-environments.json" -> environmentStore; case "appconfig-profiles.json" -> profileStore; + case "appconfig-strategies.json" -> strategyStore; case "appconfig-deployments.json" -> deploymentStore; case "appconfig-active-configs.json" -> activeConfigStore; default -> mock(AccountAwareStorageBackend.class); @@ -144,6 +156,79 @@ class AppConfigServiceTest { assertThrows(RuntimeException.class, () -> service.listDeployments("app", "env", 1, "unknown")); } + @Test + void listDeploymentsStillReportsADeploymentWhoseStrategyWasDeleted() { + String strategyId = createGradualStrategy().getId(); + startDeployment(strategyId); + + service.deleteDeploymentStrategy(strategyId); + DeploymentSummary summary = onlyDeployment(); + + assertEquals(15, summary.getDeploymentDurationInMinutes()); + assertEquals(5, summary.getFinalBakeTimeInMinutes()); + assertEquals(25f, summary.getGrowthFactor()); + assertEquals("LINEAR", summary.getGrowthType()); + } + + @Test + void listDeploymentsReportsTheStrategySettingsADeploymentStartedWith() { + DeploymentStrategy strategy = createGradualStrategy(); + startDeployment(strategy.getId()); + + // What an in-place update of the strategy changes after the deployment has started. + strategy.setDeploymentDurationInMinutes(30); + strategy.setFinalBakeTimeInMinutes(10); + strategy.setGrowthFactor(50f); + strategy.setGrowthType("EXPONENTIAL"); + DeploymentSummary summary = onlyDeployment(); + + assertEquals(15, summary.getDeploymentDurationInMinutes()); + assertEquals(5, summary.getFinalBakeTimeInMinutes()); + assertEquals(25f, summary.getGrowthFactor()); + assertEquals("LINEAR", summary.getGrowthType()); + } + + @Test + void listDeploymentsReportsTheProfileNameADeploymentStartedWith() { + ConfigurationProfile profile = service.getConfigurationProfile("app", "profile"); + profile.setName("service-settings"); + startDeployment("AppConfig.AllAtOnce"); + + profile.setName("renamed-settings"); + + assertEquals("service-settings", onlyDeployment().getConfigurationName()); + } + + @Test + void listDeploymentsReadsTheLiveProfileAndStrategyForARecordThatDoesNotHoldThem() { + // Stored by an earlier build, which recorded neither the profile's name nor the strategy's settings. + deploymentStore.put("app::env::1", deployment("app", "env", 1)); + service.getConfigurationProfile("app", "profile").setName("service-settings"); + + DeploymentSummary summary = onlyDeployment(); + + assertEquals("service-settings", summary.getConfigurationName()); + assertEquals(0, summary.getDeploymentDurationInMinutes()); + assertEquals(10, summary.getFinalBakeTimeInMinutes()); + assertEquals(100f, summary.getGrowthFactor()); + assertEquals("LINEAR", summary.getGrowthType()); + } + + @Test + void listDeploymentsLeavesOutTheStrategySettingsWhenNeitherTheRecordNorTheStrategyHoldsThem() { + Deployment stored = deployment("app", "env", 1); + stored.setDeploymentStrategyId("deleted"); + deploymentStore.put("app::env::1", stored); + + DeploymentSummary summary = onlyDeployment(); + + assertEquals(1, summary.getDeploymentNumber()); + assertNull(summary.getDeploymentDurationInMinutes()); + assertNull(summary.getFinalBakeTimeInMinutes()); + assertNull(summary.getGrowthFactor()); + assertNull(summary.getGrowthType()); + } + @Test void environmentKeepsAnImmutableCopyOfItsMonitors() { Map withRole = new HashMap<>(Map.of("AlarmArn", ALARM_ARN, "AlarmRoleArn", ALARM_ROLE_ARN)); @@ -298,6 +383,28 @@ class AppConfigServiceTest { } } + private DeploymentStrategy createGradualStrategy() { + return service.createDeploymentStrategy(Map.of( + "Name", "gradual", + "DeploymentDurationInMinutes", 15, + "FinalBakeTimeInMinutes", 5, + "GrowthFactor", 25, + "GrowthType", "LINEAR")); + } + + private void startDeployment(String strategyId) { + service.startDeployment("app", "env", Map.of( + "ConfigurationProfileId", "profile", + "ConfigurationVersion", "1", + "DeploymentStrategyId", strategyId)); + } + + private DeploymentSummary onlyDeployment() { + List items = service.listDeployments("app", "env", null, null).items(); + assertEquals(1, items.size()); + return items.get(0); + } + private static Deployment deployment(String applicationId, String environmentId, int number) { Deployment deployment = new Deployment(); deployment.setApplicationId(applicationId);