use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class CliHostListTest method testHostListJson.
@Test
public void testHostListJson() throws Exception {
final String jsonOutput = cli("hosts", "-f", "--json");
final Map<String, HostStatus> statuses = Json.readUnchecked(jsonOutput, new TypeReference<Map<String, HostStatus>>() {
});
final HeliosClient client = defaultClient();
final Map<String, HostStatus> expectedStatuses = client.hostStatuses(ImmutableList.of(hostname1, hostname2)).get();
assertThat(expectedStatuses, equalTo(statuses));
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class ConfigFileJobCreationTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
final HeliosClient client = defaultClient();
final String name = testJobName;
final String version = "17";
final String image = BUSYBOX;
final Map<String, PortMapping> ports = ImmutableMap.of("foo", PortMapping.of(4711), "bar", PortMapping.of(5000, externalPort));
final Map<ServiceEndpoint, ServicePorts> registration = ImmutableMap.of(ServiceEndpoint.of("foo-service", "tcp"), ServicePorts.of("foo"), ServiceEndpoint.of("bar-service", "http"), ServicePorts.of("bar"));
final Map<String, String> env = ImmutableMap.of("BAD", "f00d");
final Map<String, Object> configuration = ImmutableMap.of("id", name + ":" + version, "image", image, "ports", ports, "registration", registration, "env", env);
final Path file = temporaryFolder.newFile().toPath();
Files.write(file, Json.asBytes(configuration));
final String output = cli("create", "-q", "-f", file.toAbsolutePath().toString());
final JobId jobId = JobId.parse(WHITESPACE.trimFrom(output));
final Map<JobId, Job> jobs = client.jobs().get();
final Job job = jobs.get(jobId);
assertEquals(name, job.getId().getName());
assertEquals(version, job.getId().getVersion());
assertEquals(ports, job.getPorts());
assertEquals(env, job.getEnv());
assertEquals(registration, job.getRegistration());
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class HealthCheckTest method testHttp.
@Test
public void testHttp() throws Exception {
startDefaultMaster();
final HeliosClient client = defaultClient();
startDefaultAgent(testHost(), "--service-registry=" + registryAddress);
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
final HealthCheck healthCheck = HttpHealthCheck.of("http", "/");
// start a container that listens on a poke port, and once poked runs a web server
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(NGINX).setCommand(asList("sh", "-c", "nc -l -p 4711 && nginx -g 'daemon off;'")).addPort("poke", PortMapping.of(4711)).addPort("http", PortMapping.of(80)).addRegistration(ServiceEndpoint.of("foo_service", "foo_proto"), ServicePorts.of("http")).setHealthCheck(healthCheck).build();
assertContainerRegistersAfterPoke(client, job);
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class HealthCheckTest method testExec.
@Test
public void testExec() throws Exception {
// CircleCI uses lxc which doesn't support exec - https://circleci.com/docs/docker/#docker-exec
assumeFalse(isCircleCi());
final DockerClient dockerClient = getNewDockerClient();
assumeThat(dockerClient.version(), is(execCompatibleDockerVersion()));
startDefaultMaster();
final HeliosClient client = defaultClient();
startDefaultAgent(testHost(), "--service-registry=" + registryAddress);
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// check if "file" exists in the root directory as a healthcheck
final HealthCheck healthCheck = ExecHealthCheck.of("test", "-e", "file");
// start a container that listens on the service port
final String portName = "service";
final String serviceName = "foo_service";
final String serviceProtocol = "foo_proto";
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(asList("sh", "-c", "nc -l -p 4711")).addPort(portName, PortMapping.of(4711)).addRegistration(ServiceEndpoint.of(serviceName, serviceProtocol), ServicePorts.of(portName)).setHealthCheck(healthCheck).build();
final JobId jobId = createJob(job);
deployJob(jobId, testHost());
final TaskStatus jobState = awaitTaskState(jobId, testHost(), HEALTHCHECKING);
// wait a few seconds to see if the service gets registered
Thread.sleep(3000);
// shouldn't be registered, since we haven't created the file yet
verify(registrar, never()).register(any(ServiceRegistration.class));
// create the file in the container to make the healthcheck succeed
final String[] makeFileCmd = new String[] { "touch", "file" };
final ExecCreation execCreation = dockerClient.execCreate(jobState.getContainerId(), makeFileCmd);
final String execId = execCreation.id();
dockerClient.execStart(execId);
awaitTaskState(jobId, testHost(), RUNNING);
dockerClient.close();
verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS))).register(registrationCaptor.capture());
final ServiceRegistration serviceRegistration = registrationCaptor.getValue();
assertEquals(1, serviceRegistration.getEndpoints().size());
final Endpoint registeredEndpoint = serviceRegistration.getEndpoints().get(0);
assertEquals("wrong service", serviceName, registeredEndpoint.getName());
assertEquals("wrong protocol", serviceProtocol, registeredEndpoint.getProtocol());
}
use of com.spotify.helios.client.HeliosClient in project helios by spotify.
the class ImageMissingTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost());
final HeliosClient client = defaultClient();
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
final JobId jobId = createJob(testJobName, testJobVersion, "this_sould_not_exist", ImmutableList.of("/bin/true"));
deployJob(jobId, testHost());
awaitJobThrottle(client, testHost(), jobId, IMAGE_MISSING, LONG_WAIT_SECONDS, SECONDS);
final HostStatus hostStatus = client.hostStatus(testHost()).get();
final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId);
assertEquals(TaskStatus.State.FAILED, taskStatus.getState());
}
Aggregations