public PortMapping withExternalPort(final Integer externalPort) { return PortMapping.of(internalPort, externalPort, protocol); }
/** * 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(); }
final String redundantEnvKey = "BAD"; 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"),
@Before public void setup() throws Exception { startDefaultMaster(); client = defaultClient(); startDefaultAgent(testHost()); job = Job.newBuilder() .setName(testJobName) .setVersion(testJobVersion) .setImage(BUSYBOX) .addVolume("/random-vol") .addVolume("/named-vol", "my-volume") .addVolume("/hostname", "/etc/hostname") .setCommand(asList("sh", "-c", "echo foo > /random-vol/foo; " + "echo foo > /named-vol/foo;" + "nc -p 4711 -le dd if=/random-vol/foo;" + "nc -p 4712 -le dd if=/named-vol/foo;" + "nc -p 4713 -le dd if=/hostname")) .addPort("random", PortMapping.of(4711)) .addPort("named", PortMapping.of(4712)) .addPort("hostname", PortMapping.of(4713)) .setCreatingUser(TEST_USER) .build(); }
@Test public void testMergeFileAndCliArgs() throws Exception { 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"),
@Before public void setup() throws Exception { startDefaultMaster(); client = defaultClient(); startDefaultAgent(testHost()); job = Job.newBuilder() .setName(testJobName) .setVersion(testJobVersion) .setImage(BUSYBOX) .addRamdisk("/much-volatile", "rw,noexec,nosuid,size=1") .setCommand(asList("sh", "-c", "nc -p 4711 -lle sh -c \"df | grep much-volatile\"")) .addPort("df", PortMapping.of(4711)) .setCreatingUser(TEST_USER) .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); }
"foo", PortMapping.of(4711), "bar", PortMapping.of(5000, externalPort)); final Map<ServiceEndpoint, ServicePorts> registration = ImmutableMap.of( ServiceEndpoint.of("foo-service", "tcp"), ServicePorts.of("foo"), job.getRegistration().get(ServiceEndpoint.of("bar-service", "http"))); assertEquals(4711, job.getPorts().get("foo").getInternalPort()); assertEquals(PortMapping.of(5000, externalPort), job.getPorts().get("bar")); assertEquals("f00d", job.getEnv().get("BAD"));
.setImage(BUSYBOX) .setCommand(asList("sh", "-c", "nc -l -p 4711")) .addPort(portName, PortMapping.of(4711)) .addRegistration(ServiceEndpoint.of(serviceName, serviceProtocol), ServicePorts.of(portName))
@Test public void test() throws Exception { final Map<String, PortMapping> ports = ImmutableMap.of( "foos", PortMapping.of(17, externalPort));
.setVersion("v2") .setImage(MEMCACHED) .setPorts(ImmutableMap.of("tcp", PortMapping.of(11211, externalPort))) .build(); final JobId jobId2 = job2.getId();
.setImage(BUSYBOX) .setCommand(asList("nc", "-p", "4711", "-l")) .addPort("poke", PortMapping.of(4711)) .build();
private TemporaryJobBuilder port(String name, int internalPort, Integer externalPort, boolean wait, String protocol) { this.builder.addPort(name, PortMapping.of(internalPort, externalPort, protocol)); if (wait) { waitPorts.add(name); } return this; }
explicitPorts.put(portName, PortMapping.of(internal, external, protocol));