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());
}
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));
}
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);
}
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());
}
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));
}
Aggregations