Skip to content

Commit bee8fd7

Browse files
authored
Merge pull request #407 from FlowCI/develop
Develop
2 parents 462e88d + 57a4c95 commit bee8fd7

38 files changed

+301
-144
lines changed

core/src/main/java/com/flowci/core/Application.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,34 @@
1616

1717
package com.flowci.core;
1818

19+
import com.flowci.util.StringHelper;
20+
import lombok.extern.log4j.Log4j2;
21+
import org.springframework.beans.factory.annotation.Autowired;
1922
import org.springframework.boot.SpringApplication;
2023
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
import org.springframework.context.event.ContextRefreshedEvent;
25+
import org.springframework.context.event.EventListener;
26+
import org.springframework.core.io.Resource;
27+
import org.springframework.core.io.ResourceLoader;
28+
29+
import java.io.IOException;
2130

2231
/**
2332
* @author yang
2433
*/
34+
@Log4j2
2535
@SpringBootApplication
2636
public class Application {
2737

38+
@Autowired
39+
private ResourceLoader resourceLoader;
40+
41+
@EventListener(ContextRefreshedEvent.class)
42+
public void printBanner() throws IOException {
43+
Resource r = resourceLoader.getResource("classpath:welcome.txt");
44+
log.info(StringHelper.toString(r.getInputStream()));
45+
}
46+
2847
public static void main(String[] args) {
2948
SpringApplication.run(Application.class, args);
3049
}

core/src/main/java/com/flowci/core/agent/domain/ShellIn.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public enum ShellType {
5252

5353
private Set<String> secrets;
5454

55+
private Set<String> configs;
56+
5557
public ShellIn() {
5658
super(Type.SHELL);
5759
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import lombok.AllArgsConstructor;
4848
import lombok.extern.log4j.Log4j2;
4949
import org.springframework.beans.factory.annotation.Autowired;
50-
import org.springframework.context.event.ContextRefreshedEvent;
5150
import org.springframework.context.event.EventListener;
5251
import org.springframework.core.env.Environment;
5352
import org.springframework.core.task.TaskExecutor;
@@ -56,6 +55,7 @@
5655

5756
import javax.annotation.Nonnull;
5857
import javax.annotation.Nullable;
58+
import javax.annotation.PostConstruct;
5959
import java.nio.file.Files;
6060
import java.nio.file.Paths;
6161
import java.util.*;
@@ -114,6 +114,12 @@ public class AgentHostServiceImpl implements AgentHostService {
114114
mapping.put(K8sAgentHost.class, new K8sHostAdaptor());
115115
}
116116

117+
@PostConstruct
118+
public void init() {
119+
autoCreateLocalAgentHost();
120+
syncAgents();
121+
}
122+
117123
//====================================================================
118124
// %% Public functions
119125
//====================================================================
@@ -378,12 +384,6 @@ public void scheduleCollect() {
378384
// %% Internal events
379385
//====================================================================
380386

381-
@EventListener
382-
public void onContextReady(ContextRefreshedEvent event) {
383-
autoCreateLocalAgentHost();
384-
syncAgents();
385-
}
386-
387387
@EventListener
388388
public void onNoIdleAgent(NoIdleAgentEvent event) {
389389
Set<String> agentTags = event.getSelector().getLabel();

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
import com.google.common.collect.Sets;
4343
import lombok.extern.log4j.Log4j2;
4444
import org.springframework.beans.factory.annotation.Autowired;
45-
import org.springframework.context.event.ContextRefreshedEvent;
4645
import org.springframework.context.event.EventListener;
4746
import org.springframework.dao.DuplicateKeyException;
4847
import org.springframework.stereotype.Service;
4948

49+
import javax.annotation.PostConstruct;
5050
import java.io.IOException;
5151
import java.time.Instant;
5252
import java.util.*;
@@ -108,7 +108,7 @@ public class AgentServiceImpl implements AgentService {
108108
@Autowired
109109
private SocketPushManager socketPushManager;
110110

111-
@EventListener(ContextRefreshedEvent.class)
111+
@PostConstruct
112112
public void initAgentStatus() {
113113
taskManager.run("init-agent-status", true, () -> {
114114
for (Agent agent : agentDao.findAll()) {
@@ -122,7 +122,7 @@ public void initAgentStatus() {
122122
});
123123
}
124124

125-
@EventListener(ContextRefreshedEvent.class)
125+
@PostConstruct
126126
public void subscribeIdleAgentQueue() throws IOException {
127127
idleAgentQueueManager.startConsumer(idleAgentQueue, false, (header, body, envelope) -> {
128128
String agentId = new String(body);
@@ -152,6 +152,22 @@ public void subscribeIdleAgentQueue() throws IOException {
152152
}, null);
153153
}
154154

155+
@PostConstruct
156+
public void lockNodeCleanup() {
157+
List<String> children = zk.children(zkProperties.getAgentRoot());
158+
for (String path : children) {
159+
String agentId = Util.getAgentIdFromLockPath(path);
160+
Optional<Agent> optional = agentDao.findById(agentId);
161+
162+
if (!optional.isPresent()) {
163+
try {
164+
zk.delete(path, true);
165+
} catch (Throwable ignore) {
166+
}
167+
}
168+
}
169+
}
170+
155171
//====================================================================
156172
// %% Public Methods
157173
//====================================================================
@@ -369,22 +385,6 @@ public void dispatch(CmdIn cmd, Agent agent) {
369385
// %% Spring Event Listener
370386
//====================================================================
371387

372-
@EventListener(ContextRefreshedEvent.class)
373-
public void lockNodeCleanup() {
374-
List<String> children = zk.children(zkProperties.getAgentRoot());
375-
for (String path : children) {
376-
String agentId = Util.getAgentIdFromLockPath(path);
377-
Optional<Agent> optional = agentDao.findById(agentId);
378-
379-
if (!optional.isPresent()) {
380-
try {
381-
zk.delete(path, true);
382-
} catch (Throwable ignore) {
383-
}
384-
}
385-
}
386-
}
387-
388388
@EventListener
389389
public void onConnected(OnConnectedEvent event) {
390390
Optional<InterLock> lock = lock();

core/src/main/java/com/flowci/core/api/OpenRestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Secret getSecret(@PathVariable String name) {
7373

7474
if (secret instanceof RSASecret) {
7575
RSASecret rsa = (RSASecret) secret;
76-
rsa.setPublicKey(null);
76+
rsa.setPrivateKey(null);
7777
}
7878

7979
return secret;

core/src/main/java/com/flowci/core/common/config/AppProperties.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.context.annotation.Bean;
2424
import org.springframework.context.annotation.Configuration;
2525
import org.springframework.context.annotation.PropertySource;
26+
import org.springframework.core.io.Resource;
2627
import org.springframework.validation.annotation.Validated;
2728

2829
import javax.validation.constraints.NotBlank;
@@ -51,6 +52,9 @@ public class AppProperties {
5152
@Length(max = 16, min = 16)
5253
private String secret;
5354

55+
// indicate load yaml template and plugin from where
56+
private String resourceDomain;
57+
5458
private boolean autoLocalAgentHost;
5559

5660
private boolean defaultSmtpConfig;
@@ -106,7 +110,7 @@ public Minio minio() {
106110
@Data
107111
public static class Flow {
108112

109-
private String templatesUrl;
113+
private Resource templatesUrl;
110114
}
111115

112116
@Data
@@ -118,7 +122,7 @@ public static class Job {
118122
@Data
119123
public static class Plugin {
120124

121-
private String defaultRepo;
125+
private Resource defaultRepo;
122126

123127
private Boolean autoUpdate;
124128
}

core/src/main/java/com/flowci/core/common/domain/Settings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static class Action {
3232

3333
private String serverUrl;
3434

35+
/**
36+
* Indicate load resource(cn) from where
37+
*/
38+
private String source;
39+
3540
public Settings() {
3641
setId(DefaultId);
3742
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.flowci.core.common.domain;
2+
3+
import com.fasterxml.jackson.annotation.JsonAlias;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.flowci.util.StringHelper;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
9+
import java.io.Serializable;
10+
11+
@Getter
12+
@Setter
13+
public abstract class SourceWithDomain implements Serializable {
14+
15+
private static final String DOMAIN_CN = "cn";
16+
17+
@JsonAlias("url")
18+
private String source;
19+
20+
@JsonAlias("url_cn")
21+
@JsonProperty("source_cn")
22+
private String sourceCn;
23+
24+
public String getSourceWithDomain(String domain) {
25+
if (!StringHelper.hasValue(domain)) return source;
26+
return DOMAIN_CN.equalsIgnoreCase(domain) ? sourceCn : source;
27+
}
28+
}

core/src/main/java/com/flowci/core/common/domain/Variables.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public abstract static class App {
2929

3030
public static final String Host = "FLOWCI_SERVER_HOST";
3131

32+
public static final String ResourceDomain = "FLOWCI_RESOURCE_DOMAIN";
3233
}
3334

3435
public abstract static class Flow {

core/src/main/java/com/flowci/core/common/manager/SocketPushManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
import com.flowci.core.common.rabbit.RabbitOperations;
2424
import lombok.extern.log4j.Log4j2;
2525
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.context.event.ContextRefreshedEvent;
27-
import org.springframework.context.event.EventListener;
2826
import org.springframework.messaging.simp.SimpMessagingTemplate;
2927
import org.springframework.stereotype.Component;
3028

29+
import javax.annotation.PostConstruct;
3130
import java.io.IOException;
3231
import java.util.HashMap;
3332
import java.util.Map;
@@ -56,7 +55,7 @@ public class SocketPushManager {
5655
@Autowired
5756
private RabbitOperations broadcastQueueManager;
5857

59-
@EventListener(ContextRefreshedEvent.class)
58+
@PostConstruct
6059
public void subscribeBroadcastQueue() throws IOException {
6160
broadcastQueueManager.startConsumer(wsBroadcastQueue, true, (headers, body, envelope) -> {
6261
try {

0 commit comments

Comments
 (0)