Skip to content

Commit 5553baa

Browse files
committed
Merge branch 'develop' of github.com:FlowCI/flow-platform into feature/api/branches_cache
2 parents 1169248 + 135da36 commit 5553baa

File tree

88 files changed

+1677
-575
lines changed

Some content is hidden

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

88 files changed

+1677
-575
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea/
22
*.iml
33
.DS_Store
4+
deploy.sh
45

56
node_modules/
67
apidoc/

docker/app-api.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ api.workspace = ${HOME}/flow-api-data
1818
### domain ###
1919
domain = http://localhost:8080
2020

21+
domain.web = http://localhost:3000
22+
2123
### platform setting ###
2224
platform.url = http://localhost:8080/
2325
platform.zone = default

docker/app-cc.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ zone.default.default_cmd_timeout = 600
2525

2626
### rabbitmq config ###
2727
mq.host = amqp://localhost:5672
28-
mq.queue.cmd.name = flow-cmd-queue-default
2928
mq.management.host = http://localhost:15672
3029

3130
#### cmd queue settings ###
31+
queue.cmd.rabbit.enable = false
32+
queue.cmd.rabbit.name = flow-cmd-queue-default
3233
queue.cmd.idle_agent.timeout = 30
3334
queue.cmd.idle_agent.period = 5
3435

platform-agent/src/main/java/com/flow/platform/agent/AgentManager.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.flow.platform.util.Logger;
2222
import com.flow.platform.util.zk.*;
2323

24-
import java.io.Closeable;
2524
import java.io.IOException;
2625
import java.util.LinkedList;
2726
import java.util.List;
@@ -41,7 +40,9 @@ public class AgentManager implements Runnable, TreeCacheListener, AutoCloseable
4140

4241
// Zk root path /flow-agents/{zone}/{name}
4342
private final static Object STATUS_LOCKER = new Object();
44-
private final static int ZK_RECONNECT_TIME = 5;
43+
44+
private final static int ZK_RECONNECT_TIME = 1;
45+
private final static int ZK_RETRY_PERIOD = 500;
4546

4647
private String zkHost;
4748
private int zkTimeout;
@@ -59,7 +60,7 @@ public AgentManager(String zkHost, int zkTimeout, String zone, String name) thro
5960
this.zkHost = zkHost;
6061
this.zkTimeout = zkTimeout;
6162

62-
this.zkClient = new ZKClient(zkHost);
63+
this.zkClient = new ZKClient(zkHost, ZK_RETRY_PERIOD, ZK_RECONNECT_TIME);
6364
this.zone = zone;
6465
this.name = name;
6566
this.zonePath = ZKPaths.makePath(Config.ZK_ROOT, this.zone);
@@ -97,7 +98,7 @@ public void run() {
9798
try {
9899
STATUS_LOCKER.wait();
99100
} catch (InterruptedException e) {
100-
e.printStackTrace();
101+
LOGGER.warn("InterrupatdException : " + e.getMessage());
101102
}
102103
}
103104
}
@@ -106,13 +107,18 @@ public void run() {
106107
public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
107108
ChildData eventData = event.getData();
108109

110+
if (event.getType() == Type.CONNECTION_LOST) {
111+
LOGGER.traceMarker("ZK-Event", "========= Connection lost from zk server =========");
112+
return;
113+
}
114+
109115
if (event.getType() == Type.INITIALIZED) {
110-
LOGGER.trace("========= Connected to zookeeper server =========");
116+
LOGGER.traceMarker("ZK-Event", "========= Connected to zk server =========");
111117
return;
112118
}
113119

114120
if (event.getType() == Type.NODE_ADDED) {
115-
LOGGER.trace("========= Node been created: %s =========", eventData.getPath());
121+
LOGGER.traceMarker("ZK-Event", "========= Node been created: %s =========", eventData.getPath());
116122
return;
117123
}
118124

@@ -176,6 +182,6 @@ private String registerZkNodeAndWatch() {
176182
}
177183

178184
private void removeZkNode() {
179-
zkClient.delete(nodePath, false);
185+
zkClient.deleteWithoutGuaranteed(nodePath, false);
180186
}
181187
}

platform-agent/src/main/java/com/flow/platform/agent/App.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,26 @@ public static void main(String args[]) {
4343
token = args[1];
4444
}
4545

46-
LOGGER.trace("========= Run agent =========");
46+
LOGGER.trace("========= Flow Agent Started =========");
47+
LOGGER.trace("=== Server: " + baseUrl);
48+
LOGGER.trace("=== Token: " + token);
49+
4750
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
4851

4952
try {
50-
LOGGER.trace("========= Init config =========");
53+
LOGGER.trace("=== Start to load configuration");
5154

5255
Config.AGENT_SETTINGS = Config.loadAgentConfig(baseUrl, token);
53-
LOGGER.trace(" -- Settings: %s", Config.agentSettings());
56+
LOGGER.trace("====== Settings: %s", Config.agentSettings());
5457

5558
Config.ZK_URL = Config.AGENT_SETTINGS.getZookeeperUrl();
56-
LOGGER.trace(" -- Zookeeper host: %s", Config.zkUrl());
59+
LOGGER.trace("====== Zookeeper host: %s", Config.zkUrl());
5760

5861
Config.ZONE = Config.AGENT_SETTINGS.getAgentPath().getZone();
59-
LOGGER.trace(" -- Working zone: %s", Config.zone());
62+
LOGGER.trace("====== Working zone: %s", Config.zone());
6063

6164
Config.NAME = Config.AGENT_SETTINGS.getAgentPath().getName();
62-
LOGGER.trace(" -- Agent agent: %s", Config.name());
65+
LOGGER.trace("====== Agent agent: %s", Config.name());
6366

6467
LOGGER.trace("========= Config initialized =========");
6568
} catch (Throwable e) {

platform-agent/src/main/java/com/flow/platform/agent/CmdManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.flow.platform.cmd.CmdExecutor;
2020
import com.flow.platform.cmd.Log;
21-
import com.flow.platform.cmd.Log.Category;
2221
import com.flow.platform.cmd.Log.Type;
2322
import com.flow.platform.cmd.ProcListener;
2423
import com.flow.platform.domain.Cmd;
@@ -204,10 +203,10 @@ public void run() {
204203
if (cmd.getType() == CmdType.SYSTEM_INFO) {
205204
LogEventHandler logListener = new LogEventHandler(cmd);
206205
Log log = new Log(Type.STDERR, collectionAgentInfo());
207-
log.setCategory(Category.SYSTEM_INFO);
208206
logListener.onLog(log);
209207
logListener.onFinish();
210208
cmd.setStatus(CmdStatus.EXECUTED);
209+
return;
211210
}
212211

213212
// kill current running proc

platform-agent/src/main/java/com/flow/platform/agent/Config.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.flow.platform.domain.AgentSettings;
2020
import com.flow.platform.domain.Jsonable;
21+
import com.flow.platform.util.ExceptionUtil;
22+
import com.flow.platform.util.Logger;
2123
import com.flow.platform.util.http.HttpClient;
2224
import com.flow.platform.util.http.HttpResponse;
2325
import com.flow.platform.util.zk.ZKClient;
@@ -34,6 +36,8 @@
3436
*/
3537
public class Config {
3638

39+
private final static Logger LOGGER = new Logger(Config.class);
40+
3741
public final static String ZK_ROOT = "flow-agents";
3842

3943
/* Config properties by using -Dxxx.xxx = xxx as JVM parameter */
@@ -79,6 +83,8 @@ public static String getProperty(String name) {
7983
properties = new Properties();
8084
properties.load(fileInputStream);
8185
} catch (Throwable e) {
86+
LOGGER.warn("get property from application.properties error %s",
87+
ExceptionUtil.findRootCause(e).getMessage());
8288
}
8389
}
8490

platform-agent/src/main/java/com/flow/platform/agent/LogEventHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void onFinish() {
122122

123123
public String websocketLogFormat(Log log) {
124124
return String
125-
.format("%s#%s#%s#%s#%s#%s", log.getCategory(), log.getNumber(), cmd.getZoneName(), cmd.getAgentName(),
125+
.format("%s#%s#%s#%s#%s#%s", cmd.getType(), log.getNumber(), cmd.getZoneName(), cmd.getAgentName(),
126126
cmd.getId(),
127127
log.getContent());
128128
}

platform-agent/src/main/java/com/flow/platform/agent/ReportManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public boolean cmdLogUploadSync(final String cmdId, final Path path) {
115115
.retry(5)
116116
.bodyAsString();
117117

118-
if (response.hasSuccess()) {
118+
if (!response.hasSuccess()) {
119119
LOGGER.warn("Fail to upload zipped cmd log to : %s ", url);
120120
return false;
121121
}

platform-agent/src/test/java/com/flow/platform/agent/test/LogEventHandlerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.flow.platform.agent.Config;
2121
import com.flow.platform.agent.LogEventHandler;
2222
import com.flow.platform.cmd.Log;
23-
import com.flow.platform.cmd.Log.Category;
2423
import com.flow.platform.domain.Cmd;
2524
import com.flow.platform.domain.CmdType;
2625
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -59,7 +58,7 @@ public void should_get_correct_format_websocket() throws Throwable {
5958

6059
// then:
6160
String expect = String
62-
.format("%s#%s#%s#%s#%s#%s", Category.DEFAULT, null, cmd.getZoneName(), cmd.getAgentName(), cmd.getId(),
61+
.format("%s#%s#%s#%s#%s#%s", CmdType.RUN_SHELL, null, cmd.getZoneName(), cmd.getAgentName(), cmd.getId(),
6362
mockLogContent);
6463
Assert.assertEquals(expect, socketIoData);
6564
}

0 commit comments

Comments
 (0)