Search in sources :

Example 1 with ServiceRegistration

use of com.spotify.helios.serviceregistration.ServiceRegistration 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 ServiceRegistration

use of com.spotify.helios.serviceregistration.ServiceRegistration in project helios by spotify.

the class MasterServiceRegistrationTest method test.

@Test
public void test() throws Exception {
    startDefaultMaster("--service-registry=" + registryAddress);
    verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS))).register(registrationCaptor.capture());
    final ServiceRegistration registration = registrationCaptor.getValue();
    final ServiceRegistration.Endpoint endpoint = getOnlyElement(registration.getEndpoints());
    assertEquals("http", endpoint.getProtocol());
    assertEquals("helios", endpoint.getName());
    assertEquals(masterPort(), endpoint.getPort());
}
Also used : ServiceRegistration(com.spotify.helios.serviceregistration.ServiceRegistration) Test(org.junit.Test)

Example 3 with ServiceRegistration

use of com.spotify.helios.serviceregistration.ServiceRegistration 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());
}
Also used : ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) Endpoint(com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint) JobId(com.spotify.helios.common.descriptors.JobId) ServiceRegistration(com.spotify.helios.serviceregistration.ServiceRegistration)

Example 4 with ServiceRegistration

use of com.spotify.helios.serviceregistration.ServiceRegistration in project helios by spotify.

the class MasterService method startUp.

@Override
protected void startUp() throws Exception {
    logBanner();
    if (!config.getNoZooKeeperMasterRegistration()) {
        zkRegistrar.startAsync().awaitRunning();
    }
    expiredJobReaper.startAsync().awaitRunning();
    rollingUpdateService.startAsync().awaitRunning();
    agentReaper.ifPresent(reaper -> reaper.startAsync().awaitRunning());
    oldJobReaper.ifPresent(reaper -> reaper.startAsync().awaitRunning());
    jobHistoryReaper.ifPresent(reaper -> reaper.startAsync().awaitRunning());
    try {
        server.start();
    } catch (Exception e) {
        log.error("Unable to start server, shutting down", e);
        server.stop();
    }
    final ServiceRegistration serviceRegistration = ServiceRegistration.newBuilder().endpoint("helios", "http", config.getHttpEndpoint().getPort(), config.getDomain(), config.getName()).build();
    registrar.register(serviceRegistration);
}
Also used : HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) ConfigurationException(io.dropwizard.configuration.ConfigurationException) IOException(java.io.IOException) ServiceRegistration(com.spotify.helios.serviceregistration.ServiceRegistration)

Example 5 with ServiceRegistration

use of com.spotify.helios.serviceregistration.ServiceRegistration in project helios by spotify.

the class TaskConfig method registration.

public ServiceRegistration registration() throws InterruptedException {
    final ServiceRegistration.Builder builder = ServiceRegistration.newBuilder();
    for (final Map.Entry<ServiceEndpoint, ServicePorts> entry : job.getRegistration().entrySet()) {
        final ServiceEndpoint registration = entry.getKey();
        final ServicePorts servicePorts = entry.getValue();
        for (final Entry<String, ServicePortParameters> portEntry : servicePorts.getPorts().entrySet()) {
            final String portName = portEntry.getKey();
            final ServicePortParameters portParameters = portEntry.getValue();
            final PortMapping mapping = job.getPorts().get(portName);
            if (mapping == null) {
                log.error("no '{}' port mapped for registration: '{}'", portName, registration);
                continue;
            }
            final Integer externalPort;
            if (mapping.getExternalPort() != null) {
                // Use the statically assigned port if one is specified
                externalPort = mapping.getExternalPort();
            } else {
                // Otherwise use the dynamically allocated port
                externalPort = ports.get(portName);
            }
            if (externalPort == null) {
                log.error("no external '{}' port for registration: '{}'", portName, registration);
                continue;
            }
            builder.endpoint(registration.getName(), registration.getProtocol(), externalPort, fullyQualifiedRegistrationDomain(), host, portParameters.getTags(), endpointHealthCheck(portName));
        }
    }
    return builder.build();
}
Also used : ServicePorts(com.spotify.helios.common.descriptors.ServicePorts) ServicePortParameters(com.spotify.helios.common.descriptors.ServicePortParameters) PortMapping(com.spotify.helios.common.descriptors.PortMapping) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) ServiceRegistration(com.spotify.helios.serviceregistration.ServiceRegistration)

Aggregations

ServiceRegistration (com.spotify.helios.serviceregistration.ServiceRegistration)6 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)4 JobId (com.spotify.helios.common.descriptors.JobId)3 Endpoint (com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint)3 Test (org.junit.Test)3 HeliosClient (com.spotify.helios.client.HeliosClient)2 PortMapping (com.spotify.helios.common.descriptors.PortMapping)2 ServicePorts (com.spotify.helios.common.descriptors.ServicePorts)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 DockerClient (com.spotify.docker.client.DockerClient)1 ExecCreation (com.spotify.docker.client.messages.ExecCreation)1 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)1 ExecHealthCheck (com.spotify.helios.common.descriptors.ExecHealthCheck)1 HealthCheck (com.spotify.helios.common.descriptors.HealthCheck)1 HttpHealthCheck (com.spotify.helios.common.descriptors.HttpHealthCheck)1 Job (com.spotify.helios.common.descriptors.Job)1 ServicePortParameters (com.spotify.helios.common.descriptors.ServicePortParameters)1 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)1 TcpHealthCheck (com.spotify.helios.common.descriptors.TcpHealthCheck)1 ConfigurationException (io.dropwizard.configuration.ConfigurationException)1