github-advanced-security[bot] commented on code in PR #17531:
URL: 
https://github.com/apache/dolphinscheduler/pull/17531#discussion_r2379260435


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/serial/WorkflowSerialCoordinator.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.server.master.engine.workflow.serial;
+
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.dao.entity.WorkflowDefinitionLog;
+import org.apache.dolphinscheduler.dao.model.SerialCommandDto;
+import org.apache.dolphinscheduler.dao.repository.SerialCommandDao;
+import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionLogDao;
+import 
org.apache.dolphinscheduler.server.master.engine.IWorkflowSerialCoordinator;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.time.StopWatch;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Used to coordinate the serial execution of workflows.
+ * <p> Once a workflow instance is submitted with serial wait strategy, it 
will be added to the serial queue.
+ * <p> A dedicated thread will poll the serial queue and check if the workflow 
instance can be executed.
+ */
+@Slf4j
+@Component
+public class WorkflowSerialCoordinator implements IWorkflowSerialCoordinator {
+
+    @Autowired
+    private SerialCommandDao serialCommandDao;
+
+    @Autowired
+    private WorkflowDefinitionLogDao workflowDefinitionLogDao;
+
+    @Autowired
+    private SerialCommandWaitHandler serialCommandWaitHandler;
+
+    @Autowired
+    private SerialCommandDiscardHandler serialCommandDiscardHandler;
+
+    @Autowired
+    private SerialCommandPriorityHandler serialCommandPriorityHandler;
+
+    // workflowCode-> workflowVersion -> commandGroup
+    // Right now, we think each workflow has its own queue
+    private final Map<Long, Map<Integer, SerialCommandsGroup>> 
serialCommandGroupMap = new ConcurrentHashMap<>();
+
+    private boolean flag = false;
+
+    private Thread internalThread;
+
+    private static final int DEFAULT_FETCH_SIZE = 1000;
+
+    private static final int DEFAULT_FETCH_INTERVAL_SECONDS = 30;
+
+    public synchronized void start() {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [IWorkflowSerialCoordinator.start](1); it is advisable 
to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/5538)



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/serial/WorkflowSerialCoordinator.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.server.master.engine.workflow.serial;
+
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.dao.entity.WorkflowDefinitionLog;
+import org.apache.dolphinscheduler.dao.model.SerialCommandDto;
+import org.apache.dolphinscheduler.dao.repository.SerialCommandDao;
+import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionLogDao;
+import 
org.apache.dolphinscheduler.server.master.engine.IWorkflowSerialCoordinator;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.time.StopWatch;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Used to coordinate the serial execution of workflows.
+ * <p> Once a workflow instance is submitted with serial wait strategy, it 
will be added to the serial queue.
+ * <p> A dedicated thread will poll the serial queue and check if the workflow 
instance can be executed.
+ */
+@Slf4j
+@Component
+public class WorkflowSerialCoordinator implements IWorkflowSerialCoordinator {
+
+    @Autowired
+    private SerialCommandDao serialCommandDao;
+
+    @Autowired
+    private WorkflowDefinitionLogDao workflowDefinitionLogDao;
+
+    @Autowired
+    private SerialCommandWaitHandler serialCommandWaitHandler;
+
+    @Autowired
+    private SerialCommandDiscardHandler serialCommandDiscardHandler;
+
+    @Autowired
+    private SerialCommandPriorityHandler serialCommandPriorityHandler;
+
+    // workflowCode-> workflowVersion -> commandGroup
+    // Right now, we think each workflow has its own queue
+    private final Map<Long, Map<Integer, SerialCommandsGroup>> 
serialCommandGroupMap = new ConcurrentHashMap<>();
+
+    private boolean flag = false;
+
+    private Thread internalThread;
+
+    private static final int DEFAULT_FETCH_SIZE = 1000;
+
+    private static final int DEFAULT_FETCH_INTERVAL_SECONDS = 30;
+
+    public synchronized void start() {
+        log.info("WorkflowSerialCoordinator starting...");
+        if (flag) {
+            throw new IllegalStateException("WorkflowSerialCoordinator is 
already started");
+        }
+        if (internalThread != null) {
+            throw new IllegalStateException("InternalThread is already 
started");
+        }
+        flag = true;
+        internalThread = new BaseDaemonThread(this::doStart) {
+        };
+        internalThread.setName("WorkflowSerialCoordinator-Thread");
+        internalThread.start();
+        log.info("WorkflowSerialCoordinator started...");
+    }
+
+    private void doStart() {
+        while (flag) {
+            try {
+                final StopWatch workflowSerialCoordinatorRoundCost = 
StopWatch.createStarted();
+                fetchSerialCommands();
+                handleSerialCommands();
+                log.debug("WorkflowSerialCoordinator round cost: {}/ms", 
workflowSerialCoordinatorRoundCost.getTime());

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [StopWatch.getTime](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/5537)



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

Reply via email to