mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix: ecs delete resource issue (#685)
This commit is contained in:
1 parent
f9d4da69d2
commit
86bc33d115
2 files changed
+22
-3
No files matched your search
@@ -395,8 +395,9 @@ public class EcsJsonHandler {
|
||||
private Response handleDeleteService(JsonNode req, String region) {
|
||||
String cluster = req.has("cluster") ? req.path("cluster").asText() : null;
|
||||
String serviceName = req.path("service").asText();
|
||||
boolean force = req.path("force").asBoolean(false);
|
||||
|
||||
EcsServiceModel svc = service.deleteService(cluster, serviceName, region);
|
||||
EcsServiceModel svc = service.deleteService(cluster, serviceName, force, region);
|
||||
|
||||
ObjectNode resp = objectMapper.createObjectNode();
|
||||
resp.set("service", serviceNode(svc));
|
||||
|
||||
@@ -452,16 +452,34 @@ public class EcsService {
|
||||
return svc;
|
||||
}
|
||||
|
||||
public EcsServiceModel deleteService(String clusterRef, String serviceName, String region) {
|
||||
public EcsServiceModel deleteService(String clusterRef, String serviceName, boolean force, String region) {
|
||||
EcsCluster cluster = resolveClusterOrDefault(clusterRef, region);
|
||||
String key = serviceKey(region, cluster.getClusterName(), serviceName);
|
||||
EcsServiceModel svc = services.remove(key);
|
||||
EcsServiceModel svc = services.get(key);
|
||||
if (svc == null) {
|
||||
throw new AwsException("ServiceNotFoundException", "Service " + serviceName + " not found.", 404);
|
||||
}
|
||||
if (!force && svc.getDesiredCount() > 0) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"The service cannot be stopped. Update the service to 0 tasks or use the force flag.", 400);
|
||||
}
|
||||
services.remove(key);
|
||||
svc.setStatus("INACTIVE");
|
||||
svc.setDesiredCount(0);
|
||||
cluster.setActiveServicesCount(Math.max(0, cluster.getActiveServicesCount() - 1));
|
||||
tasks.values().stream()
|
||||
.filter(t -> t.getClusterArn().equals(cluster.getClusterArn()))
|
||||
.filter(t -> svc.getServiceArn().equals(t.getGroup())
|
||||
|| svc.getServiceName().equals(t.getGroup()))
|
||||
.filter(t -> !TaskStatus.STOPPED.name().equals(t.getLastStatus()))
|
||||
.forEach(t -> {
|
||||
try {
|
||||
stopTask(cluster.getClusterName(), t.getTaskArn(), "Service deleted", region);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Failed to stop task {0} on service delete: {1}",
|
||||
t.getTaskArn(), e.getMessage());
|
||||
}
|
||||
});
|
||||
return svc;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user