Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ target/
.project
.settings/
.classpath
.factorypath
.factorypath
*Proto.java
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


MVN_CLEAN := mvn clean
MVN_BUILD := mvn compile -T 4C
MVN_PKG := mvn package -T 4C -Dmaven.test.skip=true
MVN_TEST := mvn test -T 4C


CURRENT_DIR := $(shell pwd)

DOCKER_VOLUME := -v $(HOME)/.m2:/root/.m2
DOCKER_IMG := flowci/javasdk:1.0
DOCKER_RUN := docker run -it --rm -v $(CURRENT_DIR):/ws -w /ws $(DOCKER_VOLUME) --network host $(DOCKER_IMG)

DOCKER_BUILD := ./build.sh

.PHONY: build test clean package

build:
$(DOCKER_RUN) $(MVN_BUILD)

package:
$(DOCKER_RUN) $(MVN_PKG)

test:
$(DOCKER_RUN) $(MVN_TEST)

clean:
$(DOCKER_RUN) $(MVN_CLEAN)
28 changes: 28 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
<artifactId>org.eclipse.jgit</artifactId>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>

<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
Expand Down Expand Up @@ -168,6 +173,29 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>
generate-sources
</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<workingDirectory>${project.build.sourceDirectory}</workingDirectory>
<executable>protoc</executable>
<commandlineArgs>
-I=./ --java_out=./ job.proto
</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public List<User> users(String flowName) {

private Job getJob(String name, long number) {
Flow flow = flowService.get(name);
String key = JobKeyBuilder.build(flow, number);
String key = JobKeyBuilder.build(flow.getId(), number);
Optional<Job> optional = jobDao.findByKey(key);

if (optional.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
registry.addEndpoint("/ws").setAllowedOrigins("*");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ public abstract static class Job {
// {step name}={status};{step name}={status}
public static final String Steps = "FLOWCI_JOB_STEPS";
}

public abstract static class Step {

// to control run step from docker defined in step or plugin, default is true
public static final String DockerEnabled = "FLOWCI_STEP_DOCKER_ENABLED";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flowci.core.common.domain.PushBody;
import com.flowci.core.common.domain.PushEvent;
import java.io.IOException;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
* @author yang
*/
Expand All @@ -47,4 +48,8 @@ public void push(String topic, PushEvent event, Object obj) {
log.warn(e.getMessage());
}
}

public void push(String topic, byte[] bytes) {
simpMessagingTemplate.convertAndSend(topic, bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@
import com.flowci.core.flow.service.FlowService;
import com.flowci.core.flow.service.YmlService;
import com.flowci.domain.http.RequestMessage;
import java.util.Base64;
import java.util.List;

import com.flowci.tree.Node;
import com.flowci.tree.StepNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.Base64;
import java.util.List;

/**
* @author yang
Expand All @@ -49,7 +44,7 @@ public class YmlController {
private YmlService ymlService;

@GetMapping("/{name}/yml/steps")
public List<Node> listSteps(@PathVariable String name) {
public List<StepNode> listSteps(@PathVariable String name) {
Flow flow = flowService.get(name);
return ymlService.ListChildren(flow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import com.flowci.core.flow.domain.Flow;
import com.flowci.core.flow.domain.Yml;
import com.flowci.tree.Node;
import com.flowci.tree.FlowNode;

/**
* @author yang
*/
public interface CronService {

void update(Flow flow, Node root, Yml yml);
void update(Flow flow, FlowNode root, Yml yml);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.flowci.core.flow.domain.Yml;
import com.flowci.core.job.domain.Job.Trigger;
import com.flowci.core.job.event.CreateNewJobEvent;
import com.flowci.tree.Node;
import com.flowci.tree.FlowNode;
import com.flowci.tree.YmlParser;
import com.flowci.zookeeper.ZookeeperClient;
import com.flowci.zookeeper.ZookeeperException;
Expand Down Expand Up @@ -81,7 +81,7 @@ private void initZkRoot() {
}

@Override
public void update(Flow flow, Node root, Yml yml) {
public void update(Flow flow, FlowNode root, Yml yml) {
if (!root.hasCron()) {
return;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ private void scheduleNext() {
return;
}

Node node = YmlParser.load(flow.getName(), yml.getRaw());
FlowNode node = YmlParser.load(flow.getName(), yml.getRaw());
update(flow, node, optional.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@
import com.flowci.exception.NotFoundException;
import com.flowci.exception.StatusException;
import com.flowci.store.FileManager;
import com.flowci.tree.Node;
import com.flowci.tree.NodePath;
import com.flowci.tree.TriggerFilter;
import com.flowci.tree.YmlParser;
import com.flowci.tree.*;
import com.flowci.util.StringHelper;
import com.google.common.collect.Sets;
import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -345,7 +342,7 @@ public void onGitHookEvent(GitHookEvent event) {
}

Yml yml = optional.get();
Node root = YmlParser.load(flow.getName(), yml.getRaw());
FlowNode root = YmlParser.load(flow.getName(), yml.getRaw());

if (!canStartJob(root, event.getTrigger())) {
log.debug("Cannot start job since filter not matched on flow {}", flow.getName());
Expand All @@ -369,7 +366,7 @@ private void setupDefaultVars(Flow flow) {
localVars.put(Variables.Flow.Webhook, VarValue.of(getWebhook(flow.getName()), VarType.HTTP_URL, false));
}

private boolean canStartJob(Node root, GitTrigger trigger) {
private boolean canStartJob(FlowNode root, GitTrigger trigger) {
TriggerFilter condition = root.getTrigger();

if (trigger.getEvent() == GitEvent.PUSH) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import com.flowci.core.plugin.domain.Plugin;
import com.flowci.core.plugin.service.PluginService;
import com.flowci.exception.NotFoundException;
import com.flowci.tree.FlowNode;
import com.flowci.tree.Node;
import com.flowci.tree.StepNode;
import com.flowci.tree.YmlParser;
import com.flowci.util.StringHelper;
import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -115,14 +117,13 @@ public Map<String, StatsType> defaultTypes() {
@Override
public List<StatsType> getStatsType(Flow flow) {
Optional<Yml> optional = ymlDao.findById(flow.getId());

List<StatsType> list = new LinkedList<>(defaultTypes.values());
if (!optional.isPresent()) {
return list;
}

Node root = YmlParser.load(flow.getName(), optional.get().getRaw());
for (Node child : root.getChildren()) {
FlowNode root = YmlParser.load(flow.getName(), optional.get().getRaw());
for (StepNode child : root.getChildren()) {
if (!child.hasPlugin()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.flowci.core.flow.domain.Flow;
import com.flowci.core.flow.domain.Yml;
import com.flowci.tree.Node;
import com.flowci.tree.StepNode;

import java.util.List;

Expand All @@ -30,7 +31,7 @@ public interface YmlService {
/**
* List all children node from YAML
*/
List<Node> ListChildren(Flow flow);
List<StepNode> ListChildren(Flow flow);

/**
* Get yml by flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import com.flowci.domain.Vars;
import com.flowci.exception.ArgumentException;
import com.flowci.exception.NotFoundException;
import com.flowci.tree.FlowNode;
import com.flowci.tree.Node;
import com.flowci.tree.StepNode;
import com.flowci.tree.YmlParser;
import com.flowci.util.StringHelper;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -71,13 +73,13 @@ public class YmlServiceImpl implements YmlService {
//====================================================================

@Override
public List<Node> ListChildren(Flow flow) {
public List<StepNode> ListChildren(Flow flow) {
Optional<Yml> optional = ymlDao.findById(flow.getId());
if (!optional.isPresent()) {
return Collections.emptyList();
}

Node root = YmlParser.load(flow.getName(), optional.get().getRaw());
FlowNode root = YmlParser.load(flow.getName(), optional.get().getRaw());
return root.getChildren();
}

Expand All @@ -96,10 +98,10 @@ public Yml saveYml(Flow flow, String yml) {
throw new ArgumentException("Yml content cannot be null or empty");
}

Node root = YmlParser.load(flow.getName(), yml);
FlowNode root = YmlParser.load(flow.getName(), yml);

// verify plugin and throw NotFoundException if not exist
for (Node child : root.getChildren()) {
for (StepNode child : root.getChildren()) {
if (child.hasPlugin()) {
pluginService.get(child.getPlugin());
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/flowci/core/job/JobController.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public Job get(@PathVariable("flow") String name, @PathVariable String buildNumb
Flow flow = flowService.get(name);

if (ParameterLatest.equals(buildNumberOrLatest)) {
return jobService.getLatest(flow);
return jobService.getLatest(flow.getId());
}

try {
long buildNumber = Long.parseLong(buildNumberOrLatest);
return jobService.get(flow, buildNumber);
return jobService.get(flow.getId(), buildNumber);
} catch (NumberFormatException e) {
throw new ArgumentException("Build number must be a integer");
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/com/flowci/core/job/domain/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public enum Status {
*/
FAILURE,

/**
* Job will be cancelled, but waiting for response from agent
*/
CANCELLING,

/**
* Job been cancelled by user
*/
Expand Down Expand Up @@ -234,6 +239,11 @@ public boolean isRunning() {
return status == Status.RUNNING;
}

@JsonIgnore
public boolean isCancelling() {
return status == Status.CANCELLING;
}

@JsonIgnore
public boolean isQueuing() {
return status == Status.QUEUED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
import com.flowci.core.job.domain.Job;
import com.flowci.domain.CmdIn;
import com.flowci.tree.Node;
import com.flowci.tree.StepNode;

/**
* @author yang
*/
public interface CmdManager {

CmdId createId(Job job, Node node);
CmdId createId(Job job, StepNode node);

CmdIn createShellCmd(Job job, Node node);
CmdIn createShellCmd(Job job, StepNode node);

CmdIn createKillCmd();
}
Loading