Search in sources :

Example 11 with ContainerName

use of com.yahoo.vespa.hosted.dockerapi.ContainerName in project vespa by vespa-engine.

the class RunInContainerTest method testGetContainersToRunAPi.

@Ignore
@Test
public void testGetContainersToRunAPi() throws IOException, InterruptedException {
    doThrow(new OrchestratorException("Cannot suspend because...")).when(orchestratorMock).suspend(parentHostname);
    when(nodeRepositoryMock.getContainersToRun(eq(parentHostname))).thenReturn(Collections.emptyList());
    waitForJdiscContainerToServe();
    assertTrue("The initial resume command should fail because it needs to converge first", verifyWithRetries("resume", false));
    doNothing().when(orchestratorMock).resume(parentHostname);
    assertTrue(verifyWithRetries("resume", true));
    doThrow(new OrchestratorException("Cannot suspend because...")).when(orchestratorMock).suspend(parentHostname, Collections.singletonList(parentHostname));
    assertTrue("Should fail because orchestrator does not allow node-admin to suspend", verifyWithRetries("suspend/node-admin", false));
    // Orchestrator changes its mind, allows node-admin to suspend
    doNothing().when(orchestratorMock).suspend(parentHostname, Collections.singletonList(parentHostname));
    assertTrue(verifyWithRetries("suspend/node-admin", true));
    // Lets try to suspend everything now, should be trivial as we have no active containers to stop services at
    assertTrue(verifyWithRetries("suspend", false));
    assertTrue(verifyWithRetries("suspend", true));
    // Back to resume
    assertTrue(verifyWithRetries("resume", false));
    assertTrue(verifyWithRetries("resume", true));
    // Lets try the same, but with an active container running on this host
    when(nodeRepositoryMock.getContainersToRun(eq(parentHostname))).thenReturn(Collections.singletonList(new ContainerNodeSpec.Builder().hostname("host1.test.yahoo.com").wantedDockerImage(new DockerImage("dockerImage")).nodeState(Node.State.active).nodeType("tenant").nodeFlavor("docker").build()));
    doThrow(new OrchestratorException("Cannot suspend because...")).when(orchestratorMock).suspend("localhost.test.yahoo.com", Arrays.asList("host1.test.yahoo.com", parentHostname));
    // Initially we are denied to suspend because we have to freeze all the node-agents
    assertTrue(verifyWithRetries("suspend/node-admin", false));
    // At this point they should be frozen, but Orchestrator doesn't allow to suspend either the container or the node-admin
    assertTrue(verifyWithRetries("suspend/node-admin", false));
    doNothing().when(orchestratorMock).suspend("localhost.test.yahoo.com", Arrays.asList("host1.test.yahoo.com", parentHostname));
    // Orchestrator successfully suspended everything
    assertTrue(verifyWithRetries("suspend/node-admin", true));
    // Allow stopping services in active nodes
    doNothing().when(dockerOperationsMock).trySuspendNode(eq(new ContainerName("host1")));
    doNothing().when(dockerOperationsMock).stopServicesOnNode(eq(new ContainerName("host1")));
    assertTrue(verifyWithRetries("suspend", false));
    assertTrue(verifyWithRetries("suspend", true));
}
Also used : ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) OrchestratorException(com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.OrchestratorException) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with ContainerName

use of com.yahoo.vespa.hosted.dockerapi.ContainerName 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());
}
Also used : ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) ArrayList(java.util.ArrayList) NodeAgent(com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgent) Test(org.junit.Test)

Example 13 with ContainerName

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

Example 14 with ContainerName

use of com.yahoo.vespa.hosted.dockerapi.ContainerName in project vespa by vespa-engine.

the class EnvironmentTest method testPathInNodeToPathInNodeAdminAndHost.

@Test
public void testPathInNodeToPathInNodeAdminAndHost() {
    ContainerName containerName = new ContainerName("docker1-1");
    assertEquals("/host/home/docker/container-storage/" + containerName.asString(), environment.pathInNodeAdminFromPathInNode(containerName, Paths.get("/")).toString());
    assertEquals("/home/docker/container-storage/" + containerName.asString(), environment.pathInHostFromPathInNode(containerName, Paths.get("/")).toString());
}
Also used : ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) Test(org.junit.Test)

Example 15 with ContainerName

use of com.yahoo.vespa.hosted.dockerapi.ContainerName in project vespa by vespa-engine.

the class EnvironmentTest method testAbsolutePathInNodeConversion.

@Test
public void testAbsolutePathInNodeConversion() {
    String varPath = getDefaults().underVespaHome("var");
    ContainerName containerName = new ContainerName("docker1-1");
    String expected = "/host/home/docker/container-storage/" + containerName.asString() + varPath;
    String[] absolutePathsInContainer = { "/" + varPath, varPath, varPath + "/" };
    for (String pathInContainer : absolutePathsInContainer) {
        assertEquals(expected, environment.pathInNodeAdminFromPathInNode(containerName, Paths.get(pathInContainer)).toString());
    }
}
Also used : ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) Test(org.junit.Test)

Aggregations

ContainerName (com.yahoo.vespa.hosted.dockerapi.ContainerName)21 Test (org.junit.Test)13 DockerImage (com.yahoo.vespa.hosted.dockerapi.DockerImage)7 ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)7 Container (com.yahoo.vespa.hosted.dockerapi.Container)4 ProcessResult (com.yahoo.vespa.hosted.dockerapi.ProcessResult)4 PrefixLogger (com.yahoo.vespa.hosted.node.admin.util.PrefixLogger)4 Map (java.util.Map)4 Docker (com.yahoo.vespa.hosted.dockerapi.Docker)3 IOException (java.io.IOException)3 List (java.util.List)3 Optional (java.util.Optional)3 Pair (com.yahoo.collections.Pair)2 NodeType (com.yahoo.config.provision.NodeType)2 ContainerResources (com.yahoo.vespa.hosted.dockerapi.ContainerResources)2 Environment (com.yahoo.vespa.hosted.node.admin.component.Environment)2 NodeRepository (com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeRepository)2 OrchestratorException (com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.OrchestratorException)2 DockerOperations (com.yahoo.vespa.hosted.node.admin.docker.DockerOperations)2 NodeAgent (com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgent)2