From 7c90bf01bcd19949f7e3c3a92f7169093ef3700c Mon Sep 17 00:00:00 2001 From: JieguangZhou Date: Thu, 17 Nov 2022 15:59:44 +0800 Subject: [PATCH] [Improvement][Task Plugin] Improvement Kubeflow task plugin (#12928) add example check phase in status:conditions --- docs/docs/en/guide/task/kubeflow.md | 26 ++++++++++++++++++- docs/docs/zh/guide/task/kubeflow.md | 26 ++++++++++++++++++- .../plugin/kubeflow/KubeflowHelper.java | 7 +++++ .../plugin/kubeflow/KubeflowTask.java | 1 + .../plugin/kubeflow/KubeflowTaskTest.java | 2 +- .../workflow/components/dag/dag.module.scss | 4 +-- 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/docs/docs/en/guide/task/kubeflow.md b/docs/docs/en/guide/task/kubeflow.md index 63918ab438..3140314444 100644 --- a/docs/docs/en/guide/task/kubeflow.md +++ b/docs/docs/en/guide/task/kubeflow.md @@ -26,7 +26,31 @@ The task plugin picture is as follows ### Here are some specific parameters for the Kubeflow plugin - **Namespace**:The namespace parameter of the cluster -- **yamlContent**:CRD YAML file content +- **yamlContent**:CRD YAML file content, for example: + +```yaml +apiVersion: "kubeflow.org/v1" +kind: TFJob +metadata: + name: tfjob-simple + namespace: kubeflow-user-example-com +spec: + tfReplicaSpecs: + Worker: + replicas: 2 + restartPolicy: OnFailure + template: + metadata: + annotations: + sidecar.istio.io/inject: "false" + spec: + containers: + - name: tensorflow + image: gcr.io/kubeflow-ci/tf-mnist-with-summaries:1.0 + command: + - "python" + - "/var/tf_mnist/mnist_with_summaries.py" +``` ## Environment Configuration diff --git a/docs/docs/zh/guide/task/kubeflow.md b/docs/docs/zh/guide/task/kubeflow.md index d5b2b9a404..462b1d2650 100644 --- a/docs/docs/zh/guide/task/kubeflow.md +++ b/docs/docs/zh/guide/task/kubeflow.md @@ -24,7 +24,31 @@ ### Kubeflow组件独有的参数 - **Namespace**:集群命名空间参数 -- **yamlContent**:CRD YAML文件内容 +- **yamlContent**:CRD YAML文件内容, 如: + +```yaml +apiVersion: "kubeflow.org/v1" +kind: TFJob +metadata: + name: tfjob-simple + namespace: kubeflow-user-example-com +spec: + tfReplicaSpecs: + Worker: + replicas: 2 + restartPolicy: OnFailure + template: + metadata: + annotations: + sidecar.istio.io/inject: "false" + spec: + containers: + - name: tensorflow + image: gcr.io/kubeflow-ci/tf-mnist-with-summaries:1.0 + command: + - "python" + - "/var/tf_mnist/mnist_with_summaries.py" +``` ## 环境配置 diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowHelper.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowHelper.java index e01438a982..5dd111369d 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowHelper.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowHelper.java @@ -20,6 +20,8 @@ package org.apache.dolphinscheduler.plugin.kubeflow; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.plugin.task.api.TaskConstants; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -75,6 +77,7 @@ public class KubeflowHelper { } JsonNode status = data.get("status"); + String lastConditionType = ""; if (status.has("conditions")) { JsonNode conditions = status.get("conditions"); for (int x = messageIndex; x < conditions.size(); x = x + 1) { @@ -83,10 +86,14 @@ public class KubeflowHelper { logger.info(stepMessage); } messageIndex = conditions.size(); + JsonNode lastCondition = conditions.get(conditions.size() - 1); + lastConditionType = lastCondition.has("type") ? lastCondition.get("type").asText() : ""; } String phase; if (status.has("phase")) { phase = status.get("phase").asText(); + } else if (StringUtils.isNotEmpty(lastConditionType)) { + phase = lastConditionType; } else { phase = ""; } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTask.java index e55ff100dd..39adf04bf3 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/main/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTask.java @@ -109,6 +109,7 @@ public class KubeflowTask extends AbstractRemoteTask { logger.info("Kubeflow task delete command: \n{}", command); String message = runCommand(command); logger.info("Kubeflow task delete result: \n{}", message); + exitStatusCode = TaskConstants.EXIT_CODE_KILL; } protected String runCommand(String command) { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/test/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/test/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTaskTest.java index 3a0bfee231..2f9d20cc84 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/test/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-kubeflow/src/test/java/org/apache/dolphinscheduler/plugin/kubeflow/KubeflowTaskTest.java @@ -105,7 +105,7 @@ public class KubeflowTaskTest { KubeflowTask task = Mockito.spy(createTask(kubeflowParameters)); Mockito.when(task.runCommand(Mockito.anyString())).thenReturn("delete_result"); task.cancelApplication(); - Assertions.assertEquals(task.getExitStatusCode(), TaskConstants.EXIT_CODE_SUCCESS); + Assertions.assertEquals(task.getExitStatusCode(), TaskConstants.EXIT_CODE_KILL); } public KubeflowTask createTask(KubeflowParameters kubeflowParameters) { diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag.module.scss b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag.module.scss index ab61220845..7aa0c9c709 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag.module.scss +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag.module.scss @@ -202,7 +202,7 @@ $bgLight: #ffffff; background-image: url('/images/task-icons/linkis.png'); } &.icon-kubeflow { - background-image: url('/images/task-icons/kubeflow_hover.png'); + background-image: url('/images/task-icons/kubeflow.png'); } } @@ -309,7 +309,7 @@ $bgLight: #ffffff; background-image: url('/images/task-icons/linkis_hover.png'); } &.icon-kubeflow { - background-image: url('/images/task-icons/kubeflow.png'); + background-image: url('/images/task-icons/kubeflow_hover.png'); } } }