From 9d4d276e8defc71087dc07d6b5c718532543fb00 Mon Sep 17 00:00:00 2001 From: Chong Shen Date: Mon, 4 Dec 2023 19:52:45 +0800 Subject: [PATCH] feat: use 'foreground' delete policy to pass the cancel job test (#290) bypass the test case issue, and add more info when error occurs. Actual reason: - the default delete policy in k8s has changed to background since v1.20. - Plus the way you added finalizer is replaceCR, so you will sometimes miss the delete event generated by your client. --------- Co-authored-by: imbajin --- .../computer/driver/DefaultJobState.java | 59 ++++++++++++++++++- .../computer/k8s/driver/KubernetesDriver.java | 5 +- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/computer-driver/src/main/java/org/apache/hugegraph/computer/driver/DefaultJobState.java b/computer-driver/src/main/java/org/apache/hugegraph/computer/driver/DefaultJobState.java index f0f0002e5..0ae4ba6bb 100644 --- a/computer-driver/src/main/java/org/apache/hugegraph/computer/driver/DefaultJobState.java +++ b/computer-driver/src/main/java/org/apache/hugegraph/computer/driver/DefaultJobState.java @@ -19,6 +19,11 @@ import java.util.Objects; +/** + * DefaultJobState is an implementation of the JobState interface. + * It holds the state of a job including the current superstep, + * the maximum superstep, the last superstep statistics, and the job status. + */ public class DefaultJobState implements JobState { private int superstep; @@ -26,46 +31,83 @@ public class DefaultJobState implements JobState { private SuperstepStat lastSuperstepStat; private JobStatus jobStatus; + /** + * Sets the current superstep. + * @param superstep The current superstep. + * @return The updated DefaultJobState instance. + */ public DefaultJobState superstep(int superstep) { this.superstep = superstep; return this; } + /** + * Sets the maximum superstep. + * @param maxSuperstep The maximum superstep. + * @return The updated DefaultJobState instance. + */ public DefaultJobState maxSuperstep(int maxSuperstep) { this.maxSuperstep = maxSuperstep; return this; } + /** + * Sets the last superstep statistics. + * @param lastSuperstepStat The last superstep statistics. + * @return The updated DefaultJobState instance. + */ public DefaultJobState lastSuperstepStat(SuperstepStat lastSuperstepStat) { this.lastSuperstepStat = lastSuperstepStat; return this; } + /** + * Sets the job status. + * @param jobStatus The job status. + * @return The updated DefaultJobState instance. + */ public DefaultJobState jobStatus(JobStatus jobStatus) { this.jobStatus = jobStatus; return this; } + /** + * @return The current superstep. + */ @Override public int superstep() { return this.superstep; } + /** + * @return The maximum superstep. + */ @Override public int maxSuperstep() { return this.maxSuperstep; } + /** + * @return The last superstep statistics. + */ @Override public SuperstepStat lastSuperstepStat() { return this.lastSuperstepStat; } + /** + * @return The job status. + */ @Override public JobStatus jobStatus() { return this.jobStatus; } + /** + * Checks if the given object is equal to this instance. + * @param o The object to compare with. + * @return true if the given object is equal to this instance, false otherwise. + */ @Override public boolean equals(Object o) { if (this == o) { @@ -74,17 +116,30 @@ public boolean equals(Object o) { if (!(o instanceof DefaultJobState)) { return false; } + DefaultJobState jobState = (DefaultJobState) o; return this.superstep == jobState.superstep && this.maxSuperstep == jobState.maxSuperstep && - Objects.equals(this.lastSuperstepStat, - jobState.lastSuperstepStat) && + Objects.equals(this.lastSuperstepStat, jobState.lastSuperstepStat) && this.jobStatus == jobState.jobStatus; } + /** + * @return The hash code of this instance. + */ @Override public int hashCode() { return Objects.hash(this.superstep, this.maxSuperstep, this.lastSuperstepStat, this.jobStatus); } + + /** + * @return A string representation of this instance. + */ + @Override + public String toString() { + return String.format("%s[superstep=%s, maxSuperStep=%s, lastSuperstepStat=%s, " + + "jobStatus=%s]", DefaultJobState.class.getSimpleName(), + superstep, maxSuperstep, lastSuperstepStat, jobStatus); + } } diff --git a/computer-k8s/src/main/java/org/apache/hugegraph/computer/k8s/driver/KubernetesDriver.java b/computer-k8s/src/main/java/org/apache/hugegraph/computer/k8s/driver/KubernetesDriver.java index a1e6bb2a1..a6e845b65 100644 --- a/computer-k8s/src/main/java/org/apache/hugegraph/computer/k8s/driver/KubernetesDriver.java +++ b/computer-k8s/src/main/java/org/apache/hugegraph/computer/k8s/driver/KubernetesDriver.java @@ -39,6 +39,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; +import io.fabric8.kubernetes.api.model.DeletionPropagation; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; @@ -282,7 +283,9 @@ private void checkComputerConf(Map computerConf, @Override public boolean cancelJob(String jobId, Map params) { - return this.operation.withName(KubeUtil.crName(jobId)).delete(); + return this.operation.withName(KubeUtil.crName(jobId)) + .withPropagationPolicy(DeletionPropagation.FOREGROUND) + .delete(); } @Override