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'}");
}
}
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]");
}
}
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;
}
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;
}
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));
}
Aggregations