Skip to content

Commit c3c468c

Browse files
wolfboysbenjobs
andauthored
[Improve] Limit the number of running build projects #3687 (#3695)
* [Improve] Limit the number of running build projects #3687 --------- Co-authored-by: benjobs <[email protected]>
1 parent eae3265 commit c3c468c

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

streampark-console/streampark-console-service/src/main/assembly/assembly.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
<outputDirectory>lib</outputDirectory>
6464
<fileMode>0755</fileMode>
6565
</fileSet>
66+
<fileSet>
67+
<directory>${project.build.directory}/../src/main/assembly/conf</directory>
68+
<outputDirectory>conf</outputDirectory>
69+
<fileMode>0755</fileMode>
70+
</fileSet>
6671
<fileSet>
6772
<directory>${project.build.directory}/../src/main/assembly/logs</directory>
6873
<outputDirectory>logs</outputDirectory>
@@ -95,7 +100,6 @@
95100
<lineEnding>unix</lineEnding>
96101
<fileMode>0755</fileMode>
97102
<includes>
98-
<include>config.yaml</include>
99103
<include>logback-spring.xml</include>
100104
</includes>
101105
</fileSet>

streampark-console/streampark-console-service/src/main/resources/config.yaml renamed to streampark-console/streampark-console-service/src/main/assembly/conf/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ streampark:
6161
http-auth: 'simple' # default simple, or kerberos
6262
# flink on yarn or spark on yarn, HADOOP_USER_NAME
6363
hadoop-user-name: hdfs
64+
project:
65+
# Number of projects allowed to be running at the same time , If there is no limit, -1 can be configured
66+
max-build: 16
6467

6568
# flink on yarn or spark on yarn, when the hadoop cluster enable kerberos authentication, it is necessary to set Kerberos authentication parameters.
6669
security:

streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SpringProperties.java

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.streampark.console.base.config;
1919

20+
import org.apache.streampark.common.conf.ConfigConst;
2021
import org.apache.streampark.common.util.PropertiesUtils;
2122
import org.apache.streampark.common.util.SystemPropertyUtils;
2223
import org.apache.streampark.console.base.util.WebUtils;
@@ -28,7 +29,6 @@
2829
import org.slf4j.LoggerFactory;
2930

3031
import java.io.File;
31-
import java.io.InputStream;
3232
import java.util.Map;
3333
import java.util.Properties;
3434

@@ -46,10 +46,10 @@ public static Properties get() {
4646
SystemPropertyUtils.set("spring.config.location", oldConfig.getAbsolutePath());
4747
return new Properties();
4848
} else {
49-
// 1) get spring config
50-
Properties springConfig = getSpringConfig();
51-
// 2) get user config
49+
// 1) get user config
5250
Properties userConfig = getUserConfig();
51+
// 2) get spring config
52+
Properties springConfig = getSpringConfig();
5353
// 3) merge config
5454
mergeConfig(userConfig, springConfig);
5555
// 4) datasource
@@ -122,32 +122,24 @@ private static void mergeConfig(Properties userConfig, Properties springConfig)
122122
});
123123
}
124124

125-
private static boolean useOldConfig() {
126-
String appHome = WebUtils.getAppHome();
127-
if (appHome == null) {
128-
return false;
129-
}
130-
File file = new File(appHome + "/conf/application.yml");
131-
return file.exists();
132-
}
133-
134125
private static Properties getUserConfig() {
135126
String appHome = WebUtils.getAppHome();
127+
if (StringUtils.isBlank(appHome)) {
128+
throw new ExceptionInInitializerError(
129+
String.format(
130+
"[StreamPark] The system initialization check failed. If started local for development and debugging,"
131+
+ " please ensure the -D%s parameter is clearly specified,"
132+
+ " more detail: https://streampark.apache.org/docs/user-guide/deployment",
133+
ConfigConst.KEY_APP_HOME()));
134+
}
136135
Properties properties = new Properties();
137-
if (appHome != null) {
138-
File file = new File(appHome + "/conf/config.yaml");
139-
if (file.exists() && file.isFile()) {
140-
Map<String, String> config = PropertiesUtils.fromYamlFileAsJava(file.getAbsolutePath());
141-
properties.putAll(config);
142-
return properties;
143-
}
144-
throw new ExceptionInInitializerError(file.getAbsolutePath() + " not found, please check.");
145-
} else {
146-
InputStream inputStream =
147-
SpringProperties.class.getClassLoader().getResourceAsStream("config.yaml");
148-
Map<String, String> config = PropertiesUtils.fromYamlFileAsJava(inputStream);
136+
File file = new File(appHome, "conf/config.yaml");
137+
if (file.exists() && file.isFile()) {
138+
Map<String, String> config = PropertiesUtils.fromYamlFileAsJava(file.getAbsolutePath());
149139
properties.putAll(config);
150140
return properties;
141+
} else {
142+
throw new ExceptionInInitializerError(file.getAbsolutePath() + " not found, please check.");
151143
}
152144
}
153145

streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/ProjectMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ public interface ProjectMapper extends BaseMapper<Project> {
3838
Boolean existsByTeamId(@Param("teamId") Long teamId);
3939

4040
List<Project> selectByTeamId(@Param("teamId") Long teamId);
41+
42+
Long getBuildingCount();
4143
}

streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5151
import lombok.extern.slf4j.Slf4j;
5252
import org.springframework.beans.factory.annotation.Autowired;
53+
import org.springframework.beans.factory.annotation.Value;
5354
import org.springframework.stereotype.Service;
5455
import org.springframework.transaction.annotation.Propagation;
5556
import org.springframework.transaction.annotation.Transactional;
@@ -83,6 +84,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
8384

8485
@Autowired private FlinkAppHttpWatcher flinkAppHttpWatcher;
8586

87+
@Value("${streampark.project.max-build:6}")
88+
public Long maxProjectBuildNum;
89+
8690
private static final int CPU_NUM = Math.max(4, Runtime.getRuntime().availableProcessors() * 2);
8791

8892
private final ExecutorService projectBuildExecutor =
@@ -193,6 +197,14 @@ public List<Project> findByTeamId(Long teamId) {
193197

194198
@Override
195199
public void build(Long id) throws Exception {
200+
Long currentBuildCount = this.baseMapper.getBuildingCount();
201+
202+
ApiAlertException.throwIfTrue(
203+
maxProjectBuildNum > -1 && currentBuildCount > maxProjectBuildNum,
204+
String.format(
205+
"The number of running Build projects exceeds the maximum number: %d of max-build-num",
206+
maxProjectBuildNum));
207+
196208
Project project = getById(id);
197209
this.baseMapper.updateBuildState(project.getId(), BuildState.BUILDING.get());
198210
String logPath = getBuildLogPath(id);

streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,8 @@
8585
</where>
8686
</select>
8787

88+
<select id="getBuildingCount" resultType="java.lang.Long">
89+
select count(1) from t_flink_project where build_state = 0
90+
</select>
91+
8892
</mapper>

0 commit comments

Comments
 (0)