Skip to content

Commit 9d4d276

Browse files
qwtscimbajin
andauthored
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 <jin@apache.org>
1 parent 0c447be commit 9d4d276

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

computer-driver/src/main/java/org/apache/hugegraph/computer/driver/DefaultJobState.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,95 @@
1919

2020
import java.util.Objects;
2121

22+
/**
23+
* DefaultJobState is an implementation of the JobState interface.
24+
* It holds the state of a job including the current superstep,
25+
* the maximum superstep, the last superstep statistics, and the job status.
26+
*/
2227
public class DefaultJobState implements JobState {
2328

2429
private int superstep;
2530
private int maxSuperstep;
2631
private SuperstepStat lastSuperstepStat;
2732
private JobStatus jobStatus;
2833

34+
/**
35+
* Sets the current superstep.
36+
* @param superstep The current superstep.
37+
* @return The updated DefaultJobState instance.
38+
*/
2939
public DefaultJobState superstep(int superstep) {
3040
this.superstep = superstep;
3141
return this;
3242
}
3343

44+
/**
45+
* Sets the maximum superstep.
46+
* @param maxSuperstep The maximum superstep.
47+
* @return The updated DefaultJobState instance.
48+
*/
3449
public DefaultJobState maxSuperstep(int maxSuperstep) {
3550
this.maxSuperstep = maxSuperstep;
3651
return this;
3752
}
3853

54+
/**
55+
* Sets the last superstep statistics.
56+
* @param lastSuperstepStat The last superstep statistics.
57+
* @return The updated DefaultJobState instance.
58+
*/
3959
public DefaultJobState lastSuperstepStat(SuperstepStat lastSuperstepStat) {
4060
this.lastSuperstepStat = lastSuperstepStat;
4161
return this;
4262
}
4363

64+
/**
65+
* Sets the job status.
66+
* @param jobStatus The job status.
67+
* @return The updated DefaultJobState instance.
68+
*/
4469
public DefaultJobState jobStatus(JobStatus jobStatus) {
4570
this.jobStatus = jobStatus;
4671
return this;
4772
}
4873

74+
/**
75+
* @return The current superstep.
76+
*/
4977
@Override
5078
public int superstep() {
5179
return this.superstep;
5280
}
5381

82+
/**
83+
* @return The maximum superstep.
84+
*/
5485
@Override
5586
public int maxSuperstep() {
5687
return this.maxSuperstep;
5788
}
5889

90+
/**
91+
* @return The last superstep statistics.
92+
*/
5993
@Override
6094
public SuperstepStat lastSuperstepStat() {
6195
return this.lastSuperstepStat;
6296
}
6397

98+
/**
99+
* @return The job status.
100+
*/
64101
@Override
65102
public JobStatus jobStatus() {
66103
return this.jobStatus;
67104
}
68105

106+
/**
107+
* Checks if the given object is equal to this instance.
108+
* @param o The object to compare with.
109+
* @return true if the given object is equal to this instance, false otherwise.
110+
*/
69111
@Override
70112
public boolean equals(Object o) {
71113
if (this == o) {
@@ -74,17 +116,30 @@ public boolean equals(Object o) {
74116
if (!(o instanceof DefaultJobState)) {
75117
return false;
76118
}
119+
77120
DefaultJobState jobState = (DefaultJobState) o;
78121
return this.superstep == jobState.superstep &&
79122
this.maxSuperstep == jobState.maxSuperstep &&
80-
Objects.equals(this.lastSuperstepStat,
81-
jobState.lastSuperstepStat) &&
123+
Objects.equals(this.lastSuperstepStat, jobState.lastSuperstepStat) &&
82124
this.jobStatus == jobState.jobStatus;
83125
}
84126

127+
/**
128+
* @return The hash code of this instance.
129+
*/
85130
@Override
86131
public int hashCode() {
87132
return Objects.hash(this.superstep, this.maxSuperstep,
88133
this.lastSuperstepStat, this.jobStatus);
89134
}
135+
136+
/**
137+
* @return A string representation of this instance.
138+
*/
139+
@Override
140+
public String toString() {
141+
return String.format("%s[superstep=%s, maxSuperStep=%s, lastSuperstepStat=%s, " +
142+
"jobStatus=%s]", DefaultJobState.class.getSimpleName(),
143+
superstep, maxSuperstep, lastSuperstepStat, jobStatus);
144+
}
90145
}

computer-k8s/src/main/java/org/apache/hugegraph/computer/k8s/driver/KubernetesDriver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.concurrent.CompletableFuture;
4040
import java.util.concurrent.ConcurrentHashMap;
4141

42+
import io.fabric8.kubernetes.api.model.DeletionPropagation;
4243
import org.apache.commons.collections.CollectionUtils;
4344
import org.apache.commons.io.FileUtils;
4445
import org.apache.commons.lang3.StringUtils;
@@ -282,7 +283,9 @@ private void checkComputerConf(Map<String, String> computerConf,
282283

283284
@Override
284285
public boolean cancelJob(String jobId, Map<String, String> params) {
285-
return this.operation.withName(KubeUtil.crName(jobId)).delete();
286+
return this.operation.withName(KubeUtil.crName(jobId))
287+
.withPropagationPolicy(DeletionPropagation.FOREGROUND)
288+
.delete();
286289
}
287290

288291
@Override

0 commit comments

Comments
 (0)