Search in sources :

Example 21 with ContainerNodeSpec

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");
}
Also used : Path(java.nio.file.Path) InOrder(org.mockito.InOrder) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) Test(org.junit.Test)

Example 22 with ContainerNodeSpec

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("")));
}
Also used : InOrder(org.mockito.InOrder) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)

Example 23 with ContainerNodeSpec

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));
}
Also used : ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) Test(org.junit.Test)

Example 24 with ContainerNodeSpec

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));
}
Also used : InOrder(org.mockito.InOrder) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) Test(org.junit.Test)

Example 25 with ContainerNodeSpec

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());
}
Also used : DockerException(com.yahoo.vespa.hosted.dockerapi.DockerException) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) Test(org.junit.Test)

Aggregations

ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)30 Test (org.junit.Test)22 InOrder (org.mockito.InOrder)8 ContainerName (com.yahoo.vespa.hosted.dockerapi.ContainerName)7 DockerImage (com.yahoo.vespa.hosted.dockerapi.DockerImage)7 Docker (com.yahoo.vespa.hosted.dockerapi.Docker)4 DockerException (com.yahoo.vespa.hosted.dockerapi.DockerException)4 ArrayList (java.util.ArrayList)4 DimensionMetrics (com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics)3 Dimensions (com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions)3 Node (com.yahoo.vespa.hosted.provision.Node)3 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ThreadFactoryFactory (com.yahoo.concurrent.ThreadFactoryFactory)2 NodeType (com.yahoo.config.provision.NodeType)2 Container (com.yahoo.vespa.hosted.dockerapi.Container)2 ContainerResources (com.yahoo.vespa.hosted.dockerapi.ContainerResources)2 DockerExecTimeoutException (com.yahoo.vespa.hosted.dockerapi.DockerExecTimeoutException)2