use of com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint in project helios by spotify.
the class HealthCheckTest method assertContainerRegistersAfterPoke.
private void assertContainerRegistersAfterPoke(final HeliosClient client, final Job job) throws Exception {
final JobId jobId = createJob(job);
deployJob(jobId, testHost());
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 poked it yet
verify(registrar, never()).register(any(ServiceRegistration.class));
pokeAndVerifyRegistration(client, jobId, LONG_WAIT_SECONDS);
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());
}
use of com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint 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.serviceregistration.ServiceRegistration.Endpoint 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());
}
Aggregations