Search in sources :

Example 1 with HeliosClient

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

the class JobServiceRegistrationTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost(), "--service-registry=" + registryAddress);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final ImmutableMap<String, PortMapping> portMapping = ImmutableMap.of("foo_port", PortMapping.of(4711, externalPort), "bar_port", PortMapping.of(4712));
    final ImmutableMap<ServiceEndpoint, ServicePorts> registration = ImmutableMap.of(ServiceEndpoint.of("foo_service", "foo_proto"), ServicePorts.of("foo_port"), ServiceEndpoint.of("bar_service", "bar_proto"), ServicePorts.of("bar_port"));
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND, EMPTY_ENV, portMapping, registration);
    deployJob(jobId, testHost());
    awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS))).register(registrationCaptor.capture());
    final ServiceRegistration serviceRegistration = registrationCaptor.getValue();
    final Map<String, Endpoint> registered = Maps.newHashMap();
    for (final Endpoint endpoint : serviceRegistration.getEndpoints()) {
        registered.put(endpoint.getName(), endpoint);
    }
    assertEquals("wrong service", "foo_service", registered.get("foo_service").getName());
    assertEquals("wrong protocol", "foo_proto", registered.get("foo_service").getProtocol());
    assertEquals("wrong port", externalPort, registered.get("foo_service").getPort());
    assertEquals("wrong service", "bar_service", registered.get("bar_service").getName());
    assertEquals("wrong protocol", "bar_proto", registered.get("bar_service").getProtocol());
    assertNotEquals("wrong port", externalPort, registered.get("bar_service").getPort());
}
Also used : ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) Endpoint(com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint) ServicePorts(com.spotify.helios.common.descriptors.ServicePorts) PortMapping(com.spotify.helios.common.descriptors.PortMapping) HeliosClient(com.spotify.helios.client.HeliosClient) ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) JobId(com.spotify.helios.common.descriptors.JobId) ServiceRegistration(com.spotify.helios.serviceregistration.ServiceRegistration) Test(org.junit.Test)

Example 2 with HeliosClient

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

the class MultipleHostsTest method testFilteringJobAndHostStatuses.

@Test
public void testFilteringJobAndHostStatuses() throws Exception {
    final String aHost = testHost() + "a";
    final String bHost = testHost() + "b";
    startDefaultMaster();
    startDefaultAgent(aHost);
    startDefaultAgent(bHost);
    awaitHostStatus(aHost, UP, LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(bHost, UP, LONG_WAIT_SECONDS, SECONDS);
    final HeliosClient client = defaultClient();
    final Job job = Job.newBuilder().setName(testJobName + "I_WANT_THIS_ONE").setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    client.createJob(job).get();
    final Job job2 = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId2 = job2.getId();
    client.createJob(job2).get();
    final Deployment deployment = Deployment.of(jobId, Goal.START);
    client.deploy(deployment, aHost);
    client.deploy(deployment, bHost);
    client.deploy(Deployment.of(jobId2, Goal.START), aHost);
    awaitJobState(client, aHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    awaitJobState(client, bHost, jobId, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    awaitJobState(client, aHost, jobId2, State.RUNNING, LONG_WAIT_SECONDS, TimeUnit.SECONDS);
    final Map<JobId, JobStatus> cliStatuses = new ObjectMapper().readValue(cli("status", "--job", "I_WANT_THIS_ONE", "--host", aHost, "--json"), new TypeReference<Map<JobId, JobStatus>>() {
    });
    assertEquals("status should only have one job", 1, cliStatuses.size());
    assertTrue(cliStatuses.containsKey(jobId));
    final JobStatus status = cliStatuses.get(jobId);
    assertEquals("deployments should have only one item", 1, status.getDeployments().size());
    assertTrue("should only have deployment info for aHost", status.getDeployments().containsKey(aHost));
    assertEquals("Task statuses should only have one item", 1, status.getTaskStatuses().size());
    assertTrue("should only have status info for aHost", status.getTaskStatuses().containsKey(aHost));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with HeliosClient

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

the class HealthCheckTest method testTcp.

@Test
public void testTcp() 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);
    assertContainerRegistersAfterPoke(client, job);
}
Also used : 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) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) Test(org.junit.Test)

Example 4 with HeliosClient

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

the class IdMismatchJobCreateTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    final CreateJobResponse createIdMismatch = client.createJob(new Job(JobId.fromString("bad:job:deadbeef"), BUSYBOX, EMPTY_HOSTNAME, EMPTY_CREATED, IDLE_COMMAND, EMPTY_ENV, EMPTY_RESOURCES, EMPTY_PORTS, EMPTY_REGISTRATION, EMPTY_GRACE_PERIOD, EMPTY_VOLUMES, EMPTY_EXPIRES, EMPTY_REGISTRATION_DOMAIN, EMPTY_CREATING_USER, EMPTY_TOKEN, EMPTY_HEALTH_CHECK, EMPTY_SECURITY_OPT, DEFAULT_NETWORK_MODE, EMPTY_METADATA, EMPTY_CAPS, EMPTY_CAPS, EMPTY_SECONDS_TO_WAIT)).get();
    // TODO (dano): Maybe this should be ID_MISMATCH but then JobValidator must become able to
    // TODO (dano): communicate that
    assertEquals(CreateJobResponse.Status.INVALID_JOB_DEFINITION, createIdMismatch.getStatus());
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) Test(org.junit.Test)

Example 5 with HeliosClient

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

the class JobExpirationTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost());
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND, DateTime.now().plusSeconds(10).toDate());
    deployJob(jobId, testHost());
    // Make sure the job runs
    final TaskStatus taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, WAIT_TIMEOUT_SECONDS, SECONDS);
    // Then make sure it expires
    Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<JobId>() {

        @Override
        public JobId call() throws Exception {
            if (client.jobs().get().containsKey(jobId)) {
                // job still exists, return null to continue polling
                return null;
            } else {
                // job no longer exists, return non-null to exit polling
                return jobId;
            }
        }
    });
    // Wait for the agent to kill the container
    final ContainerExit exit = docker.waitContainer(taskStatus.getContainerId());
    assertThat(exit.statusCode(), is(0));
}
Also used : ContainerExit(com.spotify.docker.client.messages.ContainerExit) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) ExpectedException(org.junit.rules.ExpectedException) 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