mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(ecs): take request objects and split out the response writer (#4016)
* feat(docker): add cpu limits and readonly rootfs to container specs ECS expresses CPU as units where 1024 units is one vCPU, and a task definition can ask for a container's own filesystem to be read only. Neither reached the Docker host config. ContainerSpec gains nanoCpus, cpuShares and readonlyRootfs, the builder gains withCpuUnits, withCpuShares and withReadonlyRootfs, and ContainerLifecycleManager maps them onto withNanoCPUs, withCpuShares and withReadonlyRootfs. Existing convenience constructors keep their old shapes and default the three new components, so no current caller changes behaviour. Docker refuses a NanoCpus above the host's CPU count, while ECS accepts a task cpu of up to 196608 units, so a 16 vCPU task asked for verbatim would fail to start on a smaller machine. The quota is held to the daemon's reported NCPU, read once and left alone when the daemon does not report one. ContainerLifecycleManagerCpuLimitTest builds a spec through the builder, captures the HostConfig on create and pins the unit conversion, the zero/negative guards, the cpuShares passthrough, readonlyRootfs and both sides of the clamp. * refactor(ecs): take request objects and split out the response writer ECS's launch operations were reached through positional argument lists that had grown past what a signature can carry: registerTaskDefinition took ten parameters, createService thirteen, and the handler had started setting members on the returned object afterwards because there was nowhere in the signature to put them. EcsJsonHandler had grown the same way, with request parsing and response rendering, roughly half the file each, interleaved. CreateClusterRequest, RegisterTaskDefinitionRequest, RunTaskRequest, CreateServiceRequest, UpdateServiceRequest, CreateTaskSetRequest and ListTasksRequest carry what their operation was already given. Each positional overload stays, building the request and delegating, so the CloudFormation, EventBridge, Scheduler and Step Functions call sites are untouched. RegisterTaskDefinition's volumes and runtimePlatform move into the request, which removes the post-hoc mutate-and-persist the handler needed to get them onto the stored definition. EcsResponseWriter takes the node builders out of the handler verbatim. The handler keeps a taskNode delegate, which is what the Step Functions ecs:runTask integration renders through, and a constructor that builds its own writer for the tests that assemble it without CDI. No behaviour changes: every response is byte-for-byte what it was, and the existing ECS, CodeDeploy, EventBridge and Step Functions suites pass unchanged apart from the handler unit tests, which stub the request-object overload instead of the positional one.
This commit is contained in:
1 parent
94976360ac
commit
e1ae6b3b1f
17 files changed
+1345
-748
No files matched your search
+7
-3
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -43,13 +44,16 @@ class EcsJsonHandlerCommandEntryPointTest {
|
||||
objectMapper = new ObjectMapper();
|
||||
service = mock(EcsService.class);
|
||||
// Echo the parsed container definitions (arg index 1) back inside a task definition.
|
||||
when(service.registerTaskDefinition(anyString(), any(), any(), any(), any(), any(), any(), any(), any(), anyString()))
|
||||
when(service.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), anyString()))
|
||||
.thenAnswer(inv -> {
|
||||
RegisterTaskDefinitionRequest request = inv.getArgument(0);
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(inv.getArgument(0));
|
||||
td.setFamily(request.getFamily());
|
||||
td.setRevision(1);
|
||||
td.setStatus("ACTIVE");
|
||||
td.setContainerDefinitions(inv.getArgument(1, List.class));
|
||||
td.setContainerDefinitions(request.getContainerDefinitions());
|
||||
td.setVolumes(request.getVolumes());
|
||||
td.setRuntimePlatform(request.getRuntimePlatform());
|
||||
return td;
|
||||
});
|
||||
|
||||
|
||||
+7
-3
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -28,13 +29,16 @@ class EcsJsonHandlerFirelensTest {
|
||||
void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
EcsService service = mock(EcsService.class);
|
||||
when(service.registerTaskDefinition(anyString(), any(), any(), any(), any(), any(), any(), any(), any(), anyString()))
|
||||
when(service.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), anyString()))
|
||||
.thenAnswer(invocation -> {
|
||||
RegisterTaskDefinitionRequest request = invocation.getArgument(0);
|
||||
TaskDefinition taskDefinition = new TaskDefinition();
|
||||
taskDefinition.setFamily(invocation.getArgument(0));
|
||||
taskDefinition.setFamily(request.getFamily());
|
||||
taskDefinition.setRevision(1);
|
||||
taskDefinition.setStatus("ACTIVE");
|
||||
taskDefinition.setContainerDefinitions(invocation.getArgument(1, List.class));
|
||||
taskDefinition.setContainerDefinitions(request.getContainerDefinitions());
|
||||
taskDefinition.setVolumes(request.getVolumes());
|
||||
taskDefinition.setRuntimePlatform(request.getRuntimePlatform());
|
||||
return taskDefinition;
|
||||
});
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
|
||||
+7
-3
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -36,13 +37,16 @@ class EcsJsonHandlerHealthCheckTest {
|
||||
void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
EcsService service = mock(EcsService.class);
|
||||
when(service.registerTaskDefinition(anyString(), any(), any(), any(), any(), any(), any(), any(), any(), anyString()))
|
||||
when(service.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), anyString()))
|
||||
.thenAnswer(inv -> {
|
||||
RegisterTaskDefinitionRequest request = inv.getArgument(0);
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(inv.getArgument(0));
|
||||
td.setFamily(request.getFamily());
|
||||
td.setRevision(1);
|
||||
td.setStatus("ACTIVE");
|
||||
td.setContainerDefinitions(inv.getArgument(1, List.class));
|
||||
td.setContainerDefinitions(request.getContainerDefinitions());
|
||||
td.setVolumes(request.getVolumes());
|
||||
td.setRuntimePlatform(request.getRuntimePlatform());
|
||||
return td;
|
||||
});
|
||||
|
||||
|
||||
+7
-3
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -40,13 +41,16 @@ class EcsJsonHandlerRuntimePlatformLogConfigurationTest {
|
||||
void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
EcsService service = mock(EcsService.class);
|
||||
when(service.registerTaskDefinition(anyString(), any(), any(), any(), any(), any(), any(), any(), any(), anyString()))
|
||||
when(service.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), anyString()))
|
||||
.thenAnswer(inv -> {
|
||||
RegisterTaskDefinitionRequest request = inv.getArgument(0);
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(inv.getArgument(0));
|
||||
td.setFamily(request.getFamily());
|
||||
td.setRevision(1);
|
||||
td.setStatus("ACTIVE");
|
||||
td.setContainerDefinitions(inv.getArgument(1, List.class));
|
||||
td.setContainerDefinitions(request.getContainerDefinitions());
|
||||
td.setVolumes(request.getVolumes());
|
||||
td.setRuntimePlatform(request.getRuntimePlatform());
|
||||
return td;
|
||||
});
|
||||
|
||||
|
||||
+7
-3
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -29,13 +30,16 @@ class EcsJsonHandlerVolumesFromTest {
|
||||
void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
EcsService service = mock(EcsService.class);
|
||||
when(service.registerTaskDefinition(anyString(), any(), any(), any(), any(), any(), any(), any(), any(), anyString()))
|
||||
when(service.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), anyString()))
|
||||
.thenAnswer(invocation -> {
|
||||
RegisterTaskDefinitionRequest request = invocation.getArgument(0);
|
||||
TaskDefinition taskDefinition = new TaskDefinition();
|
||||
taskDefinition.setFamily(invocation.getArgument(0));
|
||||
taskDefinition.setFamily(request.getFamily());
|
||||
taskDefinition.setRevision(1);
|
||||
taskDefinition.setStatus("ACTIVE");
|
||||
taskDefinition.setContainerDefinitions(invocation.getArgument(1, List.class));
|
||||
taskDefinition.setContainerDefinitions(request.getContainerDefinitions());
|
||||
taskDefinition.setVolumes(request.getVolumes());
|
||||
taskDefinition.setRuntimePlatform(request.getRuntimePlatform());
|
||||
return taskDefinition;
|
||||
});
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
|
||||
+7
-3
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -55,13 +56,16 @@ class EcsJsonHandlerVolumesTest {
|
||||
objectMapper = new ObjectMapper();
|
||||
service = mock(EcsService.class);
|
||||
// Echo the parsed container definitions (arg index 1) back inside a task definition.
|
||||
when(service.registerTaskDefinition(anyString(), any(), any(), any(), any(), any(), any(), any(), any(), anyString()))
|
||||
when(service.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), anyString()))
|
||||
.thenAnswer(inv -> {
|
||||
RegisterTaskDefinitionRequest request = inv.getArgument(0);
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(inv.getArgument(0));
|
||||
td.setFamily(request.getFamily());
|
||||
td.setRevision(1);
|
||||
td.setStatus("ACTIVE");
|
||||
td.setContainerDefinitions(inv.getArgument(1, List.class));
|
||||
td.setContainerDefinitions(request.getContainerDefinitions());
|
||||
td.setVolumes(request.getVolumes());
|
||||
td.setRuntimePlatform(request.getRuntimePlatform());
|
||||
return td;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user