|
16 | 16 |
|
17 | 17 | package com.webank.wedatasphere.dss.flow.execution.entrance.restful;
|
18 | 18 |
|
| 19 | +import com.fasterxml.jackson.databind.JsonNode; |
19 | 20 | import com.webank.wedatasphere.dss.common.entity.DSSWorkspace;
|
20 | 21 | import com.webank.wedatasphere.dss.common.utils.DSSCommonUtils;
|
21 | 22 | import com.webank.wedatasphere.dss.standard.sso.utils.SSOHelper;
|
|
29 | 30 | import org.apache.linkis.protocol.constants.TaskConstant;
|
30 | 31 | import org.apache.linkis.protocol.utils.ZuulEntranceUtils;
|
31 | 32 | import org.apache.linkis.rpc.Sender;
|
| 33 | +import org.apache.linkis.scheduler.listener.LogListener; |
32 | 34 | import org.apache.linkis.scheduler.queue.Job;
|
| 35 | +import org.apache.linkis.scheduler.queue.SchedulerEventState; |
33 | 36 | import org.apache.linkis.server.Message;
|
34 | 37 | import org.apache.linkis.server.security.SecurityFilter;
|
35 | 38 | import org.slf4j.Logger;
|
36 | 39 | import org.slf4j.LoggerFactory;
|
37 | 40 | import org.springframework.web.bind.annotation.*;
|
| 41 | +import scala.Function0; |
38 | 42 | import scala.Option;
|
39 | 43 |
|
40 | 44 | import javax.servlet.http.HttpServletRequest;
|
| 45 | +import java.util.ArrayList; |
41 | 46 | import java.util.Map;
|
42 | 47 |
|
43 | 48 |
|
@@ -126,6 +131,54 @@ public Message status(@PathVariable("id") String id, @RequestParam(required = fa
|
126 | 131 | return message;
|
127 | 132 | }
|
128 | 133 |
|
| 134 | + @Override |
| 135 | + @RequestMapping(path = {"/{id}/kill"},method = {RequestMethod.GET}) |
| 136 | + public Message kill(@PathVariable("id") String id, @RequestParam(value = "taskID",required = false) Long taskID) { |
| 137 | + String realId = ZuulEntranceUtils.parseExecID(id)[3]; |
| 138 | + Option job = Option.apply((Object)null); |
| 139 | + try { |
| 140 | + job = this.entranceServer.getJob(realId); |
| 141 | + } catch (Exception var10) { |
| 142 | + logger.warn("can not find a job in entranceServer, will force to kill it", var10); |
| 143 | + JobHistoryHelper.forceKill(taskID); |
| 144 | + Message message = Message.ok("Forced Kill task (强制杀死任务)"); |
| 145 | + message.setMethod("/api/entrance/" + id + "/kill"); |
| 146 | + message.setStatus(0); |
| 147 | + return message; |
| 148 | + } |
| 149 | + Message message = null; |
| 150 | + if (job.isEmpty()) { |
| 151 | + logger.warn("can not find a job in entranceServer, will force to kill it"); |
| 152 | + JobHistoryHelper.forceKill(taskID); |
| 153 | + message = Message.ok("Forced Kill task (强制杀死任务)"); |
| 154 | + message.setMethod("/api/entrance/" + id + "/kill"); |
| 155 | + message.setStatus(0); |
| 156 | + return message; |
| 157 | + } else { |
| 158 | + try { |
| 159 | + logger.info("begin to kill job {} ", ((Job)job.get()).getId()); |
| 160 | + ((Job)job.get()).kill(); |
| 161 | + message = Message.ok("Successfully killed the job(成功kill了job)"); |
| 162 | + message.setMethod("/api/entrance/" + id + "/kill"); |
| 163 | + message.setStatus(0); |
| 164 | + message.data("execID", id); |
| 165 | + if (job.get() instanceof EntranceJob) { |
| 166 | + EntranceJob entranceJob = (EntranceJob)job.get(); |
| 167 | + JobRequest jobReq = entranceJob.getJobRequest(); |
| 168 | + entranceJob.updateJobRequestStatus(SchedulerEventState.Cancelled().toString()); |
| 169 | + this.entranceServer.getEntranceContext().getOrCreatePersistenceManager().createPersistenceEngine().updateIfNeeded(jobReq); |
| 170 | + } |
| 171 | + logger.info("end to kill job {} ", ((Job)job.get()).getId()); |
| 172 | + } catch (Throwable var9) { |
| 173 | + logger.error("kill job {} failed ", ((Job)job.get()).getId(), var9); |
| 174 | + message = Message.error("An exception occurred while killing the job, kill failed(kill job的时候出现了异常,kill失败)"); |
| 175 | + message.setMethod("/api/entrance/" + id + "/kill"); |
| 176 | + message.setStatus(1); |
| 177 | + } |
| 178 | + return message; |
| 179 | + } |
| 180 | + } |
| 181 | + |
129 | 182 | private void pushLog(String log, Job job) {
|
130 | 183 | entranceServer.getEntranceContext().getOrCreateLogManager().onLogUpdate(job, log);
|
131 | 184 | }
|
|
0 commit comments