@Override public String apply(final ServicePorts input) { return Joiner.on(", ").join(Ordering.natural().sortedCopy(input.getPorts().keySet())); } };
public static ServicePorts of(final String... ports) { return of(asList(ports)); }
private static ServicePorts of(final Iterable<String> ports) { final ImmutableMap.Builder<String, ServicePortParameters> builder = ImmutableMap.builder(); for (final String port : ports) { builder.put(port, new ServicePortParameters(null)); } return new ServicePorts(builder.build()); } }
"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");
if (servicePorts == null || servicePorts.getPorts() == null) { errors.add(format("registration for '%s' is malformed: does not have a port mapping", registration.getName())); continue; for (final String portName : servicePorts.getPorts().keySet()) { if (!job.getPorts().containsKey(portName)) { errors.add(format("Service registration refers to missing port mapping: %s=%s",
final ServicePorts servicePorts = entry.getValue(); for (final Entry<String, ServicePortParameters> portEntry : servicePorts.getPorts().entrySet()) { final String portName = portEntry.getKey(); final ServicePortParameters portParameters = portEntry.getValue();
"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(redundantEnvKey, "f00d"); final Map<String, String> volumes = Maps.newHashMap();
@Override public String apply(final ServicePorts input) { return Joiner.on(", ").join(Ordering.natural().sortedCopy(input.getPorts().keySet())); } };
"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 String registrationDomain = "my-domain"; final Map<String, String> env = ImmutableMap.of("BAD", "f00d");
final ServicePorts servicePorts = entry.getValue(); for (final Entry<String, ServicePortParameters> portEntry : servicePorts.getPorts().entrySet()) { final String portName = portEntry.getKey(); final ServicePortParameters portParameters = portEntry.getValue();
explicitRegistration.put(ServiceEndpoint.of(service, proto), ServicePorts.of(port));
/** * Starts a container that listens on a poke port, and once poked listens on the healthcheck * port. */ private Job pokeJob(final HealthCheck healthCheck) { return Job.newBuilder() .setName(testJobName) .setVersion(testJobVersion) .setImage(ALPINE) .setCommand(asList("sh", "-c", "nc -l -p 4711 && nc -lk -p 4712 -e hostname")) .addPort("poke", PortMapping.of(4711)) .addPort("health", PortMapping.of(4712)) .addRegistration(ServiceEndpoint.of("foo_service", "foo_proto"), ServicePorts.of("health")) .setHealthCheck(healthCheck) .build(); }
"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<JobId, JobStatus> statuses = Json.read(statusString, STATUSES_TYPE); final Job job = statuses.get(jobId).getJob(); assertEquals(ServicePorts.of("foo"), job.getRegistration().get(ServiceEndpoint.of("foo-service", "tcp"))); assertEquals(ServicePorts.of("bar"), job.getRegistration().get(ServiceEndpoint.of("bar-service", "http"))); assertEquals(4711, job.getPorts().get("foo").getInternalPort());
.addPort(portName, PortMapping.of(4711)) .addRegistration(ServiceEndpoint.of(serviceName, serviceProtocol), ServicePorts.of(portName)) .setHealthCheck(healthCheck) .build();
@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); }
public TemporaryJobBuilder registration(final String service, final String protocol, final String... ports) { return registration(ServiceEndpoint.of(service, protocol), ServicePorts.of(ports)); }
explicitRegistration.put(ServiceEndpoint.of(service, proto), ServicePorts.of(port));