diff options
author | Valerij Fredriksen <valerijf@oath.com> | 2017-09-19 12:37:32 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@oath.com> | 2017-09-22 22:16:19 +0200 |
commit | 4a712bf9bb58c44268459cf4fa6753493ced3608 (patch) | |
tree | 1c98a45a5044b3ddfd5fabe2bf4a09c8d1d0cecd /node-admin/src/main/java/com | |
parent | 47b852f9fed12d045fe0dda2172362485954fb80 (diff) |
Take NodeAgent interval in constructor
Diffstat (limited to 'node-admin/src/main/java/com')
3 files changed, 13 insertions, 14 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java index e39abb47788..e38a17786cd 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java @@ -55,8 +55,6 @@ public class NodeAdminImpl implements NodeAdmin { private final Map<ContainerName, NodeAgent> nodeAgents = new ConcurrentHashMap<>(); - private final int nodeAgentScanIntervalMillis; - private final GaugeWrapper numberOfContainersInLoadImageState; private final CounterWrapper numberOfUnhandledExceptionsInNodeAgent; @@ -64,13 +62,11 @@ public class NodeAdminImpl implements NodeAdmin { final Function<String, NodeAgent> nodeAgentFactory, final StorageMaintainer storageMaintainer, final AclMaintainer aclMaintainer, - final int nodeAgentScanIntervalMillis, final MetricReceiverWrapper metricReceiver, final Clock clock) { this.dockerOperations = dockerOperations; this.nodeAgentFactory = nodeAgentFactory; this.storageMaintainer = storageMaintainer; - this.nodeAgentScanIntervalMillis = nodeAgentScanIntervalMillis; this.clock = clock; this.previousWantFrozen = true; @@ -257,7 +253,7 @@ public class NodeAdminImpl implements NodeAdmin { } final NodeAgent agent = nodeAgentFactory.apply(hostname); - agent.start(nodeAgentScanIntervalMillis); + agent.start(); nodeAgents.put(containerName, agent); try { Thread.sleep(1000); diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgent.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgent.java index 5d31c10fcc1..92c44969d5e 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgent.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgent.java @@ -29,7 +29,7 @@ public interface NodeAgent { * Starts the agent. After this method is called, the agent will asynchronously maintain the node, continuously * striving to make the current state equal to the wanted state. */ - void start(int intervalMillis); + void start(); /** * Signals to the agent that the node is at the end of its lifecycle and no longer needs a managing agent. diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java index 6ea65be6799..4f07658f320 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java @@ -64,20 +64,20 @@ public class NodeAgentImpl implements NodeAgent { private final PrefixLogger logger; private DockerImage imageBeingDownloaded = null; - private final String hostname; private final ContainerName containerName; + private final String hostname; private final NodeRepository nodeRepository; private final Orchestrator orchestrator; private final DockerOperations dockerOperations; private final StorageMaintainer storageMaintainer; + private final AclMaintainer aclMaintainer; private final Environment environment; private final Clock clock; - private final AclMaintainer aclMaintainer; + private final Duration timeBetweenEachConverge; private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final LinkedList<String> debugMessages = new LinkedList<>(); - private long delaysBetweenEachConvergeMillis = 30_000; private int numberOfUnhandledException = 0; private Instant lastConverge; @@ -117,7 +117,8 @@ public class NodeAgentImpl implements NodeAgent { final StorageMaintainer storageMaintainer, final AclMaintainer aclMaintainer, final Environment environment, - final Clock clock) { + final Clock clock, + final Duration timeBetweenEachConverge) { this.containerName = ContainerName.fromHostname(hostName); this.logger = PrefixLogger.getNodeAgentLogger(NodeAgentImpl.class, containerName); this.hostname = hostName; @@ -128,7 +129,9 @@ public class NodeAgentImpl implements NodeAgent { this.aclMaintainer = aclMaintainer; this.environment = environment; this.clock = clock; + this.timeBetweenEachConverge = timeBetweenEachConverge; this.lastConverge = clock.instant(); + this.serviceRestarter = service -> { try { ProcessResult processResult = dockerOperations.executeCommandInContainerAsRoot( @@ -183,11 +186,11 @@ public class NodeAgentImpl implements NodeAgent { } @Override - public void start(int intervalMillis) { - String message = "Starting with interval " + intervalMillis + " ms"; + public void start() { + String message = "Starting with interval " + timeBetweenEachConverge.toMillis() + " ms"; logger.info(message); addDebugMessage(message); - delaysBetweenEachConvergeMillis = intervalMillis; + if (loopThread != null) { throw new RuntimeException("Can not restart a node agent."); } @@ -375,7 +378,7 @@ public class NodeAgentImpl implements NodeAgent { boolean isFrozenCopy; synchronized (monitor) { while (!workToDoNow) { - long remainder = delaysBetweenEachConvergeMillis - Duration.between(lastConverge, clock.instant()).toMillis(); + long remainder = timeBetweenEachConverge.minus(Duration.between(lastConverge, clock.instant())).toMillis(); if (remainder > 0) { try { monitor.wait(remainder); |