1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.integrationTests;
import com.yahoo.vespa.hosted.dockerapi.ContainerName;
import com.yahoo.vespa.hosted.dockerapi.DockerImage;
import com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec;
import com.yahoo.vespa.hosted.node.admin.docker.DockerOperationsImpl;
import com.yahoo.vespa.hosted.provision.Node;
import org.junit.Test;
import java.io.IOException;
/**
* @author freva
*/
public class MultiDockerTest {
@Test
public void test() throws InterruptedException, IOException {
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.updateContainerNodeSpec(
new ContainerNodeSpec.Builder(containerNodeSpec2)
.nodeState(Node.State.dirty)
.build());
// Wait until it is marked ready
while (dockerTester.getContainerNodeSpec(containerNodeSpec2.hostname)
.filter(nodeSpec -> nodeSpec.nodeState != Node.State.ready).isPresent()) {
Thread.sleep(10);
}
addAndWaitForNode(dockerTester, "host3.test.yahoo.com", new DockerImage("image1"));
CallOrderVerifier callOrderVerifier = dockerTester.getCallOrderVerifier();
callOrderVerifier.assertInOrder(
"createContainerCommand with DockerImage { imageId=image1 }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }",
"executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]",
"createContainerCommand with DockerImage { imageId=image2 }, HostName: host2.test.yahoo.com, ContainerName { name=host2 }",
"executeInContainerAsRoot with ContainerName { name=host2 }, args: [" + DockerOperationsImpl.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: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
callOrderVerifier.assertInOrderWithAssertMessage("Maintainer did not receive call to delete application storage",
"deleteContainer with ContainerName { name=host2 }",
"DeleteContainerStorage with ContainerName { name=host2 }");
callOrderVerifier.assertInOrder(
"updateNodeAttributes with HostName: host1.test.yahoo.com, NodeAttributes{restartGeneration=1, rebootGeneration=0, dockerImage=image1, vespaVersion=''}",
"updateNodeAttributes with HostName: host2.test.yahoo.com, NodeAttributes{restartGeneration=1, rebootGeneration=0, dockerImage=image2, vespaVersion=''}",
"markNodeAvailableForNewAllocation with HostName: host2.test.yahoo.com",
"updateNodeAttributes with HostName: host3.test.yahoo.com, NodeAttributes{restartGeneration=1, rebootGeneration=0, dockerImage=image1, vespaVersion=''}");
}
}
private ContainerNodeSpec addAndWaitForNode(DockerTester tester, String hostName, DockerImage dockerImage) throws InterruptedException {
ContainerNodeSpec containerNodeSpec = new ContainerNodeSpec.Builder()
.hostname(hostName)
.wantedDockerImage(dockerImage)
.nodeState(Node.State.active)
.nodeType("tenant")
.nodeFlavor("docker")
.wantedRestartGeneration(1L)
.currentRestartGeneration(1L)
.build();
tester.addContainerNodeSpec(containerNodeSpec);
// Wait for node admin to be notified with node repo state and the docker container has been started
while (tester.getNodeAdmin().getListOfHosts().size() != tester.getNumberOfContainerSpecs()) {
Thread.sleep(10);
}
ContainerName containerName = ContainerName.fromHostname(hostName);
tester.getCallOrderVerifier().assertInOrder(
"createContainerCommand with " + dockerImage + ", HostName: " + hostName + ", " + containerName,
"executeInContainerAsRoot with " + containerName + ", args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
return containerNodeSpec;
}
}
|