Skip to content

Commit f035e5b

Browse files
committed
code clean up about host offline timeout
1 parent 403bf8a commit f035e5b

File tree

4 files changed

+7
-76
lines changed

4 files changed

+7
-76
lines changed

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

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@
1616

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

19-
import java.time.Instant;
20-
import java.time.temporal.ChronoUnit;
21-
import java.util.Date;
22-
import java.util.HashSet;
23-
import java.util.Set;
24-
2519
import com.flowci.core.common.domain.Mongoable;
26-
27-
import org.springframework.data.mongodb.core.index.Indexed;
28-
2920
import lombok.Getter;
3021
import lombok.NonNull;
3122
import lombok.Setter;
23+
import org.springframework.data.mongodb.core.index.Indexed;
3224
import org.springframework.data.mongodb.core.mapping.Document;
3325

26+
import java.util.HashSet;
27+
import java.util.Set;
28+
3429
@Getter
3530
@Setter
3631
@Document(collection = "agent_host")
@@ -73,17 +68,7 @@ public enum Type {
7368
/**
7469
* Max agent size on the host
7570
*/
76-
private int maxSize = 10;
77-
78-
/**
79-
* Stop agent container if over the idle seconds
80-
*/
81-
private int maxIdleSeconds = 3600;
82-
83-
/**
84-
* Remove agent container if over the offline seconds
85-
*/
86-
private int maxOfflineSeconds = 600;
71+
private int maxSize = 5;
8772

8873
/**
8974
* Tags for all agent holed by host
@@ -94,18 +79,4 @@ public enum Type {
9479
* Error message if connection fail
9580
*/
9681
private String error;
97-
98-
public boolean isOverMaxIdleSeconds(Date date) {
99-
if (maxIdleSeconds == NoLimit) {
100-
return false;
101-
}
102-
return date.toInstant().plus(maxIdleSeconds, ChronoUnit.SECONDS).isBefore(Instant.now());
103-
}
104-
105-
public boolean isOverMaxOfflineSeconds(Date date) {
106-
if (maxOfflineSeconds == NoLimit) {
107-
return false;
108-
}
109-
return date.toInstant().plus(maxOfflineSeconds, ChronoUnit.SECONDS).isBefore(Instant.now());
110-
}
11182
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ public class CreateOrUpdateSshAgentHost {
4545

4646
private String ip;
4747

48-
private int maxSize = 10;
49-
50-
private int maxIdleSeconds = 3600;
51-
52-
private int maxOfflineSeconds = 600;
48+
private int maxSize = 5;
5349

5450
public AgentHost toObj() {
5551
if (type == AgentHost.Type.SSH) {
@@ -61,8 +57,6 @@ public AgentHost toObj() {
6157
host.setIp(ip);
6258
host.setTags(tags);
6359
host.setMaxSize(maxSize);
64-
host.setMaxIdleSeconds(maxIdleSeconds);
65-
host.setMaxOfflineSeconds(maxOfflineSeconds);
6660
return host;
6761
}
6862

@@ -71,8 +65,6 @@ public AgentHost toObj() {
7165
host.setId(id);
7266
host.setName(name);
7367
host.setMaxSize(maxSize);
74-
host.setMaxIdleSeconds(maxIdleSeconds);
75-
host.setMaxOfflineSeconds(maxOfflineSeconds);
7668
return host;
7769
}
7870

core/src/main/java/com/flowci/core/job/service/LocalTaskServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class LocalTaskServiceImpl implements LocalTaskService {
3737

3838
private static final String DefaultImage = "flowci/plugin-runtime";
3939

40-
private static final int DefaultTimeout = 120; // seconds
40+
private static final int DefaultTimeout = 300; // seconds
4141

4242
@Autowired
4343
private String serverUrl;

core/src/test/java/com/flowci/core/test/agent/AgentHostServiceTest.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
import org.junit.*;
1212
import org.springframework.beans.factory.annotation.Autowired;
1313

14-
import java.sql.Date;
15-
import java.time.Instant;
16-
import java.time.temporal.ChronoUnit;
17-
1814
public class AgentHostServiceTest extends ZookeeperScenario {
1915

2016
@Autowired
@@ -82,34 +78,6 @@ public void should_start_agents_on_host() {
8278
Assert.assertEquals(0, agentService.list().size());
8379
}
8480

85-
@Ignore
86-
@Test
87-
public void should_should_over_time_limit() {
88-
AgentHost host = new LocalUnixAgentHost();
89-
host.setMaxIdleSeconds(1800);
90-
host.setMaxOfflineSeconds(600);
91-
92-
// test idle limit
93-
Instant updatedAt = Instant.now().minus(1, ChronoUnit.HOURS);
94-
Assert.assertTrue(host.isOverMaxIdleSeconds(Date.from(updatedAt)));
95-
96-
updatedAt = Instant.now().minus(2, ChronoUnit.SECONDS);
97-
Assert.assertFalse(host.isOverMaxIdleSeconds(Date.from(updatedAt)));
98-
99-
host.setMaxIdleSeconds(AgentHost.NoLimit);
100-
Assert.assertFalse(host.isOverMaxIdleSeconds(Date.from(updatedAt)));
101-
102-
// test offline limit
103-
updatedAt = Instant.now().minus(2, ChronoUnit.HOURS);
104-
Assert.assertTrue(host.isOverMaxOfflineSeconds(Date.from(updatedAt)));
105-
106-
updatedAt = Instant.now().minus(5, ChronoUnit.MINUTES);
107-
Assert.assertFalse(host.isOverMaxOfflineSeconds(Date.from(updatedAt)));
108-
109-
host.setMaxIdleSeconds(AgentHost.NoLimit);
110-
Assert.assertFalse(host.isOverMaxOfflineSeconds(Date.from(updatedAt)));
111-
}
112-
11381
@Ignore
11482
@Test
11583
public void should_sync_agents() {

0 commit comments

Comments
 (0)