|
16 | 16 |
|
17 | 17 | package com.webank.wedatasphere.dss.appconn.mlflow.execution; |
18 | 18 |
|
19 | | -import com.webank.wedatasphere.dss.appconn.mlflow.MLFlowAppConn; |
20 | 19 | import com.webank.wedatasphere.dss.appconn.mlflow.job.JobManager; |
21 | | -import com.webank.wedatasphere.dss.standard.app.development.listener.common.AsyncExecutionRequestRef; |
22 | | -import com.webank.wedatasphere.dss.standard.app.development.listener.common.CompletedExecutionResponseRef; |
| 20 | +import com.webank.wedatasphere.dss.common.utils.DSSCommonUtils; |
23 | 21 | import com.webank.wedatasphere.dss.standard.app.development.listener.common.RefExecutionAction; |
24 | 22 | import com.webank.wedatasphere.dss.standard.app.development.listener.common.RefExecutionState; |
25 | 23 | import com.webank.wedatasphere.dss.standard.app.development.listener.core.Killable; |
26 | 24 | import com.webank.wedatasphere.dss.standard.app.development.listener.core.LongTermRefExecutionOperation; |
27 | 25 | import com.webank.wedatasphere.dss.standard.app.development.listener.core.Procedure; |
28 | | -import com.webank.wedatasphere.dss.standard.app.development.ref.ExecutionRequestRef; |
29 | | -import com.webank.wedatasphere.dss.standard.app.development.service.DevelopmentService; |
30 | | -import com.webank.wedatasphere.dss.standard.app.sso.request.SSORequestOperation; |
31 | | -import org.apache.linkis.httpclient.request.HttpAction; |
32 | | -import org.apache.linkis.httpclient.response.HttpResult; |
33 | | -import org.slf4j.Logger; |
34 | | -import org.slf4j.LoggerFactory; |
| 26 | +import com.webank.wedatasphere.dss.standard.app.development.listener.ref.ExecutionResponseRef; |
| 27 | +import com.webank.wedatasphere.dss.standard.app.development.listener.ref.RefExecutionRequestRef; |
| 28 | +import com.webank.wedatasphere.dss.standard.common.entity.ref.ResponseRef; |
| 29 | +import com.webank.wedatasphere.dss.standard.common.exception.operation.ExternalOperationFailedException; |
35 | 30 |
|
| 31 | +import java.util.HashMap; |
36 | 32 | import java.util.Map; |
37 | 33 |
|
38 | | -public class MLFlowExecutionOperation extends LongTermRefExecutionOperation implements Killable, Procedure { |
| 34 | +public class MLFlowExecutionOperation extends LongTermRefExecutionOperation<RefExecutionRequestRef.RefExecutionProjectWithContextRequestRef> implements Killable, Procedure { |
39 | 35 |
|
40 | 36 |
|
41 | | - private final static Logger logger = LoggerFactory.getLogger(MLFlowExecutionOperation.class); |
42 | | - DevelopmentService developmentService; |
43 | | -// private SSORequestOperation<HttpAction, HttpResult> ssoRequestOperation; |
44 | | - |
45 | | - public MLFlowExecutionOperation(DevelopmentService service) { |
46 | | - this.developmentService = service; |
47 | | -// this.ssoRequestOperation = this.developmentService.getSSORequestService().createSSORequestOperation(getAppName()); |
48 | | - } |
49 | | - |
50 | | - private String getAppName() { |
51 | | - return MLFlowAppConn.MLFlow_APPCONN_NAME; |
52 | | - } |
53 | | - |
54 | 37 | @Override |
55 | | - protected RefExecutionAction submit(ExecutionRequestRef requestRef) { |
56 | | - AsyncExecutionRequestRef asyncRequestRef = (AsyncExecutionRequestRef) requestRef; |
57 | | - Map<String,Object> jobContent = requestRef.getJobContent(); |
58 | | - return JobManager.submit(jobContent, asyncRequestRef.getExecutionRequestRefContext()); |
| 38 | + protected RefExecutionAction submit(RefExecutionRequestRef.RefExecutionProjectWithContextRequestRef requestRef) throws ExternalOperationFailedException { |
| 39 | + Map<String, Object> jobContent = requestRef.getRefJobContent(); |
| 40 | + HashMap contextInfo = DSSCommonUtils.COMMON_GSON.fromJson(DSSCommonUtils.COMMON_GSON.fromJson( |
| 41 | + requestRef.getParameter("dssContextId").toString(), HashMap.class).get("value").toString(), HashMap.class); |
| 42 | + return JobManager.submit(jobContent, requestRef.getExecutionRequestRefContext(), contextInfo); |
59 | 43 | } |
60 | 44 |
|
61 | 45 | @Override |
62 | | - public RefExecutionState state(RefExecutionAction action) { |
| 46 | + public RefExecutionState state(RefExecutionAction action) throws ExternalOperationFailedException { |
| 47 | + logger.info(action.toString()); |
63 | 48 | MLFlowExecutionAction mlFlowExecutionAction = (MLFlowExecutionAction) action; |
64 | 49 | return JobManager.state(mlFlowExecutionAction); |
65 | 50 | } |
66 | 51 |
|
67 | 52 | @Override |
68 | | - public CompletedExecutionResponseRef result(RefExecutionAction action) { |
69 | | - MLFlowExecutionAction mlFlowExecutionAction = (MLFlowExecutionAction) action; |
70 | | - return JobManager.result(mlFlowExecutionAction, mlFlowExecutionAction.getExecutionRequestRefContext()); |
71 | | - } |
72 | | - |
73 | | - private String getUser(AsyncExecutionRequestRef requestRef) { |
74 | | - return requestRef.getExecutionRequestRefContext().getRuntimeMap().get("wds.dss.workflow.submit.user").toString(); |
75 | | - } |
76 | | - |
77 | | - private String getId(AsyncExecutionRequestRef requestRef) { |
78 | | - return null; |
79 | | - } |
80 | | - |
81 | | - @Override |
82 | | - public void setDevelopmentService(DevelopmentService service) { |
83 | | - this.developmentService = service; |
84 | | - } |
85 | | - |
86 | | - private String getBaseUrl(){ |
87 | | - return developmentService.getAppInstance().getBaseUrl(); |
| 53 | + public ExecutionResponseRef result(RefExecutionAction action) throws ExternalOperationFailedException { |
| 54 | + HashMap resultMap = new HashMap(); |
| 55 | + int status = -1; |
| 56 | + String errorMsg = ""; |
| 57 | + if (action == null) { |
| 58 | + errorMsg = ""; |
| 59 | + return ExecutionResponseRef.newBuilder().setResponseRef( |
| 60 | + new MLFlowExecutionResponseRef("", status, errorMsg, resultMap)).build(); |
| 61 | + } |
| 62 | + logger.info(action.toString()); |
| 63 | + MLFlowExecutionAction mlssAction = (MLFlowExecutionAction) action; |
| 64 | + if (mlssAction.getState() == RefExecutionState.Success) { |
| 65 | + status = 200; |
| 66 | + } |
| 67 | + ResponseRef response = new MLFlowExecutionResponseRef("", status, errorMsg, resultMap); |
| 68 | + return ExecutionResponseRef.newBuilder().setResponseRef(response).build(); |
88 | 69 | } |
89 | 70 |
|
90 | 71 | @Override |
|
0 commit comments