Skip to content

Commit 4ee3d80

Browse files
authored
Merge pull request #436 from FlowCI/develop
Develop
2 parents 4a04e44 + 686b1fe commit 4ee3d80

File tree

104 files changed

+1414
-687
lines changed

Some content is hidden

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

104 files changed

+1414
-687
lines changed

build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ if [[ -n ${tag} ]]; then
66
versionTag="-t flowci/core:$tag"
77
fi
88

9-
docker buildx build -f ./core/Dockerfile --platform linux/arm64,linux/amd64 --push -t flowci/core:latest $versionTag ./core
9+
#docker buildx build -f ./core/Dockerfile --platform linux/arm64,linux/amd64 --push -t flowci/core:latest $versionTag ./core
10+
docker build -f ./core/Dockerfile -t flowci/core:latest $versionTag ./core

core/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM openjdk:11-jre-slim
1+
FROM amazoncorretto:11-alpine3.15
22

33
ENV WORKER=/flow.ci
44
ENV JAR=flow-ci-core.jar

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

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

1919
import com.flowci.core.auth.annotation.Action;
20-
import com.flowci.core.common.domain.http.RequestMessage;
2120
import com.flowci.core.flow.domain.Flow;
2221
import com.flowci.core.flow.domain.FlowAction;
23-
import com.flowci.core.flow.domain.Yml;
22+
import com.flowci.core.flow.domain.SimpleYml;
23+
import com.flowci.core.flow.domain.FlowYml;
2424
import com.flowci.core.flow.service.FlowService;
2525
import com.flowci.core.flow.service.YmlService;
2626
import com.flowci.tree.FlowNode;
27-
import org.springframework.beans.factory.annotation.Autowired;
28-
import org.springframework.http.MediaType;
27+
import lombok.AllArgsConstructor;
2928
import org.springframework.web.bind.annotation.*;
3029

3130
import java.util.List;
@@ -35,40 +34,29 @@
3534
*/
3635
@RestController
3736
@RequestMapping("/flows")
37+
@AllArgsConstructor
3838
public class YmlController {
3939

40-
@Autowired
4140
private FlowService flowService;
4241

43-
@Autowired
44-
private YmlService ymlService;
42+
private final YmlService ymlService;
4543

4644
@GetMapping("/{flowName}/yml")
47-
public List<Yml> list(@PathVariable String flowName) {
45+
public FlowYml get(@PathVariable String flowName) {
4846
Flow flow = flowService.get(flowName);
49-
return ymlService.list(flow.getId());
47+
return ymlService.get(flow.getId());
5048
}
5149

52-
@GetMapping("/{flowName}/yml/{ymlName}/obj")
53-
public FlowNode listSteps(@PathVariable String flowName, @PathVariable String ymlName) {
50+
@GetMapping("/{flowName}/yml/steps")
51+
public FlowNode steps(@PathVariable String flowName) {
5452
Flow flow = flowService.get(flowName);
55-
return ymlService.getTree(flow.getId(), ymlName).getRoot();
53+
return ymlService.getTree(flow.getId()).getRoot();
5654
}
5755

58-
@PostMapping("/{flowName}/yml/{ymlName}")
56+
@PostMapping("/{flowName}/yml")
5957
@Action(FlowAction.SET_YML)
60-
public void saveYml(@PathVariable String flowName,
61-
@PathVariable String ymlName,
62-
@RequestBody RequestMessage<String> body) {
58+
public void saveYml(@PathVariable String flowName, @RequestBody List<SimpleYml> body) {
6359
Flow flow = flowService.get(flowName);
64-
String yamlInB64 = body.getData();
65-
ymlService.saveYmlFromB64(flow, ymlName, yamlInB64);
66-
}
67-
68-
@GetMapping(value = "/{flowName}/yml/{ymlName}", produces = MediaType.APPLICATION_JSON_VALUE)
69-
@Action(FlowAction.GET_YML)
70-
public String getYml(@PathVariable String flowName, @PathVariable String ymlName) {
71-
Flow flow = flowService.get(flowName);
72-
return ymlService.getYmlString(flow.getId(), ymlName);
60+
ymlService.saveYml(flow, body);
7361
}
7462
}

core/src/main/java/com/flowci/core/flow/dao/YmlDao.java renamed to core/src/main/java/com/flowci/core/flow/dao/FlowYmlDao.java

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

1717
package com.flowci.core.flow.dao;
1818

19-
import com.flowci.core.flow.domain.Yml;
19+
import com.flowci.core.flow.domain.FlowYml;
2020
import org.springframework.data.mongodb.repository.MongoRepository;
2121
import org.springframework.stereotype.Repository;
2222

@@ -26,11 +26,9 @@
2626
* @author yang
2727
*/
2828
@Repository
29-
public interface YmlDao extends YmlCustomDao, MongoRepository<Yml, String> {
29+
public interface FlowYmlDao extends MongoRepository<FlowYml, String> {
3030

31-
Optional<Yml> findByFlowIdAndName(String flowId, String name);
31+
Optional<FlowYml> findByFlowId(String flowId);
3232

33-
void deleteAllByFlowId(String flowId);
34-
35-
void deleteByFlowIdAndName(String flowId, String name);
33+
void deleteByFlowId(String flowId);
3634
}

core/src/main/java/com/flowci/core/flow/dao/YmlCustomDao.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

core/src/main/java/com/flowci/core/flow/dao/YmlCustomDaoImpl.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

core/src/main/java/com/flowci/core/flow/domain/CreateOption.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
import lombok.Data;
2323
import lombok.experimental.Accessors;
2424

25+
import java.util.Objects;
26+
2527
/**
2628
* @author yang
2729
*/
2830
@Data
2931
@Accessors(chain = true)
3032
public class CreateOption {
3133

34+
private static final String TEMPLATE_BLANK = "_blank_";
35+
3236
private String groupName;
3337

3438
@JsonProperty("title")
@@ -40,6 +44,10 @@ public class CreateOption {
4044
@JsonProperty("yml")
4145
private String rawYaml;
4246

47+
public boolean isBlank() {
48+
return Objects.equals(templateTitle, TEMPLATE_BLANK);
49+
}
50+
4351
public boolean hasGroupName() {
4452
return StringHelper.hasValue(groupName);
4553
}

core/src/main/java/com/flowci/core/flow/domain/Yml.java renamed to core/src/main/java/com/flowci/core/flow/domain/FlowYml.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,56 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonIgnore;
2020
import com.flowci.core.common.domain.Mongoable;
21+
import com.flowci.util.ObjectsHelper;
2122
import com.flowci.util.StringHelper;
23+
import lombok.AllArgsConstructor;
2224
import lombok.Getter;
2325
import lombok.NoArgsConstructor;
2426
import lombok.Setter;
27+
import org.hibernate.validator.internal.util.CollectionHelper;
2528
import org.springframework.data.mongodb.core.index.CompoundIndex;
2629
import org.springframework.data.mongodb.core.index.CompoundIndexes;
2730
import org.springframework.data.mongodb.core.index.Indexed;
2831
import org.springframework.data.mongodb.core.mapping.Document;
2932

33+
import java.util.List;
34+
import java.util.Objects;
35+
3036
/**
3137
* @author yang
3238
*/
3339
@Getter
3440
@Setter
3541
@Document(collection = "flow_yml")
3642
@NoArgsConstructor
43+
@AllArgsConstructor
3744
@CompoundIndexes(
3845
@CompoundIndex(
39-
name = "index_flow_id_and_yaml_name",
40-
def = "{'flowId': 1, 'name': 1}",
46+
name = "index_flow_id_and_yml_name",
47+
def = "{'flowId': 1, 'list.name': 1}",
4148
sparse = true,
4249
unique = true
4350
)
4451
)
45-
public class Yml extends Mongoable {
52+
public class FlowYml extends Mongoable {
4653

47-
public final static String DEFAULT_NAME = "default";
54+
public final static String DEFAULT_NAME = ".flowci.yml";
4855

49-
@Indexed(name = "index_flow_id")
56+
@Indexed(name = "index_yml_flow_id", unique = true)
5057
private String flowId;
5158

52-
private String name;
53-
54-
private String rawInB64;
59+
private List<SimpleYml> list;
5560

56-
public Yml(String flowId, String name, String rawInB64) {
57-
this.flowId = flowId;
58-
this.name = name;
59-
this.rawInB64 = rawInB64;
61+
public boolean hasYml() {
62+
return ObjectsHelper.hasCollection(list);
6063
}
6164

62-
@JsonIgnore
63-
public String getRaw() {
64-
return StringHelper.fromBase64(rawInB64);
65+
public static String[] toRawArray(List<SimpleYml> list) {
66+
var array = new String[list.size()];
67+
int i = 0;
68+
for (var item : list) {
69+
array[0] = StringHelper.fromBase64(item.getRawInB64());
70+
}
71+
return array;
6572
}
6673
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2022 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.flowci.core.flow.domain;
18+
19+
import lombok.AllArgsConstructor;
20+
import lombok.Getter;
21+
import lombok.NoArgsConstructor;
22+
import lombok.Setter;
23+
24+
@Getter
25+
@Setter
26+
@NoArgsConstructor
27+
@AllArgsConstructor
28+
public class SimpleYml {
29+
30+
private String name;
31+
32+
private String rawInB64;
33+
}

core/src/main/java/com/flowci/core/flow/service/CronServiceImpl.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import com.flowci.core.common.manager.SpringEventManager;
2323
import com.flowci.core.common.manager.SpringTaskManager;
2424
import com.flowci.core.flow.domain.Flow;
25-
import com.flowci.core.flow.domain.Yml;
2625
import com.flowci.core.flow.event.FlowInitEvent;
2726
import com.flowci.core.job.domain.Job.Trigger;
2827
import com.flowci.core.job.event.CreateNewJobEvent;
2928
import com.flowci.exception.NotFoundException;
3029
import lombok.extern.log4j.Log4j2;
31-
import org.springframework.beans.factory.annotation.Autowired;
3230
import org.springframework.context.event.EventListener;
3331
import org.springframework.scheduling.TaskScheduler;
3432
import org.springframework.scheduling.support.CronTrigger;
@@ -50,17 +48,20 @@ public class CronServiceImpl implements CronService {
5048

5149
private final Map<String, ScheduledFuture<?>> scheduled = new ConcurrentHashMap<>();
5250

53-
@Autowired
54-
private TaskScheduler cronScheduler;
51+
private final TaskScheduler cronScheduler;
5552

56-
@Autowired
57-
private SpringEventManager eventManager;
53+
private final SpringEventManager eventManager;
5854

59-
@Autowired
60-
private SpringTaskManager taskManager;
55+
private final SpringTaskManager taskManager;
6156

62-
@Autowired
63-
private YmlService ymlService;
57+
private final YmlService ymlService;
58+
59+
public CronServiceImpl(TaskScheduler cronScheduler, SpringEventManager eventManager, SpringTaskManager taskManager, YmlService ymlService) {
60+
this.cronScheduler = cronScheduler;
61+
this.eventManager = eventManager;
62+
this.taskManager = taskManager;
63+
this.ymlService = ymlService;
64+
}
6465

6566
//====================================================================
6667
// %% Internal events
@@ -121,10 +122,9 @@ public void run() {
121122

122123
taskManager.run(taskName, false, () -> {
123124
try {
124-
Yml yml = ymlService.getYml(flow.getId(), Yml.DEFAULT_NAME);
125125
log.info("Start flow '{}' from cron task", flow.getName());
126-
127-
eventManager.publish(new CreateNewJobEvent(this, flow, yml.getRaw(), Trigger.SCHEDULER, null));
126+
var event = new CreateNewJobEvent(this, flow, ymlService.get(flow.getId()), Trigger.SCHEDULER, null);
127+
eventManager.publish(event);
128128
} catch (NotFoundException ignore) {
129129
// ignore
130130
}

core/src/main/java/com/flowci/core/flow/service/FlowGroupServiceImpl.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.flowci.exception.DuplicateException;
1212
import com.flowci.exception.NotFoundException;
1313
import com.google.common.collect.Sets;
14+
import lombok.AllArgsConstructor;
1415
import org.springframework.beans.factory.annotation.Autowired;
1516
import org.springframework.dao.DuplicateKeyException;
1617
import org.springframework.stereotype.Service;
@@ -19,6 +20,7 @@
1920
import java.util.Optional;
2021

2122
@Service
23+
@AllArgsConstructor
2224
public class FlowGroupServiceImpl implements FlowGroupService {
2325

2426
private final FlowDao flowDao;
@@ -29,17 +31,6 @@ public class FlowGroupServiceImpl implements FlowGroupService {
2931

3032
private final SessionManager sessionManager;
3133

32-
@Autowired
33-
public FlowGroupServiceImpl(FlowDao flowDao,
34-
FlowGroupDao flowGroupDao,
35-
FlowUserDao flowUserDao,
36-
SessionManager sessionManager) {
37-
this.flowDao = flowDao;
38-
this.flowGroupDao = flowGroupDao;
39-
this.flowUserDao = flowUserDao;
40-
this.sessionManager = sessionManager;
41-
}
42-
4334
@Override
4435
public FlowGroup get(String name) {
4536
Optional<FlowGroup> optional = flowGroupDao.findByName(name);

0 commit comments

Comments
 (0)