Skip to content

Commit

Permalink
Merge pull request #436 from FlowCI/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
gy2006 authored Jan 3, 2023
2 parents 4a04e44 + 686b1fe commit 4ee3d80
Show file tree
Hide file tree
Showing 104 changed files with 1,414 additions and 687 deletions.
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ if [[ -n ${tag} ]]; then
versionTag="-t flowci/core:$tag"
fi

docker buildx build -f ./core/Dockerfile --platform linux/arm64,linux/amd64 --push -t flowci/core:latest $versionTag ./core
#docker buildx build -f ./core/Dockerfile --platform linux/arm64,linux/amd64 --push -t flowci/core:latest $versionTag ./core
docker build -f ./core/Dockerfile -t flowci/core:latest $versionTag ./core
2 changes: 1 addition & 1 deletion core/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11-jre-slim
FROM amazoncorretto:11-alpine3.15

ENV WORKER=/flow.ci
ENV JAR=flow-ci-core.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
package com.flowci.core.flow.controller;

import com.flowci.core.auth.annotation.Action;
import com.flowci.core.common.domain.http.RequestMessage;
import com.flowci.core.flow.domain.Flow;
import com.flowci.core.flow.domain.FlowAction;
import com.flowci.core.flow.domain.Yml;
import com.flowci.core.flow.domain.SimpleYml;
import com.flowci.core.flow.domain.FlowYml;
import com.flowci.core.flow.service.FlowService;
import com.flowci.core.flow.service.YmlService;
import com.flowci.tree.FlowNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -35,40 +34,29 @@
*/
@RestController
@RequestMapping("/flows")
@AllArgsConstructor
public class YmlController {

@Autowired
private FlowService flowService;

@Autowired
private YmlService ymlService;
private final YmlService ymlService;

@GetMapping("/{flowName}/yml")
public List<Yml> list(@PathVariable String flowName) {
public FlowYml get(@PathVariable String flowName) {
Flow flow = flowService.get(flowName);
return ymlService.list(flow.getId());
return ymlService.get(flow.getId());
}

@GetMapping("/{flowName}/yml/{ymlName}/obj")
public FlowNode listSteps(@PathVariable String flowName, @PathVariable String ymlName) {
@GetMapping("/{flowName}/yml/steps")
public FlowNode steps(@PathVariable String flowName) {
Flow flow = flowService.get(flowName);
return ymlService.getTree(flow.getId(), ymlName).getRoot();
return ymlService.getTree(flow.getId()).getRoot();
}

@PostMapping("/{flowName}/yml/{ymlName}")
@PostMapping("/{flowName}/yml")
@Action(FlowAction.SET_YML)
public void saveYml(@PathVariable String flowName,
@PathVariable String ymlName,
@RequestBody RequestMessage<String> body) {
public void saveYml(@PathVariable String flowName, @RequestBody List<SimpleYml> body) {
Flow flow = flowService.get(flowName);
String yamlInB64 = body.getData();
ymlService.saveYmlFromB64(flow, ymlName, yamlInB64);
}

@GetMapping(value = "/{flowName}/yml/{ymlName}", produces = MediaType.APPLICATION_JSON_VALUE)
@Action(FlowAction.GET_YML)
public String getYml(@PathVariable String flowName, @PathVariable String ymlName) {
Flow flow = flowService.get(flowName);
return ymlService.getYmlString(flow.getId(), ymlName);
ymlService.saveYml(flow, body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.flowci.core.flow.dao;

import com.flowci.core.flow.domain.Yml;
import com.flowci.core.flow.domain.FlowYml;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -26,11 +26,9 @@
* @author yang
*/
@Repository
public interface YmlDao extends YmlCustomDao, MongoRepository<Yml, String> {
public interface FlowYmlDao extends MongoRepository<FlowYml, String> {

Optional<Yml> findByFlowIdAndName(String flowId, String name);
Optional<FlowYml> findByFlowId(String flowId);

void deleteAllByFlowId(String flowId);

void deleteByFlowIdAndName(String flowId, String name);
void deleteByFlowId(String flowId);
}
14 changes: 0 additions & 14 deletions core/src/main/java/com/flowci/core/flow/dao/YmlCustomDao.java

This file was deleted.

33 changes: 0 additions & 33 deletions core/src/main/java/com/flowci/core/flow/dao/YmlCustomDaoImpl.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Objects;

/**
* @author yang
*/
@Data
@Accessors(chain = true)
public class CreateOption {

private static final String TEMPLATE_BLANK = "_blank_";

private String groupName;

@JsonProperty("title")
Expand All @@ -40,6 +44,10 @@ public class CreateOption {
@JsonProperty("yml")
private String rawYaml;

public boolean isBlank() {
return Objects.equals(templateTitle, TEMPLATE_BLANK);
}

public boolean hasGroupName() {
return StringHelper.hasValue(groupName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,56 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.flowci.core.common.domain.Mongoable;
import com.flowci.util.ObjectsHelper;
import com.flowci.util.StringHelper;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.internal.util.CollectionHelper;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;
import java.util.Objects;

/**
* @author yang
*/
@Getter
@Setter
@Document(collection = "flow_yml")
@NoArgsConstructor
@AllArgsConstructor
@CompoundIndexes(
@CompoundIndex(
name = "index_flow_id_and_yaml_name",
def = "{'flowId': 1, 'name': 1}",
name = "index_flow_id_and_yml_name",
def = "{'flowId': 1, 'list.name': 1}",
sparse = true,
unique = true
)
)
public class Yml extends Mongoable {
public class FlowYml extends Mongoable {

public final static String DEFAULT_NAME = "default";
public final static String DEFAULT_NAME = ".flowci.yml";

@Indexed(name = "index_flow_id")
@Indexed(name = "index_yml_flow_id", unique = true)
private String flowId;

private String name;

private String rawInB64;
private List<SimpleYml> list;

public Yml(String flowId, String name, String rawInB64) {
this.flowId = flowId;
this.name = name;
this.rawInB64 = rawInB64;
public boolean hasYml() {
return ObjectsHelper.hasCollection(list);
}

@JsonIgnore
public String getRaw() {
return StringHelper.fromBase64(rawInB64);
public static String[] toRawArray(List<SimpleYml> list) {
var array = new String[list.size()];
int i = 0;
for (var item : list) {
array[0] = StringHelper.fromBase64(item.getRawInB64());
}
return array;
}
}
33 changes: 33 additions & 0 deletions core/src/main/java/com/flowci/core/flow/domain/SimpleYml.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2022 flow.ci
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.flowci.core.flow.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimpleYml {

private String name;

private String rawInB64;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import com.flowci.core.common.manager.SpringEventManager;
import com.flowci.core.common.manager.SpringTaskManager;
import com.flowci.core.flow.domain.Flow;
import com.flowci.core.flow.domain.Yml;
import com.flowci.core.flow.event.FlowInitEvent;
import com.flowci.core.job.domain.Job.Trigger;
import com.flowci.core.job.event.CreateNewJobEvent;
import com.flowci.exception.NotFoundException;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
Expand All @@ -50,17 +48,20 @@ public class CronServiceImpl implements CronService {

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

@Autowired
private TaskScheduler cronScheduler;
private final TaskScheduler cronScheduler;

@Autowired
private SpringEventManager eventManager;
private final SpringEventManager eventManager;

@Autowired
private SpringTaskManager taskManager;
private final SpringTaskManager taskManager;

@Autowired
private YmlService ymlService;
private final YmlService ymlService;

public CronServiceImpl(TaskScheduler cronScheduler, SpringEventManager eventManager, SpringTaskManager taskManager, YmlService ymlService) {
this.cronScheduler = cronScheduler;
this.eventManager = eventManager;
this.taskManager = taskManager;
this.ymlService = ymlService;
}

//====================================================================
// %% Internal events
Expand Down Expand Up @@ -121,10 +122,9 @@ public void run() {

taskManager.run(taskName, false, () -> {
try {
Yml yml = ymlService.getYml(flow.getId(), Yml.DEFAULT_NAME);
log.info("Start flow '{}' from cron task", flow.getName());

eventManager.publish(new CreateNewJobEvent(this, flow, yml.getRaw(), Trigger.SCHEDULER, null));
var event = new CreateNewJobEvent(this, flow, ymlService.get(flow.getId()), Trigger.SCHEDULER, null);
eventManager.publish(event);
} catch (NotFoundException ignore) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.flowci.exception.DuplicateException;
import com.flowci.exception.NotFoundException;
import com.google.common.collect.Sets;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
Expand All @@ -19,6 +20,7 @@
import java.util.Optional;

@Service
@AllArgsConstructor
public class FlowGroupServiceImpl implements FlowGroupService {

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

private final SessionManager sessionManager;

@Autowired
public FlowGroupServiceImpl(FlowDao flowDao,
FlowGroupDao flowGroupDao,
FlowUserDao flowUserDao,
SessionManager sessionManager) {
this.flowDao = flowDao;
this.flowGroupDao = flowGroupDao;
this.flowUserDao = flowUserDao;
this.sessionManager = sessionManager;
}

@Override
public FlowGroup get(String name) {
Optional<FlowGroup> optional = flowGroupDao.findByName(name);
Expand Down
Loading

0 comments on commit 4ee3d80

Please sign in to comment.