You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/10/31 01:04:47 UTC

[GitHub] [dolphinscheduler] zhongjiajie commented on a diff in pull request #11759: [Feature-6586][Server]add some ds process definition demo when init

zhongjiajie commented on code in PR #11759:
URL: https://github.com/apache/dolphinscheduler/pull/11759#discussion_r1008958143


##########
docs/docs/zh/guide/demo.md:
##########
@@ -0,0 +1,37 @@
+# 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
   demo:
     tenant-code: default
     api-server-port: 5173
   ```



##########
docs/docs/en/guide/demo.md:
##########
@@ -0,0 +1,37 @@
+# DolphinScheduler Initialize The Workflow Demo

Review Comment:
   I think we should also add a hyperlink to https://dolphinscheduler.apache.org/en-us/docs/latest/user_doc/guide/start/quick-start.html to told user we can create demo, WDYT?



##########
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/demo/CreateDemoTenant.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.dao.entity.Tenant;
+import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
+
+import java.util.Date;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class CreateDemoTenant {
+
+    private static final Logger logger = LoggerFactory.getLogger(CreateDemoTenant.class);
+    @Autowired
+    private TenantMapper tenantMapper;
+
+    public void createTenantCode(String tenantCode) {
+        Date now = new Date();
+
+        if (!tenantCode.equals("default")) {
+            Boolean existTenant = tenantMapper.existTenant(tenantCode);
+            if (!Boolean.TRUE.equals(existTenant)) {
+                Tenant tenant = new Tenant();
+                tenant.setTenantCode(tenantCode);
+                tenant.setQueueId(1);

Review Comment:
   can we use a Constant variable here instead of a bare number? also to `userMapper.selectById("1")` in processdefinitionDemo.java



##########
dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/demo/ProcessDefinitionDemo.java:
##########
@@ -0,0 +1,827 @@
+/*
+ * 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 static org.apache.dolphinscheduler.common.enums.ConditionType.NONE;
+import static org.apache.dolphinscheduler.common.enums.Flag.YES;
+import static org.apache.dolphinscheduler.common.enums.Priority.MEDIUM;
+import static org.apache.dolphinscheduler.common.enums.ProcessExecutionTypeEnum.PARALLEL;
+
+import org.apache.dolphinscheduler.common.enums.TimeoutFlag;
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import org.apache.dolphinscheduler.common.utils.DateUtils;
+import org.apache.dolphinscheduler.common.utils.EncryptionUtils;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.dao.entity.AccessToken;
+import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog;
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
+import org.apache.dolphinscheduler.dao.entity.Project;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.AccessTokenMapper;
+import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
+import org.apache.dolphinscheduler.dao.mapper.UserMapper;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ProcessDefinitionDemo {
+
+    private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionDemo.class);
+
+    @Value("${demo.tenant-code}")
+    private String tenantCode;
+
+    @Autowired
+    private ProjectMapper projectMapper;
+
+    @Autowired
+    private UserMapper userMapper;
+
+    @Autowired
+    private AccessTokenMapper accessTokenMapper;
+
+    @Autowired
+    private ProxyProcessDefinitionController proxyProcessDefinitionController;
+
+    public void createProcessDefinitionDemo() throws Exception {
+        // get user
+        User loginUser = userMapper.selectById("1");
+        Date now = new Date();
+
+        // create demo tenantCode
+        CreateDemoTenant createDemoTenant = new CreateDemoTenant();
+        createDemoTenant.createTenantCode(tenantCode);
+
+        // create and get demo projectCode
+        Project project = projectMapper.queryByName("demo");
+        if (project != null) {
+            logger.warn("Project {} already exists.", project.getName());
+        }
+        try {
+            project = Project
+                    .builder()
+                    .name("demo")
+                    .code(CodeGenerateUtils.getInstance().genCode())
+                    .description("")
+                    .userId(loginUser.getId())
+                    .userName(loginUser.getUserName())
+                    .createTime(now)
+                    .updateTime(now)
+                    .build();
+        } catch (CodeGenerateUtils.CodeGenerateException e) {
+            logger.error("create project error", e);
+        }
+        if (projectMapper.insert(project) > 0) {
+            logger.info("create project success");
+        } else {
+            throw new Exception("create project error");
+        }
+        Long projectCode = null;
+        try {
+            projectCode = project.getCode();
+        } catch (NullPointerException e) {
+            logger.error("project code is null", e);
+        }
+
+        // generate access token
+        String expireTime = "2050-09-30 15:59:23";

Review Comment:
   maybe we should better add those constant values in this file to `DemoContants.java`



##########
docs/docs/en/guide/demo.md:
##########
@@ -0,0 +1,37 @@
+# DolphinScheduler Initialize The Workflow Demo
+
+## Prepare
+
+### Backup Previous Version's Files and Database
+
+To prevent data loss by some miss-operation, it is recommended to back up data before initializing the workflow demo. The backup way according to your environment.
+
+### Download the Latest Version Installation Package
+
+Download the latest binary distribute package from [download](/en-us/download/download.html) and then put it in the different
+directory where current service running. And all below command is running in this directory.
+
+## Start
+
+### Start Services of DolphinScheduler
+
+Start all services of dolphinscheduler according to your deployment method. If you deploy your dolphinscheduler according to [cluster deployment](installation/cluster.md), you can start all services by command `sh ./script/start-all.sh`.
+
+### Database Configuration
+
+Initializing the workflow demo needs to store metabase in other database like MySQL or PostgreSQL, they have to change some configuration. Follow the instructions in [datasource-setting](howto/datasource-setting.md) `Standalone Switching Metadata Database Configuration` section to create and initialize database.
+
+### Tenant Configuration
+
+#### Change `dolphinscheduler-tools/resources/application.yaml` Placement Details
+
+        ```
+        demo:
+          tenant-code: default
+          api-server-port: 5173

Review Comment:
   ```suggestion
   demo:
     tenant-code: default
     api-server-port: 5173
   ```



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org