mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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>
This commit is contained in:
1 parent
0332b5cc24
commit
c2482e2844
7 files changed
+379
-11
No files matched your search
+95
@@ -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 + "\"}";
|
||||
}
|
||||
}
|
||||
+42
-1
@@ -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();
|
||||
|
||||
+107
@@ -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<DeploymentStrategy> strategyStore = mock(AccountAwareStorageBackend.class);
|
||||
Map<String, DeploymentStrategy> 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<String, Object> 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<DeploymentSummary> 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);
|
||||
|
||||
Reference in new issue
Block a user