Skip to content

Commit 14d7ff2

Browse files
author
Yang Guo
committed
merge from develop
2 parents 631fb6d + 10c89c1 commit 14d7ff2

File tree

6 files changed

+152
-6
lines changed

6 files changed

+152
-6
lines changed

platform-api/src/main/java/com/flow/platform/api/controller/JobController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import com.flow.platform.util.git.model.GitEventType;
3232
import com.google.common.collect.Lists;
3333
import java.util.Collection;
34-
import java.util.Collections;
35-
import java.util.HashMap;
3634
import java.util.LinkedHashMap;
3735
import java.util.List;
3836
import java.util.Map;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.flow.platform.api.controller;
17+
18+
import com.flow.platform.api.domain.request.ThreadConfigParam;
19+
import com.flow.platform.api.service.node.YmlService;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.web.bind.annotation.PostMapping;
22+
import org.springframework.web.bind.annotation.RequestBody;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.RestController;
25+
26+
/**
27+
* @author lhl
28+
*/
29+
@RestController
30+
@RequestMapping(path = "/thread/config")
31+
public class ThreadConfigController {
32+
33+
@Autowired
34+
private YmlService ymlService;
35+
36+
/**
37+
* @api {post}
38+
* @apiName thread config
39+
* @apiGroup Thread
40+
* @apiDescription set thread config
41+
*
42+
* @apiParamExample {json} Request-Body:
43+
* {
44+
* "maxPoolSize": 1,
45+
* "corePoolSize": 1,
46+
* "queueSize": 2,
47+
* "threadNamePrefix": "git-fetch-task"
48+
* }
49+
*
50+
* @apiSuccessExample {json} Success-Response:
51+
* HTTP/1.1 200 OK
52+
*
53+
*/
54+
@PostMapping
55+
public void ymlConfigQueueSize(@RequestBody ThreadConfigParam threadConfigParam) {
56+
ymlService.threadConfig(threadConfigParam);
57+
}
58+
59+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.flow.platform.api.domain.request;
17+
18+
/**
19+
* @author lhl
20+
*/
21+
public class ThreadConfigParam {
22+
23+
private Integer maxPoolSize;
24+
25+
private Integer corePoolSize;
26+
27+
private Integer queueSize;
28+
29+
private String threadNamePrefix;
30+
31+
public Integer getMaxPoolSize() {
32+
return maxPoolSize;
33+
}
34+
35+
public void setMaxPoolSize(Integer maxPoolSize) {
36+
this.maxPoolSize = maxPoolSize;
37+
}
38+
39+
public Integer getCorePoolSize() {
40+
return corePoolSize;
41+
}
42+
43+
public void setCorePoolSize(Integer corePoolSize) {
44+
this.corePoolSize = corePoolSize;
45+
}
46+
47+
public Integer getQueueSize() {
48+
return queueSize;
49+
}
50+
51+
public void setQueueSize(Integer queueSize) {
52+
this.queueSize = queueSize;
53+
}
54+
55+
public String getThreadNamePrefix() {
56+
return threadNamePrefix;
57+
}
58+
59+
public void setThreadNamePrefix(String threadNamePrefix) {
60+
this.threadNamePrefix = threadNamePrefix;
61+
}
62+
63+
public ThreadConfigParam(Integer maxPoolSize, Integer corePoolSize, Integer queueSize,
64+
String threadNamePrefix) {
65+
this.maxPoolSize = maxPoolSize;
66+
this.corePoolSize = corePoolSize;
67+
this.queueSize = queueSize;
68+
this.threadNamePrefix = threadNamePrefix;
69+
}
70+
71+
public ThreadConfigParam() {
72+
}
73+
}

platform-api/src/main/java/com/flow/platform/api/service/node/YmlService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.flow.platform.api.domain.node.Node;
2020
import com.flow.platform.api.domain.node.Yml;
21+
import com.flow.platform.api.domain.request.ThreadConfigParam;
2122
import java.util.function.Consumer;
2223

2324
/**
@@ -66,4 +67,11 @@ public interface YmlService {
6667
*/
6768
void stopLoadYmlContent(Node root);
6869

70+
/**
71+
* Config load yml thread pool
72+
*
73+
* @param threadConfigParam
74+
*/
75+
void threadConfig(ThreadConfigParam threadConfigParam);
76+
6977
}

platform-api/src/main/java/com/flow/platform/api/service/node/YmlServiceImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.flow.platform.api.domain.envs.GitEnvs;
2727
import com.flow.platform.api.domain.node.Node;
2828
import com.flow.platform.api.domain.node.Yml;
29+
import com.flow.platform.api.domain.request.ThreadConfigParam;
2930
import com.flow.platform.api.exception.NodeSettingsException;
3031
import com.flow.platform.api.exception.YmlException;
3132
import com.flow.platform.api.service.CredentialService;
@@ -65,15 +66,15 @@ public class YmlServiceImpl implements YmlService, ContextEvent {
6566

6667
private final static int NODE_THREAD_POOL_CACHE_SIZE = 100;
6768

68-
private final static int NODE_THREAD_POOL_SIZE = 1;
69-
7069
// To cache thread pool for node path
7170
private Cache<String, ThreadPoolTaskExecutor> nodeThreadPool = CacheBuilder
7271
.newBuilder()
7372
.expireAfterAccess(NODE_THREAD_POOL_CACHE_EXPIRE, TimeUnit.SECONDS)
7473
.maximumSize(NODE_THREAD_POOL_CACHE_SIZE)
7574
.build();
7675

76+
private ThreadConfigParam threadConfigParam = new ThreadConfigParam(1, 1, 0, "git-fetch-task");
77+
7778
@Autowired
7879
private GitService gitService;
7980

@@ -194,6 +195,12 @@ public void stopLoadYmlContent(final Node root) {
194195
nodeService.updateYmlState(root, YmlStatusValue.NOT_FOUND, null);
195196
}
196197

198+
@Override
199+
public void threadConfig(ThreadConfigParam threadConfigParam) {
200+
this.threadConfigParam = threadConfigParam;
201+
nodeThreadPool.invalidateAll();
202+
}
203+
197204
private boolean isYmlLoading(final Node node) {
198205
String ymlStatus = node.getEnv(FlowEnvs.FLOW_YML_STATUS);
199206
return YmlStatusValue.isLoadingStatus(ymlStatus);
@@ -247,7 +254,8 @@ private void findNodeCredential(Node node) {
247254
private ThreadPoolTaskExecutor findThreadPoolFromCache(String path) throws ExecutionException {
248255
return nodeThreadPool.get(path, () -> {
249256
ThreadPoolTaskExecutor taskExecutor = ThreadUtil
250-
.createTaskExecutor(NODE_THREAD_POOL_SIZE, NODE_THREAD_POOL_SIZE, 0, "git-fetch-task");
257+
.createTaskExecutor(threadConfigParam.getMaxPoolSize(), threadConfigParam.getCorePoolSize(),
258+
threadConfigParam.getQueueSize(), threadConfigParam.getThreadNamePrefix());
251259
taskExecutor.initialize();
252260
return taskExecutor;
253261
});

platform-api/src/main/java/com/flow/platform/api/util/I18nUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
public class I18nUtil {
2626

27-
private static ResourceBundle resourceBundle = ResourceBundle.getBundle("i18n");
27+
private static ResourceBundle resourceBundle;
2828

2929
public static void initLocale(String language, String countryCode) {
3030
Locale.setDefault(new Locale(language, countryCode));

0 commit comments

Comments
 (0)