This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-hugegraph-computer.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d4d276e feat: use 'foreground' delete policy to pass the cancel job 
test (#290)
9d4d276e is described below

commit 9d4d276e8defc71087dc07d6b5c718532543fb00
Author: Chong Shen <[email protected]>
AuthorDate: Mon Dec 4 19:52:45 2023 +0800

    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 <[email protected]>
---
 .../hugegraph/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 f0f0002e..0ae4ba6b 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 @@ package org.apache.hugegraph.computer.driver;
 
 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 class DefaultJobState implements JobState {
         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 a1e6bb2a..a6e845b6 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.UUID;
 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 @@ public class KubernetesDriver implements ComputerDriver {
 
     @Override
     public boolean cancelJob(String jobId, Map<String, String> params) {
-        return this.operation.withName(KubeUtil.crName(jobId)).delete();
+        return this.operation.withName(KubeUtil.crName(jobId))
+                             
.withPropagationPolicy(DeletionPropagation.FOREGROUND)
+                             .delete();
     }
 
     @Override

Reply via email to