kezhenxu94 commented on code in PR #11759:
URL:
https://github.com/apache/dolphinscheduler/pull/11759#discussion_r1009091706
##########
docs/docs/zh/guide/demo.md:
##########
@@ -0,0 +1,39 @@
+# DolphinScheduler 初始化工作流 demo
+
+## 准备工作
+
+### 备份上一版本文件和数据库
+
+为了防止操作错误导致数据丢失,建议初始化工作流 demo 服务之前备份数据,备份方法请结合你数据库的情况来定
+
+### 下载新版本的安装包
+
+在[下载](/zh-cn/download/download.html)页面下载最新版本的二进制安装包,并将二进制包放到与当前
dolphinscheduler 服务不一样的路径中,以下服务启动操作都需要在新版本的目录进行。
+
+## 服务启动步骤
+
+### 开启 dolphinscheduler 服务
+
+根据你部署方式开启 dolphinscheduler 的所有服务,如果你是通过 [集群部署](installation/cluster.md) 来部署你的
dolphinscheduler 的话,可以通过 `sh ./script/start-all.sh` 开启全部服务。
+
+### 数据库配置
+
+初始化工作流 demo 服务需要使用 MySQL 或 PostgreSQL 等其他数据库作为其元数据存储数据,因此必须更改一些配置。
+请参考[数据源配置](howto/datasource-setting.md) `Standalone 切换元数据库`创建并初始化数据库 ,然后运行
demo 服务启动脚本。
+
+### 租户配置
+
+#### 修改 `dolphinscheduler-tools/resources/application.yaml` 配置内容
+
+```
+demo:
+tenant-code: default
+api-server-port: 5173
Review Comment:
```suggestion
tenant-code: default
api-server-port: 5173
```
##########
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/demo/ProxyProcessDefinitionController.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the 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.
+ * The 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.tools.demo;
+
+import org.apache.dolphinscheduler.common.enums.ProcessExecutionTypeEnum;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.common.utils.OkHttpUtils;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ProxyProcessDefinitionController {
+
+ @Value("${demo.api-server-port}")
+ private String ServerPort;
+
+ public ProxyResult createProcessDefinition(String token,
+ long projectCode,
+ String name,
+ String description,
+ String globalParams,
+ String locations,
+ int timeout,
+ String tenantCode,
+ String taskRelationJson,
+ String taskDefinitionJson,
+ ProcessExecutionTypeEnum
executionType) {
+ ProxyResult proxyResult = new ProxyResult();
+ String url =
+ "http://localhost:" + ServerPort +
"/dolphinscheduler/projects/" + projectCode + "/process-definition";
+ String responseBody;
+ Map<String, Object> requestBodyMap = new HashMap<>();
+
+ requestBodyMap.put("name", name);
+ requestBodyMap.put("description", description);
+ requestBodyMap.put("globalParams", globalParams);
+ requestBodyMap.put("locations", locations);
+ requestBodyMap.put("timeout", timeout);
+ requestBodyMap.put("tenantCode", tenantCode);
+ requestBodyMap.put("taskRelationJson", taskRelationJson);
+ requestBodyMap.put("taskDefinitionJson", taskDefinitionJson);
+ requestBodyMap.put("otherParamsJson", null);
+ requestBodyMap.put("executionType", executionType);
+
+ try {
+ responseBody = OkHttpUtils.demoPost(url, token, requestBodyMap);
Review Comment:
Ideally, I would prefer we should use `RestTemplate` to perform http
requests, but this looks OK to me if you want to refactor later.
##########
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/demo/ProxyProcessDefinitionController.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the 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.
+ * The 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.tools.demo;
+
+import org.apache.dolphinscheduler.common.enums.ProcessExecutionTypeEnum;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.common.utils.OkHttpUtils;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ProxyProcessDefinitionController {
+
+ @Value("${demo.api-server-port}")
+ private String ServerPort;
+
+ public ProxyResult createProcessDefinition(String token,
+ long projectCode,
+ String name,
+ String description,
+ String globalParams,
+ String locations,
+ int timeout,
+ String tenantCode,
+ String taskRelationJson,
+ String taskDefinitionJson,
+ ProcessExecutionTypeEnum
executionType) {
+ ProxyResult proxyResult = new ProxyResult();
+ String url =
+ "http://localhost:" + ServerPort +
"/dolphinscheduler/projects/" + projectCode + "/process-definition";
Review Comment:
I think `localhost` should be also configurable, if users don't deploy on
local machine
##########
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/demo/ProxyResult.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the 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.
+ * The 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.tools.demo;
+
+public class ProxyResult<T> {
Review Comment:
Try to use lombok annotations to simplify this class
##########
dolphinscheduler-tools/src/main/bin/demo-start.sh:
##########
@@ -0,0 +1,31 @@
+#!/bin/bash
Review Comment:
What about renaming this file to something like `create-demo-processes.sh`?
`-start` sounds like it's a long-running server but it is not
--
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]