Search in sources :

Example 56 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class PredefinedPortImageDeploymentTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    final HeliosClient client = defaultClient();
    // Create a job using an image exposing port 11211 but without mapping it
    final Job job1 = Job.newBuilder().setName(testTag + "memcached").setVersion("v1").setImage(MEMCACHED).build();
    final JobId jobId1 = job1.getId();
    client.createJob(job1).get();
    // Create a job using an image exposing port 11211 and map it to a specific external port
    final Job job2 = Job.newBuilder().setName(testTag + "memcached").setVersion("v2").setImage(MEMCACHED).setPorts(ImmutableMap.of("tcp", PortMapping.of(11211, externalPort))).build();
    final JobId jobId2 = job2.getId();
    client.createJob(job2).get();
    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Deploy the jobs on the agent
    client.deploy(Deployment.of(jobId1, START), testHost()).get();
    client.deploy(Deployment.of(jobId2, START), testHost()).get();
    // Wait for the jobs to run
    awaitJobState(client, testHost(), jobId1, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    awaitJobState(client, testHost(), jobId2, RUNNING, LONG_WAIT_SECONDS, SECONDS);
}
Also used : HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 57 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class AgentZooKeeperDownTolerationTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    final DockerClient dockerClient = getNewDockerClient();
    final HeliosClient client = defaultClient();
    final AgentMain agent1 = startDefaultAgent(testHost());
    // Create a job
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Deploy the job on the agent
    final Deployment deployment = Deployment.of(jobId, START);
    final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    // Wait for the job to run
    final TaskStatus firstTaskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    assertJobEquals(job, firstTaskStatus.getJob());
    assertNotNull(dockerClient.inspectContainer(firstTaskStatus.getContainerId()));
    // Stop zookeeper
    zk().stop();
    // Wait for a while and make sure that the container is still running
    Thread.sleep(5000);
    assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
    // Stop the agent
    agent1.stopAsync().awaitTerminated();
    // Start the agent again
    final AgentMain agent2 = startDefaultAgent(testHost());
    // Wait for a while and make sure that the same container is still running
    Thread.sleep(5000);
    assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
    // Kill the container
    dockerClient.killContainer(firstTaskStatus.getContainerId());
    assertFalse(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running());
    // Wait for a while and make sure that a new container was spawned
    final String firstRestartedContainerId = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {

        @Override
        public String call() throws Exception {
            final List<Container> containers = listContainers(dockerClient, testTag);
            return containers.size() == 1 ? containers.get(0).id() : null;
        }
    });
    // Stop the agent
    agent2.stopAsync().awaitTerminated();
    // Kill the container
    dockerClient.killContainer(firstRestartedContainerId);
    assertFalse(dockerClient.inspectContainer(firstRestartedContainerId).state().running());
    // Start the agent again
    startDefaultAgent(testHost());
    // Wait for a while and make sure that a new container was spawned
    final String secondRestartedContainerId = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {

        @Override
        public String call() throws Exception {
            final List<Container> containers = listContainers(dockerClient, testTag);
            return containers.size() == 1 ? containers.get(0).id() : null;
        }
    });
    assertTrue(dockerClient.inspectContainer(secondRestartedContainerId).state().running());
    // Start zookeeper
    zk().start();
    // Verify that the agent is listed as up
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Wait for the new container id to be reflected in the task status
    Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<TaskStatus>() {

        @Override
        public TaskStatus call() throws Exception {
            final JobStatus jobStatus = client.jobStatus(jobId).get();
            final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(testHost());
            return taskStatus != null && Objects.equals(taskStatus.getContainerId(), secondRestartedContainerId) ? taskStatus : null;
        }
    });
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobStatus(com.spotify.helios.common.descriptors.JobStatus) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) AgentMain(com.spotify.helios.agent.AgentMain) List(java.util.List) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Aggregations

HeliosClient (com.spotify.helios.client.HeliosClient)57 Test (org.junit.Test)53 JobId (com.spotify.helios.common.descriptors.JobId)35 Job (com.spotify.helios.common.descriptors.Job)25 Deployment (com.spotify.helios.common.descriptors.Deployment)19 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)14 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)13 Matchers.containsString (org.hamcrest.Matchers.containsString)11 DockerClient (com.spotify.docker.client.DockerClient)10 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)10 HostStatus (com.spotify.helios.common.descriptors.HostStatus)9 AgentMain (com.spotify.helios.agent.AgentMain)8 JobStatus (com.spotify.helios.common.descriptors.JobStatus)6 PortMapping (com.spotify.helios.common.descriptors.PortMapping)5 Map (java.util.Map)5 ExecHealthCheck (com.spotify.helios.common.descriptors.ExecHealthCheck)4 HealthCheck (com.spotify.helios.common.descriptors.HealthCheck)4 HttpHealthCheck (com.spotify.helios.common.descriptors.HttpHealthCheck)4 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)4 TcpHealthCheck (com.spotify.helios.common.descriptors.TcpHealthCheck)4