Skip to content

Commit fd8629e

Browse files
authored
Merge pull request #344 from FlowCI/feature/1410
Feature/1410
2 parents 38ab671 + a9b1feb commit fd8629e

Some content is hidden

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

57 files changed

+913
-514
lines changed

core/src/main/java/com/flowci/core/agent/config/AgentConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public Settings baseSettings() {
5353
Settings.RabbitMQ mq = new Settings.RabbitMQ();
5454
mq.setUri(getRabbitUri());
5555
mq.setCallback(rabbitProperties.getCallbackQueue());
56-
mq.setLogsExchange(rabbitProperties.getLoggingExchange());
56+
mq.setShellLogEx(rabbitProperties.getShellLogEx());
57+
mq.setTtyLogEx(rabbitProperties.getTtyLogEx());
5758

5859
Settings settings = new Settings();
5960
settings.setZookeeper(zk);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.flowci.core.agent.domain;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public abstract class CmdIn {
9+
10+
public enum Type {
11+
/**
12+
* Execute shell script
13+
*/
14+
SHELL,
15+
16+
/**
17+
* Kill running shell
18+
*/
19+
KILL,
20+
21+
/**
22+
* TTY cmd
23+
*/
24+
TTY,
25+
26+
/**
27+
* Close agent
28+
*/
29+
CLOSE;
30+
}
31+
32+
protected Type type;
33+
34+
protected CmdIn(Type type) {
35+
this.type = type;
36+
}
37+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.flowci.core.agent.domain;
2+
3+
/**
4+
* Cmd output from callback queue,
5+
* first byte is indicator to indicate cmd out type
6+
*
7+
* @author yang
8+
*/
9+
public interface CmdOut {
10+
11+
/**
12+
* ShellOut
13+
*/
14+
byte ShellOutInd = 1;
15+
16+
/**
17+
* TtyOut
18+
*/
19+
byte TtyOutInd = 2;
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.flowci.core.agent.domain;
2+
3+
import com.flowci.core.common.rabbit.RabbitOperations;
4+
5+
import java.util.Objects;
6+
import java.util.Optional;
7+
8+
public abstract class CmdStdLog {
9+
10+
public static final String ID_HEADER = "id";
11+
12+
public static Optional<String> getId(RabbitOperations.Message message) {
13+
if (!message.hasHeader()) {
14+
return Optional.empty();
15+
}
16+
17+
Object id = message.getHeaders().get(CmdStdLog.ID_HEADER);
18+
if (Objects.isNull(id)) {
19+
return Optional.empty();
20+
}
21+
22+
return Optional.of(id.toString());
23+
}
24+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.flowci.core.agent.domain;
2+
3+
import com.flowci.domain.DockerOption;
4+
import com.flowci.domain.StringVars;
5+
import com.flowci.domain.Vars;
6+
import com.google.common.base.Strings;
7+
import lombok.Getter;
8+
import lombok.Setter;
9+
import lombok.experimental.Accessors;
10+
11+
import java.util.LinkedHashSet;
12+
import java.util.LinkedList;
13+
import java.util.List;
14+
import java.util.Set;
15+
16+
@Getter
17+
@Setter
18+
@Accessors(chain = true)
19+
public final class ShellIn extends CmdIn {
20+
21+
// from ExecutedCmd id
22+
private String id;
23+
24+
private String flowId;
25+
26+
private String jobId;
27+
28+
private boolean allowFailure;
29+
30+
private String plugin;
31+
32+
private DockerOption docker;
33+
34+
private List<String> scripts = new LinkedList<>();
35+
36+
private int timeout = 1800;
37+
38+
private Vars<String> inputs = new StringVars();
39+
40+
private Set<String> envFilters = new LinkedHashSet<>();
41+
42+
public ShellIn() {
43+
super(Type.SHELL);
44+
}
45+
46+
public void addScript(String script) {
47+
if (Strings.isNullOrEmpty(script)) {
48+
return;
49+
}
50+
scripts.add(script);
51+
}
52+
53+
public void addEnvFilters(Set<String> exports) {
54+
this.envFilters.addAll(exports);
55+
}
56+
57+
public void addInputs(StringVars vars) {
58+
inputs.putAll(vars);
59+
}
60+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.flowci.core.agent.domain;
2+
3+
/**
4+
* Kill current executing shell command
5+
*/
6+
public final class ShellKill extends CmdIn {
7+
8+
public ShellKill() {
9+
super(Type.KILL);
10+
}
11+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.flowci.core.agent.domain;
2+
3+
import com.flowci.core.job.domain.Executed;
4+
import com.flowci.domain.StringVars;
5+
import com.flowci.domain.Vars;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
9+
import java.util.Date;
10+
11+
@Getter
12+
@Setter
13+
public final class ShellOut implements Executed, CmdOut {
14+
15+
private String id;
16+
17+
private int processId;
18+
19+
private String containerId;
20+
21+
private Executed.Status status;
22+
23+
private Integer code;
24+
25+
private Vars<String> output = new StringVars();
26+
27+
private Date startAt;
28+
29+
private Date finishAt;
30+
31+
private String error;
32+
33+
private long logSize;
34+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.flowci.core.agent.domain;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import lombok.experimental.Accessors;
6+
7+
/**
8+
* @author yang
9+
*/
10+
public abstract class TtyCmd {
11+
12+
public enum Action {
13+
OPEN,
14+
15+
CLOSE,
16+
17+
SHELL
18+
}
19+
20+
@Getter
21+
@Setter
22+
@Accessors(chain = true)
23+
public final static class In extends CmdIn {
24+
25+
private String id;
26+
27+
private Action action;
28+
29+
private String input;
30+
31+
public In() {
32+
super(Type.TTY);
33+
}
34+
}
35+
36+
@Getter
37+
@Setter
38+
@Accessors(chain = true)
39+
public final static class Out implements CmdOut {
40+
41+
private String id;
42+
43+
private Action action;
44+
45+
private boolean success;
46+
47+
private String error;
48+
}
49+
50+
@Getter
51+
@Setter
52+
@Accessors(chain = true)
53+
public final static class Log {
54+
55+
private String id;
56+
57+
private String content;
58+
}
59+
}

core/src/main/java/com/flowci/core/agent/event/CmdSentEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.flowci.core.agent.event;
1818

19+
import com.flowci.core.agent.domain.CmdIn;
1920
import com.flowci.domain.Agent;
20-
import com.flowci.domain.CmdIn;
2121
import lombok.Getter;
2222
import org.springframework.context.ApplicationEvent;
2323

core/src/main/java/com/flowci/core/agent/service/AgentService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
package com.flowci.core.agent.service;
1818

1919
import com.flowci.core.agent.domain.AgentInit;
20+
import com.flowci.core.agent.domain.CmdIn;
2021
import com.flowci.core.job.domain.Job;
2122
import com.flowci.domain.Agent;
22-
import com.flowci.domain.CmdIn;
2323
import com.flowci.domain.Settings;
24-
import com.flowci.tree.Selector;
2524

2625
import java.util.List;
2726
import java.util.Optional;

0 commit comments

Comments
 (0)