This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


The following commit(s) were added to refs/heads/dev by this push:
     new 12ff1be11 [Improve][project-build] Limit the number of running build 
projects (#3696)
12ff1be11 is described below

commit 12ff1be1189a1d9bf44c394f834b5b0dbcda736b
Author: ZhilinLi <[email protected]>
AuthorDate: Sat May 4 13:55:38 2024 +0800

    [Improve][project-build] Limit the number of running build projects (#3696)
---
 .../apache/streampark/console/core/mapper/ProjectMapper.java   |  2 ++
 .../console/core/service/impl/ProjectServiceImpl.java          | 10 ++++++++++
 .../streampark-console-service/src/main/resources/config.yaml  |  3 +++
 .../src/main/resources/mapper/core/ProjectMapper.xml           |  3 +++
 4 files changed, 18 insertions(+)

diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/ProjectMapper.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/ProjectMapper.java
index d14f79e0b..ad55f6b71 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/ProjectMapper.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/ProjectMapper.java
@@ -38,4 +38,6 @@ public interface ProjectMapper extends BaseMapper<Project> {
   boolean existsByTeamId(@Param("teamId") Long teamId);
 
   List<Project> selectProjectsByTeamId(@Param("teamId") Long teamId);
+
+  Long getBuildingCount();
 }
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
index 13f5a137b..f6097bb39 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
@@ -55,6 +55,7 @@ import 
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -92,6 +93,9 @@ public class ProjectServiceImpl extends 
ServiceImpl<ProjectMapper, Project>
   @Autowired
   private Executor executorService;
 
+  @Value("${streampark.project.max-build:6}")
+  private Long maxProjectBuildNum;
+
   @Override
   public RestResponse create(Project project) {
     LambdaQueryWrapper<Project> queryWrapper =
@@ -225,6 +229,12 @@ public class ProjectServiceImpl extends 
ServiceImpl<ProjectMapper, Project>
 
   @Override
   public void build(Long id) throws Exception {
+    Long currentBuildCount = this.baseMapper.getBuildingCount();
+    ApiAlertException.throwIfTrue(
+        maxProjectBuildNum > -1 && currentBuildCount > maxProjectBuildNum,
+        String.format(
+            "The number of running Build projects exceeds the maximum number: 
%d of max-build-num",
+            maxProjectBuildNum));
     Project project = getById(id);
     this.baseMapper.updateBuildState(project.getId(), 
BuildStateEnum.BUILDING.get());
     String logPath = getBuildLogPath(id);
diff --git 
a/streampark-console/streampark-console-service/src/main/resources/config.yaml 
b/streampark-console/streampark-console-service/src/main/resources/config.yaml
index e97991827..49a9ef0e9 100644
--- 
a/streampark-console/streampark-console-service/src/main/resources/config.yaml
+++ 
b/streampark-console/streampark-console-service/src/main/resources/config.yaml
@@ -61,6 +61,9 @@ streampark:
         http-auth: 'simple'  # default simple, or kerberos
     # flink on yarn or spark on yarn, HADOOP_USER_NAME
     hadoop-user-name: hdfs
+    project:
+        # Number of projects allowed to be running at the same time , If there 
is no limit, -1 can be configured
+        max-build: 16
 
 # flink on yarn or spark on yarn, when the hadoop cluster enable kerberos 
authentication, it is necessary to set Kerberos authentication parameters.
 security:
diff --git 
a/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml
 
b/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml
index e69136ecd..35a081d96 100644
--- 
a/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml
+++ 
b/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml
@@ -89,5 +89,8 @@
             </if>
         </where>
     </select>
+    <select id="getBuildingCount" resultType="java.lang.Long">
+        select count(1) from t_flink_project where build_state = 0
+    </select>
 
 </mapper>

Reply via email to