Search in sources :

Example 1 with DockerImage

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

the class MultiDockerTest method test.

@Test
public void test() throws InterruptedException {
    try (DockerTester dockerTester = new DockerTester()) {
        addAndWaitForNode(dockerTester, "host1.test.yahoo.com", new DockerImage("image1"));
        ContainerNodeSpec containerNodeSpec2 = addAndWaitForNode(dockerTester, "host2.test.yahoo.com", new DockerImage("image2"));
        dockerTester.addContainerNodeSpec(new ContainerNodeSpec.Builder(containerNodeSpec2).nodeState(Node.State.dirty).minCpuCores(1).minMainMemoryAvailableGb(1).minDiskAvailableGb(1).build());
        // Wait until it is marked ready
        while (dockerTester.nodeRepositoryMock.getContainerNodeSpec(containerNodeSpec2.hostname).filter(nodeSpec -> nodeSpec.nodeState != Node.State.ready).isPresent()) {
            Thread.sleep(10);
        }
        addAndWaitForNode(dockerTester, "host3.test.yahoo.com", new DockerImage("image1"));
        dockerTester.callOrderVerifier.assertInOrder("createContainerCommand with DockerImage { imageId=image1 }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }", "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]", "createContainerCommand with DockerImage { imageId=image2 }, HostName: host2.test.yahoo.com, ContainerName { name=host2 }", "executeInContainerAsRoot with ContainerName { name=host2 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]", "stopContainer with ContainerName { name=host2 }", "deleteContainer with ContainerName { name=host2 }", "createContainerCommand with DockerImage { imageId=image1 }, HostName: host3.test.yahoo.com, ContainerName { name=host3 }", "executeInContainerAsRoot with ContainerName { name=host3 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]");
        dockerTester.callOrderVerifier.assertInOrderWithAssertMessage("Maintainer did not receive call to delete application storage", "deleteContainer with ContainerName { name=host2 }", "DeleteContainerStorage with ContainerName { name=host2 }");
        dockerTester.callOrderVerifier.assertInOrder("updateNodeAttributes with HostName: host1.test.yahoo.com, NodeAttributes{restartGeneration=1, rebootGeneration=0, dockerImage=image1, vespaVersion='1.2.3', hardwareDivergence='null'}", "updateNodeAttributes with HostName: host2.test.yahoo.com, NodeAttributes{restartGeneration=1, rebootGeneration=0, dockerImage=image2, vespaVersion='1.2.3', hardwareDivergence='null'}", "markNodeAvailableForNewAllocation with HostName: host2.test.yahoo.com", "updateNodeAttributes with HostName: host3.test.yahoo.com, NodeAttributes{restartGeneration=1, rebootGeneration=0, dockerImage=image1, vespaVersion='1.2.3', hardwareDivergence='null'}");
    }
}
Also used : ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) DockerOperationsImpl(com.yahoo.vespa.hosted.node.admin.docker.DockerOperationsImpl) Test(org.junit.Test) IOException(java.io.IOException) Node(com.yahoo.vespa.hosted.provision.Node) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) Test(org.junit.Test)

Example 2 with DockerImage

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

the class NodeStateTest method activeToInactiveToActive.

@Test
public void activeToInactiveToActive() throws InterruptedException, IOException {
    try (DockerTester dockerTester = new DockerTester()) {
        setup(dockerTester);
        DockerImage newDockerImage = new DockerImage("newDockerImage");
        // Change node state to inactive and change the wanted docker image
        dockerTester.addContainerNodeSpec(new ContainerNodeSpec.Builder(initialContainerNodeSpec).wantedDockerImage(newDockerImage).nodeState(Node.State.inactive).minCpuCores(1).minMainMemoryAvailableGb(1).minDiskAvailableGb(1).build());
        dockerTester.callOrderVerifier.assertInOrderWithAssertMessage("Node set to inactive, but no stop/delete call received", "stopContainer with ContainerName { name=host1 }", "deleteContainer with ContainerName { name=host1 }");
        // Change node state to active
        dockerTester.addContainerNodeSpec(new ContainerNodeSpec.Builder(initialContainerNodeSpec).wantedDockerImage(newDockerImage).nodeState(Node.State.active).minCpuCores(1).minMainMemoryAvailableGb(1).minDiskAvailableGb(1).build());
        // Check that the container is started again after the delete call
        dockerTester.callOrderVerifier.assertInOrderWithAssertMessage("Node not started again after being put to active state", "deleteContainer with ContainerName { name=host1 }", "createContainerCommand with DockerImage { imageId=newDockerImage }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }", "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]");
    }
}
Also used : DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) Test(org.junit.Test)

Example 3 with DockerImage

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

the class AclMaintainerTest method makeContainer.

private Container makeContainer(String hostname, Container.State state, int pid) {
    final ContainerName containerName = new ContainerName(hostname);
    final Container container = new Container(hostname, new DockerImage("mock"), null, containerName, state, pid);
    containers.add(container);
    return container;
}
Also used : Container(com.yahoo.vespa.hosted.dockerapi.Container) ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage)

Example 4 with DockerImage

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

the class DockerOperationsImplTest method makeContainer.

private Container makeContainer(String name, Container.State state, int pid) {
    final Container container = new Container(name + ".fqdn", new DockerImage("mock"), null, new ContainerName(name), state, pid);
    when(docker.getContainer(eq(container.name))).thenReturn(Optional.of(container));
    return container;
}
Also used : Container(com.yahoo.vespa.hosted.dockerapi.Container) ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage)

Example 5 with DockerImage

use of com.yahoo.vespa.hosted.dockerapi.DockerImage 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)

Aggregations

DockerImage (com.yahoo.vespa.hosted.dockerapi.DockerImage)12 Test (org.junit.Test)8 ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)7 ContainerName (com.yahoo.vespa.hosted.dockerapi.ContainerName)6 Container (com.yahoo.vespa.hosted.dockerapi.Container)3 OrchestratorException (com.yahoo.vespa.hosted.node.admin.configserver.orchestrator.OrchestratorException)2 NodeAttributes (com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAttributes)2 Node (com.yahoo.vespa.hosted.provision.Node)2 InOrder (org.mockito.InOrder)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ThreadFactoryFactory (com.yahoo.concurrent.ThreadFactoryFactory)1 NodeType (com.yahoo.config.provision.NodeType)1 ContainerResources (com.yahoo.vespa.hosted.dockerapi.ContainerResources)1 Docker (com.yahoo.vespa.hosted.dockerapi.Docker)1 DockerException (com.yahoo.vespa.hosted.dockerapi.DockerException)1 DockerExecTimeoutException (com.yahoo.vespa.hosted.dockerapi.DockerExecTimeoutException)1 ProcessResult (com.yahoo.vespa.hosted.dockerapi.ProcessResult)1 DimensionMetrics (com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics)1 Dimensions (com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions)1 MetricReceiverWrapper (com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper)1