Skip to content

Commit 8c6a33f

Browse files
author
yang.guo
authored
Merge pull request #110 from FlowCI/develop
Develop
2 parents f4e0b41 + 1a4295e commit 8c6a33f

File tree

37 files changed

+960
-137
lines changed

37 files changed

+960
-137
lines changed
Binary file not shown.

platform-api/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
<artifactId>gson</artifactId>
6666
</dependency>
6767

68+
<dependency>
69+
<groupId>org.springframework</groupId>
70+
<artifactId>spring-context-support</artifactId>
71+
</dependency>
72+
6873
<dependency>
6974
<groupId>org.hibernate</groupId>
7075
<artifactId>hibernate-validator</artifactId>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
17+
package com.flow.platform.api.config;
18+
19+
import com.google.common.cache.CacheBuilder;
20+
import java.util.concurrent.TimeUnit;
21+
import org.springframework.cache.CacheManager;
22+
import org.springframework.cache.annotation.EnableCaching;
23+
import org.springframework.cache.guava.GuavaCacheManager;
24+
import org.springframework.context.annotation.Bean;
25+
import org.springframework.context.annotation.Configuration;
26+
27+
/**
28+
* @author yh@firim
29+
*/
30+
@Configuration
31+
@EnableCaching
32+
public class CachingConfig {
33+
34+
private final static int EXPIRE_CACHE_SECOND = 3600 * 24;
35+
36+
private final static int MAX_CACHE_NUM = 100;
37+
38+
private CacheBuilder cacheBuilder = CacheBuilder
39+
.newBuilder()
40+
.expireAfterAccess(EXPIRE_CACHE_SECOND, TimeUnit.SECONDS)
41+
.maximumSize(MAX_CACHE_NUM);
42+
43+
44+
@Bean
45+
public CacheManager cacheManager() {
46+
GuavaCacheManager guavaCacheManager = new GuavaCacheManager();
47+
guavaCacheManager.setCacheBuilder(cacheBuilder);
48+
return guavaCacheManager;
49+
}
50+
}

platform-api/src/main/java/com/flow/platform/api/config/WebConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"com.flow.platform.api.util",
6565
"com.flow.platform.api.consumer",
6666
"com.flow.platform.api.initializers"})
67-
@Import({AppConfig.class})
67+
@Import({AppConfig.class, CachingConfig.class})
6868
public class WebConfig extends WebMvcConfigurerAdapter {
6969

7070
private final static Gson GSON_CONFIG_FOR_RESPONE = new GsonBuilder()

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public List<AgentWithFlow> index() {
8686
* }
8787
*/
8888
@PostMapping(path = "/create")
89-
public Agent create(@RequestBody AgentPath agentPath) {
89+
public AgentWithFlow create(@RequestBody AgentPath agentPath) {
9090
if (agentPath.isEmpty()) {
9191
throw new IllegalParameterException("Zone and agent name are required");
9292
}
@@ -195,4 +195,30 @@ public BooleanValue shutDown(@RequestParam String zone,
195195
public void callback(@RequestBody Agent agent) {
196196
this.dispatchEvent(new AgentStatusChangeEvent(this, agent));
197197
}
198+
199+
/**
200+
* @api {Post} /agents/delete Delete
201+
* @apiName Delete Agent
202+
* @apiGroup Agent
203+
* @apiDescription Delete agent by agentPath
204+
*
205+
* @apiParamExample {json} Request-Example:
206+
* {
207+
* zone: xxx,
208+
* name: xxx
209+
* }
210+
*
211+
* @apiSuccessExample {json} Success-Response:
212+
* HTTP/1.1 200 OK
213+
*
214+
* @apiErrorExample {json} Error-Response:
215+
* HTTP/1.1 400
216+
* {
217+
* "message": xxx
218+
* }
219+
*/
220+
@PostMapping(path = "/delete")
221+
public void delete(@RequestBody AgentPath agentPath){
222+
agentService.delete(agentPath);
223+
}
198224
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package com.flow.platform.api.controller;
1818

19-
import com.flow.platform.api.domain.permission.Actions;
2019
import com.flow.platform.api.domain.node.Flow;
2120
import com.flow.platform.api.domain.node.Node;
21+
import com.flow.platform.api.domain.permission.Actions;
2222
import com.flow.platform.api.domain.request.ListParam;
2323
import com.flow.platform.api.domain.response.BooleanValue;
2424
import com.flow.platform.api.domain.user.User;
@@ -114,7 +114,7 @@ public Node createEmptyFlow() {
114114
}
115115

116116
/**
117-
* @api {delete} /flows/:root/delete Delete
117+
* @api {delete} /flows/:root Delete
118118
* @apiParam {String} root flow node name will be deleted
119119
* @apiDescription Delete flow node by name and return flow node object
120120
* @apiGroup Flows
@@ -235,6 +235,7 @@ public BooleanValue isFlowNameExist() {
235235
/**
236236
* @api {get} /flows/:root/branches List Branches
237237
* @apiParam {String} root flow node name
238+
* @apiParam {Boolean} [refresh] true or false, the default is false
238239
* @apiGroup Flows
239240
*
240241
* @apiSuccessExample {json} Success-Response
@@ -246,9 +247,13 @@ public BooleanValue isFlowNameExist() {
246247
* ]
247248
*/
248249
@GetMapping("/{root}/branches")
249-
public List<String> listBranches() {
250+
public List<String> listBranches(@RequestParam(required = false) Boolean refresh) {
251+
if (refresh == null) {
252+
refresh = false;
253+
}
254+
250255
Node root = nodeService.find(currentNodePath.get());
251-
return gitService.branches(root);
256+
return gitService.branches(root, refresh);
252257
}
253258

254259
/**
@@ -266,7 +271,7 @@ public List<String> listBranches() {
266271
@GetMapping("/{root}/tags")
267272
public List<String> listTags() {
268273
Node root = nodeService.find(currentNodePath.get());
269-
return gitService.tags(root);
274+
return gitService.tags(root, false);
270275
}
271276

272277
/**
@@ -415,7 +420,7 @@ public Node createFromYml(@RequestBody String yml) {
415420
*/
416421
@PostMapping("/{root}/users/auth")
417422
@WebSecurity(action = Actions.FLOW_AUTH)
418-
public List<User> flowAuthUsers(@RequestBody ListParam<String> listParam){
423+
public List<User> flowAuthUsers(@RequestBody ListParam<String> listParam) {
419424
return nodeService.authUsers(listParam.getArrays(), currentNodePath.get());
420425
}
421426
}

platform-api/src/main/java/com/flow/platform/api/domain/envs/GitEnvs.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public enum GitEnvs implements EnvKey {
2626
*/
2727
FLOW_GIT_SOURCE,
2828

29+
/**
30+
* For diff FLOW_GIT_SOURCE
31+
* - UNDEFINED_SSH and UNDEFINED_HTTP is repo url
32+
* - GITLAB is gitlab host url
33+
*/
2934
FLOW_GIT_URL,
3035

3136
FLOW_GIT_BRANCH,
@@ -69,5 +74,12 @@ public enum GitEnvs implements EnvKey {
6974

7075
FLOW_GIT_HTTP_USER,
7176

72-
FLOW_GIT_HTTP_PASS
77+
FLOW_GIT_HTTP_PASS,
78+
79+
/**
80+
* Env variables for GitLab
81+
*/
82+
FLOW_GITLAB_TOKEN,
83+
84+
FLOW_GITLAB_PROJECT
7385
}

platform-api/src/main/java/com/flow/platform/api/git/GitClientBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.flow.platform.api.domain.envs.GitEnvs;
2020
import com.flow.platform.api.domain.node.Node;
2121
import com.flow.platform.util.git.GitClient;
22+
import com.flow.platform.util.git.GitException;
2223
import java.nio.file.Path;
2324

2425
/**
@@ -41,5 +42,5 @@ public GitClientBuilder(final Node node, final Path sourceFolder) {
4142
this.sourceFolder = sourceFolder;
4243
}
4344

44-
public abstract GitClient build();
45+
public abstract GitClient build() throws GitException;
4546
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
17+
package com.flow.platform.api.git;
18+
19+
import com.flow.platform.api.domain.envs.GitEnvs;
20+
import com.flow.platform.api.domain.node.Node;
21+
import com.flow.platform.util.git.GitClient;
22+
import com.flow.platform.util.git.GitException;
23+
import com.flow.platform.util.git.GitLabClient;
24+
import java.nio.file.Path;
25+
26+
/**
27+
* @author yang
28+
*/
29+
public class GitLabClientBuilder extends GitClientBuilder {
30+
31+
private final String host;
32+
33+
private final String token;
34+
35+
private final String project;
36+
37+
public GitLabClientBuilder(Node node, Path sourceFolder) {
38+
super(node, sourceFolder);
39+
host = node.getEnv(GitEnvs.FLOW_GIT_URL);
40+
token = node.getEnv(GitEnvs.FLOW_GITLAB_TOKEN);
41+
project = node.getEnv(GitEnvs.FLOW_GITLAB_PROJECT);
42+
}
43+
44+
@Override
45+
public GitClient build() throws GitException {
46+
return new GitLabClient(host, token, project);
47+
}
48+
}

platform-api/src/main/java/com/flow/platform/api/service/AgentService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ public interface AgentService {
4242
/**
4343
* Create agent and return token from cc
4444
*/
45-
Agent create(AgentPath agentPath);
45+
AgentWithFlow create(AgentPath agentPath);
4646

4747
/**
4848
* Get agent setting by token from cc
4949
*/
5050
AgentSettings settings(String token);
5151

52+
/**
53+
* Delete agent by agentPath from cc
54+
*/
55+
void delete(AgentPath agentPath);
5256
/**
5357
* send sys cmd
5458
* @param agentPath required

0 commit comments

Comments
 (0)