SbloodyS commented on code in PR #10670: URL: https://github.com/apache/dolphinscheduler/pull/10670#discussion_r925369512
########## dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/WorkFlowAPITest.java: ########## @@ -0,0 +1,115 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.api.test.cases; + +import lombok.extern.slf4j.Slf4j; +import org.apache.dolphinscheduler.api.test.core.DolphinScheduler; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.entity.LoginResponseData; +import org.apache.dolphinscheduler.api.test.pages.LoginPage; +import org.apache.dolphinscheduler.api.test.pages.project.ProjectPage; +import org.apache.dolphinscheduler.api.test.pages.project.WorkFlowDefinitionPage; +import org.apache.dolphinscheduler.api.test.pages.security.TenantPage; +import org.apache.dolphinscheduler.api.test.utils.JSONUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@DolphinScheduler(composeFiles = "docker/basic/docker-compose.yaml") +@Slf4j +public class WorkFlowAPITest { + private static final Logger logger = LoggerFactory.getLogger(ProjectAPITest.class); + + private static final String projectName = "case02_wen"; + + private static final String projectDesc = "123"; + + private static final String workFlowName = "shell123"; + + private static final String tenantName = "admin"; + + private static final String user = "admin"; + + private static final String password = "dolphinscheduler123"; + + private static String sessionId = null; + + @BeforeAll + public static void setup() { + LoginPage loginPage = new LoginPage(); + ProjectPage projectPage = new ProjectPage(); + HttpResponse loginHttpResponse = loginPage.login(user, password); + TenantPage tenantPage = new TenantPage(); + + sessionId = JSONUtils.convertValue(loginHttpResponse.body().data(), LoginResponseData.class).sessionId(); + projectPage.createProject(sessionId, projectName, projectDesc, user); + tenantPage.createTenant(sessionId, tenantName, 1, ""); + + } + + @Test + @Order(1) + public void testCreateWorkflow() { + WorkFlowDefinitionPage flow = new WorkFlowDefinitionPage(); + flow.getGenNumId(sessionId, projectName); + HttpResponse res = flow.createWorkflow(sessionId, projectName, workFlowName); + + logger.info("Create workflow res:%s", res); + Assertions.assertTrue(res.body().success()); + } + + @Test + @Order(2) + public void testOnlineWorkflow() { + WorkFlowDefinitionPage flow = new WorkFlowDefinitionPage(); + HttpResponse res = flow.onLineWorkflow(sessionId, projectName, workFlowName); + + logger.info("Online workflow res:%s", res); + Assertions.assertTrue(res.body().success()); + + } + + @Test + @Order(3) + public void testQueryWorkflow() { + WorkFlowDefinitionPage flow = new WorkFlowDefinitionPage(); + flow.getGenNumId(sessionId, projectName); + HttpResponse res = flow.queryWorkflow(sessionId, projectName, workFlowName); + + logger.info("Query workflow res:%s", res); + Assertions.assertTrue(res.body().success()); + } + + @Test + @Order(4) + public void testRunWorkflow() { + WorkFlowDefinitionPage flow = new WorkFlowDefinitionPage(); + HttpResponse res = flow.runWorkflow(sessionId, projectName, workFlowName); + + logger.info("Run workflow res:%s", res); + Assertions.assertTrue(res.body().success()); + Review Comment: Because our workflow runs asynchronously, we need to verify the workflow running state through workflow instance query. ########## .github/workflows/api-test.yml: ########## @@ -90,6 +90,12 @@ jobs: case: - name: Tenant class: org.apache.dolphinscheduler.api.test.cases.TenantAPITest + - name: Project + class: org.apache.dolphinscheduler.api.test.cases.ProjectAPITest + - name: WorkFlow + class: org.apache.dolphinscheduler.api.test.cases.WorkFlowAPITest + - name: WorkFlowInstance + class: org.apache.dolphinscheduler.api.test.cases.WorkFlowInstanceAPITest Review Comment: I think we should combine workflow use cases of the same task type into the same file since workflow operation and query belong to the same type. And it's better rename to `WorkFlowShellAPITest`. ########## dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/project/TaskInstancePage.java: ########## @@ -0,0 +1,100 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.api.test.pages.project; + + +import org.apache.dolphinscheduler.api.test.cases.ProjectAPITest; +import org.apache.dolphinscheduler.api.test.core.Constants; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.entity.TaskInstanceResponseData; +import org.apache.dolphinscheduler.api.test.entity.TaskInstanceResponseTotalList; +import org.apache.dolphinscheduler.api.test.utils.JSONUtils; +import org.apache.dolphinscheduler.api.test.utils.RequestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +import java.util.HashMap; +import java.util.Map; + +public final class TaskInstancePage { + private static final Logger logger = LoggerFactory.getLogger(TaskInstancePage.class); + private static String taskState = null; + private static Integer taskInstanceId = null; + + public String queryTaskInstance(String sessionId, String projectName, String workFlowName){ + Map<String, Object> params = new HashMap<>(); + Map<String, String> headers = new HashMap<>(); + params.put("pageSize", 10); + params.put("pageNo", 1); + params.put("searchVal", ""); + params.put("processInstanceId", ""); + params.put("host", ""); + params.put("stateType", ""); + params.put("startDate", ""); + params.put("endDate", ""); + params.put("executorName", ""); + params.put("processInstanceName", workFlowName); + + headers.put(Constants.SESSION_ID_KEY, sessionId); + RequestClient requestClient = new RequestClient(); + ProjectPage project = new ProjectPage(); + String projectCode = project.getProjectCode(sessionId, projectName); + + WorkFlowDefinitionPage workflow = new WorkFlowDefinitionPage(); + workflow.runWorkflow(sessionId, projectName, workFlowName); + + HttpResponse res = requestClient.get("/projects/"+projectCode+"/task-instances", headers, params); + + + for (TaskInstanceResponseTotalList taskInstanceRes : JSONUtils.convertValue(res.body().data(), TaskInstanceResponseData.class).totalList()) { + + taskState = taskInstanceRes.state(); + taskInstanceId = taskInstanceRes.id(); + } + + logger.info("查询task状态:%s", taskState); Review Comment: English please. BTW, I think it's unnessnary. ########## dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/project/WorkFlowDefinitionPage.java: ########## @@ -0,0 +1,212 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.api.test.pages.project; + + +import org.apache.dolphinscheduler.api.test.core.Constants; +import org.apache.dolphinscheduler.api.test.entity.TaskParamsMap; +import org.apache.dolphinscheduler.api.test.entity.TaskDefinitionRequestData; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowRunRequestData; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowCreateRequestData; +import org.apache.dolphinscheduler.api.test.entity.TaskRelationRequestData; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseData; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseTotalList; +import org.apache.dolphinscheduler.api.test.utils.JSONUtils; +import org.apache.dolphinscheduler.api.test.utils.RequestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + + +public final class WorkFlowDefinitionPage { + private static String genNumId = null; + private static String workFlowCode = null; + private static final Logger logger = LoggerFactory.getLogger(WorkFlowDefinitionPage.class); + + public void getGenNumId(String sessionId, String projectName) { + + Map<String, Object> params = new HashMap<>(); + Map<String, String> headers = new HashMap<>(); + params.put("genNum", 1); + headers.put(Constants.SESSION_ID_KEY, sessionId); + ProjectPage project = new ProjectPage(); + String projectCode = project.getProjectCode(sessionId, projectName); + RequestClient requestClient = new RequestClient(); + HttpResponse res = requestClient.get("/projects/"+projectCode+"/task-definition/gen-task-codes", headers, params); + ArrayList list = (ArrayList) res.body().data(); + genNumId = list.get(0).toString(); + + } + + + public HttpResponse createWorkflow(String sessionId, String projectName, String workFlowName) { + Map<String, String> headers = new HashMap<>(); + WorkFlowCreateRequestData workFlowCreateRequestData = new WorkFlowCreateRequestData(); + TaskDefinitionRequestData taskDefinitionRequestData = new TaskDefinitionRequestData(); + TaskRelationRequestData taskRelationRequestData = new TaskRelationRequestData(); + + TaskParamsMap taskParams = new TaskParamsMap(); + ArrayList<Object> localParams = new ArrayList<>(); + ArrayList<Object> resourceList = new ArrayList<>(); + taskParams.localParams(localParams); + taskParams.resourceList(resourceList); + taskParams.rawScript("echo 123"); + + taskDefinitionRequestData.code(genNumId); + taskDefinitionRequestData.delayTime("0"); + taskDefinitionRequestData.description(""); + taskDefinitionRequestData.environmentCode("-1"); + taskDefinitionRequestData.failRetryInterval("1"); + taskDefinitionRequestData.failRetryTimes("0"); + taskDefinitionRequestData.flag("YES"); + taskDefinitionRequestData.name("echo_123"); + taskDefinitionRequestData.taskParams(taskParams); + taskDefinitionRequestData.taskPriority("MEDIUM"); + taskDefinitionRequestData.taskType("SHELL"); + taskDefinitionRequestData.timeout(0); + taskDefinitionRequestData.timeoutFlag("CLOSE"); + taskDefinitionRequestData.timeoutNotifyStrategy(""); + taskDefinitionRequestData.workerGroup("default"); + + ArrayList<Object> taskDefinitionRequestDataList = new ArrayList<>(); + taskDefinitionRequestDataList.add(taskDefinitionRequestData); + + logger.info("taskDefinitionRequestData:aaaa: %s"); + logger.info(String.valueOf(taskDefinitionRequestData)); + logger.info(String.valueOf(taskDefinitionRequestData.getClass())); + logger.info(String.valueOf(taskDefinitionRequestDataList)); + logger.info(String.valueOf(taskDefinitionRequestDataList.getClass())); + logger.info("taskDefinitionRequestData:bbbb: %s"); Review Comment: Please remove unnessnary log ouput. ########## dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/project/WorkFlowDefinitionPage.java: ########## @@ -0,0 +1,212 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.api.test.pages.project; + + +import org.apache.dolphinscheduler.api.test.core.Constants; +import org.apache.dolphinscheduler.api.test.entity.TaskParamsMap; +import org.apache.dolphinscheduler.api.test.entity.TaskDefinitionRequestData; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowRunRequestData; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowCreateRequestData; +import org.apache.dolphinscheduler.api.test.entity.TaskRelationRequestData; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseData; +import org.apache.dolphinscheduler.api.test.entity.WorkFlowResponseTotalList; +import org.apache.dolphinscheduler.api.test.utils.JSONUtils; +import org.apache.dolphinscheduler.api.test.utils.RequestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + + +public final class WorkFlowDefinitionPage { + private static String genNumId = null; + private static String workFlowCode = null; + private static final Logger logger = LoggerFactory.getLogger(WorkFlowDefinitionPage.class); + + public void getGenNumId(String sessionId, String projectName) { + + Map<String, Object> params = new HashMap<>(); + Map<String, String> headers = new HashMap<>(); + params.put("genNum", 1); + headers.put(Constants.SESSION_ID_KEY, sessionId); + ProjectPage project = new ProjectPage(); + String projectCode = project.getProjectCode(sessionId, projectName); + RequestClient requestClient = new RequestClient(); + HttpResponse res = requestClient.get("/projects/"+projectCode+"/task-definition/gen-task-codes", headers, params); + ArrayList list = (ArrayList) res.body().data(); + genNumId = list.get(0).toString(); + + } + + + public HttpResponse createWorkflow(String sessionId, String projectName, String workFlowName) { + Map<String, String> headers = new HashMap<>(); + WorkFlowCreateRequestData workFlowCreateRequestData = new WorkFlowCreateRequestData(); + TaskDefinitionRequestData taskDefinitionRequestData = new TaskDefinitionRequestData(); + TaskRelationRequestData taskRelationRequestData = new TaskRelationRequestData(); + + TaskParamsMap taskParams = new TaskParamsMap(); + ArrayList<Object> localParams = new ArrayList<>(); + ArrayList<Object> resourceList = new ArrayList<>(); + taskParams.localParams(localParams); + taskParams.resourceList(resourceList); + taskParams.rawScript("echo 123"); + + taskDefinitionRequestData.code(genNumId); + taskDefinitionRequestData.delayTime("0"); + taskDefinitionRequestData.description(""); + taskDefinitionRequestData.environmentCode("-1"); + taskDefinitionRequestData.failRetryInterval("1"); + taskDefinitionRequestData.failRetryTimes("0"); + taskDefinitionRequestData.flag("YES"); + taskDefinitionRequestData.name("echo_123"); + taskDefinitionRequestData.taskParams(taskParams); + taskDefinitionRequestData.taskPriority("MEDIUM"); + taskDefinitionRequestData.taskType("SHELL"); + taskDefinitionRequestData.timeout(0); + taskDefinitionRequestData.timeoutFlag("CLOSE"); + taskDefinitionRequestData.timeoutNotifyStrategy(""); + taskDefinitionRequestData.workerGroup("default"); + + ArrayList<Object> taskDefinitionRequestDataList = new ArrayList<>(); + taskDefinitionRequestDataList.add(taskDefinitionRequestData); + + logger.info("taskDefinitionRequestData:aaaa: %s"); + logger.info(String.valueOf(taskDefinitionRequestData)); + logger.info(String.valueOf(taskDefinitionRequestData.getClass())); + logger.info(String.valueOf(taskDefinitionRequestDataList)); + logger.info(String.valueOf(taskDefinitionRequestDataList.getClass())); + logger.info("taskDefinitionRequestData:bbbb: %s"); + + HashMap<String, Object> conditionParams = new HashMap(); + + taskRelationRequestData.name(""); + taskRelationRequestData.preTaskCode(0); + taskRelationRequestData.preTaskVersion(0); + taskRelationRequestData.preTaskCode(0); + taskRelationRequestData.postTaskCode(genNumId); + taskRelationRequestData.conditionType("NONE"); + taskRelationRequestData.conditionParams(conditionParams); + ArrayList<Object> taskRelationRequestDataList = new ArrayList<>(); + taskRelationRequestDataList.add(taskRelationRequestData); + + HashMap<String, Object> locations = new HashMap(); + locations.put("taskCode", genNumId); + locations.put("x", 33.5); + locations.put("y", 38.5); + ArrayList<Object> locationsList = new ArrayList<>(); + locationsList.add(locations); + + workFlowCreateRequestData.locations(JSONUtils.toJsonString(locationsList)); + workFlowCreateRequestData.taskDefinitionJson(JSONUtils.toJsonString(taskDefinitionRequestDataList)); + workFlowCreateRequestData.taskRelationJson(JSONUtils.toJsonString(taskRelationRequestDataList)); + workFlowCreateRequestData.name(workFlowName); + workFlowCreateRequestData.tenantCode("admin"); + workFlowCreateRequestData.executionType("PARALLEL"); + workFlowCreateRequestData.description(""); + workFlowCreateRequestData.globalParams("[]"); + workFlowCreateRequestData.timeout(0); + + headers.put(Constants.SESSION_ID_KEY, sessionId); + RequestClient requestClient = new RequestClient(); + ProjectPage project = new ProjectPage(); + String projectCode = project.getProjectCode(sessionId, projectName); + + logger.info(String.valueOf(workFlowCreateRequestData)); Review Comment: Please remove unnessnary log ouput. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
