Search in sources :

Example 41 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class TerminationTest method testTermOnExit.

@Test
public void testTermOnExit() throws Exception {
    startDefaultMaster();
    final String host = testHost();
    startDefaultAgent(host);
    final HeliosClient client = defaultClient();
    awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
    // Note: signal 15 is SIGTERM
    final Job jobToInterrupt = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(asList("/bin/sh", "-c", "trap handle 15; handle() { echo term; exit 0; }; " + "while true; do sleep 1; done")).build();
    final JobId jobId = createJob(jobToInterrupt);
    deployJob(jobId, host);
    awaitTaskState(jobId, host, RUNNING);
    client.setGoal(new Deployment(jobId, Goal.STOP, Deployment.EMTPY_DEPLOYER_USER, Deployment.EMPTY_DEPLOYER_MASTER, Deployment.EMPTY_DEPLOYMENT_GROUP_NAME), host);
    final TaskStatus taskStatus = awaitTaskState(jobId, host, STOPPED);
    final String log;
    try (final DockerClient dockerClient = getNewDockerClient();
        LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout())) {
        log = logs.readFully();
    }
    // Message expected, because the SIGTERM handler in the script should have run
    assertEquals("term\n", log);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Deployment(com.spotify.helios.common.descriptors.Deployment) LogStream(com.spotify.docker.client.LogStream) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 42 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class DeploymentTest method testLotsOfConcurrentJobs.

@Test
public void testLotsOfConcurrentJobs() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost());
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final int numberOfJobs = 40;
    final List<JobId> jobIds = Lists.newArrayListWithCapacity(numberOfJobs);
    final String jobName = testJobName + "_" + toHexString(ThreadLocalRandom.current().nextInt());
    // create and deploy a bunch of jobs
    for (Integer i = 0; i < numberOfJobs; i++) {
        final Job job = Job.newBuilder().setName(jobName).setVersion(i.toString()).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());
        final Deployment deployment = Deployment.of(jobId, START, TEST_USER);
        final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
        assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
        jobIds.add(jobId);
    }
    // get the container ID's for the jobs
    final Set<String> containerIds = Sets.newHashSetWithExpectedSize(numberOfJobs);
    for (final JobId jobId : jobIds) {
        final TaskStatus taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
        containerIds.add(taskStatus.getContainerId());
    }
    try (final DockerClient dockerClient = getNewDockerClient()) {
        // kill all the containers for the jobs
        for (final String containerId : containerIds) {
            dockerClient.killContainer(containerId);
        }
        // make sure all the containers come back up
        final int restartedContainers = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                int matchingContainerCount = 0;
                for (final Container c : dockerClient.listContainers()) {
                    for (final String name : c.names()) {
                        if (name.contains(jobName)) {
                            matchingContainerCount++;
                        }
                    }
                }
                if (matchingContainerCount < containerIds.size()) {
                    return null;
                } else {
                    return matchingContainerCount;
                }
            }
        });
        assertEquals(numberOfJobs, restartedContainers);
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Deployment(com.spotify.helios.common.descriptors.Deployment) Integer.toHexString(java.lang.Integer.toHexString) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) Container(com.spotify.docker.client.messages.Container) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 43 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class DnsServerTest method testDnsParam.

@Test
public void testDnsParam() throws Exception {
    final String server1 = "127.0.0.1";
    final String server2 = "127.0.0.2";
    startDefaultMaster();
    startDefaultAgent(testHost(), "--dns", server1, "--dns", server2);
    awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, asList("cat", "/etc/resolv.conf"));
    deployJob(jobId, testHost());
    final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
    try (final DockerClient dockerClient = getNewDockerClient()) {
        final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr());
        final String log = logs.readFully();
        assertThat(log, containsString(server1));
        assertThat(log, containsString(server2));
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Matchers.containsString(org.hamcrest.Matchers.containsString) LogStream(com.spotify.docker.client.LogStream) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 44 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class FlappingTest method test.

@Test
public void test() throws Exception {
    // CircleCI boxes are too slow -- the job doesn't stop or restart fast enough to ever flap
    assumeFalse(isCircleCi());
    startDefaultMaster();
    final String host = testHost();
    startDefaultAgent(host);
    final HeliosClient client = defaultClient();
    awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
    final Job flapper = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(asList("nc", "-p", "4711", "-l")).addPort("poke", PortMapping.of(4711)).build();
    final JobId jobId = createJob(flapper);
    deployJob(jobId, host);
    awaitTaskState(jobId, host, RUNNING);
    // Poke the container to make it exit until it's classified as flapping
    Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final JobStatus jobStatus = getOrNull(client.jobStatus(jobId));
            final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(host);
            if (taskStatus.getThrottled() == FLAPPING) {
                return true;
            }
            final PortMapping port = taskStatus.getPorts().get("poke");
            assert port.getExternalPort() != null;
            poke(port.getExternalPort());
            return null;
        }
    });
    // Verify that the job recovers after we stop poking
    awaitJobThrottle(client, host, jobId, NO, LONG_WAIT_SECONDS, SECONDS);
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) PortMapping(com.spotify.helios.common.descriptors.PortMapping) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) IOException(java.io.IOException) Test(org.junit.Test)

Example 45 with TaskStatus

use of com.spotify.helios.common.descriptors.TaskStatus in project helios by spotify.

the class HealthCheckTest method testContainerDiesDuringHealthcheck.

@Test
public void testContainerDiesDuringHealthcheck() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost(), "--service-registry=" + registryAddress);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final HealthCheck healthCheck = TcpHealthCheck.of("health");
    final Job job = pokeJob(healthCheck);
    final JobId jobId = createJob(job);
    deployJob(jobId, testHost());
    awaitTaskState(jobId, testHost(), HEALTHCHECKING);
    // kill the underlying container
    final JobStatus jobStatus = getOrNull(client.jobStatus(jobId));
    final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(testHost());
    getNewDockerClient().killContainer(taskStatus.getContainerId());
    // ensure the job is marked as failed
    final int timeout = WAIT_TIMEOUT_SECONDS;
    Polling.await(timeout, SECONDS, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final TaskStatusEvents jobHistory = getOrNull(client.jobHistory(jobId));
            for (final TaskStatusEvent event : jobHistory.getEvents()) {
                if (event.getStatus().getState() == FAILED) {
                    return true;
                }
            }
            return null;
        }
    });
    // wait for the job to come back up and start healthchecking again
    awaitTaskState(jobId, testHost(), HEALTHCHECKING);
    pokeAndVerifyRegistration(client, jobId, timeout);
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) HttpHealthCheck(com.spotify.helios.common.descriptors.HttpHealthCheck) HealthCheck(com.spotify.helios.common.descriptors.HealthCheck) ExecHealthCheck(com.spotify.helios.common.descriptors.ExecHealthCheck) TcpHealthCheck(com.spotify.helios.common.descriptors.TcpHealthCheck) TaskStatusEvents(com.spotify.helios.common.protocol.TaskStatusEvents) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) Endpoint(com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint) IOException(java.io.IOException) JobStatus(com.spotify.helios.common.descriptors.JobStatus) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Aggregations

TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)53 JobId (com.spotify.helios.common.descriptors.JobId)40 Test (org.junit.Test)27 DockerClient (com.spotify.docker.client.DockerClient)18 Deployment (com.spotify.helios.common.descriptors.Deployment)15 Job (com.spotify.helios.common.descriptors.Job)14 HeliosClient (com.spotify.helios.client.HeliosClient)13 LogStream (com.spotify.docker.client.LogStream)10 HostStatus (com.spotify.helios.common.descriptors.HostStatus)10 JobStatus (com.spotify.helios.common.descriptors.JobStatus)8 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)7 PortMapping (com.spotify.helios.common.descriptors.PortMapping)6 Map (java.util.Map)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)4 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4