use of com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec in project vespa by vespa-engine.
the class NodeAgentImplTest method testRunningConfigServer.
@Test
public void testRunningConfigServer() throws IOException {
final long rebootGeneration = 0;
final ContainerNodeSpec nodeSpec = nodeSpecBuilder.nodeType("config").wantedDockerImage(dockerImage).nodeState(Node.State.active).wantedVespaVersion(vespaVersion).build();
System.out.println(nodeSpec);
NodeAgentImpl nodeAgent = makeNodeAgent(null, false);
when(nodeRepository.getContainerNodeSpec(hostName)).thenReturn(Optional.of(nodeSpec));
Path tempDirectory = Files.createTempDirectory("foo");
when(pathResolver.getApplicationStoragePathForHost()).thenReturn(tempDirectory);
when(dockerOperations.pullImageAsyncIfNeeded(eq(dockerImage))).thenReturn(false);
when(storageMaintainer.getDiskUsageFor(eq(containerName))).thenReturn(Optional.of(201326592000L));
nodeAgent.converge();
verify(dockerOperations, never()).removeContainer(any(), any());
verify(orchestrator, never()).suspend(any(String.class));
final InOrder inOrder = inOrder(dockerOperations, orchestrator, nodeRepository, aclMaintainer);
inOrder.verify(dockerOperations, times(1)).pullImageAsyncIfNeeded(eq(dockerImage));
inOrder.verify(dockerOperations, times(1)).createContainer(eq(containerName), eq(nodeSpec));
inOrder.verify(dockerOperations, times(1)).startContainer(eq(containerName), eq(nodeSpec));
inOrder.verify(aclMaintainer, times(1)).run();
inOrder.verify(dockerOperations, times(1)).resumeNode(eq(containerName));
inOrder.verify(nodeRepository).updateNodeAttributes(hostName, new NodeAttributes().withRebootGeneration(rebootGeneration).withDockerImage(dockerImage).withVespaVersion(vespaVersion));
inOrder.verify(orchestrator).resume(hostName);
// Files written in createContainerData()
assertFileExists(containerName, tempDirectory, "node-repository-config.xml");
assertFileExists(containerName, tempDirectory, "configserver-config.xml");
}
use of com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec in project vespa by vespa-engine.
the class NodeAgentImplTest method nodeRunningContainerIsTakenDownAndCleanedAndRecycled.
private void nodeRunningContainerIsTakenDownAndCleanedAndRecycled(Node.State nodeState, Optional<Long> wantedRestartGeneration) {
wantedRestartGeneration.ifPresent(restartGeneration -> nodeSpecBuilder.wantedRestartGeneration(restartGeneration).currentRestartGeneration(restartGeneration));
final ContainerNodeSpec nodeSpec = nodeSpecBuilder.wantedDockerImage(dockerImage).currentDockerImage(dockerImage).nodeState(nodeState).build();
NodeAgentImpl nodeAgent = makeNodeAgent(dockerImage, true);
when(nodeRepository.getContainerNodeSpec(hostName)).thenReturn(Optional.of(nodeSpec));
nodeAgent.converge();
final InOrder inOrder = inOrder(storageMaintainer, dockerOperations, nodeRepository);
inOrder.verify(dockerOperations, times(1)).removeContainer(any(), any());
inOrder.verify(storageMaintainer, times(1)).cleanupNodeStorage(eq(containerName), eq(nodeSpec));
inOrder.verify(nodeRepository, times(1)).markNodeAvailableForNewAllocation(eq(hostName));
verify(dockerOperations, never()).createContainer(eq(containerName), any());
verify(dockerOperations, never()).startContainer(eq(containerName), any());
verify(orchestrator, never()).resume(any(String.class));
verify(orchestrator, never()).suspend(any(String.class));
// current Docker image and vespa version should be cleared
verify(nodeRepository, times(1)).updateNodeAttributes(any(String.class), eq(new NodeAttributes().withRestartGeneration(wantedRestartGeneration.orElse(null)).withRebootGeneration(0L).withDockerImage(new DockerImage("")).withVespaVersion("")));
}
use of com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec in project vespa by vespa-engine.
the class NodeAgentImplTest method provisionedNodeIsMarkedAsDirty.
@Test
public void provisionedNodeIsMarkedAsDirty() {
final ContainerNodeSpec nodeSpec = nodeSpecBuilder.wantedDockerImage(dockerImage).nodeState(Node.State.provisioned).build();
NodeAgentImpl nodeAgent = makeNodeAgent(null, false);
when(nodeRepository.getContainerNodeSpec(hostName)).thenReturn(Optional.of(nodeSpec));
nodeAgent.converge();
verify(nodeRepository, times(1)).markAsDirty(eq(hostName));
}
use of com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec in project vespa by vespa-engine.
the class NodeAgentImplTest method containerIsNotStoppedIfNewImageMustBePulled.
@Test
public void containerIsNotStoppedIfNewImageMustBePulled() {
final DockerImage newDockerImage = new DockerImage("new-image");
final long wantedRestartGeneration = 2;
final long currentRestartGeneration = 1;
final ContainerNodeSpec nodeSpec = nodeSpecBuilder.wantedDockerImage(newDockerImage).currentDockerImage(dockerImage).nodeState(Node.State.active).wantedVespaVersion(vespaVersion).vespaVersion(vespaVersion).wantedRestartGeneration(wantedRestartGeneration).currentRestartGeneration(currentRestartGeneration).build();
NodeAgentImpl nodeAgent = makeNodeAgent(dockerImage, true);
when(nodeRepository.getContainerNodeSpec(hostName)).thenReturn(Optional.of(nodeSpec));
when(dockerOperations.pullImageAsyncIfNeeded(any())).thenReturn(true);
when(storageMaintainer.getDiskUsageFor(eq(containerName))).thenReturn(Optional.of(201326592000L));
nodeAgent.converge();
verify(orchestrator, never()).suspend(any(String.class));
verify(orchestrator, never()).resume(any(String.class));
verify(dockerOperations, never()).removeContainer(any(), any());
final InOrder inOrder = inOrder(dockerOperations);
inOrder.verify(dockerOperations, times(1)).pullImageAsyncIfNeeded(eq(newDockerImage));
}
use of com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec in project vespa by vespa-engine.
the class NodeAgentImplTest method start_container_subtask_failure_leads_to_container_restart.
@Test
public void start_container_subtask_failure_leads_to_container_restart() throws IOException {
final long restartGeneration = 1;
final long rebootGeneration = 0;
final ContainerNodeSpec nodeSpec = nodeSpecBuilder.wantedDockerImage(dockerImage).nodeState(Node.State.active).wantedVespaVersion(vespaVersion).wantedRestartGeneration(restartGeneration).currentRestartGeneration(restartGeneration).wantedRebootGeneration(rebootGeneration).build();
NodeAgentImpl nodeAgent = spy(makeNodeAgent(null, false));
when(nodeRepository.getContainerNodeSpec(hostName)).thenReturn(Optional.of(nodeSpec));
when(pathResolver.getApplicationStoragePathForNodeAdmin()).thenReturn(Files.createTempDirectory("foo"));
when(pathResolver.getApplicationStoragePathForHost()).thenReturn(Files.createTempDirectory("bar"));
when(dockerOperations.pullImageAsyncIfNeeded(eq(dockerImage))).thenReturn(false);
when(storageMaintainer.getDiskUsageFor(eq(containerName))).thenReturn(Optional.of(201326592000L));
doThrow(new DockerException("Failed to set up network")).doNothing().when(dockerOperations).startContainer(eq(containerName), eq(nodeSpec));
try {
nodeAgent.converge();
fail("Expected to get DockerException");
} catch (DockerException ignored) {
}
verify(dockerOperations, never()).removeContainer(any(), any());
verify(dockerOperations, times(1)).createContainer(eq(containerName), eq(nodeSpec));
verify(dockerOperations, times(1)).startContainer(eq(containerName), eq(nodeSpec));
verify(nodeAgent, never()).runLocalResumeScriptIfNeeded(any());
// The docker container was actually started and is running, but subsequent exec calls to set up
// networking failed
mockGetContainer(dockerImage, true);
nodeAgent.converge();
verify(dockerOperations, times(1)).removeContainer(any(), eq(nodeSpec));
verify(dockerOperations, times(2)).createContainer(eq(containerName), eq(nodeSpec));
verify(dockerOperations, times(2)).startContainer(eq(containerName), eq(nodeSpec));
verify(nodeAgent, times(1)).runLocalResumeScriptIfNeeded(any());
}
Aggregations