Skip to content

Commit de1ca21

Browse files
authored
Merge pull request #431 from FlowCI/feature/1600
Feature/1600
2 parents 32c34cc + 5c99bc0 commit de1ca21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+827
-490
lines changed

.run/Application - 1.run.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Application - 1" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
3-
<module name="core" />
4-
<option name="SPRING_BOOT_MAIN_CLASS" value="com.flowci.core.Application" />
5-
<option name="VM_PARAMETERS" value="-Xms1g -Xmx1g -Xmn600m -XX:-UseAdaptiveSizePolicy -XX:SurvivorRatio=4 -verbose:gc" />
6-
<option name="ALTERNATIVE_JRE_PATH" />
3+
<option name="ACTIVE_PROFILES" />
74
<envs>
5+
<env name="FLOWCI_AGENT_IMAGE" value="flowci/agent:dev" />
6+
<env name="FLOWCI_AGENT_VOLUMES" value="name=pyenv,dest=/ci/python,script=init.sh,image=flowci/pyenv,init=init-pyenv-volume.sh" />
7+
<env name="FLOWCI_AUTO_AGENT" value="false" />
88
<env name="FLOWCI_LOG_LEVEL" value="DEBUG" />
99
<env name="FLOWCI_PLUGIN_URL" value="https://raw.githubusercontent.com/FlowCI/plugins/develop/repository.json" />
1010
<env name="FLOWCI_RABBITMQ_URI" value="amqp://guest:[email protected]:5672" />
11-
<env name="FLOWCI_ZK_HOST" value="127.0.0.1" />
12-
<env name="FLOWCI_AUTO_AGENT" value="false" />
13-
<env name="FLOWCI_AGENT_VOLUMES" value="name=pyenv,dest=/ci/python,script=init.sh,image=flowci/pyenv,init=init-pyenv-volume.sh" />
1411
<env name="FLOWCI_SERVER_PORT" value="8080" />
12+
<env name="FLOWCI_SERVER_URL" value="http://localhost:8080" />
1513
<env name="FLOWCI_TEMPLATES" value="https://raw.githubusercontent.com/FlowCI/templates/develop/templates.json" />
16-
<env name="FLOWCI_AGENT_IMAGE" value="flowci/agent:dev" />
17-
<env name="FLOWCI_SERVER_URL" value="http://192.168.31.173:8080" />
14+
<env name="FLOWCI_ZK_HOST" value="127.0.0.1" />
1815
</envs>
16+
<module name="core" />
17+
<option name="SPRING_BOOT_MAIN_CLASS" value="com.flowci.core.Application" />
18+
<option name="VM_PARAMETERS" value="-Xms1g -Xmx1g -Xmn600m -XX:-UseAdaptiveSizePolicy -XX:SurvivorRatio=4 -verbose:gc" />
1919
<method v="2">
2020
<option name="Make" enabled="true" />
2121
</method>

core/src/main/java/com/flowci/core/api/OpenRestController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.flowci.core.api.domain.CreateJobReport;
2323
import com.flowci.core.api.service.OpenRestService;
2424
import com.flowci.core.config.domain.Config;
25-
import com.flowci.core.flow.domain.StatsCounter;
25+
import com.flowci.core.flow.domain.MatrixCounter;
2626
import com.flowci.core.job.domain.JobCache;
2727
import com.flowci.core.job.service.CacheService;
2828
import com.flowci.core.job.service.LoggingService;
@@ -92,7 +92,7 @@ public List<User> listFlowUserEmail(@PathVariable String name) {
9292
@PostMapping("/flow/{name}/stats")
9393
public void addStatsItem(@PathVariable String name,
9494
@Validated @RequestBody AddStatsItem body) {
95-
openRestService.saveStatsForFlow(name, body.getType(), StatsCounter.from(body.getData()));
95+
openRestService.saveStatsForFlow(name, body.getType(), MatrixCounter.from(body.getData()));
9696
}
9797

9898
@PostMapping("/flow/{name}/job/{number}/context")

core/src/main/java/com/flowci/core/api/service/OpenRestService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.flowci.core.api.domain.CreateJobArtifact;
2121
import com.flowci.core.api.domain.CreateJobReport;
2222
import com.flowci.core.config.domain.Config;
23-
import com.flowci.core.flow.domain.StatsCounter;
23+
import com.flowci.core.flow.domain.MatrixCounter;
2424
import com.flowci.core.secret.domain.Secret;
2525
import com.flowci.core.user.domain.User;
2626
import org.springframework.core.io.Resource;
@@ -51,7 +51,7 @@ public interface OpenRestService {
5151
/**
5252
* Save statistic data for flow
5353
*/
54-
void saveStatsForFlow(String flowName, String statsType, StatsCounter counter);
54+
void saveStatsForFlow(String flowName, String statsType, MatrixCounter counter);
5555

5656
/**
5757
* Save uploaded job report with file

core/src/main/java/com/flowci/core/api/service/OpenRestServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import com.flowci.core.config.service.ConfigService;
2525
import com.flowci.core.flow.dao.FlowUserDao;
2626
import com.flowci.core.flow.domain.Flow;
27-
import com.flowci.core.flow.domain.StatsCounter;
27+
import com.flowci.core.flow.domain.MatrixCounter;
2828
import com.flowci.core.flow.service.FlowService;
29-
import com.flowci.core.flow.service.StatsService;
29+
import com.flowci.core.flow.service.MatrixService;
3030
import com.flowci.core.job.dao.JobDao;
3131
import com.flowci.core.job.domain.Job;
3232
import com.flowci.core.job.domain.JobKey;
@@ -69,7 +69,7 @@ public class OpenRestServiceImpl implements OpenRestService {
6969
private SecretService credentialService;
7070

7171
@Autowired
72-
private StatsService statsService;
72+
private MatrixService matrixService;
7373

7474
@Autowired
7575
private ReportService reportService;
@@ -115,10 +115,10 @@ public Resource getResource(Secret secret, String file) {
115115
}
116116

117117
@Override
118-
public void saveStatsForFlow(String flowName, String statsType, StatsCounter counter) {
118+
public void saveStatsForFlow(String flowName, String statsType, MatrixCounter counter) {
119119
Flow flow = flowService.get(flowName);
120120
int today = DateHelper.toIntDay(new Date());
121-
statsService.add(flow.getId(), today, statsType, counter);
121+
matrixService.add(flow.getId(), today, statsType, counter);
122122
}
123123

124124
@Override

core/src/main/java/com/flowci/core/common/config/MongoConfig.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.flowci.core.common.mongo.VariableMapConverter;
2525
import com.flowci.core.config.domain.SmtpConfig;
2626
import com.flowci.core.config.domain.TextConfig;
27+
import com.flowci.core.flow.domain.Flow;
28+
import com.flowci.core.flow.domain.FlowGroup;
2729
import com.flowci.core.git.domain.GitConfig;
2830
import com.flowci.core.git.domain.GitConfigWithHost;
2931
import com.flowci.core.job.domain.JobItem;
@@ -58,14 +60,17 @@
5860
@EnableMongoAuditing(auditorAwareRef = "sessionManager")
5961
public class MongoConfig extends AbstractMongoClientConfiguration {
6062

61-
@Autowired
62-
private AppProperties appProperties;
63+
private final AppProperties appProperties;
6364

64-
@Autowired
65-
private MongoProperties mongoProperties;
65+
private final MongoProperties mongoProperties;
6666

67-
@Autowired
68-
private ObjectMapper objectMapper;
67+
private final ObjectMapper objectMapper;
68+
69+
public MongoConfig(AppProperties appProperties, MongoProperties mongoProperties, ObjectMapper objectMapper) {
70+
this.appProperties = appProperties;
71+
this.mongoProperties = mongoProperties;
72+
this.objectMapper = objectMapper;
73+
}
6974

7075
@NonNull
7176
@Override
@@ -97,6 +102,9 @@ public MongoMappingContext mongoMappingContext(MongoCustomConversions customConv
97102
context.setAutoIndexCreation(true);
98103

99104
// add addPersistentEntity for subtypes since not registered if called within same thread
105+
context.addEntity(Flow.class);
106+
context.addEntity(FlowGroup.class);
107+
100108
context.addEntity(SmtpConfig.class);
101109
context.addEntity(TextConfig.class);
102110

core/src/main/java/com/flowci/core/common/config/WebConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void addInterceptors(InterceptorRegistry registry) {
7171
.addPathPatterns("/users/**")
7272
.excludePathPatterns("/users/default")
7373
.addPathPatterns("/flows/**")
74+
.addPathPatterns("/flow_groups/**")
7475
.addPathPatterns("/jobs/**")
7576
.addPathPatterns("/agents/**")
7677
.addPathPatterns("/hosts/**")

core/src/main/java/com/flowci/core/common/domain/Mongoable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.flowci.core.common.domain;
1818

19+
import com.flowci.core.flow.domain.Flow;
1920
import com.flowci.util.StringHelper;
2021
import lombok.EqualsAndHashCode;
2122
import lombok.Getter;
@@ -26,6 +27,7 @@
2627

2728
import java.io.Serializable;
2829
import java.util.Date;
30+
import java.util.Objects;
2931

3032
/**
3133
* @author yang

core/src/main/java/com/flowci/core/flow/controller/FlowController.java

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
package com.flowci.core.flow.controller;
1818

1919
import com.flowci.core.auth.annotation.Action;
20-
import com.flowci.core.flow.domain.ConfirmOption;
21-
import com.flowci.core.flow.domain.Flow;
22-
import com.flowci.core.flow.domain.Flow.Status;
23-
import com.flowci.core.flow.domain.FlowAction;
24-
import com.flowci.core.flow.domain.Template;
20+
import com.flowci.core.flow.domain.*;
21+
import com.flowci.core.flow.service.FlowGroupService;
22+
import com.flowci.core.flow.service.FlowItemService;
2523
import com.flowci.core.flow.service.FlowService;
2624
import com.flowci.core.user.domain.User;
2725
import com.flowci.core.user.service.UserService;
2826
import com.flowci.domain.SimpleAuthPair;
2927
import com.flowci.domain.SimpleKeyPair;
3028
import com.google.common.collect.Lists;
31-
import org.springframework.beans.factory.annotation.Autowired;
3229
import org.springframework.web.bind.annotation.*;
3330

3431
import java.util.List;
@@ -40,19 +37,32 @@
4037
@RequestMapping("/flows")
4138
public class FlowController {
4239

43-
@Autowired
44-
private List<Template> templates;
40+
private final List<Template> templates;
4541

46-
@Autowired
47-
private UserService userService;
42+
private final UserService userService;
4843

49-
@Autowired
50-
private FlowService flowService;
44+
private final FlowService flowService;
45+
46+
private final FlowGroupService flowGroupService;
47+
48+
private final FlowItemService flowItemService;
49+
50+
public FlowController(List<Template> templates,
51+
UserService userService,
52+
FlowService flowService,
53+
FlowGroupService flowGroupService,
54+
FlowItemService flowItemService) {
55+
this.templates = templates;
56+
this.userService = userService;
57+
this.flowService = flowService;
58+
this.flowGroupService = flowGroupService;
59+
this.flowItemService = flowItemService;
60+
}
5161

5262
@GetMapping
5363
@Action(FlowAction.LIST)
54-
public List<Flow> list() {
55-
return flowService.list(Status.CONFIRMED);
64+
public List<FlowItem> list() {
65+
return flowItemService.list();
5666
}
5767

5868
@GetMapping("/templates")
@@ -63,47 +73,32 @@ public List<Template> getTemplates() {
6373

6474
@GetMapping(value = "/{name}")
6575
@Action(FlowAction.GET)
66-
public Flow get(@PathVariable String name) {
67-
return flowService.get(name);
76+
public Flow get(@PathVariable String name, @RequestParam boolean group) {
77+
var flow = flowService.get(name);
78+
if (group && flow.hasParentId()) {
79+
flow.setParent(flowGroupService.getById(flow.getParentId()));
80+
}
81+
return flow;
6882
}
6983

7084
@GetMapping(value = "/{name}/exist")
7185
@Action(FlowAction.CHECK_NAME)
7286
public Boolean exist(@PathVariable String name) {
73-
return flowService.exist(name);
87+
return flowItemService.existed(name);
7488
}
7589

7690
@PostMapping(value = "/{name}")
7791
@Action(FlowAction.CREATE)
78-
public Flow create(@PathVariable String name) {
79-
return flowService.create(name);
80-
}
81-
82-
@PostMapping(value = "/{name}/confirm")
83-
@Action(FlowAction.CONFIRM)
84-
public Flow confirm(@PathVariable String name, @RequestBody ConfirmOption option) {
85-
return flowService.confirm(name, option);
92+
public Flow create(@PathVariable String name, @RequestBody CreateOption option) {
93+
return flowService.create(name, option);
8694
}
8795

8896
@DeleteMapping("/{name}")
8997
@Action(FlowAction.DELETE)
9098
public Flow delete(@PathVariable String name) {
91-
return flowService.delete(name);
92-
}
93-
94-
/**
95-
* Create credential for flow only
96-
*/
97-
@PostMapping("/{name}/secret/rsa")
98-
@Action(FlowAction.SETUP_CREDENTIAL)
99-
public String setupRSACredential(@PathVariable String name, @RequestBody SimpleKeyPair pair) {
100-
return flowService.setSshRsaCredential(name, pair);
101-
}
102-
103-
@PostMapping("/{name}/secret/auth")
104-
@Action(FlowAction.SETUP_CREDENTIAL)
105-
public String setupAuthCredential(@PathVariable String name, @RequestBody SimpleAuthPair pair) {
106-
return flowService.setAuthCredential(name, pair);
99+
var flow = flowService.get(name);
100+
flowService.delete(flow);
101+
return flow;
107102
}
108103

109104
@PostMapping("/{name}/users")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.flowci.core.flow.controller;
2+
3+
import com.flowci.core.auth.annotation.Action;
4+
import com.flowci.core.flow.domain.FlowAction;
5+
import com.flowci.core.flow.domain.FlowGroup;
6+
import com.flowci.core.flow.service.FlowGroupService;
7+
import com.flowci.core.flow.service.FlowService;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.web.bind.annotation.*;
10+
11+
@RestController
12+
@RequestMapping("/flow_groups")
13+
public class FlowGroupController {
14+
15+
private final FlowService flowService;
16+
private final FlowGroupService flowGroupService;
17+
18+
@Autowired
19+
public FlowGroupController(FlowService flowService, FlowGroupService flowGroupService) {
20+
this.flowService = flowService;
21+
this.flowGroupService = flowGroupService;
22+
}
23+
24+
@PostMapping("/{name}")
25+
@Action(FlowAction.GROUP_UPDATE)
26+
public FlowGroup create(@PathVariable String name) {
27+
return flowGroupService.create(name);
28+
}
29+
30+
@PostMapping("/{groupName}/{flowName}")
31+
@Action(FlowAction.GROUP_UPDATE)
32+
public void addToGroup(@PathVariable String groupName, @PathVariable String flowName) {
33+
flowGroupService.addToGroup(flowName, groupName);
34+
}
35+
36+
@DeleteMapping("/{name}")
37+
@Action(FlowAction.GROUP_UPDATE)
38+
public void delete(@PathVariable String name, @RequestParam(required = false) boolean deleteFlow) {
39+
var group = flowGroupService.get(name);
40+
41+
if (deleteFlow) {
42+
var flowList = flowGroupService.flows(group.getId());
43+
for (var flow : flowList) {
44+
flowService.delete(flow);
45+
}
46+
}
47+
48+
flowGroupService.delete(group.getName());
49+
}
50+
}

0 commit comments

Comments
 (0)