Skip to content

Commit ed02c9b

Browse files
committed
Merge branch 'develop' of github.com:FlowCI/flow-platform into develop
2 parents 292db41 + e135b95 commit ed02c9b

File tree

13 files changed

+101
-26
lines changed

13 files changed

+101
-26
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.flow.platform.api.controller;
1818

19+
import com.flow.platform.api.config.AppConfig;
1920
import com.flow.platform.api.domain.envs.FlowEnvs;
2021
import com.flow.platform.api.domain.envs.FlowEnvs.YmlStatusValue;
2122
import com.flow.platform.api.domain.node.Flow;
@@ -65,11 +66,11 @@ public class GitWebHookController extends NodeController {
6566
@PostMapping(path = "/{root}")
6667
public void onEventReceived(@RequestHeader HttpHeaders headers, HttpServletRequest request) {
6768
final String path = currentNodePath.get();
68-
6969
Map<String, String> headerAsMap = headers.toSingleValueMap();
70+
7071
String body;
7172
try {
72-
request.setCharacterEncoding("utf8");
73+
request.setCharacterEncoding(AppConfig.DEFAULT_CHARSET.name());
7374
body = CharStreams.toString(request.getReader());
7475
} catch (IOException e) {
7576
throw new IllegalStatusException("Cannot read raw body");

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.flow.platform.api.service.job.JobSearchService;
2626
import com.flow.platform.api.service.node.YmlService;
2727
import com.flow.platform.api.util.I18nUtil;
28+
import com.flow.platform.core.exception.NotFoundException;
2829
import com.flow.platform.util.Logger;
2930
import com.flow.platform.util.StringUtil;
3031
import com.flow.platform.util.git.model.GitEventType;
@@ -174,7 +175,12 @@ public Job show(@PathVariable Integer buildNumber) {
174175
@GetMapping(path = "/{root}/{buildNumber}/yml")
175176
public String yml(@PathVariable Integer buildNumber) {
176177
String path = currentNodePath.get();
177-
return jobService.findYml(path, buildNumber);
178+
try {
179+
return jobService.findYml(path, buildNumber);
180+
} catch (NotFoundException ignore) {
181+
// ignore job node not found exception since maybe job node created when yml loading
182+
return StringUtil.EMPTY;
183+
}
178184
}
179185

180186
/**

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@
2121
*/
2222
public enum AgentEnvs implements EnvKey {
2323

24-
FLOW_AGENT_WORKSPACE,
25-
26-
FLOW_AGENT_OUTPUT_ENV_PREFIX
24+
FLOW_AGENT_WORKSPACE
2725
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public enum FlowEnvs implements EnvKey {
3636
/**
3737
* For yml error message while loading yml from git
3838
*/
39-
FLOW_YML_ERROR_MSG;
39+
FLOW_YML_ERROR_MSG,
40+
41+
42+
/**
43+
* Defined env variable output prefix
44+
*/
45+
FLOW_ENV_OUTPUT_PREFIX;
4046

4147
public enum StatusValue implements EnvValue {
4248

platform-api/src/main/java/com/flow/platform/api/service/job/CmdServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.flow.platform.api.service.job;
1818

1919
import com.flow.platform.api.domain.envs.AgentEnvs;
20+
import com.flow.platform.api.domain.envs.FlowEnvs;
2021
import com.flow.platform.api.domain.job.Job;
2122
import com.flow.platform.api.domain.node.Node;
2223
import com.flow.platform.api.util.PlatformURL;
@@ -102,7 +103,7 @@ public CmdInfo runShell(Job job, Node node, String cmdId) {
102103
CmdInfo cmdInfo = new CmdInfo(zone, null, CmdType.RUN_SHELL, node.getScript());
103104
cmdInfo.setInputs(node.getEnvs());
104105
cmdInfo.setWebhook(buildCmdWebhook(job));
105-
cmdInfo.setOutputEnvFilter(job.getEnv(AgentEnvs.FLOW_AGENT_OUTPUT_ENV_PREFIX, "FLOW_OUTPUT"));
106+
cmdInfo.setOutputEnvFilter(job.getEnv(FlowEnvs.FLOW_ENV_OUTPUT_PREFIX, "FLOW_OUTPUT"));
106107
cmdInfo.setSessionId(job.getSessionId());
107108
cmdInfo.setExtra(node.getPath()); // use cmd.extra to keep node path info
108109
cmdInfo.setCustomizedId(cmdId);

platform-api/src/main/java/com/flow/platform/api/service/job/JobServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ private void run(Node node, Job job) {
296296
// pass job env to node
297297
EnvUtil.merge(job.getEnvs(), node.getEnvs(), false);
298298

299+
// pass root node output to current node
300+
NodeResult rootResult = nodeResultService.find(tree.root().getPath(), job.getId());
301+
EnvUtil.merge(rootResult.getOutputs(), node.getEnvs(), false);
302+
299303
// to run node with customized cmd id
300304
try {
301305
NodeResult nodeResult = nodeResultService.find(node.getPath(), job.getId());
@@ -450,6 +454,10 @@ public void createJobNodesAndCreateSession(Job job, String yml) {
450454
//create yml snapshot for job
451455
jobNodeService.save(job, yml);
452456

457+
// set root node env from yml to job env
458+
Node root = jobNodeService.get(job).root();
459+
EnvUtil.merge(root.getEnvs(), job.getEnvs(), true);
460+
453461
// init for node result and set to job object
454462
List<NodeResult> resultList = nodeResultService.create(job);
455463
NodeResult rootResult = resultList.remove(resultList.size() - 1);

platform-api/src/main/java/com/flow/platform/api/service/node/YmlServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.concurrent.TimeUnit;
5050
import java.util.function.Consumer;
5151
import org.springframework.beans.factory.annotation.Autowired;
52+
import org.springframework.core.task.TaskRejectedException;
5253
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
5354
import org.springframework.stereotype.Service;
5455

@@ -163,7 +164,7 @@ public Node loadYmlContent(final Node root, final Consumer<Yml> onSuccess, final
163164

164165
// async to load yml file
165166
executor.execute(new UpdateNodeYmlTask(root, nodeService, gitService, onSuccess, onError));
166-
} catch (ExecutionException e) {
167+
} catch (ExecutionException | TaskRejectedException e) {
167168
LOGGER.warn("Fail to get task executor for node: " + root.getPath());
168169
nodeService.updateYmlState(root, YmlStatusValue.ERROR, e.getMessage());
169170
}

platform-api/src/main/java/com/flow/platform/api/service/user/UserServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ public User register(User user, List<String> roles, boolean isSendEmail, List<St
173173

174174
@Override
175175
public void delete(List<String> emailList) {
176+
if (emailList.contains(currentUser().getEmail())){
177+
throw new IllegalParameterException("params emails include yourself email, not delete");
178+
}
176179
// un-assign user from role and flow
177180
List<User> users = userDao.list(emailList);
178181
for (User user : users) {

platform-api/src/test/java/com/flow/platform/api/test/controller/CmdWebhookControllerTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
2121
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2222

23-
import com.flow.platform.api.domain.job.JobStatus;
24-
import com.flow.platform.api.domain.node.Flow;
2523
import com.flow.platform.api.domain.job.Job;
26-
import com.flow.platform.api.domain.node.Node;
24+
import com.flow.platform.api.domain.job.JobStatus;
2725
import com.flow.platform.api.domain.job.NodeResult;
2826
import com.flow.platform.api.domain.job.NodeStatus;
27+
import com.flow.platform.api.domain.node.Flow;
28+
import com.flow.platform.api.domain.node.Node;
2929
import com.flow.platform.api.domain.node.Step;
3030
import com.flow.platform.api.test.TestBase;
31+
import com.flow.platform.api.util.EnvUtil;
3132
import com.flow.platform.domain.Cmd;
3233
import com.flow.platform.domain.CmdResult;
3334
import com.flow.platform.domain.CmdStatus;
3435
import com.flow.platform.domain.CmdType;
3536
import com.flow.platform.util.git.model.GitEventType;
3637
import com.flow.platform.util.http.HttpURL;
37-
import java.util.List;
3838
import org.junit.Assert;
3939
import org.junit.Before;
4040
import org.junit.Test;
@@ -103,6 +103,7 @@ public void should_callback_session_success() throws Throwable {
103103

104104
CmdResult cmdResult = new CmdResult(0);
105105
cmdResult.setDuration(100L);
106+
cmdResult.setOutput(EnvUtil.build("OUTPUT_ENV", "hello"));
106107
cmd.setCmdResult(cmdResult);
107108

108109
performMockHttpRequest(cmd, job);
@@ -112,9 +113,18 @@ public void should_callback_session_success() throws Throwable {
112113
job = reload(job);
113114
Assert.assertEquals(JobStatus.RUNNING, job.getStatus());
114115

116+
// check step 1 node result
115117
resultForStep1 = nodeResultService.find(step1.getPath(), job.getId());
116118
Assert.assertEquals(NodeStatus.SUCCESS, resultForStep1.getStatus());
117119
Assert.assertEquals(0, resultForStep1.getExitCode().intValue());
120+
Assert.assertEquals(1, resultForStep1.getOutputs().size());
121+
Assert.assertEquals("hello", resultForStep1.getOutputs().get("OUTPUT_ENV"));
122+
123+
// check root node result
124+
NodeResult rootNodeResult = nodeResultService.find(job.getNodePath(), job.getId());
125+
Assert.assertEquals(2, rootNodeResult.getOutputs().size());
126+
Assert.assertNotNull(rootNodeResult.getOutputs().get("FLOW_JOB_LOG_PATH"));
127+
Assert.assertEquals("hello", rootNodeResult.getOutputs().get("OUTPUT_ENV"));
118128

119129
resultForRoot = nodeResultService.find(job.getNodePath(), job.getId());
120130
Assert.assertEquals(NodeStatus.RUNNING, resultForRoot.getStatus());

platform-api/src/test/java/com/flow/platform/api/test/service/JobServiceTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public void should_job_failure_since_cannot_create_session() throws Throwable {
9393
public void should_create_node_success() throws IOException {
9494
Node rootForFlow = createRootFlow("flow1", "demo_flow2.yaml");
9595
Job job = createMockJob(rootForFlow.getPath());
96+
Assert.assertNotNull(job.getEnv("FLOW_WORKSPACE"));
97+
Assert.assertNotNull(job.getEnv("FLOW_VERSION"));
9698

9799
Step step1 = (Step) nodeService.find("flow1/step1");
98100
Step step2 = (Step) nodeService.find("flow1/step2");
@@ -229,6 +231,8 @@ public void should_stop_success() throws IOException {
229231
public void should_job_time_out_and_reject_callback() throws IOException, InterruptedException {
230232
Node rootForFlow = createRootFlow("flow1", "demo_flow2.yaml");
231233
Job job = jobService.createJob(rootForFlow.getPath(), GitEventType.TAG, null, mockUser);
234+
Assert.assertNotNull(job.getEnv("FLOW_WORKSPACE"));
235+
Assert.assertNotNull(job.getEnv("FLOW_VERSION"));
232236

233237
build_relation(rootForFlow, job);
234238

0 commit comments

Comments
 (0)