com.spotify.docker.client.messages.HostConfig Java Examples

The following examples show how to use com.spotify.docker.client.messages.HostConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetworkModeTest.java    From helios with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
  final CreateJobResponse created = client.createJob(job).get();
  assertEquals(CreateJobResponse.Status.OK, created.getStatus());

  final JobId jobId = job.getId();
  // Wait for agent to come up
  awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
  awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);

  // Deploy the job on the agent
  final Deployment deployment = Deployment.of(jobId, START);
  final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
  assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());

  // Wait for the job to run
  final TaskStatus taskStatus = awaitJobState(
      client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);

  try (final DockerClient docker = getNewDockerClient()) {
    final HostConfig hostConfig =
        docker.inspectContainer(taskStatus.getContainerId()).hostConfig();
    assertEquals(NETWORK_MODE, hostConfig.networkMode());
  }
}
 
Example #2
Source File: DockerBasedTestExecutor.java    From pravega with Apache License 2.0 6 votes vote down vote up
private ContainerConfig setContainerConfig(String methodName, String className) {

        Map<String, String> labels = new HashMap<>(2);
        labels.put("testMethodName", methodName);
        labels.put("testClassName", className);

        HostConfig hostConfig = HostConfig.builder()
                .portBindings(ImmutableMap.of(DOCKER_CLIENT_PORT + "/tcp", Arrays.asList(PortBinding.
                        of(LoginClient.MESOS_MASTER, DOCKER_CLIENT_PORT)))).networkMode("docker_gwbridge").build();

        ContainerConfig containerConfig = ContainerConfig.builder()
                .hostConfig(hostConfig)
                .image(IMAGE)
                .user("root")
                .workingDir("/data")
                .cmd("sh", "-c", "java -DmasterIP=" + LoginClient.MESOS_MASTER + " -DexecType=" + getConfig("execType",
                        "LOCAL") + " -Dlog.level=" + LOG_LEVEL +  " -cp /data/build/libs/test-docker-collection.jar io.pravega.test.system." +
                        "SingleJUnitTestRunner " + className + "#" + methodName + " > server.log 2>&1")
                .labels(labels)
                .build();

        return containerConfig;
    }
 
Example #3
Source File: DefaultDockerClientUnitTest.java    From docker-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testChunkedRequestEntityProcessing() throws Exception {
  builder.useRequestEntityProcessing(RequestEntityProcessing.CHUNKED);
  final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
  
  final HostConfig hostConfig = HostConfig.builder().build();

  final ContainerConfig containerConfig = ContainerConfig.builder()
      .hostConfig(hostConfig)
      .build();

  server.enqueue(new MockResponse());

  dockerClient.createContainer(containerConfig);

  final RecordedRequest recordedRequest = takeRequestImmediately();

  assertThat(recordedRequest.getHeader("Content-Length"), nullValue());
  assertThat(recordedRequest.getHeader("Transfer-Encoding"), is("chunked"));
}
 
Example #4
Source File: SamlIdpITConfigFactory.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private static Builder keycloakConfigBuilder(final String image,
                                             final String userName,
                                             final String password,
                                             final List<String> portMappingPorts,
                                             final DockerCommandLineConfig config)
{
  HostConfig.Builder hostConfig = HostConfig.builder()
      .portBindings(portMappingPorts.stream()
          .collect(toMap(o -> o, b -> singletonList(randomPort(PORT_MAPPING_IP)))));

  return DockerContainerConfig.builder()
      .image(image)
      .env("KEYCLOAK_USER=" + userName, "KEYCLOAK_PASSWORD=" + password)
      .withHostConfigBuilder(hostConfig.appendBinds(config.getPathBinds()))
      .withDockerClientBuilder(defaultDockerClientBuilder().readTimeoutMillis(SECONDS.toMillis(5000)));
}
 
Example #5
Source File: SyslogRedirectingContainerDecoratorTest.java    From helios with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDockerVersionPost1_9() {
  final Optional<String> dockerVersion = Optional.of("1.12.1");

  final SyslogRedirectingContainerDecorator decorator =
      new SyslogRedirectingContainerDecorator(SYSLOG_HOST_PORT);

  final HostConfig.Builder hostBuilder = HostConfig.builder();
  decorator.decorateHostConfig(JOB, dockerVersion, hostBuilder);

  final ContainerConfig.Builder containerBuilder = ContainerConfig.builder();
  decorator.decorateContainerConfig(JOB, imageInfo, dockerVersion, containerBuilder);

  final ContainerConfig containerConfig = containerBuilder.build();
  assertThat(containerConfig.entrypoint(), not(hasItem("/helios/syslog-redirector")));

  final HostConfig hostConfig = hostBuilder.build();
  final LogConfig logConfig = hostConfig.logConfig();
  assertEquals("syslog", logConfig.logType());
  assertEquals(JOB.getId().toString(), logConfig.logOptions().get("tag"));
  assertEquals("udp://" + SYSLOG_HOST_PORT, logConfig.logOptions().get("syslog-address"));
}
 
Example #6
Source File: SyslogRedirectingContainerDecoratorTest.java    From helios with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDockerVersionPre1_9() {
  final Optional<String> dockerVersion = Optional.of("1.6.0");

  final SyslogRedirectingContainerDecorator decorator =
      new SyslogRedirectingContainerDecorator(SYSLOG_HOST_PORT);

  final HostConfig.Builder hostBuilder = HostConfig.builder();
  decorator.decorateHostConfig(JOB, dockerVersion, hostBuilder);

  final ContainerConfig.Builder containerBuilder = ContainerConfig.builder();
  decorator.decorateContainerConfig(JOB, imageInfo, dockerVersion, containerBuilder);

  final ContainerConfig containerConfig = containerBuilder.build();
  assertThat(containerConfig.entrypoint(), hasItem("/helios/syslog-redirector"));

  final HostConfig hostConfig = hostBuilder.build();
  assertNull(hostConfig.logConfig());
  assertFalse(hostConfig.binds().isEmpty());
}
 
Example #7
Source File: DefaultDockerClientUnitTest.java    From docker-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testBufferedRequestEntityProcessing() throws Exception {
  builder.useRequestEntityProcessing(RequestEntityProcessing.BUFFERED);
  final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
  
  final HostConfig hostConfig = HostConfig.builder().build();

  final ContainerConfig containerConfig = ContainerConfig.builder()
      .hostConfig(hostConfig)
      .build();

  server.enqueue(new MockResponse());

  dockerClient.createContainer(containerConfig);

  final RecordedRequest recordedRequest = takeRequestImmediately();

  assertThat(recordedRequest.getHeader("Content-Length"), notNullValue());
  assertThat(recordedRequest.getHeader("Transfer-Encoding"), nullValue());
}
 
Example #8
Source File: SyslogRedirectingContainerDecorator.java    From helios with Apache License 2.0 6 votes vote down vote up
@Override
public void decorateHostConfig(Job job, Optional<String> dockerVersion,
                               HostConfig.Builder hostConfigBuilder) {
  final HostConfig hostConfig = hostConfigBuilder.build();
  if (useSyslogRedirector(dockerVersion)) {
    final List<String> binds = Lists.newArrayList();
    if (hostConfig.binds() != null) {
      binds.addAll(hostConfig.binds());
    }
    binds.add("/usr/lib/helios:/helios:ro");
    hostConfigBuilder.binds(binds);
  } else {
    final ImmutableMap.Builder<String, String> logOpts = ImmutableMap.builder();

    logOpts.put("syslog-address", "udp://" + syslogHostPort);
    logOpts.put("syslog-facility", "local0"); // match the behavior of syslog-redirector

    logOpts.put("tag", job.getId().toString());

    hostConfigBuilder.logConfig(LogConfig.create("syslog", logOpts.build()));
  }
}
 
Example #9
Source File: RedisContainer.java    From pay-publicapi with MIT License 6 votes vote down vote up
RedisContainer(DockerClient docker, String host) throws DockerException, InterruptedException {

        this.docker = docker;
        this.host = host;

        failsafeDockerPull(docker);
        docker.listImages(DockerClient.ListImagesParam.create("name", REDIS_IMAGE));

        final HostConfig hostConfig = HostConfig.builder().logConfig(LogConfig.create("json-file")).publishAllPorts(true).build();
        ContainerConfig containerConfig = ContainerConfig.builder()
                .image(REDIS_IMAGE)
                .hostConfig(hostConfig)
                .build();
        containerId = docker.createContainer(containerConfig).id();
        docker.startContainer(containerId);
        port = hostPortNumber(docker.inspectContainer(containerId));
        registerShutdownHook();
        waitForRedisToStart();
    }
 
Example #10
Source File: DefaultDockerClient.java    From docker-client with Apache License 2.0 6 votes vote down vote up
@Override
public ContainerUpdate updateContainer(final String containerId, final HostConfig config)
    throws DockerException, InterruptedException {
  assertApiVersionIsAbove("1.22");
  try {
    WebTarget resource = resource().path("containers").path(containerId).path("update");
    return request(POST, ContainerUpdate.class, resource, resource.request(APPLICATION_JSON_TYPE),
            Entity.json(config));
  } catch (DockerRequestException e) {
    switch (e.status()) {
      case 404:
        throw new ContainerNotFoundException(containerId);
      default:
        throw e;
    }
  }
}
 
Example #11
Source File: BindVolumeContainerDecorator.java    From helios with Apache License 2.0 5 votes vote down vote up
@Override
public void decorateHostConfig(Job job, Optional<String> dockerVersion,
                               HostConfig.Builder hostConfigBuilder) {
  final List<String> b = Lists.newArrayList();

  final HostConfig hostConfig = hostConfigBuilder.build();

  if (hostConfig.binds() != null) {
    b.addAll(hostConfig.binds());
  }

  b.addAll(this.binds);

  hostConfigBuilder.binds(b);
}
 
Example #12
Source File: ReapingTest.java    From helios with Apache License 2.0 5 votes vote down vote up
private void startContainer(final String name)
    throws DockerException, InterruptedException {
  docker.pull(BUSYBOX);
  final HostConfig hostConfig = HostConfig.builder().build();
  final ContainerConfig config = ContainerConfig.builder()
      .image(BUSYBOX)
      .cmd(IDLE_COMMAND)
      .hostConfig(hostConfig)
      .build();
  final ContainerCreation creation = docker.createContainer(config, name);
  final String containerId = creation.id();
  docker.startContainer(containerId);
}
 
Example #13
Source File: TaskConfig.java    From helios with Apache License 2.0 5 votes vote down vote up
/**
 * Create a container host configuration for the job.
 *
 * @return The host configuration.
 */
public HostConfig hostConfig(final Optional<String> dockerVersion) {
  final List<String> securityOpt = job.getSecurityOpt();
  final HostConfig.Builder builder = HostConfig.builder()
      .binds(binds())
      .portBindings(portBindings())
      .dns(dns)
      .securityOpt(securityOpt.toArray(new String[securityOpt.size()]))
      .runtime(job.getRuntime())
      .networkMode(job.getNetworkMode());

  if (!job.getRamdisks().isEmpty()) {
    builder.tmpfs(job.getRamdisks());
  }

  final Resources resources = job.getResources();
  if (resources != null) {
    builder.memory(resources.getMemory());
    builder.memorySwap(resources.getMemorySwap());
    builder.cpusetCpus(resources.getCpuset());
    builder.cpuShares(resources.getCpuShares());
  }

  builder.capAdd(ImmutableList.copyOf(job.getAddCapabilities()));
  builder.capDrop(ImmutableList.copyOf(job.getDropCapabilities()));

  for (final ContainerDecorator decorator : containerDecorators) {
    decorator.decorateHostConfig(job, dockerVersion, builder);
  }

  return builder.build();
}
 
Example #14
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
private static String startAuthedRegistry(final DockerClient client) throws Exception {
  final Map<String, List<PortBinding>> ports = singletonMap(
      "5000/tcp", Collections.singletonList(PortBinding.of("0.0.0.0", 5000)));
  final HostConfig hostConfig = HostConfig.builder().portBindings(ports)
      .binds(ImmutableList.of(
          Resources.getResource("dockerRegistry/auth").getPath() + ":/auth",
          Resources.getResource("dockerRegistry/certs").getPath() + ":/certs"
      ))
      /*
       *  Mounting volumes requires special permissions on Docker >= 1.10.
       *  Until a proper Seccomp profile is in place, run container privileged.
       */
      .privileged(true)
      .build();

  final ContainerConfig containerConfig = ContainerConfig.builder()
      .image(REGISTRY_IMAGE)
      .hostConfig(hostConfig)
      .env(ImmutableList.of(
          "REGISTRY_AUTH=htpasswd",
          "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm",
          "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd",
          "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt",
          "REGISTRY_HTTP_TLS_KEY=/certs/domain.key",
          "REGISTRY_HTTP_SECRET=super-secret"
      ))
      .build();

  return startAndAwaitContainer(client, containerConfig, REGISTRY_NAME);
}
 
Example #15
Source File: TaskRunner.java    From helios with Apache License 2.0 5 votes vote down vote up
private String startContainer(final String image, final Optional<String> dockerVersion)
    throws InterruptedException, DockerException {

  // Get container image info
  final ImageInfo imageInfo = docker.inspectImage(image);
  if (imageInfo == null) {
    throw new HeliosRuntimeException("docker inspect image returned null on image " + image);
  }

  // Create container
  final HostConfig hostConfig = config.hostConfig(dockerVersion);
  final ContainerConfig containerConfig = config.containerConfig(imageInfo, dockerVersion)
      .toBuilder()
      .hostConfig(hostConfig)
      .build();
  listener.creating();
  final ContainerCreation container = docker.createContainer(containerConfig, containerName);
  log.info("created container: {}: {}, {}", config, container, containerConfig);
  listener.created(container.id());

  // Start container
  log.info("starting container: {}: {} {}", config, container.id(), hostConfig);
  listener.starting();
  docker.startContainer(container.id());
  log.info("started container: {}: {}", config, container.id());
  listener.started();

  return container.id();
}
 
Example #16
Source File: TaskConfigTest.java    From helios with Apache License 2.0 5 votes vote down vote up
@Test
public void testHostConfig() throws Exception {
  final TaskConfig taskConfig = TaskConfig.builder()
      .namespace("test")
      .host(HOST)
      .job(JOB)
      .build();

  final HostConfig hostConfig = taskConfig.hostConfig(Optional.absent());
  assertThat(ImmutableSet.copyOf(hostConfig.capAdd()), equalTo(CAP_ADDS));
  assertThat(ImmutableSet.copyOf(hostConfig.capDrop()), equalTo(CAP_DROPS));
}
 
Example #17
Source File: TaskConfigTest.java    From helios with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuntimeHostConfig() throws Exception {

  Job nvidiaRuntimeJob = JOB.toBuilder().setRuntime("nvidia").build();

  final TaskConfig taskConfig = TaskConfig.builder()
      .namespace("test")
      .host(HOST)
      .job(nvidiaRuntimeJob)
      .build();

  final HostConfig hostConfig = taskConfig.hostConfig(Optional.absent());
  assertThat(hostConfig.runtime(), equalTo("nvidia"));
}
 
Example #18
Source File: AddExtraHostContainerDecoratorTest.java    From helios with Apache License 2.0 5 votes vote down vote up
@Test
public void simpleTest() {
  final List<String> hosts = ImmutableList.of("one:one", "two:two");
  final AddExtraHostContainerDecorator decorator = new AddExtraHostContainerDecorator(hosts);

  final HostConfig.Builder hostBuilder = HostConfig.builder();
  decorator.decorateHostConfig(null, Optional.absent(), hostBuilder);

  final HostConfig config = hostBuilder.build();
  assertThat(config.extraHosts(), equalTo(hosts));
}
 
Example #19
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
private static String startUnauthedRegistry(final DockerClient client) throws Exception {
  final Map<String, List<PortBinding>> ports = singletonMap(
      "5000/tcp", Collections.singletonList(PortBinding.of("0.0.0.0", 5000)));
  final HostConfig hostConfig = HostConfig.builder().portBindings(ports)
      .build();

  final ContainerConfig containerConfig = ContainerConfig.builder()
      .image(REGISTRY_IMAGE)
      .hostConfig(hostConfig)
      .build();

  return startAndAwaitContainer(client, containerConfig, REGISTRY_NAME);
}
 
Example #20
Source File: DefaultDockerClientUnitTest.java    From docker-client with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testCapAddAndDrop() throws Exception {
  final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);

  final HostConfig hostConfig = HostConfig.builder()
      .capAdd(ImmutableList.of("foo", "bar"))
      .capAdd(ImmutableList.of("baz", "qux"))
      .build();

  final ContainerConfig containerConfig = ContainerConfig.builder()
      .hostConfig(hostConfig)
      .build();

  server.enqueue(new MockResponse());

  dockerClient.createContainer(containerConfig);

  final RecordedRequest recordedRequest = takeRequestImmediately();

  assertThat(recordedRequest.getMethod(), is("POST"));
  assertThat(recordedRequest.getPath(), is("/containers/create"));

  assertThat(recordedRequest.getHeader("Content-Type"), is("application/json"));

  final JsonNode requestJson = toJson(recordedRequest.getBody());
  assertThat(requestJson, is(jsonObject()
      .where("HostConfig", is(jsonObject()
          .where("CapAdd", is(jsonArray(
              containsInAnyOrder(jsonText("baz"), jsonText("qux")))))))));
}
 
Example #21
Source File: DockerClientITConfigFactory.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static DockerContainerConfig.Builder nginxConfigBuilder(final String image,
                                                                final List<String> portMappingPorts,
                                                                final DockerCommandLineConfig config)
{
  HostConfig.Builder hostConfig = HostConfig.builder()
      .portBindings(portMappingPorts.stream()
          .collect(toMap(o -> o, b -> singletonList(randomPort(PORT_MAPPING_IP)))));

  return DockerContainerConfig.builder()
      .image(image)
      .withHostConfigBuilder(hostConfig.appendBinds(config.getPathBinds()))
      .withDockerClientBuilder(defaultDockerClientBuilder().readTimeoutMillis(SECONDS.toMillis(5000)));
}
 
Example #22
Source File: DockerContainer.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
private static List<String> extraHosts(ContainerInfo containerInfo) {
    HostConfig hostConfig = containerInfo.hostConfig();
    if (hostConfig != null) {
       return hostConfig.extraHosts();
    }
    return new ArrayList<>();
}
 
Example #23
Source File: GCloudEmulatorManager.java    From flink with Apache License 2.0 4 votes vote down vote up
public static void launchDocker() throws DockerException, InterruptedException, DockerCertificateException {
	// Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars
	docker = DefaultDockerClient.fromEnv().build();

	terminateAndDiscardAnyExistingContainers(true);

	LOG.info("");
	LOG.info("/===========================================");
	LOG.info("| GCloud Emulator");

	ContainerInfo containerInfo;
	String id;

	try {
		docker.inspectImage(DOCKER_IMAGE_NAME);
	} catch (ImageNotFoundException e) {
		// No such image so we must download it first.
		LOG.info("| - Getting docker image \"{}\"", DOCKER_IMAGE_NAME);
		docker.pull(DOCKER_IMAGE_NAME, message -> {
			if (message.id() != null && message.progress() != null) {
				LOG.info("| - Downloading > {} : {}", message.id(), message.progress());
			}
		});
	}

	// No such container. Good, we create one!
	LOG.info("| - Creating new container");

	// Bind container ports to host ports
	final Map<String, List<PortBinding>> portBindings = new HashMap<>();
	portBindings.put(INTERNAL_PUBSUB_PORT, Collections.singletonList(PortBinding.randomPort("0.0.0.0")));

	final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();

	// Create new container with exposed ports
	final ContainerConfig containerConfig = ContainerConfig.builder()
		.hostConfig(hostConfig)
		.exposedPorts(INTERNAL_PUBSUB_PORT)
		.image(DOCKER_IMAGE_NAME)
		.cmd("sh", "-c", "mkdir -p /opt/data/pubsub ; gcloud beta emulators pubsub start --data-dir=/opt/data/pubsub --host-port=0.0.0.0:" + INTERNAL_PUBSUB_PORT)
		.build();

	final ContainerCreation creation = docker.createContainer(containerConfig, CONTAINER_NAME_JUNIT);
	id = creation.id();

	containerInfo = docker.inspectContainer(id);

	if (!containerInfo.state().running()) {
		LOG.warn("| - Starting it up ....");
		docker.startContainer(id);
		Thread.sleep(1000);
	}

	containerInfo = docker.inspectContainer(id);

	dockerIpAddress = "127.0.0.1";

	Map<String, List<PortBinding>> ports = containerInfo.networkSettings().ports();

	assertNotNull("Unable to retrieve the ports where to connect to the emulators", ports);
	assertEquals("We expect 1 port to be mapped", 1, ports.size());

	pubsubPort = getPort(ports, INTERNAL_PUBSUB_PORT, "PubSub");

	LOG.info("| Waiting for the emulators to be running");

	// PubSub exposes an "Ok" at the root url when running.
	if (!waitForOkStatus("PubSub", pubsubPort)) {
		// Oops, we did not get an "Ok" within 10 seconds
		startHasFailedKillEverything();
	}
	LOG.info("\\===========================================");
	LOG.info("");
}
 
Example #24
Source File: GCloudEmulatorManager.java    From flink with Apache License 2.0 4 votes vote down vote up
public static void launchDocker() throws DockerException, InterruptedException, DockerCertificateException {
	// Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars
	docker = DefaultDockerClient.fromEnv().build();

	terminateAndDiscardAnyExistingContainers(true);

	LOG.info("");
	LOG.info("/===========================================");
	LOG.info("| GCloud Emulator");

	ContainerInfo containerInfo;
	String id;

	try {
		docker.inspectImage(DOCKER_IMAGE_NAME);
	} catch (ImageNotFoundException e) {
		// No such image so we must download it first.
		LOG.info("| - Getting docker image \"{}\"", DOCKER_IMAGE_NAME);
		docker.pull(DOCKER_IMAGE_NAME, message -> {
			if (message.id() != null && message.progress() != null) {
				LOG.info("| - Downloading > {} : {}", message.id(), message.progress());
			}
		});
	}

	// No such container. Good, we create one!
	LOG.info("| - Creating new container");

	// Bind container ports to host ports
	final Map<String, List<PortBinding>> portBindings = new HashMap<>();
	portBindings.put(INTERNAL_PUBSUB_PORT, Collections.singletonList(PortBinding.randomPort("0.0.0.0")));

	final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();

	// Create new container with exposed ports
	final ContainerConfig containerConfig = ContainerConfig.builder()
		.hostConfig(hostConfig)
		.exposedPorts(INTERNAL_PUBSUB_PORT)
		.image(DOCKER_IMAGE_NAME)
		.cmd("sh", "-c", "mkdir -p /opt/data/pubsub ; gcloud beta emulators pubsub start --data-dir=/opt/data/pubsub  --host-port=0.0.0.0:" + INTERNAL_PUBSUB_PORT)
		.build();

	final ContainerCreation creation = docker.createContainer(containerConfig, CONTAINER_NAME_JUNIT);
	id = creation.id();

	containerInfo = docker.inspectContainer(id);

	if (!containerInfo.state().running()) {
		LOG.warn("| - Starting it up ....");
		docker.startContainer(id);
		Thread.sleep(1000);
	}

	containerInfo = docker.inspectContainer(id);

	dockerIpAddress = "127.0.0.1";

	Map<String, List<PortBinding>> ports = containerInfo.networkSettings().ports();

	assertNotNull("Unable to retrieve the ports where to connect to the emulators", ports);
	assertEquals("We expect 1 port to be mapped", 1, ports.size());

	pubsubPort = getPort(ports, INTERNAL_PUBSUB_PORT, "PubSub");

	LOG.info("| Waiting for the emulators to be running");

	// PubSub exposes an "Ok" at the root url when running.
	if (!waitForOkStatus("PubSub", pubsubPort)) {
		// Oops, we did not get an "Ok" within 10 seconds
		startHasFailedKillEverything();
	}
	LOG.info("\\===========================================");
	LOG.info("");
}
 
Example #25
Source File: ResourcesTest.java    From helios with Apache License 2.0 4 votes vote down vote up
@Test
public void testClient() throws Exception {
  // Doesn't work on CircleCI because their lxc-driver can't set cpus
  // See output of `docker run --cpuset-cpus 0-1 spotify/busybox:latest true`
  assumeFalse(isCircleCi());

  final CreateJobResponse created = client.createJob(job).get();
  assertEquals(CreateJobResponse.Status.OK, created.getStatus());

  final JobId jobId = job.getId();
  // Wait for agent to come up
  awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
  awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);

  // Deploy the job on the agent
  final Deployment deployment = Deployment.of(jobId, START);
  final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
  assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());

  // Wait for the job to run
  final TaskStatus taskStatus = awaitJobState(
      client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
  assertJobEquals(job, taskStatus.getJob());

  try (final DockerClient docker = getNewDockerClient()) {

    final HostConfig hostConfig =
        docker.inspectContainer(taskStatus.getContainerId()).hostConfig();

    assertEquals(CPU_SHARES, hostConfig.cpuShares());
    assertEquals(CPUSET_CPUS, hostConfig.cpusetCpus());

    final Info info = docker.info();
    final Iterable<String> split = Splitter.on(".").split(docker.version().apiVersion());
    //noinspection ConstantConditions
    final int major = Integer.parseInt(Iterables.get(split, 0, "0"));
    //noinspection ConstantConditions
    final int minor = Integer.parseInt(Iterables.get(split, 1, "0"));

    // TODO (dxia) This doesn't work on docker < 1.7 ie docker API < 1.19 for some reason.
    if (major >= 1 && minor >= 19) {
      if (info.memoryLimit()) {
        assertEquals(MEMORY, hostConfig.memory());
      }
      if (info.swapLimit()) {
        assertEquals(MEMORY_SWAP, hostConfig.memorySwap());
      }
    }
  }
}
 
Example #26
Source File: AddExtraHostContainerDecorator.java    From helios with Apache License 2.0 4 votes vote down vote up
@Override
public void decorateHostConfig(final Job job, final Optional<String> dockerVersion,
                               final HostConfig.Builder hostConfig) {
  hostConfig.extraHosts(this.extraHosts);
}
 
Example #27
Source File: DockerContainerConfig.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public HostConfig.Builder getHostConfigBuilder() {
  return hostConfigBuilder;
}
 
Example #28
Source File: NoOpContainerDecorator.java    From helios with Apache License 2.0 4 votes vote down vote up
@Override
public void decorateHostConfig(Job job, Optional<String> dockerVersion,
                               HostConfig.Builder hostConfig) {
  //noop
}
 
Example #29
Source File: DockerContainerConfig.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public static HostConfig.Builder defaultHostConfigBuilder() {
  return HostConfig.builder()
      .portBindings(stream(PORT_MAPPING_PORTS)
          .collect(toMap(o -> o, b -> singletonList(randomPort(PORT_MAPPING_IP)))));
}
 
Example #30
Source File: DockerContainerConfig.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public Builder withHostConfigBuilder(HostConfig.Builder hostConfigBuilder) {
  this.hostConfigBuilder = hostConfigBuilder;
  return this;
}