Skip to content

Commit

Permalink
[Improve] Limit the number of running build projects #3687 (#3695)
Browse files Browse the repository at this point in the history
* [Improve] Limit the number of running build projects #3687

---------

Co-authored-by: benjobs <[email protected]>
  • Loading branch information
wolfboys and benjobs authored Apr 30, 2024
1 parent eae3265 commit c3c468c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<outputDirectory>lib</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>${project.build.directory}/../src/main/assembly/conf</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>${project.build.directory}/../src/main/assembly/logs</directory>
<outputDirectory>logs</outputDirectory>
Expand Down Expand Up @@ -95,7 +100,6 @@
<lineEnding>unix</lineEnding>
<fileMode>0755</fileMode>
<includes>
<include>config.yaml</include>
<include>logback-spring.xml</include>
</includes>
</fileSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

import org.apache.streampark.common.conf.ConfigConst;
import org.apache.streampark.common.util.PropertiesUtils;
import org.apache.streampark.common.util.SystemPropertyUtils;
import org.apache.streampark.console.base.util.WebUtils;
Expand All @@ -28,7 +29,6 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;

Expand All @@ -46,10 +46,10 @@ public static Properties get() {
SystemPropertyUtils.set("spring.config.location", oldConfig.getAbsolutePath());
return new Properties();
} else {
// 1) get spring config
Properties springConfig = getSpringConfig();
// 2) get user config
// 1) get user config
Properties userConfig = getUserConfig();
// 2) get spring config
Properties springConfig = getSpringConfig();
// 3) merge config
mergeConfig(userConfig, springConfig);
// 4) datasource
Expand Down Expand Up @@ -122,32 +122,24 @@ private static void mergeConfig(Properties userConfig, Properties springConfig)
});
}

private static boolean useOldConfig() {
String appHome = WebUtils.getAppHome();
if (appHome == null) {
return false;
}
File file = new File(appHome + "/conf/application.yml");
return file.exists();
}

private static Properties getUserConfig() {
String appHome = WebUtils.getAppHome();
if (StringUtils.isBlank(appHome)) {
throw new ExceptionInInitializerError(
String.format(
"[StreamPark] The system initialization check failed. If started local for development and debugging,"
+ " please ensure the -D%s parameter is clearly specified,"
+ " more detail: https://streampark.apache.org/docs/user-guide/deployment",
ConfigConst.KEY_APP_HOME()));
}
Properties properties = new Properties();
if (appHome != null) {
File file = new File(appHome + "/conf/config.yaml");
if (file.exists() && file.isFile()) {
Map<String, String> config = PropertiesUtils.fromYamlFileAsJava(file.getAbsolutePath());
properties.putAll(config);
return properties;
}
throw new ExceptionInInitializerError(file.getAbsolutePath() + " not found, please check.");
} else {
InputStream inputStream =
SpringProperties.class.getClassLoader().getResourceAsStream("config.yaml");
Map<String, String> config = PropertiesUtils.fromYamlFileAsJava(inputStream);
File file = new File(appHome, "conf/config.yaml");
if (file.exists() && file.isFile()) {
Map<String, String> config = PropertiesUtils.fromYamlFileAsJava(file.getAbsolutePath());
properties.putAll(config);
return properties;
} else {
throw new ExceptionInInitializerError(file.getAbsolutePath() + " not found, please check.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public interface ProjectMapper extends BaseMapper<Project> {
Boolean existsByTeamId(@Param("teamId") Long teamId);

List<Project> selectByTeamId(@Param("teamId") Long teamId);

Long getBuildingCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -83,6 +84,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>

@Autowired private FlinkAppHttpWatcher flinkAppHttpWatcher;

@Value("${streampark.project.max-build:6}")
public Long maxProjectBuildNum;

private static final int CPU_NUM = Math.max(4, Runtime.getRuntime().availableProcessors() * 2);

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

@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(), BuildState.BUILDING.get());
String logPath = getBuildLogPath(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@
</where>
</select>

<select id="getBuildingCount" resultType="java.lang.Long">
select count(1) from t_flink_project where build_state = 0
</select>

</mapper>

0 comments on commit c3c468c

Please sign in to comment.