30 | * So that instances created are auto-registered with the server, the agent instance MUST have an
31 | * autoregister.properties
file.
32 | * @param request the request object
33 | * @param pluginRequest the plugin request object
34 | * @param consoleLogAppender appender for console log
35 | */
36 | T create(CreateAgentRequest request, PluginRequest pluginRequest, ConsoleLogAppender consoleLogAppender) throws Exception;
37 |
38 | /**
39 | * This message is sent when the plugin needs to terminate the agent instance.
40 | *
41 | * @param agentId the elastic agent id
42 | * @param settings the plugin settings object
43 | */
44 | void terminate(String agentId, PluginSettings settings) throws Exception;
45 |
46 | /**
47 | * This message is sent from the {@link cd.go.contrib.elasticagents.docker.executors.ServerPingRequestExecutor}
48 | * to terminate instances that did not register with the server after a timeout. The timeout may be configurable and
49 | * set via the {@link PluginSettings} instance that is passed in.
50 | *
51 | * @param settings the plugin settings object
52 | * @param agents the list of all the agents
53 | */
54 | void terminateUnregisteredInstances(PluginSettings settings, Agents agents) throws Exception;
55 |
56 | /**
57 | * This message is sent from the {@link cd.go.contrib.elasticagents.docker.executors.ServerPingRequestExecutor}
58 | * to filter out any new agents, that have registered before the timeout period. The timeout may be configurable and
59 | * set via the {@link PluginSettings} instance that is passed in.
60 | *
61 | * @param settings the plugin settings object
62 | * @param agents the list of all the agents
63 | * @return a list of agent instances which were created after {@link PluginSettings#getAutoRegisterPeriod()} ago.
64 | */
65 | Agents instancesCreatedAfterTimeout(PluginSettings settings, Agents agents);
66 |
67 | /**
68 | * This message is sent after plugin initialization time so that the plugin may connect to the cloud provider
69 | * and fetch a list of all instances that have been spun up by this plugin (before the server was shut down).
70 | * This call should be should ideally remember if the agent instances are refreshed from the cluster,
71 | * and do nothing if instances were previously refreshed.
72 | *
73 | * @param clusterProfileProperties the list of cluster profile properties
74 | */
75 | void refreshAll(ClusterProfileProperties clusterProfileProperties) throws Exception;
76 |
77 | /**
78 | * This
79 | * Returns an agent instance with the specified id
or null
, if the agent is not found.
80 | *
81 | * @param agentId the elastic agent id
82 | */
83 | T find(String agentId);
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/cd/go/contrib/elasticagents/docker/Agents.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 Thoughtworks, Inc.
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 cd.go.contrib.elasticagents.docker;
18 |
19 | import java.util.*;
20 | import java.util.function.Predicate;
21 | import java.util.stream.Collectors;
22 |
23 | /**
24 | * Represents a map of {@link Agent#elasticAgentId()} to the {@link Agent} for easy lookups
25 | */
26 | public class Agents {
27 |
28 | private final Map
11 | *
14 | * The "cpus" settings is not allowed by the Spotify docker client yet.
15 | * Once the client supports the parameter, this can be simplified.
16 | * Currently, the "cpus" value is translated as it is written in documentation:
17 | * --cpus="1.5" is equivalent of setting --cpu-period="100000"
18 | * and --cpu-quota="150000".
19 | *
20 | * @see Docker CPU settings.
21 | */
22 | public class CpusSpecification {
23 | private List
16 | *
19 | */
20 | public class MemorySpecification {
21 | private static final Pattern PATTERN = Pattern.compile("(\\d+(\\.\\d+)?)(\\D)");
22 |
23 | private static final Map
15 | *
16 | * Support host config cpus
17 | */
18 | public class CpusMetadata extends Metadata {
19 | public CpusMetadata(String key) {
20 | super(key);
21 | }
22 |
23 | @Override
24 | protected String doValidate(String input) {
25 | final List