mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -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
@@ -16,6 +16,7 @@ import io.github.hectorvent.floci.services.codedeploy.model.DeploymentGroup;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.OnPremisesInstance;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ecs.EcsService;
|
||||
import io.github.hectorvent.floci.services.ecs.model.CreateTaskSetRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskSet;
|
||||
import io.github.hectorvent.floci.services.elbv2.ElbV2Service;
|
||||
import io.github.hectorvent.floci.services.elbv2.model.TargetGroup;
|
||||
@@ -1357,8 +1358,14 @@ public class CodeDeployService {
|
||||
// Install: create green task set
|
||||
Map<String, Object> installEvent = addLifecycleEvent(ecsTargetMap, "Install");
|
||||
try {
|
||||
greenTaskSet = ecsService.createTaskSet(clusterName, serviceName,
|
||||
appSpec.taskDefinition, null, 100.0, "PERCENT", deploymentId, region);
|
||||
CreateTaskSetRequest createTaskSet = new CreateTaskSetRequest();
|
||||
createTaskSet.setCluster(clusterName);
|
||||
createTaskSet.setService(serviceName);
|
||||
createTaskSet.setTaskDefinition(appSpec.taskDefinition);
|
||||
createTaskSet.setScaleValue(100.0);
|
||||
createTaskSet.setScaleUnit("PERCENT");
|
||||
createTaskSet.setExternalId(deploymentId);
|
||||
greenTaskSet = ecsService.createTaskSet(createTaskSet, region);
|
||||
appendTaskSetInfo(ecsTargetMap, greenTaskSet, greenTgArn, 0.0);
|
||||
finishLifecycleEvent(installEvent, "Succeeded");
|
||||
} catch (Exception e) {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,612 @@
|
||||
package io.github.hectorvent.floci.services.ecs;
|
||||
|
||||
import io.github.hectorvent.floci.services.ecs.model.Attribute;
|
||||
import io.github.hectorvent.floci.services.ecs.model.AwsVpcConfiguration;
|
||||
import io.github.hectorvent.floci.services.ecs.model.CapacityProvider;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Container;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerInstance;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Deployment;
|
||||
import io.github.hectorvent.floci.services.ecs.model.EcsCluster;
|
||||
import io.github.hectorvent.floci.services.ecs.model.EcsLoadBalancer;
|
||||
import io.github.hectorvent.floci.services.ecs.model.EcsServiceModel;
|
||||
import io.github.hectorvent.floci.services.ecs.model.EcsTask;
|
||||
import io.github.hectorvent.floci.services.ecs.model.EfsVolumeConfiguration;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Failure;
|
||||
import io.github.hectorvent.floci.services.ecs.model.FirelensConfiguration;
|
||||
import io.github.hectorvent.floci.services.ecs.model.HealthCheck;
|
||||
import io.github.hectorvent.floci.services.ecs.model.KeyValuePair;
|
||||
import io.github.hectorvent.floci.services.ecs.model.LogConfiguration;
|
||||
import io.github.hectorvent.floci.services.ecs.model.MountPoint;
|
||||
import io.github.hectorvent.floci.services.ecs.model.NetworkBinding;
|
||||
import io.github.hectorvent.floci.services.ecs.model.PortMapping;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ProtectedTask;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RuntimePlatform;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Secret;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ServiceDeployment;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ServiceRevision;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskSet;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Volume;
|
||||
import io.github.hectorvent.floci.services.ecs.model.VolumeFrom;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Renders ECS domain objects to the JSON 1.1 shapes the data plane returns.
|
||||
*
|
||||
* <p>Split from {@link EcsJsonHandler} so that request parsing and response rendering, which had
|
||||
* grown to comparable size, stay separately readable. The handler dispatches and parses; this
|
||||
* writes.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class EcsResponseWriter {
|
||||
|
||||
private final EcsService service;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public EcsResponseWriter(EcsService service, ObjectMapper objectMapper) {
|
||||
this.service = service;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
// ── Clusters ──────────────────────────────────────────────────────────────
|
||||
|
||||
public ObjectNode clusterNode(EcsCluster c) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("clusterArn", c.getClusterArn());
|
||||
n.put("clusterName", c.getClusterName());
|
||||
n.put("status", c.getStatus());
|
||||
n.put("registeredContainerInstancesCount", c.getRegisteredContainerInstancesCount());
|
||||
n.put("runningTasksCount", c.getRunningTasksCount());
|
||||
n.put("pendingTasksCount", c.getPendingTasksCount());
|
||||
n.put("activeServicesCount", c.getActiveServicesCount());
|
||||
if (c.getSettings() != null && !c.getSettings().isEmpty()) {
|
||||
ArrayNode settings = objectMapper.createArrayNode();
|
||||
c.getSettings().forEach(s -> {
|
||||
ObjectNode sn = objectMapper.createObjectNode();
|
||||
sn.put("name", s.name());
|
||||
sn.put("value", s.value());
|
||||
settings.add(sn);
|
||||
});
|
||||
n.set("settings", settings);
|
||||
}
|
||||
if (c.getCapacityProviders() != null) {
|
||||
ArrayNode cp = objectMapper.createArrayNode();
|
||||
c.getCapacityProviders().forEach(cp::add);
|
||||
n.set("capacityProviders", cp);
|
||||
}
|
||||
if (c.getTags() != null && !c.getTags().isEmpty()) {
|
||||
n.set("tags", tagsNode(c.getTags()));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Task definitions ──────────────────────────────────────────────────────
|
||||
|
||||
public ObjectNode taskDefinitionNode(TaskDefinition td) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("taskDefinitionArn", td.getTaskDefinitionArn());
|
||||
n.put("family", td.getFamily());
|
||||
n.put("revision", td.getRevision());
|
||||
n.put("status", td.getStatus());
|
||||
if (td.getNetworkMode() != null) {
|
||||
n.put("networkMode", td.getNetworkMode().name());
|
||||
}
|
||||
if (td.getCpu() != null) { n.put("cpu", td.getCpu()); }
|
||||
if (td.getMemory() != null) { n.put("memory", td.getMemory()); }
|
||||
if (td.getTaskRoleArn() != null) { n.put("taskRoleArn", td.getTaskRoleArn()); }
|
||||
if (td.getExecutionRoleArn() != null) { n.put("executionRoleArn", td.getExecutionRoleArn()); }
|
||||
if (td.getRuntimePlatform() != null) {
|
||||
RuntimePlatform platform = td.getRuntimePlatform();
|
||||
ObjectNode platformNode = objectMapper.createObjectNode();
|
||||
if (platform.cpuArchitecture() != null) {
|
||||
platformNode.put("cpuArchitecture", platform.cpuArchitecture());
|
||||
}
|
||||
if (platform.operatingSystemFamily() != null) {
|
||||
platformNode.put("operatingSystemFamily", platform.operatingSystemFamily());
|
||||
}
|
||||
n.set("runtimePlatform", platformNode);
|
||||
}
|
||||
if (td.getRequiresCompatibilities() != null && !td.getRequiresCompatibilities().isEmpty()) {
|
||||
ArrayNode arr = objectMapper.createArrayNode();
|
||||
td.getRequiresCompatibilities().forEach(arr::add);
|
||||
n.set("requiresCompatibilities", arr);
|
||||
}
|
||||
if (td.getCompatibilities() != null && !td.getCompatibilities().isEmpty()) {
|
||||
ArrayNode arr = objectMapper.createArrayNode();
|
||||
td.getCompatibilities().forEach(arr::add);
|
||||
n.set("compatibilities", arr);
|
||||
}
|
||||
|
||||
ArrayNode containers = objectMapper.createArrayNode();
|
||||
if (td.getContainerDefinitions() != null) {
|
||||
for (ContainerDefinition def : td.getContainerDefinitions()) {
|
||||
containers.add(containerDefinitionNode(def));
|
||||
}
|
||||
}
|
||||
n.set("containerDefinitions", containers);
|
||||
if (td.getVolumes() != null && !td.getVolumes().isEmpty()) {
|
||||
n.set("volumes", volumesNode(td.getVolumes()));
|
||||
}
|
||||
if (td.getTags() != null && !td.getTags().isEmpty()) {
|
||||
n.set("tags", tagsNode(td.getTags()));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
private ArrayNode volumesNode(List<Volume> volumes) {
|
||||
ArrayNode vols = objectMapper.createArrayNode();
|
||||
for (Volume v : volumes) {
|
||||
ObjectNode vNode = objectMapper.createObjectNode();
|
||||
vNode.put("name", v.name());
|
||||
if (v.hostSourcePath() != null) {
|
||||
ObjectNode host = objectMapper.createObjectNode();
|
||||
host.put("sourcePath", v.hostSourcePath());
|
||||
vNode.set("host", host);
|
||||
}
|
||||
if (v.efs() != null) {
|
||||
EfsVolumeConfiguration e = v.efs();
|
||||
ObjectNode efs = objectMapper.createObjectNode();
|
||||
efs.put("fileSystemId", e.fileSystemId());
|
||||
if (e.rootDirectory() != null) {
|
||||
efs.put("rootDirectory", e.rootDirectory());
|
||||
}
|
||||
if (e.transitEncryption() != null) {
|
||||
efs.put("transitEncryption", e.transitEncryption());
|
||||
}
|
||||
if (e.transitEncryptionPort() != null) {
|
||||
efs.put("transitEncryptionPort", e.transitEncryptionPort());
|
||||
}
|
||||
if (e.accessPointId() != null || e.iam() != null) {
|
||||
ObjectNode auth = objectMapper.createObjectNode();
|
||||
if (e.accessPointId() != null) {
|
||||
auth.put("accessPointId", e.accessPointId());
|
||||
}
|
||||
if (e.iam() != null) {
|
||||
auth.put("iam", e.iam());
|
||||
}
|
||||
efs.set("authorizationConfig", auth);
|
||||
}
|
||||
vNode.set("efsVolumeConfiguration", efs);
|
||||
}
|
||||
vols.add(vNode);
|
||||
}
|
||||
return vols;
|
||||
}
|
||||
|
||||
public ObjectNode containerDefinitionNode(ContainerDefinition def) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("name", def.getName());
|
||||
n.put("image", def.getImage());
|
||||
n.put("essential", def.isEssential());
|
||||
if (def.getCpu() != null) { n.put("cpu", def.getCpu()); }
|
||||
if (def.getMemory() != null) { n.put("memory", def.getMemory()); }
|
||||
|
||||
if (def.getPortMappings() != null && !def.getPortMappings().isEmpty()) {
|
||||
ArrayNode pms = objectMapper.createArrayNode();
|
||||
for (PortMapping pm : def.getPortMappings()) {
|
||||
ObjectNode pmNode = objectMapper.createObjectNode();
|
||||
pmNode.put("containerPort", pm.containerPort());
|
||||
pmNode.put("hostPort", pm.hostPort());
|
||||
pmNode.put("protocol", pm.protocol());
|
||||
pms.add(pmNode);
|
||||
}
|
||||
n.set("portMappings", pms);
|
||||
}
|
||||
|
||||
if (def.getEntryPoint() != null && !def.getEntryPoint().isEmpty()) {
|
||||
n.set("entryPoint", stringArray(def.getEntryPoint()));
|
||||
}
|
||||
if (def.getCommand() != null && !def.getCommand().isEmpty()) {
|
||||
n.set("command", stringArray(def.getCommand()));
|
||||
}
|
||||
if (def.getEnvironment() != null && !def.getEnvironment().isEmpty()) {
|
||||
n.set("environment", keyValuePairsNode(def.getEnvironment()));
|
||||
}
|
||||
if (def.getSecrets() != null && !def.getSecrets().isEmpty()) {
|
||||
n.set("secrets", secretsNode(def.getSecrets()));
|
||||
}
|
||||
if (def.getMountPoints() != null && !def.getMountPoints().isEmpty()) {
|
||||
ArrayNode mps = objectMapper.createArrayNode();
|
||||
for (MountPoint mp : def.getMountPoints()) {
|
||||
ObjectNode mpNode = objectMapper.createObjectNode();
|
||||
mpNode.put("sourceVolume", mp.sourceVolume());
|
||||
mpNode.put("containerPath", mp.containerPath());
|
||||
mpNode.put("readOnly", mp.readOnly());
|
||||
mps.add(mpNode);
|
||||
}
|
||||
n.set("mountPoints", mps);
|
||||
}
|
||||
if (def.getVolumesFrom() != null && !def.getVolumesFrom().isEmpty()) {
|
||||
ArrayNode volumesFrom = objectMapper.createArrayNode();
|
||||
for (VolumeFrom volumeFrom : def.getVolumesFrom()) {
|
||||
ObjectNode volumeFromNode = objectMapper.createObjectNode();
|
||||
volumeFromNode.put("sourceContainer", volumeFrom.sourceContainer());
|
||||
volumeFromNode.put("readOnly", volumeFrom.readOnly());
|
||||
volumesFrom.add(volumeFromNode);
|
||||
}
|
||||
n.set("volumesFrom", volumesFrom);
|
||||
}
|
||||
|
||||
if (def.getLogConfiguration() != null) {
|
||||
LogConfiguration logConfig = def.getLogConfiguration();
|
||||
ObjectNode logNode = objectMapper.createObjectNode();
|
||||
if (logConfig.logDriver() != null) {
|
||||
logNode.put("logDriver", logConfig.logDriver());
|
||||
}
|
||||
if (logConfig.options() != null) {
|
||||
ObjectNode options = objectMapper.createObjectNode();
|
||||
logConfig.options().forEach(options::put);
|
||||
logNode.set("options", options);
|
||||
}
|
||||
if (logConfig.secretOptions() != null) {
|
||||
logNode.set("secretOptions", secretsNode(logConfig.secretOptions()));
|
||||
}
|
||||
n.set("logConfiguration", logNode);
|
||||
}
|
||||
|
||||
if (def.getFirelensConfiguration() != null) {
|
||||
FirelensConfiguration firelens = def.getFirelensConfiguration();
|
||||
ObjectNode firelensNode = objectMapper.createObjectNode();
|
||||
if (firelens.type() != null) {
|
||||
firelensNode.put("type", firelens.type());
|
||||
}
|
||||
if (firelens.options() != null) {
|
||||
ObjectNode options = objectMapper.createObjectNode();
|
||||
firelens.options().forEach(options::put);
|
||||
firelensNode.set("options", options);
|
||||
}
|
||||
n.set("firelensConfiguration", firelensNode);
|
||||
}
|
||||
if (def.getHealthCheck() != null) {
|
||||
HealthCheck hc = def.getHealthCheck();
|
||||
ObjectNode hcNode = objectMapper.createObjectNode();
|
||||
if (hc.command() != null) {
|
||||
hcNode.set("command", stringArray(hc.command()));
|
||||
}
|
||||
if (hc.interval() != null) { hcNode.put("interval", hc.interval()); }
|
||||
if (hc.timeout() != null) { hcNode.put("timeout", hc.timeout()); }
|
||||
if (hc.retries() != null) { hcNode.put("retries", hc.retries()); }
|
||||
if (hc.startPeriod() != null) { hcNode.put("startPeriod", hc.startPeriod()); }
|
||||
n.set("healthCheck", hcNode);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Tasks ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Renders an ECS task to its data-plane JSON shape. Reused by the Step Functions
|
||||
* ecs:runTask integration ({@link io.github.hectorvent.floci.services.stepfunctions.AslExecutor}). */
|
||||
public ObjectNode taskNode(EcsTask t) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("taskArn", t.getTaskArn());
|
||||
n.put("clusterArn", t.getClusterArn());
|
||||
n.put("taskDefinitionArn", t.getTaskDefinitionArn());
|
||||
n.put("lastStatus", t.getLastStatus());
|
||||
n.put("desiredStatus", t.getDesiredStatus());
|
||||
if (t.getLaunchType() != null) { n.put("launchType", t.getLaunchType().name()); }
|
||||
if (t.getCpu() != null) { n.put("cpu", t.getCpu()); }
|
||||
if (t.getMemory() != null) { n.put("memory", t.getMemory()); }
|
||||
if (t.getGroup() != null) { n.put("group", t.getGroup()); }
|
||||
if (t.getStartedBy() != null) { n.put("startedBy", t.getStartedBy()); }
|
||||
if (t.getContainerInstanceArn() != null) { n.put("containerInstanceArn", t.getContainerInstanceArn()); }
|
||||
if (t.getCreatedAt() != null) { n.put("createdAt", t.getCreatedAt().toEpochMilli() / 1000.0); }
|
||||
if (t.getStartedAt() != null) { n.put("startedAt", t.getStartedAt().toEpochMilli() / 1000.0); }
|
||||
if (t.getStoppedAt() != null) { n.put("stoppedAt", t.getStoppedAt().toEpochMilli() / 1000.0); }
|
||||
if (t.getStoppedReason() != null) { n.put("stoppedReason", t.getStoppedReason()); }
|
||||
if (t.getNetworkInterfaceId() != null) {
|
||||
n.putArray("attachments").add(eniAttachmentNode(t));
|
||||
}
|
||||
|
||||
ArrayNode containers = objectMapper.createArrayNode();
|
||||
if (t.getContainers() != null) {
|
||||
for (Container c : t.getContainers()) {
|
||||
containers.add(containerNode(c));
|
||||
}
|
||||
}
|
||||
n.set("containers", containers);
|
||||
if (t.getTags() != null && !t.getTags().isEmpty()) {
|
||||
n.set("tags", tagsNode(t.getTags()));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
private ObjectNode eniAttachmentNode(EcsTask t) {
|
||||
ObjectNode attachment = objectMapper.createObjectNode();
|
||||
attachment.put("id", "eni-attach-" + t.getNetworkInterfaceId());
|
||||
attachment.put("type", "ElasticNetworkInterface");
|
||||
attachment.put("status", "ATTACHED");
|
||||
ArrayNode details = objectMapper.createArrayNode();
|
||||
if (t.getNetworkConfiguration() != null
|
||||
&& t.getNetworkConfiguration().getAwsvpcConfiguration() != null
|
||||
&& !t.getNetworkConfiguration().getAwsvpcConfiguration().getSubnets().isEmpty()) {
|
||||
details.addObject().put("name", "subnetId").put("value",
|
||||
t.getNetworkConfiguration().getAwsvpcConfiguration().getSubnets().getFirst());
|
||||
}
|
||||
details.addObject().put("name", "networkInterfaceId").put("value", t.getNetworkInterfaceId());
|
||||
details.addObject().put("name", "privateIPv4Address").put("value", t.getPrivateIpAddress());
|
||||
attachment.set("details", details);
|
||||
return attachment;
|
||||
}
|
||||
|
||||
private ObjectNode containerNode(Container c) {
|
||||
ObjectNode cn = objectMapper.createObjectNode();
|
||||
cn.put("containerArn", c.getContainerArn());
|
||||
cn.put("taskArn", c.getTaskArn());
|
||||
cn.put("name", c.getName());
|
||||
cn.put("image", c.getImage());
|
||||
cn.put("lastStatus", c.getLastStatus());
|
||||
if (c.getExitCode() != null) { cn.put("exitCode", c.getExitCode()); }
|
||||
if (c.getReason() != null) { cn.put("reason", c.getReason()); }
|
||||
|
||||
ArrayNode bindings = objectMapper.createArrayNode();
|
||||
if (c.getNetworkBindings() != null) {
|
||||
for (NetworkBinding nb : c.getNetworkBindings()) {
|
||||
ObjectNode bn = objectMapper.createObjectNode();
|
||||
bn.put("bindIP", nb.bindIP());
|
||||
bn.put("containerPort", nb.containerPort());
|
||||
bn.put("hostPort", nb.hostPort());
|
||||
bn.put("protocol", nb.protocol());
|
||||
bindings.add(bn);
|
||||
}
|
||||
}
|
||||
cn.set("networkBindings", bindings);
|
||||
return cn;
|
||||
}
|
||||
|
||||
// ── Services ──────────────────────────────────────────────────────────────
|
||||
|
||||
public ObjectNode serviceNode(EcsServiceModel s) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("serviceArn", s.getServiceArn());
|
||||
n.put("serviceName", s.getServiceName());
|
||||
n.put("clusterArn", s.getClusterArn());
|
||||
n.put("taskDefinition", s.getTaskDefinition());
|
||||
n.put("desiredCount", s.getDesiredCount());
|
||||
n.put("runningCount", s.getRunningCount());
|
||||
n.put("pendingCount", s.getPendingCount());
|
||||
n.put("status", s.getStatus());
|
||||
if (s.getLaunchType() != null) { n.put("launchType", s.getLaunchType().name()); }
|
||||
if (s.getCreatedAt() != null) { n.put("createdAt", s.getCreatedAt().toEpochMilli() / 1000.0); }
|
||||
if (s.getNamespace() != null) { n.put("namespace", s.getNamespace()); }
|
||||
// Services persisted before these fields existed read back with the AWS defaults.
|
||||
n.put("schedulingStrategy", s.getSchedulingStrategy() != null
|
||||
? s.getSchedulingStrategy() : EcsService.DEFAULT_SCHEDULING_STRATEGY);
|
||||
n.putObject("deploymentController").put("type", s.getDeploymentController() != null
|
||||
? s.getDeploymentController() : EcsService.DEFAULT_DEPLOYMENT_CONTROLLER);
|
||||
n.put("availabilityZoneRebalancing", s.getAvailabilityZoneRebalancing() != null
|
||||
? s.getAvailabilityZoneRebalancing() : EcsService.DEFAULT_AZ_REBALANCING_UNSET);
|
||||
if (s.getTags() != null && !s.getTags().isEmpty()) {
|
||||
n.set("tags", tagsNode(s.getTags()));
|
||||
}
|
||||
if (s.getLoadBalancers() != null && !s.getLoadBalancers().isEmpty()) {
|
||||
ArrayNode lbs = objectMapper.createArrayNode();
|
||||
for (EcsLoadBalancer lb : s.getLoadBalancers()) {
|
||||
lbs.add(loadBalancerNode(lb));
|
||||
}
|
||||
n.set("loadBalancers", lbs);
|
||||
}
|
||||
if (s.getNetworkConfiguration() != null
|
||||
&& s.getNetworkConfiguration().getAwsvpcConfiguration() != null) {
|
||||
n.set("networkConfiguration",
|
||||
networkConfigurationNode(s.getNetworkConfiguration().getAwsvpcConfiguration()));
|
||||
}
|
||||
ArrayNode deployments = objectMapper.createArrayNode();
|
||||
service.deploymentsFor(s).forEach(d -> deployments.add(deploymentNode(d)));
|
||||
n.set("deployments", deployments);
|
||||
return n;
|
||||
}
|
||||
|
||||
private ObjectNode loadBalancerNode(EcsLoadBalancer lb) {
|
||||
ObjectNode ln = objectMapper.createObjectNode();
|
||||
if (lb.getTargetGroupArn() != null) { ln.put("targetGroupArn", lb.getTargetGroupArn()); }
|
||||
if (lb.getLoadBalancerName() != null) { ln.put("loadBalancerName", lb.getLoadBalancerName()); }
|
||||
if (lb.getContainerName() != null) { ln.put("containerName", lb.getContainerName()); }
|
||||
if (lb.getContainerPort() != null) { ln.put("containerPort", lb.getContainerPort()); }
|
||||
return ln;
|
||||
}
|
||||
|
||||
private ObjectNode networkConfigurationNode(AwsVpcConfiguration awsvpc) {
|
||||
ObjectNode awsvpcNode = objectMapper.createObjectNode();
|
||||
awsvpcNode.set("subnets", stringArray(awsvpc.getSubnets()));
|
||||
awsvpcNode.set("securityGroups", stringArray(awsvpc.getSecurityGroups()));
|
||||
if (awsvpc.getAssignPublicIp() != null) {
|
||||
awsvpcNode.put("assignPublicIp", awsvpc.getAssignPublicIp());
|
||||
}
|
||||
ObjectNode networkConfig = objectMapper.createObjectNode();
|
||||
networkConfig.set("awsvpcConfiguration", awsvpcNode);
|
||||
return networkConfig;
|
||||
}
|
||||
|
||||
public ObjectNode deploymentNode(Deployment d) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("id", d.getId());
|
||||
n.put("status", d.getStatus());
|
||||
n.put("taskDefinition", d.getTaskDefinition());
|
||||
n.put("desiredCount", d.getDesiredCount());
|
||||
n.put("pendingCount", d.getPendingCount());
|
||||
n.put("runningCount", d.getRunningCount());
|
||||
n.put("failedTasks", d.getFailedTasks());
|
||||
n.put("rolloutState", d.getRolloutState());
|
||||
n.put("rolloutStateReason", d.getRolloutStateReason());
|
||||
if (d.getLaunchType() != null) { n.put("launchType", d.getLaunchType().name()); }
|
||||
if (d.getCreatedAt() != null) { n.put("createdAt", d.getCreatedAt().toEpochMilli() / 1000.0); }
|
||||
if (d.getUpdatedAt() != null) { n.put("updatedAt", d.getUpdatedAt().toEpochMilli() / 1000.0); }
|
||||
if (d.getServiceConnectConfiguration() != null) {
|
||||
n.set("serviceConnectConfiguration", objectMapper.valueToTree(d.getServiceConnectConfiguration()));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public ObjectNode failureNode(Failure f) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("arn", f.arn());
|
||||
n.put("reason", f.reason());
|
||||
if (f.detail() != null) { n.put("detail", f.detail()); }
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Container instances ───────────────────────────────────────────────────
|
||||
|
||||
public ObjectNode containerInstanceNode(ContainerInstance ci) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("containerInstanceArn", ci.getContainerInstanceArn());
|
||||
n.put("ec2InstanceId", ci.getEc2InstanceId());
|
||||
n.put("status", ci.getStatus());
|
||||
n.put("runningTasksCount", ci.getRunningTasksCount());
|
||||
n.put("pendingTasksCount", ci.getPendingTasksCount());
|
||||
n.put("agentVersion", ci.getAgentVersion());
|
||||
n.put("agentConnected", ci.isAgentConnected());
|
||||
if (ci.getAttributes() != null && !ci.getAttributes().isEmpty()) {
|
||||
ArrayNode attrs = objectMapper.createArrayNode();
|
||||
ci.getAttributes().forEach(a -> attrs.add(attributeNode(a)));
|
||||
n.set("attributes", attrs);
|
||||
}
|
||||
if (ci.getTags() != null && !ci.getTags().isEmpty()) {
|
||||
n.set("tags", tagsNode(ci.getTags()));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Capacity providers ────────────────────────────────────────────────────
|
||||
|
||||
public ObjectNode capacityProviderNode(CapacityProvider cp) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("name", cp.getName());
|
||||
n.put("status", cp.getStatus());
|
||||
if (cp.getCapacityProviderArn() != null) { n.put("capacityProviderArn", cp.getCapacityProviderArn()); }
|
||||
if (cp.getTags() != null && !cp.getTags().isEmpty()) {
|
||||
n.set("tags", tagsNode(cp.getTags()));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Task sets ─────────────────────────────────────────────────────────────
|
||||
|
||||
public ObjectNode taskSetNode(TaskSet ts) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("id", ts.getId());
|
||||
n.put("taskSetArn", ts.getTaskSetArn());
|
||||
n.put("serviceArn", ts.getServiceArn());
|
||||
n.put("clusterArn", ts.getClusterArn());
|
||||
n.put("taskDefinition", ts.getTaskDefinition());
|
||||
n.put("status", ts.getStatus());
|
||||
n.put("computedDesiredCount", ts.getComputedDesiredCount());
|
||||
n.put("pendingCount", ts.getPendingCount());
|
||||
n.put("runningCount", ts.getRunningCount());
|
||||
n.put("stabilityStatus", ts.getStabilityStatus());
|
||||
if (ts.getLaunchType() != null) { n.put("launchType", ts.getLaunchType().name()); }
|
||||
if (ts.getExternalId() != null) { n.put("externalId", ts.getExternalId()); }
|
||||
ObjectNode scale = objectMapper.createObjectNode();
|
||||
scale.put("value", ts.getScaleValue());
|
||||
scale.put("unit", ts.getScaleUnit());
|
||||
n.set("scale", scale);
|
||||
if (ts.getCreatedAt() != null) { n.put("createdAt", ts.getCreatedAt().toEpochMilli() / 1000.0); }
|
||||
if (ts.getUpdatedAt() != null) { n.put("updatedAt", ts.getUpdatedAt().toEpochMilli() / 1000.0); }
|
||||
if (ts.getTags() != null && !ts.getTags().isEmpty()) {
|
||||
n.set("tags", tagsNode(ts.getTags()));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Service deployments and revisions ─────────────────────────────────────
|
||||
|
||||
public ObjectNode serviceDeploymentNode(ServiceDeployment d) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("serviceDeploymentArn", d.getServiceDeploymentArn());
|
||||
n.put("serviceArn", d.getServiceArn());
|
||||
n.put("clusterArn", d.getClusterArn());
|
||||
n.put("taskDefinition", d.getTaskDefinition());
|
||||
n.put("status", d.getStatus());
|
||||
if (d.getCreatedAt() != null) { n.put("createdAt", d.getCreatedAt().toEpochMilli() / 1000.0); }
|
||||
if (d.getUpdatedAt() != null) { n.put("updatedAt", d.getUpdatedAt().toEpochMilli() / 1000.0); }
|
||||
return n;
|
||||
}
|
||||
|
||||
public ObjectNode serviceRevisionNode(ServiceRevision r) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("serviceRevisionArn", r.getServiceRevisionArn());
|
||||
n.put("serviceArn", r.getServiceArn());
|
||||
n.put("clusterArn", r.getClusterArn());
|
||||
n.put("taskDefinition", r.getTaskDefinition());
|
||||
if (r.getLaunchType() != null) { n.put("launchType", r.getLaunchType().name()); }
|
||||
if (r.getCreatedAt() != null) { n.put("createdAt", r.getCreatedAt().toEpochMilli() / 1000.0); }
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Shared members ────────────────────────────────────────────────────────
|
||||
|
||||
public ObjectNode protectedTaskNode(ProtectedTask pt) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("taskArn", pt.taskArn());
|
||||
n.put("protectionEnabled", pt.protectionEnabled());
|
||||
if (pt.expirationDate() != null) {
|
||||
n.put("expirationDate", pt.expirationDate().toEpochMilli() / 1000.0);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public ObjectNode attributeNode(Attribute a) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("name", a.name());
|
||||
if (a.value() != null) { n.put("value", a.value()); }
|
||||
if (a.targetType() != null) { n.put("targetType", a.targetType()); }
|
||||
if (a.targetId() != null) { n.put("targetId", a.targetId()); }
|
||||
return n;
|
||||
}
|
||||
|
||||
public ObjectNode settingNode(String name, String value) {
|
||||
ObjectNode n = objectMapper.createObjectNode();
|
||||
n.put("name", name);
|
||||
n.put("value", value);
|
||||
return n;
|
||||
}
|
||||
|
||||
public ArrayNode tagsNode(Map<String, String> tags) {
|
||||
ArrayNode arr = objectMapper.createArrayNode();
|
||||
tags.forEach((k, v) -> {
|
||||
ObjectNode tag = objectMapper.createObjectNode();
|
||||
tag.put("key", k);
|
||||
tag.put("value", v);
|
||||
arr.add(tag);
|
||||
});
|
||||
return arr;
|
||||
}
|
||||
|
||||
private ArrayNode keyValuePairsNode(List<KeyValuePair> pairs) {
|
||||
ArrayNode arr = objectMapper.createArrayNode();
|
||||
for (KeyValuePair kv : pairs) {
|
||||
ObjectNode kvNode = objectMapper.createObjectNode();
|
||||
kvNode.put("name", kv.name());
|
||||
kvNode.put("value", kv.value());
|
||||
arr.add(kvNode);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
private ArrayNode secretsNode(List<Secret> secrets) {
|
||||
ArrayNode arr = objectMapper.createArrayNode();
|
||||
for (Secret secret : secrets) {
|
||||
ObjectNode secretNode = objectMapper.createObjectNode();
|
||||
secretNode.put("name", secret.name());
|
||||
secretNode.put("valueFrom", secret.valueFrom());
|
||||
arr.add(secretNode);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
private ArrayNode stringArray(List<String> values) {
|
||||
ArrayNode arr = objectMapper.createArrayNode();
|
||||
values.forEach(arr::add);
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ import io.github.hectorvent.floci.services.ecs.model.CapacityProvider;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ClusterSetting;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerInstance;
|
||||
import io.github.hectorvent.floci.services.ecs.model.CreateClusterRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.CreateServiceRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.CreateTaskSetRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Deployment;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Failure;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerOverride;
|
||||
@@ -27,14 +30,18 @@ import io.github.hectorvent.floci.services.ecs.model.EcsServiceModel;
|
||||
import io.github.hectorvent.floci.services.ecs.model.EcsTask;
|
||||
import io.github.hectorvent.floci.services.ecs.model.FirelensConfiguration;
|
||||
import io.github.hectorvent.floci.services.ecs.model.LaunchType;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ListTasksRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration;
|
||||
import io.github.hectorvent.floci.services.ecs.model.NetworkMode;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ProtectedTask;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RunTaskRequest;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ServiceDeployment;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ServiceRevision;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskSet;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskStatus;
|
||||
import io.github.hectorvent.floci.services.ecs.model.UpdateServiceRequest;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -280,7 +287,16 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
*/
|
||||
public EcsCluster createCluster(String clusterName, Map<String, String> tags,
|
||||
List<ClusterSetting> settings, String region) {
|
||||
String name = (clusterName == null || clusterName.isBlank()) ? DEFAULT_CLUSTER : clusterName;
|
||||
CreateClusterRequest request = new CreateClusterRequest();
|
||||
request.setClusterName(clusterName);
|
||||
request.setTags(tags);
|
||||
request.setSettings(settings);
|
||||
return createCluster(request, region);
|
||||
}
|
||||
|
||||
public EcsCluster createCluster(CreateClusterRequest request, String region) {
|
||||
String name = (request.getClusterName() == null || request.getClusterName().isBlank())
|
||||
? DEFAULT_CLUSTER : request.getClusterName();
|
||||
String key = clusterKey(region, name);
|
||||
if (clusters.containsKey(key)) {
|
||||
return clusters.get(key);
|
||||
@@ -289,11 +305,11 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
cluster.setClusterName(name);
|
||||
cluster.setClusterArn(regionResolver.buildArn("ecs", region, "cluster/" + name));
|
||||
cluster.setStatus("ACTIVE");
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
cluster.setTags(new LinkedHashMap<>(tags));
|
||||
if (request.getTags() != null && !request.getTags().isEmpty()) {
|
||||
cluster.setTags(new LinkedHashMap<>(request.getTags()));
|
||||
}
|
||||
if (settings != null && !settings.isEmpty()) {
|
||||
cluster.setSettings(new ArrayList<>(settings));
|
||||
if (request.getSettings() != null && !request.getSettings().isEmpty()) {
|
||||
cluster.setSettings(new ArrayList<>(request.getSettings()));
|
||||
}
|
||||
clusters.put(key, cluster);
|
||||
LOG.infov("Created ECS cluster: {0} in {1}", name, region);
|
||||
@@ -378,46 +394,65 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
String taskRoleArn, String executionRoleArn,
|
||||
List<String> requiresCompatibilities,
|
||||
Map<String, String> tags, String region) {
|
||||
boolean fargate = requiresCompatibilities != null && requiresCompatibilities.contains("FARGATE");
|
||||
RegisterTaskDefinitionRequest request = new RegisterTaskDefinitionRequest();
|
||||
request.setFamily(family);
|
||||
request.setContainerDefinitions(containerDefs);
|
||||
request.setNetworkMode(networkMode);
|
||||
request.setCpu(cpu);
|
||||
request.setMemory(memory);
|
||||
request.setTaskRoleArn(taskRoleArn);
|
||||
request.setExecutionRoleArn(executionRoleArn);
|
||||
request.setRequiresCompatibilities(requiresCompatibilities);
|
||||
request.setTags(tags);
|
||||
return registerTaskDefinition(request, region);
|
||||
}
|
||||
|
||||
public TaskDefinition registerTaskDefinition(RegisterTaskDefinitionRequest request, String region) {
|
||||
List<ContainerDefinition> containerDefs = request.getContainerDefinitions();
|
||||
List<String> requiresCompatibilities = request.getRequiresCompatibilities();
|
||||
boolean fargate = request.isFargate();
|
||||
if (fargate) {
|
||||
if (networkMode != NetworkMode.awsvpc) {
|
||||
if (request.getNetworkMode() != NetworkMode.awsvpc) {
|
||||
throw new AwsException("ClientException", "Fargate only supports network mode 'awsvpc'.", 400);
|
||||
}
|
||||
if (cpu == null) {
|
||||
if (request.getCpu() == null) {
|
||||
throw new AwsException("ClientException", "Fargate requires that 'cpu' be defined at the task level.", 400);
|
||||
}
|
||||
if (memory == null) {
|
||||
if (request.getMemory() == null) {
|
||||
throw new AwsException("ClientException", "Fargate requires that 'memory' be defined at the task level.", 400);
|
||||
}
|
||||
if (!isValidFargateCpuMemory(cpu, memory)) {
|
||||
if (!isValidFargateCpuMemory(request.getCpu(), request.getMemory())) {
|
||||
throw new AwsException("ClientException", "No Fargate configuration exists for given values.", 400);
|
||||
}
|
||||
}
|
||||
validateFirelensS3Config(containerDefs, fargate);
|
||||
String family = request.getFamily();
|
||||
int revision = latestRevisions.merge(family, 1, Integer::sum);
|
||||
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(family);
|
||||
td.setRevision(revision);
|
||||
td.setStatus("ACTIVE");
|
||||
td.setNetworkMode(networkMode != null ? networkMode : NetworkMode.bridge);
|
||||
td.setCpu(cpu);
|
||||
td.setMemory(memory);
|
||||
td.setTaskRoleArn(taskRoleArn);
|
||||
td.setExecutionRoleArn(executionRoleArn);
|
||||
td.setNetworkMode(request.getNetworkMode() != null ? request.getNetworkMode() : NetworkMode.bridge);
|
||||
td.setCpu(request.getCpu());
|
||||
td.setMemory(request.getMemory());
|
||||
td.setTaskRoleArn(request.getTaskRoleArn());
|
||||
td.setExecutionRoleArn(request.getExecutionRoleArn());
|
||||
td.setContainerDefinitions(containerDefs != null ? containerDefs : List.of());
|
||||
td.setRequiresCompatibilities(requiresCompatibilities);
|
||||
td.setVolumes(request.getVolumes());
|
||||
td.setRuntimePlatform(request.getRuntimePlatform());
|
||||
|
||||
if (requiresCompatibilities != null && !requiresCompatibilities.isEmpty()) {
|
||||
td.setCompatibilities(new java.util.ArrayList<>(requiresCompatibilities));
|
||||
td.setCompatibilities(new ArrayList<>(requiresCompatibilities));
|
||||
} else {
|
||||
td.setCompatibilities(java.util.List.of("EC2"));
|
||||
td.setCompatibilities(List.of("EC2"));
|
||||
}
|
||||
|
||||
td.setTaskDefinitionArn(regionResolver.buildArn("ecs", region,
|
||||
"task-definition/" + family + ":" + revision));
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
td.setTags(new LinkedHashMap<>(tags));
|
||||
if (request.getTags() != null && !request.getTags().isEmpty()) {
|
||||
td.setTags(new LinkedHashMap<>(request.getTags()));
|
||||
}
|
||||
|
||||
taskDefinitions.put(family + ":" + revision, td);
|
||||
@@ -572,22 +607,50 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
LaunchType launchType, String group, String startedBy,
|
||||
List<ContainerOverride> containerOverrides,
|
||||
NetworkConfiguration networkConfiguration, String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(clusterRef, region);
|
||||
TaskDefinition taskDef = resolveTaskDefinitionOrThrow(taskDefinitionRef, region);
|
||||
return launchTasks(cluster, taskDef, count, launchType, group, startedBy, null,
|
||||
containerOverrides, networkConfiguration, null, region);
|
||||
RunTaskRequest request = new RunTaskRequest();
|
||||
request.setCluster(clusterRef);
|
||||
request.setTaskDefinition(taskDefinitionRef);
|
||||
request.setCount(count);
|
||||
request.setLaunchType(launchType);
|
||||
request.setGroup(group);
|
||||
request.setStartedBy(startedBy);
|
||||
request.setContainerOverrides(containerOverrides);
|
||||
request.setNetworkConfiguration(networkConfiguration);
|
||||
return runTask(request, region);
|
||||
}
|
||||
|
||||
public List<EcsTask> runTask(RunTaskRequest request, String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(request.getCluster(), region);
|
||||
TaskDefinition taskDef = resolveTaskDefinitionOrThrow(request.getTaskDefinition(), region);
|
||||
return launchTasks(cluster, taskDef, request, null, null, region);
|
||||
}
|
||||
|
||||
public List<EcsTask> startTask(String clusterRef, List<String> containerInstanceRefs,
|
||||
String taskDefinitionRef, String group, String startedBy, String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(clusterRef, region);
|
||||
TaskDefinition taskDef = resolveTaskDefinitionOrThrow(taskDefinitionRef, region);
|
||||
RunTaskRequest request = new RunTaskRequest();
|
||||
request.setCluster(clusterRef);
|
||||
request.setTaskDefinition(taskDefinitionRef);
|
||||
request.setGroup(group);
|
||||
request.setStartedBy(startedBy);
|
||||
request.setContainerInstances(containerInstanceRefs);
|
||||
return startTask(request, region);
|
||||
}
|
||||
|
||||
public List<EcsTask> startTask(RunTaskRequest request, String region) {
|
||||
List<String> instanceRefs = request.getContainerInstances() != null
|
||||
? request.getContainerInstances() : List.of();
|
||||
EcsCluster cluster = resolveClusterOrDefault(request.getCluster(), region);
|
||||
TaskDefinition taskDef = resolveTaskDefinitionOrThrow(request.getTaskDefinition(), region);
|
||||
List<EcsTask> result = new ArrayList<>();
|
||||
for (String instanceRef : containerInstanceRefs) {
|
||||
// StartTask places one task onto each named container instance, which is EC2 by definition.
|
||||
request.setCount(1);
|
||||
request.setLaunchType(LaunchType.EC2);
|
||||
request.setContainerOverrides(null);
|
||||
request.setNetworkConfiguration(null);
|
||||
for (String instanceRef : instanceRefs) {
|
||||
ContainerInstance instance = resolveContainerInstanceOrThrow(cluster.getClusterArn(), instanceRef);
|
||||
List<EcsTask> launched = launchTasks(cluster, taskDef, 1, LaunchType.EC2,
|
||||
group, startedBy, instance.getContainerInstanceArn(), null, null, null, region);
|
||||
result.addAll(launched);
|
||||
result.addAll(launchTasks(cluster, taskDef, request,
|
||||
instance.getContainerInstanceArn(), null, region));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -599,11 +662,8 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
* task as service-owned, since the caller-supplied {@code group}
|
||||
* cannot be trusted for that.
|
||||
*/
|
||||
private List<EcsTask> launchTasks(EcsCluster cluster, TaskDefinition taskDef, int count,
|
||||
LaunchType launchType, String group, String startedBy,
|
||||
private List<EcsTask> launchTasks(EcsCluster cluster, TaskDefinition taskDef, RunTaskRequest request,
|
||||
String containerInstanceArn,
|
||||
List<ContainerOverride> containerOverrides,
|
||||
NetworkConfiguration networkConfiguration,
|
||||
String owningServiceArn, String region) {
|
||||
// Fail loudly instead of silently launching zero containers and leaving
|
||||
// a task that looks RUNNING with nothing behind it.
|
||||
@@ -613,6 +673,12 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
throw new AwsException("ClientException",
|
||||
"Task definition " + taskDef.getTaskDefinitionArn() + " has no container definitions.", 400);
|
||||
}
|
||||
int count = request.getCount();
|
||||
LaunchType launchType = request.getLaunchType();
|
||||
String group = request.getGroup();
|
||||
String startedBy = request.getStartedBy();
|
||||
List<ContainerOverride> containerOverrides = request.getContainerOverrides();
|
||||
NetworkConfiguration networkConfiguration = request.getNetworkConfiguration();
|
||||
List<EcsTask> launched = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
String taskId = UUID.randomUUID().toString().replace("-", "");
|
||||
@@ -689,8 +755,13 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
private EcsTask launchServiceTask(EcsCluster cluster, EcsServiceModel svc, LaunchType launchType,
|
||||
String containerInstanceArn, String region) {
|
||||
TaskDefinition taskDef = resolveTaskDefinitionOrThrow(svc.getTaskDefinition(), region);
|
||||
EcsTask task = launchTasks(cluster, taskDef, 1, launchType, svc.getServiceName(), "ecs-svc",
|
||||
containerInstanceArn, null, svc.getNetworkConfiguration(),
|
||||
RunTaskRequest request = new RunTaskRequest();
|
||||
request.setCount(1);
|
||||
request.setLaunchType(launchType);
|
||||
request.setGroup(svc.getServiceName());
|
||||
request.setStartedBy("ecs-svc");
|
||||
request.setNetworkConfiguration(svc.getNetworkConfiguration());
|
||||
EcsTask task = launchTasks(cluster, taskDef, request, containerInstanceArn,
|
||||
svc.getServiceArn(), region).getFirst();
|
||||
task.setDeploymentId(deploymentId(svc));
|
||||
return task;
|
||||
@@ -797,6 +868,19 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
public List<String> listTasks(String clusterRef, String family, String desiredStatus,
|
||||
String serviceName, String region) {
|
||||
ListTasksRequest request = new ListTasksRequest();
|
||||
request.setCluster(clusterRef);
|
||||
request.setFamily(family);
|
||||
request.setDesiredStatus(desiredStatus);
|
||||
request.setServiceName(serviceName);
|
||||
return listTasks(request, region);
|
||||
}
|
||||
|
||||
public List<String> listTasks(ListTasksRequest request, String region) {
|
||||
String clusterRef = request.getCluster();
|
||||
String family = request.getFamily();
|
||||
String desiredStatus = request.getDesiredStatus();
|
||||
String serviceName = request.getServiceName();
|
||||
// Resolving the default cluster also creates and persists it, and ListTasks is a read:
|
||||
// when no cluster is named, look the default up without materializing it. A service
|
||||
// filter then simply matches nothing if that cluster does not exist yet.
|
||||
@@ -899,10 +983,30 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
String deploymentControllerType, String availabilityZoneRebalancing,
|
||||
Map<String, Object> serviceConnectConfiguration,
|
||||
String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(clusterRef, region);
|
||||
CreateServiceRequest request = new CreateServiceRequest();
|
||||
request.setCluster(clusterRef);
|
||||
request.setServiceName(serviceName);
|
||||
request.setTaskDefinition(taskDefinition);
|
||||
request.setDesiredCount(desiredCount);
|
||||
request.setLaunchType(launchType);
|
||||
request.setLoadBalancers(loadBalancers);
|
||||
request.setNetworkConfiguration(networkConfiguration);
|
||||
request.setTags(tags);
|
||||
request.setSchedulingStrategy(schedulingStrategy);
|
||||
request.setDeploymentControllerType(deploymentControllerType);
|
||||
request.setAvailabilityZoneRebalancing(availabilityZoneRebalancing);
|
||||
request.setServiceConnectConfiguration(serviceConnectConfiguration);
|
||||
return createService(request, region);
|
||||
}
|
||||
|
||||
public EcsServiceModel createService(CreateServiceRequest request, String region) {
|
||||
String serviceName = request.getServiceName();
|
||||
int desiredCount = request.getDesiredCount();
|
||||
EcsCluster cluster = resolveClusterOrDefault(request.getCluster(), region);
|
||||
// AWS resolves family / family:revision at create time and stores the ARN; the
|
||||
// reconciler compares it with each task's taskDefinitionArn, so pin it here.
|
||||
taskDefinition = resolveTaskDefinitionOrThrow(taskDefinition, region).getTaskDefinitionArn();
|
||||
String taskDefinition =
|
||||
resolveTaskDefinitionOrThrow(request.getTaskDefinition(), region).getTaskDefinitionArn();
|
||||
|
||||
String key = serviceKey(region, cluster.getClusterName(), serviceName);
|
||||
if (services.containsKey(key)) {
|
||||
@@ -920,19 +1024,20 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
svc.setServiceName(serviceName);
|
||||
svc.setClusterArn(cluster.getClusterArn());
|
||||
svc.setTaskDefinition(taskDefinition);
|
||||
svc.setLaunchType(launchType != null ? launchType : LaunchType.FARGATE);
|
||||
svc.setLaunchType(request.getLaunchType() != null ? request.getLaunchType() : LaunchType.FARGATE);
|
||||
if (desiredCount < 0) {
|
||||
throw new AwsException("InvalidParameterException", "desiredCount cannot be a negative number.", 400);
|
||||
}
|
||||
svc.setDesiredCount(desiredCount);
|
||||
svc.setLoadBalancers(loadBalancers);
|
||||
svc.setNetworkConfiguration(networkConfiguration);
|
||||
svc.setLoadBalancers(request.getLoadBalancers());
|
||||
svc.setNetworkConfiguration(request.getNetworkConfiguration());
|
||||
// AWS echoes these on every DescribeServices; clients that persist them (Terraform's
|
||||
// aws_ecs_service reads all three, and schedulingStrategy is ForceNew) treat a missing
|
||||
// value as drift and replace the service on every apply.
|
||||
String strategy = schedulingStrategy != null ? schedulingStrategy : DEFAULT_SCHEDULING_STRATEGY;
|
||||
String controller = deploymentControllerType != null
|
||||
? deploymentControllerType : DEFAULT_DEPLOYMENT_CONTROLLER;
|
||||
String strategy = request.getSchedulingStrategy() != null
|
||||
? request.getSchedulingStrategy() : DEFAULT_SCHEDULING_STRATEGY;
|
||||
String controller = request.getDeploymentControllerType() != null
|
||||
? request.getDeploymentControllerType() : DEFAULT_DEPLOYMENT_CONTROLLER;
|
||||
if (SCHEDULING_DAEMON.equals(strategy)
|
||||
&& (svc.getLaunchType() == LaunchType.FARGATE || !DEFAULT_DEPLOYMENT_CONTROLLER.equals(controller))) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
@@ -941,15 +1046,15 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
svc.setSchedulingStrategy(strategy);
|
||||
svc.setDeploymentController(controller);
|
||||
svc.setAvailabilityZoneRebalancing(availabilityZoneRebalancing != null
|
||||
? availabilityZoneRebalancing : DEFAULT_AZ_REBALANCING_ON_CREATE);
|
||||
svc.setServiceConnectConfiguration(serviceConnectConfiguration);
|
||||
svc.setAvailabilityZoneRebalancing(request.getAvailabilityZoneRebalancing() != null
|
||||
? request.getAvailabilityZoneRebalancing() : DEFAULT_AZ_REBALANCING_ON_CREATE);
|
||||
svc.setServiceConnectConfiguration(request.getServiceConnectConfiguration());
|
||||
svc.setStatus("ACTIVE");
|
||||
svc.setCreatedAt(Instant.now());
|
||||
svc.setLastDeploymentAt(svc.getCreatedAt());
|
||||
svc.setDeploymentId(newDeploymentId());
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
svc.setTags(new LinkedHashMap<>(tags));
|
||||
if (request.getTags() != null && !request.getTags().isEmpty()) {
|
||||
svc.setTags(new LinkedHashMap<>(request.getTags()));
|
||||
}
|
||||
|
||||
services.put(key, svc);
|
||||
@@ -991,9 +1096,22 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
String availabilityZoneRebalancing, boolean forceNewDeployment,
|
||||
Map<String, Object> serviceConnectConfiguration,
|
||||
String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(clusterRef, region);
|
||||
UpdateServiceRequest request = new UpdateServiceRequest();
|
||||
request.setCluster(clusterRef);
|
||||
request.setService(serviceName);
|
||||
request.setTaskDefinition(taskDefinition);
|
||||
request.setDesiredCount(desiredCount);
|
||||
request.setNetworkConfiguration(networkConfiguration);
|
||||
request.setAvailabilityZoneRebalancing(availabilityZoneRebalancing);
|
||||
request.setForceNewDeployment(forceNewDeployment);
|
||||
request.setServiceConnectConfiguration(serviceConnectConfiguration);
|
||||
return updateService(request, region);
|
||||
}
|
||||
|
||||
serviceName = extractServiceName(serviceName);
|
||||
public EcsServiceModel updateService(UpdateServiceRequest request, String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(request.getCluster(), region);
|
||||
|
||||
String serviceName = extractServiceName(request.getService());
|
||||
|
||||
String key = serviceKey(region, cluster.getClusterName(), serviceName);
|
||||
EcsServiceModel svc = services.get(key);
|
||||
@@ -1004,33 +1122,36 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
throw new AwsException("ServiceNotActiveException",
|
||||
"Service " + serviceName + " is not active.", 400);
|
||||
}
|
||||
Integer desiredCount = request.getDesiredCount();
|
||||
if (desiredCount != null) {
|
||||
if (desiredCount < 0) {
|
||||
throw new AwsException("InvalidParameterException", "desiredCount cannot be a negative number.", 400);
|
||||
}
|
||||
svc.setDesiredCount(desiredCount);
|
||||
}
|
||||
if (networkConfiguration != null) {
|
||||
svc.setNetworkConfiguration(networkConfiguration);
|
||||
if (request.getNetworkConfiguration() != null) {
|
||||
svc.setNetworkConfiguration(request.getNetworkConfiguration());
|
||||
}
|
||||
if (availabilityZoneRebalancing != null) {
|
||||
svc.setAvailabilityZoneRebalancing(availabilityZoneRebalancing);
|
||||
if (request.getAvailabilityZoneRebalancing() != null) {
|
||||
svc.setAvailabilityZoneRebalancing(request.getAvailabilityZoneRebalancing());
|
||||
}
|
||||
// UpdateServiceRequest.serviceConnectConfiguration is documented as "This parameter
|
||||
// triggers a new service deployment", so a real change rolls the deployment the way a
|
||||
// task-definition change does. An omitted parameter is not a change and rolls nothing.
|
||||
Map<String, Object> serviceConnectConfiguration = request.getServiceConnectConfiguration();
|
||||
boolean serviceConnectChanged = serviceConnectConfiguration != null
|
||||
&& !serviceConnectConfiguration.equals(svc.getServiceConnectConfiguration());
|
||||
if (serviceConnectConfiguration != null) {
|
||||
svc.setServiceConnectConfiguration(serviceConnectConfiguration);
|
||||
}
|
||||
boolean taskDefChanged = false;
|
||||
if (taskDefinition != null) {
|
||||
String resolvedArn = resolveTaskDefinitionOrThrow(taskDefinition, region).getTaskDefinitionArn();
|
||||
if (request.getTaskDefinition() != null) {
|
||||
String resolvedArn =
|
||||
resolveTaskDefinitionOrThrow(request.getTaskDefinition(), region).getTaskDefinitionArn();
|
||||
taskDefChanged = !resolvedArn.equals(svc.getTaskDefinition());
|
||||
svc.setTaskDefinition(resolvedArn);
|
||||
}
|
||||
if (taskDefChanged || forceNewDeployment || serviceConnectChanged) {
|
||||
if (taskDefChanged || request.isForceNewDeployment() || serviceConnectChanged) {
|
||||
svc.setDeploymentId(newDeploymentId());
|
||||
svc.setLastDeploymentAt(Instant.now());
|
||||
recordServiceDeployment(svc, svc.getTaskDefinition(), region);
|
||||
@@ -1467,9 +1588,21 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
public TaskSet createTaskSet(String clusterRef, String serviceRef, String taskDefinitionRef,
|
||||
LaunchType launchType, double scaleValue, String scaleUnit,
|
||||
String externalId, String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(clusterRef, region);
|
||||
EcsServiceModel svc = resolveServiceOrThrow(cluster.getClusterName(), serviceRef, region);
|
||||
TaskDefinition taskDef = resolveTaskDefinitionOrThrow(taskDefinitionRef, region);
|
||||
CreateTaskSetRequest request = new CreateTaskSetRequest();
|
||||
request.setCluster(clusterRef);
|
||||
request.setService(serviceRef);
|
||||
request.setTaskDefinition(taskDefinitionRef);
|
||||
request.setLaunchType(launchType);
|
||||
request.setScaleValue(scaleValue);
|
||||
request.setScaleUnit(scaleUnit);
|
||||
request.setExternalId(externalId);
|
||||
return createTaskSet(request, region);
|
||||
}
|
||||
|
||||
public TaskSet createTaskSet(CreateTaskSetRequest request, String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(request.getCluster(), region);
|
||||
EcsServiceModel svc = resolveServiceOrThrow(cluster.getClusterName(), request.getService(), region);
|
||||
TaskDefinition taskDef = resolveTaskDefinitionOrThrow(request.getTaskDefinition(), region);
|
||||
|
||||
String setId = "ecs-svc/" + UUID.randomUUID().toString().replace("-", "");
|
||||
String taskSetArn = regionResolver.buildArn("ecs", region, "task-set/"
|
||||
@@ -1482,10 +1615,10 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
ts.setClusterArn(cluster.getClusterArn());
|
||||
ts.setTaskDefinition(taskDef.getTaskDefinitionArn());
|
||||
ts.setStatus("ACTIVE");
|
||||
ts.setScaleValue(scaleValue);
|
||||
ts.setScaleUnit(scaleUnit != null ? scaleUnit : "PERCENT");
|
||||
ts.setLaunchType(launchType != null ? launchType : LaunchType.FARGATE);
|
||||
ts.setExternalId(externalId);
|
||||
ts.setScaleValue(request.getScaleValue() != null ? request.getScaleValue() : 100.0);
|
||||
ts.setScaleUnit(request.getScaleUnit() != null ? request.getScaleUnit() : "PERCENT");
|
||||
ts.setLaunchType(request.getLaunchType() != null ? request.getLaunchType() : LaunchType.FARGATE);
|
||||
ts.setExternalId(request.getExternalId());
|
||||
ts.setStabilityStatus("STEADY_STATE");
|
||||
ts.setCreatedAt(Instant.now());
|
||||
ts.setUpdatedAt(Instant.now());
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.hectorvent.floci.services.ecs.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** A parsed {@code CreateCluster} request. */
|
||||
@RegisterForReflection
|
||||
public class CreateClusterRequest {
|
||||
|
||||
private String clusterName;
|
||||
private Map<String, String> tags;
|
||||
private List<ClusterSetting> settings;
|
||||
|
||||
public String getClusterName() { return clusterName; }
|
||||
public void setClusterName(String clusterName) { this.clusterName = clusterName; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
public List<ClusterSetting> getSettings() { return settings; }
|
||||
public void setSettings(List<ClusterSetting> settings) { this.settings = settings; }
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.github.hectorvent.floci.services.ecs.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** A parsed {@code CreateService} request. */
|
||||
@RegisterForReflection
|
||||
public class CreateServiceRequest {
|
||||
|
||||
private String cluster;
|
||||
private String serviceName;
|
||||
private String taskDefinition;
|
||||
private int desiredCount = 1;
|
||||
private LaunchType launchType;
|
||||
private List<EcsLoadBalancer> loadBalancers;
|
||||
private NetworkConfiguration networkConfiguration;
|
||||
private Map<String, String> tags;
|
||||
private String schedulingStrategy;
|
||||
private String deploymentControllerType;
|
||||
private String availabilityZoneRebalancing;
|
||||
private Map<String, Object> serviceConnectConfiguration;
|
||||
|
||||
public String getCluster() { return cluster; }
|
||||
public void setCluster(String cluster) { this.cluster = cluster; }
|
||||
|
||||
public String getServiceName() { return serviceName; }
|
||||
public void setServiceName(String serviceName) { this.serviceName = serviceName; }
|
||||
|
||||
public String getTaskDefinition() { return taskDefinition; }
|
||||
public void setTaskDefinition(String taskDefinition) { this.taskDefinition = taskDefinition; }
|
||||
|
||||
public int getDesiredCount() { return desiredCount; }
|
||||
public void setDesiredCount(int desiredCount) { this.desiredCount = desiredCount; }
|
||||
|
||||
public LaunchType getLaunchType() { return launchType; }
|
||||
public void setLaunchType(LaunchType launchType) { this.launchType = launchType; }
|
||||
|
||||
public List<EcsLoadBalancer> getLoadBalancers() { return loadBalancers; }
|
||||
public void setLoadBalancers(List<EcsLoadBalancer> loadBalancers) { this.loadBalancers = loadBalancers; }
|
||||
|
||||
public NetworkConfiguration getNetworkConfiguration() { return networkConfiguration; }
|
||||
public void setNetworkConfiguration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
public String getSchedulingStrategy() { return schedulingStrategy; }
|
||||
public void setSchedulingStrategy(String schedulingStrategy) { this.schedulingStrategy = schedulingStrategy; }
|
||||
|
||||
public String getDeploymentControllerType() { return deploymentControllerType; }
|
||||
public void setDeploymentControllerType(String deploymentControllerType) {
|
||||
this.deploymentControllerType = deploymentControllerType;
|
||||
}
|
||||
|
||||
public String getAvailabilityZoneRebalancing() { return availabilityZoneRebalancing; }
|
||||
public void setAvailabilityZoneRebalancing(String availabilityZoneRebalancing) {
|
||||
this.availabilityZoneRebalancing = availabilityZoneRebalancing;
|
||||
}
|
||||
|
||||
public Map<String, Object> getServiceConnectConfiguration() { return serviceConnectConfiguration; }
|
||||
public void setServiceConnectConfiguration(Map<String, Object> serviceConnectConfiguration) {
|
||||
this.serviceConnectConfiguration = serviceConnectConfiguration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.hectorvent.floci.services.ecs.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** A parsed {@code CreateTaskSet} request. */
|
||||
@RegisterForReflection
|
||||
public class CreateTaskSetRequest {
|
||||
|
||||
private String cluster;
|
||||
private String service;
|
||||
private String taskDefinition;
|
||||
private LaunchType launchType;
|
||||
private Double scaleValue;
|
||||
private String scaleUnit;
|
||||
private String externalId;
|
||||
|
||||
public String getCluster() { return cluster; }
|
||||
public void setCluster(String cluster) { this.cluster = cluster; }
|
||||
|
||||
public String getService() { return service; }
|
||||
public void setService(String service) { this.service = service; }
|
||||
|
||||
public String getTaskDefinition() { return taskDefinition; }
|
||||
public void setTaskDefinition(String taskDefinition) { this.taskDefinition = taskDefinition; }
|
||||
|
||||
public LaunchType getLaunchType() { return launchType; }
|
||||
public void setLaunchType(LaunchType launchType) { this.launchType = launchType; }
|
||||
|
||||
public Double getScaleValue() { return scaleValue; }
|
||||
public void setScaleValue(Double scaleValue) { this.scaleValue = scaleValue; }
|
||||
|
||||
public String getScaleUnit() { return scaleUnit; }
|
||||
public void setScaleUnit(String scaleUnit) { this.scaleUnit = scaleUnit; }
|
||||
|
||||
public String getExternalId() { return externalId; }
|
||||
public void setExternalId(String externalId) { this.externalId = externalId; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.github.hectorvent.floci.services.ecs.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** A parsed {@code ListTasks} request. Every member narrows the listing. */
|
||||
@RegisterForReflection
|
||||
public class ListTasksRequest {
|
||||
|
||||
private String cluster;
|
||||
private String desiredStatus;
|
||||
private String family;
|
||||
private String serviceName;
|
||||
|
||||
public String getCluster() { return cluster; }
|
||||
public void setCluster(String cluster) { this.cluster = cluster; }
|
||||
|
||||
public String getDesiredStatus() { return desiredStatus; }
|
||||
public void setDesiredStatus(String desiredStatus) { this.desiredStatus = desiredStatus; }
|
||||
|
||||
public String getFamily() { return family; }
|
||||
public void setFamily(String family) { this.family = family; }
|
||||
|
||||
public String getServiceName() { return serviceName; }
|
||||
public void setServiceName(String serviceName) { this.serviceName = serviceName; }
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package io.github.hectorvent.floci.services.ecs.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A parsed {@code RegisterTaskDefinition} request.
|
||||
*
|
||||
* <p>Everything the request carried reaches the service in one object, so validation that spans
|
||||
* several members (the Fargate rules, which read {@code requiresCompatibilities},
|
||||
* {@code networkMode}, the task size and the container definitions together) happens in one place
|
||||
* rather than being split between the handler and the service.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public class RegisterTaskDefinitionRequest {
|
||||
|
||||
private String family;
|
||||
private List<ContainerDefinition> containerDefinitions;
|
||||
private NetworkMode networkMode;
|
||||
private String cpu;
|
||||
private String memory;
|
||||
private String taskRoleArn;
|
||||
private String executionRoleArn;
|
||||
private List<String> requiresCompatibilities;
|
||||
private List<Volume> volumes;
|
||||
private RuntimePlatform runtimePlatform;
|
||||
private Map<String, String> tags;
|
||||
|
||||
public String getFamily() { return family; }
|
||||
public void setFamily(String family) { this.family = family; }
|
||||
|
||||
public List<ContainerDefinition> getContainerDefinitions() { return containerDefinitions; }
|
||||
public void setContainerDefinitions(List<ContainerDefinition> containerDefinitions) {
|
||||
this.containerDefinitions = containerDefinitions;
|
||||
}
|
||||
|
||||
public NetworkMode getNetworkMode() { return networkMode; }
|
||||
public void setNetworkMode(NetworkMode networkMode) { this.networkMode = networkMode; }
|
||||
|
||||
public String getCpu() { return cpu; }
|
||||
public void setCpu(String cpu) { this.cpu = cpu; }
|
||||
|
||||
public String getMemory() { return memory; }
|
||||
public void setMemory(String memory) { this.memory = memory; }
|
||||
|
||||
public String getTaskRoleArn() { return taskRoleArn; }
|
||||
public void setTaskRoleArn(String taskRoleArn) { this.taskRoleArn = taskRoleArn; }
|
||||
|
||||
public String getExecutionRoleArn() { return executionRoleArn; }
|
||||
public void setExecutionRoleArn(String executionRoleArn) { this.executionRoleArn = executionRoleArn; }
|
||||
|
||||
public List<String> getRequiresCompatibilities() { return requiresCompatibilities; }
|
||||
public void setRequiresCompatibilities(List<String> requiresCompatibilities) {
|
||||
this.requiresCompatibilities = requiresCompatibilities;
|
||||
}
|
||||
|
||||
public List<Volume> getVolumes() { return volumes; }
|
||||
public void setVolumes(List<Volume> volumes) { this.volumes = volumes; }
|
||||
|
||||
public RuntimePlatform getRuntimePlatform() { return runtimePlatform; }
|
||||
public void setRuntimePlatform(RuntimePlatform runtimePlatform) { this.runtimePlatform = runtimePlatform; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
public boolean isFargate() {
|
||||
return requiresCompatibilities != null && requiresCompatibilities.contains("FARGATE");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package io.github.hectorvent.floci.services.ecs.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A parsed {@code RunTask} (or {@code StartTask}) request.
|
||||
*
|
||||
* <p>ECS's launch surface is wide enough that threading it through positional parameters stopped
|
||||
* scaling, so the handler fills this and the service reads it. The narrower
|
||||
* {@code runTask(...)} overloads on the service remain for callers that only need the common
|
||||
* members, such as the EventBridge, Scheduler and Step Functions ECS targets.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public class RunTaskRequest {
|
||||
|
||||
private String cluster;
|
||||
private String taskDefinition;
|
||||
private int count = 1;
|
||||
private LaunchType launchType;
|
||||
private String group;
|
||||
private String startedBy;
|
||||
private List<ContainerOverride> containerOverrides;
|
||||
private NetworkConfiguration networkConfiguration;
|
||||
private List<String> containerInstances;
|
||||
|
||||
public String getCluster() { return cluster; }
|
||||
public void setCluster(String cluster) { this.cluster = cluster; }
|
||||
|
||||
public String getTaskDefinition() { return taskDefinition; }
|
||||
public void setTaskDefinition(String taskDefinition) { this.taskDefinition = taskDefinition; }
|
||||
|
||||
public int getCount() { return count; }
|
||||
public void setCount(int count) { this.count = count; }
|
||||
|
||||
public LaunchType getLaunchType() { return launchType; }
|
||||
public void setLaunchType(LaunchType launchType) { this.launchType = launchType; }
|
||||
|
||||
public String getGroup() { return group; }
|
||||
public void setGroup(String group) { this.group = group; }
|
||||
|
||||
public String getStartedBy() { return startedBy; }
|
||||
public void setStartedBy(String startedBy) { this.startedBy = startedBy; }
|
||||
|
||||
public List<ContainerOverride> getContainerOverrides() { return containerOverrides; }
|
||||
public void setContainerOverrides(List<ContainerOverride> containerOverrides) {
|
||||
this.containerOverrides = containerOverrides;
|
||||
}
|
||||
|
||||
public NetworkConfiguration getNetworkConfiguration() { return networkConfiguration; }
|
||||
public void setNetworkConfiguration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
}
|
||||
|
||||
public List<String> getContainerInstances() { return containerInstances; }
|
||||
public void setContainerInstances(List<String> containerInstances) {
|
||||
this.containerInstances = containerInstances;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package io.github.hectorvent.floci.services.ecs.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A parsed {@code UpdateService} request.
|
||||
*
|
||||
* <p>Every member is nullable: UpdateService leaves anything the request omitted exactly as it
|
||||
* was, so {@code null} means "unchanged" rather than "clear it".
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public class UpdateServiceRequest {
|
||||
|
||||
private String cluster;
|
||||
private String service;
|
||||
private String taskDefinition;
|
||||
private Integer desiredCount;
|
||||
private NetworkConfiguration networkConfiguration;
|
||||
private String availabilityZoneRebalancing;
|
||||
private boolean forceNewDeployment;
|
||||
private Map<String, Object> serviceConnectConfiguration;
|
||||
|
||||
public String getCluster() { return cluster; }
|
||||
public void setCluster(String cluster) { this.cluster = cluster; }
|
||||
|
||||
public String getService() { return service; }
|
||||
public void setService(String service) { this.service = service; }
|
||||
|
||||
public String getTaskDefinition() { return taskDefinition; }
|
||||
public void setTaskDefinition(String taskDefinition) { this.taskDefinition = taskDefinition; }
|
||||
|
||||
public Integer getDesiredCount() { return desiredCount; }
|
||||
public void setDesiredCount(Integer desiredCount) { this.desiredCount = desiredCount; }
|
||||
|
||||
public NetworkConfiguration getNetworkConfiguration() { return networkConfiguration; }
|
||||
public void setNetworkConfiguration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
}
|
||||
|
||||
public String getAvailabilityZoneRebalancing() { return availabilityZoneRebalancing; }
|
||||
public void setAvailabilityZoneRebalancing(String availabilityZoneRebalancing) {
|
||||
this.availabilityZoneRebalancing = availabilityZoneRebalancing;
|
||||
}
|
||||
|
||||
public boolean isForceNewDeployment() { return forceNewDeployment; }
|
||||
public void setForceNewDeployment(boolean forceNewDeployment) { this.forceNewDeployment = forceNewDeployment; }
|
||||
|
||||
public Map<String, Object> getServiceConnectConfiguration() { return serviceConnectConfiguration; }
|
||||
public void setServiceConnectConfiguration(Map<String, Object> serviceConnectConfiguration) {
|
||||
this.serviceConnectConfiguration = serviceConnectConfiguration;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user