Skip to content

Commit 278ceb2

Browse files
author
yang.guo
authored
Merge pull request #203 from FlowCI/develop
Develop
2 parents c0b4f7c + 4fa0f44 commit 278ceb2

File tree

145 files changed

+5755
-337
lines changed

Some content is hidden

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

145 files changed

+5755
-337
lines changed

config/app-api.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ hibernate.hbm2ddl.auto = validate
1414

1515
### api settings ###
1616
api.workspace = ${HOME}/flow-api-data
17+
api.git.cache = ${HOME}/flow-api-data/git-cache
18+
api.git.workspace = ${HOME}/flow-api-data/git-repos
1719
api.zone.default = default
1820

1921
### expiration duration of token, it's in millisecond ###
@@ -29,6 +31,9 @@ system.email = [email protected]
2931
system.username = admin
3032
system.password = 123456
3133

34+
## plugin repos url
35+
plugins.repository = https://raw.githubusercontent.com/flowci/plugins/master/repository.json
36+
3237
task.job.toggle.execution_timeout = true
3338
## expired in 1800 seconds for create session
3439
task.job.toggle.execution_create_session_duration = 1800

config/app-cc.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jdbc.connection.timeout = 20000
1212
hibernate.show_sql = false
1313
hibernate.hbm2ddl.auto = validate
1414

15+
### control center configuration
16+
cc.workspace = ${HOME}/flow-api/cc
17+
1518
### zookeeper config ###
1619
zk.server.embedded = true
1720
zk.host = 127.0.0.1:2181

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
@@ -205,7 +205,7 @@ private void writeZipStream(final ZipOutputStream stream, final String log) {
205205
// write to zip output stream
206206
try {
207207
stream.write(log.getBytes());
208-
stream.write("\n".getBytes());
208+
stream.write(Cmd.NEW_LINE.getBytes());
209209
} catch (IOException e) {
210210
LOGGER.warn("Log cannot write : " + log);
211211
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.flow.platform.domain.CmdResult;
2424
import com.flow.platform.domain.CmdStatus;
2525
import com.flow.platform.domain.CmdType;
26+
import com.google.common.collect.Lists;
2627
import java.io.IOException;
2728
import java.util.Map;
2829
import java.util.UUID;
@@ -119,19 +120,19 @@ public void onException(CmdResult result) {
119120
String content = String.format("source %s", resourcePath);
120121

121122
Cmd cmd1 = new Cmd("zone1", "agent1", CmdType.RUN_SHELL, content);
122-
cmd1.setOutputEnvFilter("FLOW_AGENT");
123+
cmd1.setOutputEnvFilter(Lists.newArrayList("FLOW_AGENT"));
123124
cmd1.setId(UUID.randomUUID().toString());
124125

125126
Cmd cmd2 = new Cmd("zone1", "agent1", CmdType.RUN_SHELL, content);
126-
cmd2.setOutputEnvFilter("FLOW_AGENT");
127+
cmd2.setOutputEnvFilter(Lists.newArrayList("FLOW_AGENT"));
127128
cmd2.setId(UUID.randomUUID().toString());
128129

129130
Cmd cmd3 = new Cmd("zone1", "agent1", CmdType.RUN_SHELL, content);
130-
cmd3.setOutputEnvFilter("FLOW_AGENT");
131+
cmd3.setOutputEnvFilter(Lists.newArrayList("FLOW_AGENT"));
131132
cmd3.setId(UUID.randomUUID().toString());
132133

133134
Cmd cmd4 = new Cmd("zone1", "agent1", CmdType.RUN_SHELL, content);
134-
cmd4.setOutputEnvFilter("FLOW_AGENT");
135+
cmd4.setOutputEnvFilter(Lists.newArrayList("FLOW_AGENT"));
135136
cmd4.setId(UUID.randomUUID().toString());
136137

137138
// when: execute four command by thread

platform-api/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@
107107
<version>${project.version}</version>
108108
</dependency>
109109

110+
<dependency>
111+
<groupId>com.flow.platform</groupId>
112+
<artifactId>platform-plugin</artifactId>
113+
<version>${project.version}</version>
114+
</dependency>
115+
110116
<dependency>
111117
<groupId>com.flow.platform</groupId>
112118
<artifactId>platform-util-resource</artifactId>
@@ -159,6 +165,11 @@
159165
<artifactId>quartz-jobs</artifactId>
160166
</dependency>
161167

168+
<dependency>
169+
<groupId>org.eclipse.jgit</groupId>
170+
<artifactId>org.eclipse.jgit.http.server</artifactId>
171+
</dependency>
172+
162173
<dependency>
163174
<groupId>junit</groupId>
164175
<artifactId>junit</artifactId>
@@ -182,5 +193,6 @@
182193
<artifactId>jjwt</artifactId>
183194
<version>0.7.0</version>
184195
</dependency>
196+
185197
</dependencies>
186198
</project>

platform-api/src/main/java/com/flow/platform/api/AppInit.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
import com.flow.platform.api.resource.PropertyResourceLoader;
2222
import com.flow.platform.util.resource.AppResourceLoader;
2323
import java.io.IOException;
24+
import java.nio.file.Files;
25+
import java.nio.file.Path;
26+
import java.nio.file.Paths;
2427
import javax.servlet.ServletContext;
2528
import javax.servlet.ServletException;
26-
import javax.servlet.ServletRegistration;
29+
import javax.servlet.ServletRegistration.Dynamic;
30+
import org.eclipse.jgit.http.server.GitServlet;
2731
import org.springframework.core.io.support.ResourcePropertySource;
2832
import org.springframework.web.WebApplicationInitializer;
2933
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3034
import org.springframework.web.servlet.DispatcherServlet;
3135

3236
/**
3337
* Created by gyfirim on 14/07/2017.
34-
*
35-
* @Copyright fir.im
3638
*/
3739
public class AppInit implements WebApplicationInitializer {
3840

@@ -43,9 +45,9 @@ public void onStartup(ServletContext servletContext) throws ServletException {
4345
applicationContext.register(WebConfig.class, WebSocketConfig.class);
4446
applicationContext.setServletContext(servletContext);
4547

46-
// Add the servlet mapping manually and make it initialize automatically
48+
// Add the mvcServlet mapping manually and make it initialize automatically
4749
DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);
48-
ServletRegistration.Dynamic servlet = servletContext.addServlet("mvc-dispatcher", dispatcherServlet);
50+
Dynamic mvcServlet = servletContext.addServlet("mvc-dispatcher", dispatcherServlet);
4951

5052
// set app property resource
5153
try {
@@ -55,11 +57,32 @@ public void onStartup(ServletContext servletContext) throws ServletException {
5557
.getPropertySources()
5658
.addFirst(new ResourcePropertySource(propertyLoader.find()));
5759
} catch (IOException e) {
58-
throw new RuntimeException(e);
60+
throw new ServletException(e.getMessage());
61+
}
62+
63+
mvcServlet.addMapping("/");
64+
mvcServlet.setAsyncSupported(true);
65+
mvcServlet.setLoadOnStartup(2);
66+
67+
try {
68+
Path gitWorkspace = Paths.get(applicationContext.getEnvironment().getProperty("api.git.workspace"));
69+
initGitServlet(gitWorkspace, servletContext);
70+
} catch (IOException e) {
71+
throw new ServletException(e.getMessage());
72+
}
73+
}
74+
75+
private void initGitServlet(Path gitWorkspace, ServletContext servletContext) throws IOException {
76+
if (!Files.exists(gitWorkspace)) {
77+
Files.createDirectories(gitWorkspace);
5978
}
6079

61-
servlet.addMapping("/");
62-
servlet.setAsyncSupported(true);
63-
servlet.setLoadOnStartup(1);
80+
// add git servlet mapping
81+
Dynamic gitServlet = servletContext.addServlet("git-servlet", new GitServlet());
82+
gitServlet.addMapping("/git/*");
83+
gitServlet.setInitParameter("base-path", gitWorkspace.toString());
84+
gitServlet.setInitParameter("export-all", "true");
85+
gitServlet.setAsyncSupported(true);
86+
gitServlet.setLoadOnStartup(1);
6487
}
6588
}

platform-api/src/main/java/com/flow/platform/api/config/AppConfig.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616

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

19-
import com.flow.platform.api.domain.CmdCallbackQueueItem;
2019
import com.flow.platform.api.domain.user.User;
2120
import com.flow.platform.api.util.PlatformURL;
2221
import com.flow.platform.core.config.AppConfigBase;
2322
import com.flow.platform.core.config.DatabaseConfig;
24-
import com.flow.platform.core.queue.InMemoryQueue;
25-
import com.flow.platform.core.queue.PlatformQueue;
26-
import com.flow.platform.core.queue.PriorityMessage;
2723
import com.flow.platform.core.util.ThreadUtil;
24+
import com.flow.platform.plugin.PluginConfig;
2825
import com.flow.platform.util.Logger;
2926
import java.io.IOException;
3027
import java.nio.charset.Charset;
@@ -47,7 +44,7 @@
4744
* @author yang
4845
*/
4946
@Configuration
50-
@Import({SchedulerConfig.class, CachingConfig.class, DatabaseConfig.class})
47+
@Import({SchedulerConfig.class, CachingConfig.class, DatabaseConfig.class, QueueConfig.class, PluginConfig.class})
5148
public class AppConfig extends AppConfigBase {
5249

5350
public final static String NAME = "API";
@@ -78,6 +75,12 @@ public class AppConfig extends AppConfigBase {
7875
@Value("${api.workspace}")
7976
private String workspace;
8077

78+
@Value("${api.git.cache}")
79+
private String gitCloneCache;
80+
81+
@Value("${api.git.workspace}")
82+
private String gitWorkspace;
83+
8184
@Value("${domain.cc}")
8285
private String ccDomain;
8386

@@ -98,14 +101,17 @@ public User superUser() {
98101
@Bean
99102
public Path workspace() {
100103
try {
101-
Path dir = Files.createDirectories(Paths.get(workspace));
102-
LOGGER.trace("flow.ci working dir been created : %s", dir);
103-
return dir;
104+
return Files.createDirectories(Paths.get(workspace));
104105
} catch (IOException e) {
105106
throw new RuntimeException("Fail to create flow.ci api working dir", e);
106107
}
107108
}
108109

110+
@Bean
111+
public Path gitWorkspace() {
112+
return Paths.get(gitWorkspace);
113+
}
114+
109115
@Bean(name = "applicationEventMulticaster")
110116
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
111117
multicasterExecutor.initialize();
@@ -130,14 +136,6 @@ public ThreadPoolTaskExecutor taskExecutor() {
130136
return executor;
131137
}
132138

133-
/**
134-
* Queue to process cmd callback task
135-
*/
136-
@Bean
137-
public PlatformQueue<PriorityMessage> cmdCallbackQueue() {
138-
return new InMemoryQueue<>(executor, 50, "CmdCallbackQueue");
139-
}
140-
141139
@Override
142140
protected String getName() {
143141
return NAME;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.flow.platform.api.config;
18+
19+
import com.flow.platform.api.service.SyncService;
20+
import com.flow.platform.core.queue.MemoryQueue;
21+
import com.flow.platform.core.queue.PriorityMessage;
22+
import com.flow.platform.queue.PlatformQueue;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.beans.factory.annotation.Configurable;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
27+
28+
/**
29+
* @author yang
30+
*/
31+
@Configurable
32+
public class QueueConfig {
33+
34+
@Autowired
35+
private ThreadPoolTaskExecutor taskExecutor;
36+
37+
/**
38+
* Queue to process cmd callback task
39+
*/
40+
@Bean
41+
public PlatformQueue<PriorityMessage> cmdCallbackQueue() {
42+
return new MemoryQueue(taskExecutor, 50, "CmdCallbackQueue");
43+
}
44+
45+
@Bean
46+
public SyncService.QueueCreator syncQueueCreator() {
47+
return name -> new MemoryQueue(taskExecutor, 50, name);
48+
}
49+
}

platform-api/src/main/java/com/flow/platform/api/config/WebConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@
4242
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
4343
import org.springframework.http.MediaType;
4444
import org.springframework.http.converter.HttpMessageConverter;
45-
import org.springframework.scheduling.annotation.EnableScheduling;
4645
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
4746
import org.springframework.security.web.util.matcher.RequestMatcher;
48-
import org.springframework.web.context.request.WebRequestInterceptor;
4947
import org.springframework.web.multipart.MultipartResolver;
5048
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
5149
import org.springframework.web.servlet.config.annotation.CorsRegistry;
@@ -65,6 +63,8 @@
6563
"com.flow.platform.api.context",
6664
"com.flow.platform.api.util",
6765
"com.flow.platform.api.consumer",
66+
"com.flow.platform.plugin.service",
67+
"com.flow.platform.plugin.consumer",
6868
"com.flow.platform.api.initializers"})
6969
@Import({AppConfig.class})
7070
public class WebConfig extends WebMvcConfigurerAdapter {

platform-api/src/main/java/com/flow/platform/api/consumer/CmdCallbackQueueConsumer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import com.flow.platform.api.service.job.JobService;
2121
import com.flow.platform.core.exception.FlowException;
2222
import com.flow.platform.core.exception.NotFoundException;
23-
import com.flow.platform.core.queue.PlatformQueue;
2423
import com.flow.platform.core.queue.PriorityMessage;
25-
import com.flow.platform.core.queue.QueueListener;
2624
import com.flow.platform.core.util.ThreadUtil;
25+
import com.flow.platform.queue.PlatformQueue;
26+
import com.flow.platform.queue.QueueListener;
2727
import com.flow.platform.util.Logger;
2828
import javax.annotation.PostConstruct;
2929
import org.springframework.beans.factory.annotation.Autowired;

0 commit comments

Comments
 (0)