use of com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgent in project vespa by vespa-engine.
the class NodeAdminImpl method updateNodeAgentMetrics.
private void updateNodeAgentMetrics() {
int numberContainersWaitingImage = 0;
int numberOfNewUnhandledExceptions = 0;
for (NodeAgent nodeAgent : nodeAgents.values()) {
if (nodeAgent.isDownloadingImage())
numberContainersWaitingImage++;
numberOfNewUnhandledExceptions += nodeAgent.getAndResetNumberOfUnhandledExceptions();
}
numberOfContainersInLoadImageState.sample(numberContainersWaitingImage);
numberOfUnhandledExceptionsInNodeAgent.add(numberOfNewUnhandledExceptions);
}
use of com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgent in project vespa by vespa-engine.
the class NodeAdminImpl method ensureNodeAgentForNodeIsStarted.
private void ensureNodeAgentForNodeIsStarted(ContainerName containerName, String hostname) {
if (nodeAgents.containsKey(containerName)) {
return;
}
final NodeAgent agent = nodeAgentFactory.apply(hostname);
agent.start();
nodeAgents.put(containerName, agent);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.info("Interrupted while waiting between starting node-agents");
}
}
use of com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgent in project vespa by vespa-engine.
the class NodeAdminImplTest method mockNodeAgentSetFrozenResponse.
private void mockNodeAgentSetFrozenResponse(List<NodeAgent> nodeAgents, boolean... responses) {
for (int i = 0; i < nodeAgents.size(); i++) {
NodeAgent nodeAgent = nodeAgents.get(i);
when(nodeAgent.setFrozen(anyBoolean())).thenReturn(responses[i]);
}
}
use of com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgent in project vespa by vespa-engine.
the class NodeAdminImplTest method testSetFrozen.
@Test
public void testSetFrozen() throws Exception {
List<NodeAgent> nodeAgents = new ArrayList<>();
List<String> existingContainerHostnames = new ArrayList<>();
for (int i = 0; i < 3; i++) {
final String hostName = "host" + i + ".test.yahoo.com";
NodeAgent nodeAgent = mock(NodeAgent.class);
nodeAgents.add(nodeAgent);
when(nodeAgentFactory.apply(eq(hostName))).thenReturn(nodeAgent);
existingContainerHostnames.add(hostName);
}
nodeAdmin.synchronizeNodeSpecsToNodeAgents(existingContainerHostnames, existingContainerHostnames.stream().map(ContainerName::fromHostname).collect(Collectors.toList()));
// Initially everything is frozen to force convergence
assertTrue(nodeAdmin.isFrozen());
mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true);
// Unfreeze everything
assertTrue(nodeAdmin.setFrozen(false));
mockNodeAgentSetFrozenResponse(nodeAgents, false, false, false);
// NodeAdmin freezes only when all the NodeAgents are frozen
assertFalse(nodeAdmin.setFrozen(true));
mockNodeAgentSetFrozenResponse(nodeAgents, false, true, true);
assertFalse(nodeAdmin.setFrozen(true));
assertFalse(nodeAdmin.isFrozen());
mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true);
assertTrue(nodeAdmin.setFrozen(true));
assertTrue(nodeAdmin.isFrozen());
mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true);
assertTrue(nodeAdmin.setFrozen(true));
assertTrue(nodeAdmin.isFrozen());
mockNodeAgentSetFrozenResponse(nodeAgents, false, false, false);
assertFalse(nodeAdmin.setFrozen(false));
// NodeAdmin unfreezes instantly
assertFalse(nodeAdmin.isFrozen());
mockNodeAgentSetFrozenResponse(nodeAgents, false, false, true);
assertFalse(nodeAdmin.setFrozen(false));
assertFalse(nodeAdmin.isFrozen());
mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true);
assertTrue(nodeAdmin.setFrozen(false));
assertFalse(nodeAdmin.isFrozen());
}
use of com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgent in project vespa by vespa-engine.
the class NodeAdminImplTest method nodeAgentsAreProperlyLifeCycleManaged.
@Test
public void nodeAgentsAreProperlyLifeCycleManaged() throws Exception {
final String hostName1 = "host1.test.yahoo.com";
final String hostName2 = "host2.test.yahoo.com";
final ContainerName containerName1 = ContainerName.fromHostname(hostName1);
final NodeAgent nodeAgent1 = mock(NodeAgentImpl.class);
final NodeAgent nodeAgent2 = mock(NodeAgentImpl.class);
when(nodeAgentFactory.apply(eq(hostName1))).thenReturn(nodeAgent1);
when(nodeAgentFactory.apply(eq(hostName2))).thenReturn(nodeAgent2);
final InOrder inOrder = inOrder(nodeAgentFactory, nodeAgent1, nodeAgent2);
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.emptyList(), Collections.singletonList(containerName1));
verifyNoMoreInteractions(nodeAgentFactory);
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.singletonList(hostName1), Collections.singletonList(containerName1));
inOrder.verify(nodeAgentFactory).apply(hostName1);
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();
inOrder.verify(nodeAgent1, never()).stop();
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.emptyList(), Collections.singletonList(containerName1));
inOrder.verify(nodeAgentFactory, never()).apply(any(String.class));
verify(nodeAgent1).stop();
nodeAdmin.synchronizeNodeSpecsToNodeAgents(Collections.singletonList(hostName2), Collections.singletonList(containerName1));
inOrder.verify(nodeAgentFactory).apply(hostName2);
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();
inOrder.verify(nodeAgent2).stop();
verifyNoMoreInteractions(nodeAgent1);
verifyNoMoreInteractions(nodeAgent2);
}
Aggregations