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 2020/06/25 10:35:34 UTC

[GitHub] [incubator-dolphinscheduler] yangyichao-mango commented on a change in pull request #3053: [Feature-2154] Workflow version control

yangyichao-mango commented on a change in pull request #3053:
URL: https://github.com/apache/incubator-dolphinscheduler/pull/3053#discussion_r445464527



##########
File path: dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionService.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.api.service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
+import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion;
+import org.apache.dolphinscheduler.dao.entity.Project;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionVersionMapper;
+import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.common.collect.ImmutableMap;
+
+@Service
+public class ProcessDefinitionVersionService {
+
+    @Autowired
+    private ProcessDefinitionVersionMapper processDefinitionVersionMapper;
+
+    @Autowired
+    private ProjectService projectService;
+
+    @Autowired
+    private ProjectMapper projectMapper;
+
+    /**
+     * add the newest version of one process definition
+     *
+     * @param processDefinition the process definition that need to record version
+     * @return the newest version number of this process definition
+     */
+    public long addProcessDefinitionVersion(ProcessDefinition processDefinition) {
+
+        long version = this.queryMaxVersionByProcessDefinitionId(processDefinition.getId()) + 1;
+
+        ProcessDefinitionVersion processDefinitionVersion = ProcessDefinitionVersion
+                .newBuilder()
+                .processDefinitionId(processDefinition.getId())
+                .version(version)
+                .processDefinitionJson(processDefinition.getProcessDefinitionJson())
+                .description(processDefinition.getDescription())
+                .locations(processDefinition.getLocations())
+                .connects(processDefinition.getConnects())
+                .timeout(processDefinition.getTimeout())
+                .globalParams(processDefinition.getGlobalParams())
+                .createTime(processDefinition.getUpdateTime())
+                .receivers(processDefinition.getReceivers())
+                .receiversCc(processDefinition.getReceiversCc())
+                .resourceIds(processDefinition.getResourceIds())
+                .build();
+
+        processDefinitionVersionMapper.insert(processDefinitionVersion);
+
+        return version;
+    }
+
+    /**
+     * query the max version number by the process definition id
+     *
+     * @param processDefinitionId process definition id
+     * @return the max version number of this id
+     */
+    public long queryMaxVersionByProcessDefinitionId(int processDefinitionId) {
+        // TODO Is it necessary to add distributed locks?
+        Long maxVersion =  processDefinitionVersionMapper.queryMaxVersionByProcessDefinitionId(processDefinitionId);
+        if (Objects.isNull(maxVersion)) {
+            return 0L;
+        } else {
+            return maxVersion;
+        }
+    }

Review comment:
       Hi @dailidong , Is it necessary to add distributed locks?




----------------------------------------------------------------
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.

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