summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@oath.com>2017-09-19 12:37:32 +0200
committerValerij Fredriksen <valerijf@oath.com>2017-09-22 09:13:01 +0200
commitd22657f665119997a3a1f338c950d78a62619e08 (patch)
tree16ab9632bc51f4917fbc6c34450d854ea9bad46f
parent57e34c696f3a38b65da4b66bc47ebfbb8e30d018 (diff)
Take NodeAgent interval in constructor
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java6
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgent.java2
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java19
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImplTest.java11
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java3
5 files changed, 20 insertions, 21 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);
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImplTest.java
index d3bce7919e6..582992869aa 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImplTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImplTest.java
@@ -31,7 +31,6 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
@@ -53,7 +52,7 @@ public class NodeAdminImplTest {
private final ManualClock clock = new ManualClock();
private final NodeAdminImpl nodeAdmin = new NodeAdminImpl(dockerOperations, nodeAgentFactory, storageMaintainer, aclMaintainer,
- 100, new MetricReceiverWrapper(MetricReceiver.nullImplementation), clock);
+ new MetricReceiverWrapper(MetricReceiver.nullImplementation), clock);
@Test
public void nodeAgentsAreProperlyLifeCycleManaged() throws Exception {
@@ -72,12 +71,12 @@ public class NodeAdminImplTest {
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.singletonList(hostName1), Collections.singletonList(containerName1));
inOrder.verify(nodeAgentFactory).apply(hostName1);
- inOrder.verify(nodeAgent1).start(100);
+ inOrder.verify(nodeAgent1).start();
inOrder.verify(nodeAgent1, never()).stop();
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.singletonList(hostName1), Collections.singletonList(containerName1));
inOrder.verify(nodeAgentFactory, never()).apply(any(String.class));
- inOrder.verify(nodeAgent1, never()).start(anyInt());
+ inOrder.verify(nodeAgent1, never()).start();
inOrder.verify(nodeAgent1, never()).stop();
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.emptyList(), Collections.singletonList(containerName1));
@@ -86,13 +85,13 @@ public class NodeAdminImplTest {
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.singletonList(hostName2), Collections.singletonList(containerName1));
inOrder.verify(nodeAgentFactory).apply(hostName2);
- inOrder.verify(nodeAgent2).start(100);
+ inOrder.verify(nodeAgent2).start();
inOrder.verify(nodeAgent2, never()).stop();
verify(nodeAgent1).stop();
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.emptyList(), Collections.emptyList());
inOrder.verify(nodeAgentFactory, never()).apply(any(String.class));
- inOrder.verify(nodeAgent2, never()).start(anyInt());
+ inOrder.verify(nodeAgent2, never()).start();
inOrder.verify(nodeAgent2).stop();
verifyNoMoreInteractions(nodeAgent1);
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java
index fd3e72d7eac..ceaa1d58f92 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java
@@ -57,6 +57,7 @@ import static org.mockito.Mockito.when;
* @author bakksjo
*/
public class NodeAgentImplTest {
+ private static final Duration NODE_AGENT_SCAN_INTERVAL = Duration.ofSeconds(30);
private static final double MIN_CPU_CORES = 2;
private static final double MIN_MAIN_MEMORY_AVAILABLE_GB = 16;
private static final double MIN_DISK_AVAILABLE_GB = 250;
@@ -621,6 +622,6 @@ public class NodeAgentImplTest {
doNothing().when(storageMaintainer).writeMetricsConfig(any(), any());
return new NodeAgentImpl(hostName, nodeRepository, orchestrator, dockerOperations,
- storageMaintainer, aclMaintainer, environment, clock);
+ storageMaintainer, aclMaintainer, environment, clock, NODE_AGENT_SCAN_INTERVAL);
}
}