Skip to content

Commit 4588556

Browse files
author
yang.guo
authored
Merge pull request #118 from FlowCI/develop
Develop
2 parents 1dce076 + 01a672d commit 4588556

File tree

27 files changed

+268
-112
lines changed

27 files changed

+268
-112
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ api-doc/
66

77
node_modules/
88
apidoc/
9+
dist/
910
logs/
1011
target/
1112
pom.xml.tag

platform-agent/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<artifactId>platform-agent</artifactId>
1313

1414
<properties>
15-
<client.version>0.0.7</client.version>
15+
<agent.version>0.1.0</agent.version>
1616
</properties>
1717

1818
<dependencies>
@@ -96,8 +96,6 @@
9696
</dependencies>
9797

9898
<build>
99-
<finalName>flow-agent-${client.version}</finalName>
100-
10199
<resources>
102100
<resource>
103101
<directory>src/main/resources</directory>
@@ -124,14 +122,16 @@
124122
<goal>shade</goal>
125123
</goals>
126124
<configuration>
125+
<finalName>flow-agent-${agent.version}</finalName>
127126
<transformers>
128127
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
129128
<manifestEntries>
130129
<Main-Class>com.flow.platform.agent.App</Main-Class>
131-
<Build-Number>${client.version}</Build-Number>
130+
<Build-Number>${agent.version}</Build-Number>
132131
</manifestEntries>
133132
</transformer>
134133
</transformers>
134+
<outputDirectory>${project.build.directory}/../../dist</outputDirectory>
135135
</configuration>
136136
</execution>
137137
</executions>

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,38 @@ public void run() {
107107
public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
108108
ChildData eventData = event.getData();
109109

110+
if (event.getType() == Type.CONNECTION_RECONNECTED) {
111+
LOGGER.traceMarker("ZK-Event", "========= Reconnect =========");
112+
registerZkNodeAndWatch();
113+
return;
114+
}
115+
110116
if (event.getType() == Type.CONNECTION_LOST) {
111-
LOGGER.traceMarker("ZK-Event", "========= Connection lost from zk server =========");
117+
LOGGER.traceMarker("ZK-Event", "========= Lost =========");
112118
return;
113119
}
114120

115121
if (event.getType() == Type.INITIALIZED) {
116-
LOGGER.traceMarker("ZK-Event", "========= Connected to zk server =========");
122+
LOGGER.traceMarker("ZK-Event", "========= Initialized =========");
117123
return;
118124
}
119125

120126
if (event.getType() == Type.NODE_ADDED) {
121-
LOGGER.traceMarker("ZK-Event", "========= Node been created: %s =========", eventData.getPath());
127+
LOGGER.traceMarker("ZK-Event", "========= Node Added: %s =========", eventData.getPath());
122128
return;
123129
}
124130

125131
if (event.getType() == Type.NODE_UPDATED) {
132+
LOGGER.traceMarker("ZK-Event", "========= Node Updated: %s =========", eventData.getPath());
126133
onDataChanged(eventData.getPath());
127134
return;
128135
}
136+
137+
if (event.getType() == Type.NODE_REMOVED) {
138+
LOGGER.traceMarker("ZK-Event", "========= Node Removed: %s =========", eventData.getPath());
139+
close();
140+
return;
141+
}
129142
}
130143

131144
@Override
@@ -159,10 +172,15 @@ private void onDataChanged(String path) {
159172
}
160173

161174
cmd = Jsonable.parse(rawData, Cmd.class);
162-
cmdHistory.add(cmd);
175+
if (cmd == null) {
176+
LOGGER.warn("Unable to parse cmd from zk node: " + new String(rawData));
177+
return;
178+
}
163179

180+
cmdHistory.add(cmd);
164181
LOGGER.trace("Received command: " + cmd.toString());
165182
CmdManager.getInstance().execute(cmd);
183+
166184
} catch (Throwable e) {
167185
LOGGER.error("Invalid cmd from server", e);
168186
// TODO: should report agent status directly...

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,19 @@ private String collectionAgentInfo() {
237237
String javaVersion = System.getProperty("java.version");
238238
String osName = System.getProperty("os.name");
239239
Runtime runtime = Runtime.getRuntime();
240-
int kb = 1024;
241240
long total = runtime.totalMemory();
242241
long free = runtime.freeMemory();
243242
long use = total - free;
243+
244244
Map<String, String> dic = new HashMap<>(7);
245245
dic.put("javaVersion", javaVersion);
246246
dic.put("osName", osName);
247-
dic.put("totalMemory", total / kb + "MB");
248-
dic.put("useMemory", use / kb + "MB");
247+
dic.put("totalMemory", Long.toString(total));
248+
dic.put("useMemory", Long.toString(use));
249249
dic.put("zone", Config.zone());
250250
dic.put("name", Config.name());
251251
dic.put("agentVersion", Config.getProperty("version"));
252+
252253
return Jsonable.GSON_CONFIG.toJson(dic);
253254
}
254255

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.flow.platform.domain.Jsonable;
2121
import com.flow.platform.util.ExceptionUtil;
2222
import com.flow.platform.util.Logger;
23+
import com.flow.platform.util.StringUtil;
2324
import com.flow.platform.util.http.HttpClient;
2425
import com.flow.platform.util.http.HttpResponse;
2526
import com.flow.platform.util.zk.ZKClient;
@@ -77,14 +78,13 @@ public static int zkTimeout() {
7778
*/
7879
public static String getProperty(String name) {
7980
String value;
80-
URL resource = Config.class.getClassLoader().getResource("application.properties");
8181
if (properties == null) {
82-
try (InputStream fileInputStream = new FileInputStream(resource.getFile())) {
82+
try (InputStream fileInputStream = Config.class.getResourceAsStream("/application.properties")) {
8383
properties = new Properties();
8484
properties.load(fileInputStream);
8585
} catch (Throwable e) {
86-
LOGGER.warn("get property from application.properties error %s",
87-
ExceptionUtil.findRootCause(e).getMessage());
86+
LOGGER.error("Fail to load application.properties:", e);
87+
return StringUtil.EMPTY;
8888
}
8989
}
9090

platform-api/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
<artifactId>platform-api</artifactId>
1414
<packaging>war</packaging>
1515

16+
<properties>
17+
<api.version>0.1.0</api.version>
18+
</properties>
19+
1620
<build>
17-
<finalName>flow-api</finalName>
21+
<finalName>flow-api-${api.version}</finalName>
1822
<plugins>
1923
<plugin>
2024
<groupId>org.apache.maven.plugins</groupId>
2125
<artifactId>maven-war-plugin</artifactId>
2226
<version>3.1.0</version>
2327
<configuration>
2428
<failOnMissingWebXml>false</failOnMissingWebXml>
29+
<outputDirectory>${project.build.directory}/../../dist</outputDirectory>
2530
</configuration>
2631
</plugin>
2732
</plugins>

platform-api/src/main/java/com/flow/platform/api/controller/AgentController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.flow.platform.api.events.AgentStatusChangeEvent;
2323
import com.flow.platform.api.service.AgentService;
2424
import com.flow.platform.core.exception.IllegalParameterException;
25-
import com.flow.platform.core.service.ApplicationEventService;
2625
import com.flow.platform.domain.Agent;
2726
import com.flow.platform.domain.AgentPath;
2827
import com.flow.platform.domain.AgentSettings;
@@ -42,7 +41,7 @@
4241
*/
4342
@RestController
4443
@RequestMapping(path = "/agents")
45-
public class AgentController extends ApplicationEventService {
44+
public class AgentController {
4645

4746
@Autowired
4847
private AgentService agentService;
@@ -193,7 +192,7 @@ public BooleanValue shutDown(@RequestParam String zone,
193192
*/
194193
@PostMapping(path = "/callback")
195194
public void callback(@RequestBody Agent agent) {
196-
this.dispatchEvent(new AgentStatusChangeEvent(this, agent));
195+
agentService.onAgentStatusChange(agent);
197196
}
198197

199198
/**

platform-api/src/main/java/com/flow/platform/api/dao/job/JobDao.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public interface JobDao extends BaseDao<BigInteger, Job> {
6969
*/
7070
Job get(String path, Integer number);
7171

72+
/**
73+
* get job by session id
74+
*/
75+
Job get(String sessionId);
76+
7277
/**
7378
* get max build number for node path
7479
*/

platform-api/src/main/java/com/flow/platform/api/dao/job/JobDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public Job get(BigInteger key) {
8787
});
8888
}
8989

90+
91+
9092
@Override
9193
public List<Job> latestByPath(List<String> paths) {
9294
return execute((Session session) -> {
@@ -163,6 +165,13 @@ public Job get(String path, Integer number) {
163165
});
164166
}
165167

168+
@Override
169+
public Job get(String sessionId) {
170+
return execute(session -> session.createQuery("from Job where sessionId = :sessionId", Job.class)
171+
.setParameter("sessionId", sessionId)
172+
.uniqueResult());
173+
}
174+
166175
@Override
167176
public Integer maxBuildNumber(String path) {
168177
return execute((Session session) -> {

platform-api/src/main/java/com/flow/platform/api/domain/envs/FlowEnvs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public enum FlowEnvs implements EnvKey {
4242
/**
4343
* Defined env variable output prefix
4444
*/
45-
FLOW_OUTPUT_ENV_PREFIX;
45+
FLOW_ENV_OUTPUT_PREFIX;
4646

4747
public enum StatusValue implements EnvValue {
4848

0 commit comments

Comments
 (0)