core(deploy): DeploymentStrategy enum with safe wire conversion

Typed enum (BLUE_GREEN, ROLLING) with fromWire/toWire kebab-case
translation. fromWire falls back to BLUE_GREEN for unknown or null
input so the executor dispatch site never null-checks and no
misconfigured container-config can throw at runtime.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-23 09:42:35 +02:00
parent 2c82f29aef
commit 5304c8ee01
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package com.cameleer.server.core.runtime;
/**
* Supported deployment strategies. Persisted as a kebab-case string on
* ApplicationConfig / ResolvedContainerConfig; {@link #fromWire(String)} is
* the only conversion entry point and falls back to {@link #BLUE_GREEN} for
* unknown or null input so the executor never has to null-check.
*/
public enum DeploymentStrategy {
BLUE_GREEN("blue-green"),
ROLLING("rolling");
private final String wire;
DeploymentStrategy(String wire) {
this.wire = wire;
}
public String toWire() {
return wire;
}
public static DeploymentStrategy fromWire(String value) {
if (value == null) return BLUE_GREEN;
String normalized = value.trim().toLowerCase();
for (DeploymentStrategy s : values()) {
if (s.wire.equals(normalized)) return s;
}
return BLUE_GREEN;
}
}

View File

@@ -0,0 +1,34 @@
package com.cameleer.server.core.runtime;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class DeploymentStrategyTest {
@Test
void fromWire_knownValues() {
assertThat(DeploymentStrategy.fromWire("blue-green")).isEqualTo(DeploymentStrategy.BLUE_GREEN);
assertThat(DeploymentStrategy.fromWire("rolling")).isEqualTo(DeploymentStrategy.ROLLING);
}
@Test
void fromWire_caseInsensitiveAndTrims() {
assertThat(DeploymentStrategy.fromWire("BLUE-GREEN")).isEqualTo(DeploymentStrategy.BLUE_GREEN);
assertThat(DeploymentStrategy.fromWire(" Rolling ")).isEqualTo(DeploymentStrategy.ROLLING);
}
@Test
void fromWire_unknownOrNullFallsBackToBlueGreen() {
assertThat(DeploymentStrategy.fromWire(null)).isEqualTo(DeploymentStrategy.BLUE_GREEN);
assertThat(DeploymentStrategy.fromWire("")).isEqualTo(DeploymentStrategy.BLUE_GREEN);
assertThat(DeploymentStrategy.fromWire("canary")).isEqualTo(DeploymentStrategy.BLUE_GREEN);
}
@Test
void toWire_roundTrips() {
for (DeploymentStrategy s : DeploymentStrategy.values()) {
assertThat(DeploymentStrategy.fromWire(s.toWire())).isEqualTo(s);
}
}
}