Skip to content

Commit 3f7d684

Browse files
authored
Merge pull request #389 from FlowCI/develop
Develop
2 parents 9d64c7d + 063b8e9 commit 3f7d684

File tree

132 files changed

+3695
-1856
lines changed

Some content is hidden

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

132 files changed

+3695
-1856
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ target/
77
.settings/
88
.classpath
99
.factorypath
10-
*Proto.java
10+
*Proto.java
11+
.run/

.run/Application - 1.run.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.run/Application - 2.run.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

core/src/main/java/com/flowci/core/agent/controller/AgentAuth.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

core/src/main/java/com/flowci/core/agent/controller/AgentController.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616

1717
package com.flowci.core.agent.controller;
1818

19+
import com.flowci.core.agent.domain.Agent;
1920
import com.flowci.core.agent.domain.AgentAction;
2021
import com.flowci.core.agent.domain.CreateOrUpdateAgent;
2122
import com.flowci.core.agent.domain.DeleteAgent;
2223
import com.flowci.core.agent.service.AgentService;
2324
import com.flowci.core.auth.annotation.Action;
24-
import com.flowci.core.job.service.LoggingService;
25-
import com.flowci.core.agent.domain.Agent;
2625
import lombok.extern.log4j.Log4j2;
2726
import org.springframework.beans.factory.annotation.Autowired;
2827
import org.springframework.validation.annotation.Validated;
2928
import org.springframework.web.bind.annotation.*;
30-
import org.springframework.web.multipart.MultipartFile;
3129

32-
import java.io.IOException;
33-
import java.io.InputStream;
3430
import java.util.List;
3531
import java.util.Optional;
3632

@@ -45,9 +41,6 @@ public class AgentController {
4541
@Autowired
4642
private AgentService agentService;
4743

48-
@Autowired
49-
private LoggingService loggingService;
50-
5144
@GetMapping("/{name}")
5245
@Action(AgentAction.GET)
5346
public Agent getByName(@PathVariable String name) {
@@ -75,23 +68,4 @@ public Agent createOrUpdate(@Validated @RequestBody CreateOrUpdateAgent body) {
7568
public Agent delete(@Validated @RequestBody DeleteAgent body) {
7669
return agentService.delete(body.getToken());
7770
}
78-
79-
// --------------------------------------------------------
80-
// Functions require agent token header
81-
// --------------------------------------------------------
82-
83-
@PostMapping("/api/profile")
84-
public void profile(@RequestHeader(AgentAuth.HeaderAgentToken) String token,
85-
@RequestBody Agent.Resource resource) {
86-
agentService.update(token, resource);
87-
}
88-
89-
@PostMapping("/api/logs/upload")
90-
public void upload(@RequestPart("file") MultipartFile file) {
91-
try(InputStream stream = file.getInputStream()) {
92-
loggingService.save(file.getOriginalFilename(), stream);
93-
} catch (IOException e) {
94-
log.warn("Unable to save log, cause {}", e.getMessage());
95-
}
96-
}
9771
}

core/src/main/java/com/flowci/core/agent/controller/AgentHostController.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@ public AgentHost getByName(@PathVariable String name) {
5151
@DeleteMapping("/{name}")
5252
@Action(AgentHostAction.DELETE)
5353
public AgentHost deleteByName(@PathVariable String name) {
54-
AgentHost host = agentHostService.get(name);
55-
agentHostService.delete(host);
56-
return host;
54+
return agentHostService.delete(name);
5755
}
5856

5957
@PostMapping
6058
@Action(AgentHostAction.CREATE_UPDATE)
6159
public AgentHost createOrUpdate(@RequestBody @Validated SaveAgentHost body) {
6260
AgentHost host = body.toObj();
63-
agentHostService.createOrUpdate(host);
64-
return host;
61+
return agentHostService.createOrUpdate(host);
6562
}
6663

6764
@PostMapping("/{name}/test")
@@ -70,4 +67,10 @@ public void testConnection(@PathVariable String name) {
7067
AgentHost host = agentHostService.get(name);
7168
agentHostService.testConn(host);
7269
}
70+
71+
@PostMapping("/{name}/switch/{value}")
72+
@Action(AgentHostAction.CREATE_UPDATE)
73+
public AgentHost disableOrEnableByName(@PathVariable String name, @PathVariable boolean value) {
74+
return agentHostService.disableOrEnable(name, value);
75+
}
7376
}

core/src/main/java/com/flowci/core/agent/dao/AgentDao.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
import org.springframework.stereotype.Repository;
2222

2323
import java.util.List;
24-
import java.util.Set;
2524

2625
/**
2726
* @author yang
2827
*/
2928
@Repository
3029
public interface AgentDao extends MongoRepository<Agent, String>, CustomAgentDao {
3130

32-
List<Agent> findAllByTagsIn(Set<String> tags);
33-
3431
List<Agent> findAllByHostId(String hostId);
3532

3633
Agent findByToken(String token);

core/src/main/java/com/flowci/core/agent/dao/CustomAgentDao.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import com.flowci.core.agent.domain.Agent;
44

5+
import java.util.Collection;
6+
import java.util.List;
7+
58
public interface CustomAgentDao {
69

710
long updateAllStatus(Agent.Status status);
11+
12+
List<Agent> findAll(Collection<String> tags, Collection<Agent.Status> statuses);
813
}

core/src/main/java/com/flowci/core/agent/dao/CustomAgentDaoImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package com.flowci.core.agent.dao;
22

33
import com.flowci.core.agent.domain.Agent;
4+
import com.flowci.util.ObjectsHelper;
45
import com.mongodb.client.result.UpdateResult;
56
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.data.mongodb.core.MongoOperations;
8+
import org.springframework.data.mongodb.core.query.Criteria;
79
import org.springframework.data.mongodb.core.query.Query;
810
import org.springframework.data.mongodb.core.query.Update;
911

12+
import java.util.Collection;
13+
import java.util.List;
14+
1015
public class CustomAgentDaoImpl implements CustomAgentDao {
1116

1217
@Autowired
@@ -17,4 +22,23 @@ public long updateAllStatus(Agent.Status status) {
1722
UpdateResult r = operations.updateMulti(new Query(), new Update().set("status", status), Agent.class);
1823
return r.getModifiedCount();
1924
}
25+
26+
@Override
27+
public List<Agent> findAll(Collection<String> tags, Collection<Agent.Status> statuses) {
28+
Query q = new Query();
29+
30+
if (ObjectsHelper.hasCollection(tags)) {
31+
q.addCriteria(Criteria.where("tags").in(tags));
32+
} else {
33+
q.addCriteria(Criteria.where("tags.0").exists(false));
34+
}
35+
36+
if (ObjectsHelper.hasCollection(statuses)) {
37+
q.addCriteria(Criteria.where("status").in(statuses));
38+
}
39+
40+
return operations.find(q, Agent.class);
41+
}
42+
43+
2044
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.flowci.core.common.domain.Mongoable;
2121
import com.flowci.domain.Common.OS;
2222
import com.flowci.domain.SimpleKeyPair;
23+
import com.flowci.tree.Selector;
2324
import com.google.common.base.Strings;
2425
import lombok.*;
2526
import lombok.experimental.Accessors;
@@ -29,6 +30,7 @@
2930
import java.time.Instant;
3031
import java.util.Collections;
3132
import java.util.Date;
33+
import java.util.HashSet;
3234
import java.util.Set;
3335

3436
/**
@@ -116,14 +118,18 @@ public Agent(String name) {
116118

117119
public Agent(String name, Set<String> tags) {
118120
this.name = name;
119-
this.tags = tags;
121+
this.setTags(tags);
120122
}
121123

122124
public void setStatus(Status status) {
123125
this.status = status;
124126
this.statusUpdatedAt = new Date();
125127
}
126128

129+
public void setTags(Set<String> tags) {
130+
this.tags = tags == null ? Collections.emptySet() : tags;
131+
}
132+
127133
@JsonIgnore
128134
public boolean isStartingOver(int seconds) {
129135
if (status == Status.STARTING) {
@@ -169,4 +175,14 @@ public boolean isOnline() {
169175
public boolean isStarting() {
170176
return status == Status.STARTING;
171177
}
178+
179+
public boolean match(Selector selector) {
180+
Set<String> labels = new HashSet<>(selector.getLabel());
181+
if (labels.isEmpty() && tags.isEmpty()) {
182+
return true;
183+
}
184+
185+
labels.retainAll(tags);
186+
return !labels.isEmpty();
187+
}
172188
}

0 commit comments

Comments
 (0)