mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(emr): terminate transient clusters after steps (#6085)
* fix(emr): terminate transient clusters after steps * fix(emr): I preserve terminal state on later requests
This commit is contained in:
1 parent
5aaa37284c
commit
67e4bfec1c
3 files changed
+162
-6
No files matched your search
@@ -34,8 +34,9 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* EMR management-plane business logic. Cluster and step lifecycles are simulated
|
||||
* through immediate state transitions (no Hadoop runs): clusters land in WAITING and
|
||||
* initial steps in COMPLETED. The {@code clusterStartupDelaySeconds} config exists for
|
||||
* through immediate state transitions (no Hadoop runs): steps complete immediately,
|
||||
* leaving persistent clusters WAITING and transient clusters with steps TERMINATED.
|
||||
* The {@code clusterStartupDelaySeconds} config exists for
|
||||
* future deferred transitions; Phase 1 advances synchronously for deterministic tests.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@@ -111,6 +112,7 @@ public class EmrService {
|
||||
completeStep(step);
|
||||
}
|
||||
advanceToWaiting(cluster);
|
||||
terminateAfterCompletedSteps(cluster);
|
||||
clusterStore.put(id, cluster);
|
||||
return cluster;
|
||||
}
|
||||
@@ -147,11 +149,11 @@ public class EmrService {
|
||||
if (cluster == null) {
|
||||
continue;
|
||||
}
|
||||
if (cluster.isTerminationProtected()) {
|
||||
anyProtected = true;
|
||||
if ("TERMINATED".equals(cluster.getState())) {
|
||||
continue;
|
||||
}
|
||||
if ("TERMINATED".equals(cluster.getState())) {
|
||||
if (cluster.isTerminationProtected()) {
|
||||
anyProtected = true;
|
||||
continue;
|
||||
}
|
||||
cluster.setState("TERMINATED");
|
||||
@@ -205,6 +207,9 @@ public class EmrService {
|
||||
cluster.getSteps().add(step);
|
||||
ids.add(step.getId());
|
||||
}
|
||||
if (!steps.isEmpty()) {
|
||||
terminateAfterCompletedSteps(cluster);
|
||||
}
|
||||
clusterStore.put(clusterId, cluster);
|
||||
return ids;
|
||||
}
|
||||
@@ -780,6 +785,17 @@ public class EmrService {
|
||||
cluster.setReadyDateTime(Instant.now());
|
||||
}
|
||||
|
||||
private void terminateAfterCompletedSteps(EmrCluster cluster) {
|
||||
if (cluster.getSteps().isEmpty() || !cluster.isAutoTerminate()
|
||||
|| "TERMINATED".equals(cluster.getState())) {
|
||||
return;
|
||||
}
|
||||
cluster.setState("TERMINATED");
|
||||
cluster.setStateChangeReasonCode("ALL_STEPS_COMPLETED");
|
||||
cluster.setStateChangeMessage("All steps completed.");
|
||||
cluster.setEndDateTime(Instant.now());
|
||||
}
|
||||
|
||||
private void initStep(EmrStep step) {
|
||||
step.setId("s-" + randomId(13));
|
||||
step.setState("PENDING");
|
||||
|
||||
Reference in new issue
Block a user