com.spotify.docker.client.messages.mount.Mount Java Examples

The following examples show how to use com.spotify.docker.client.messages.mount.Mount. 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: DockerMounts.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 6 votes vote down vote up
public List<Mount> toMount() {
    final List<Mount> mounts = new ArrayList<>();

    for (DockerMount dockerMount : this) {
        final Mount mount = Mount.builder()
                .type(dockerMount.type())
                .source(dockerMount.source())
                .target(dockerMount.target())
                .readOnly(dockerMount.readOnly())
                .build();

        mounts.add(mount);
    }

    return mounts;
}
 
Example #2
Source File: DockerMountsTest.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBuildMountFromDockerMount() {
    final DockerMounts dockerMounts = DockerMounts.fromString("source=namedVolume, target=/path/in/container\ntype=bind, src=/path/in/host, target=/path/in/container2, readonly");
    final Volume volume = mock(Volume.class);

    when(volume.name()).thenReturn("namedVolume");

    final List<Mount> mounts = dockerMounts.toMount();

    assertThat(mounts, hasSize(2));
    assertThat(mounts.get(0).type(), is("volume"));
    assertThat(mounts.get(0).source(), is("namedVolume"));
    assertThat(mounts.get(0).target(), is("/path/in/container"));
    assertThat(mounts.get(0).readOnly(), is(false));

    assertThat(mounts.get(1).type(), is("bind"));
    assertThat(mounts.get(1).source(), is("/path/in/host"));
    assertThat(mounts.get(1).target(), is("/path/in/container2"));
    assertThat(mounts.get(1).readOnly(), is(true));
}
 
Example #3
Source File: DockerServiceElasticAgentTest.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldStartContainerWithMountedVolume() throws Exception {
    requireDockerApiVersionAtLeast("1.26", "Docker volume mount.");

    final String volumeName = UUID.randomUUID().toString();

    final Volume volume = docker.createVolume(Volume.builder()
            .name(volumeName)
            .driver("local")
            .labels(Collections.singletonMap("cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerPlugin", ""))
            .build()
    );

    Map<String, String> properties = new HashMap<>();
    properties.put("Image", "alpine:latest");
    properties.put("Mounts", "source=" + volumeName + ", target=/path/in/container");

    DockerService service = DockerService.create(new CreateAgentRequest("key", properties, "prod", new JobIdentifier(100L), new HashMap<>()), createClusterProfiles(), docker);
    services.add(service.name());

    final Service inspectServiceInfo = docker.inspectService(service.name());
    final Mount mount = inspectServiceInfo.spec().taskTemplate().containerSpec().mounts().get(0);

    assertThat(mount.source(), is(volumeName));
    assertThat(mount.type(), is("volume"));
}
 
Example #4
Source File: ContainerSpec.java    From docker-client with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated  As of release 7.0.0, replaced by {@link #mounts(Mount...)}.
 */
@Deprecated
public Builder withMounts(final Mount... mounts) {
  if (mounts != null && mounts.length > 0) {
    mounts(mounts);
  }
  return this;
}
 
Example #5
Source File: ContainerSpec.java    From docker-client with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated  As of release 7.0.0, replaced by {@link #mounts(List)}.
 */
@Deprecated
public Builder withMounts(final List<Mount> mounts) {
  if (mounts != null && !mounts.isEmpty()) {
    mounts(mounts);
  }
  return this;
}
 
Example #6
Source File: HDFSDockerService.java    From pravega with Apache License 2.0 4 votes vote down vote up
private ServiceSpec setServiceSpec() {
    Map<String, String> labels = new HashMap<>();
    labels.put("com.docker.swarm.task.name", serviceName);
    Mount mount = Mount.builder().type("volume").source("hadoop-logs").target("/opt/hadoop/logs").build();
    String env1 = "SSH_PORT=2222";
    String env2 = "HDFS_HOST=" + serviceName;

    final TaskSpec taskSpec = TaskSpec
            .builder()
            .networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build())
            .containerSpec(ContainerSpec.builder().image(hdfsimage).env(Arrays.asList(env1, env2))
                    .healthcheck(ContainerConfig.Healthcheck.builder().test(customHealthCheck("ss -l | grep " + HDFS_PORT + " || exit 1")).build())
                    .mounts(mount)
                    .labels(labels)
                    .hostname(serviceName)
                    .build())
            .resources(ResourceRequirements.builder()
                    .reservations(Resources.builder()
                            .memoryBytes(setMemInBytes(mem)).nanoCpus(setNanoCpus(cpu)).build())
                    .build())
            .build();
    List<PortConfig> portConfigs = new ArrayList<>();
    PortConfig port1 = PortConfig.builder().publishedPort(8020).targetPort(8020).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs").build();
    PortConfig port2 = PortConfig.builder().publishedPort(50090).targetPort(50090).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-secondary").build();
    PortConfig port3 = PortConfig.builder().publishedPort(50010).targetPort(50010).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode").build();
    PortConfig port4 = PortConfig.builder().publishedPort(50020).targetPort(50020).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode-ipc").build();
    PortConfig port5 = PortConfig.builder().publishedPort(50075).targetPort(50075).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode-http").build();
    PortConfig port6 = PortConfig.builder().publishedPort(50070).targetPort(50070).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-web").build();
    PortConfig port7 = PortConfig.builder().publishedPort(2222).targetPort(2222).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-ssh").build();
    portConfigs.add(port1);
    portConfigs.add(port2);
    portConfigs.add(port3);
    portConfigs.add(port4);
    portConfigs.add(port5);
    portConfigs.add(port6);
    portConfigs.add(port7);

    ServiceSpec spec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(ServiceMode.withReplicas(instances))
            .networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build())
            .endpointSpec(EndpointSpec.builder().ports(portConfigs)
                    .build()).build();
    return spec;
}
 
Example #7
Source File: PravegaControllerDockerService.java    From pravega with Apache License 2.0 4 votes vote down vote up
private ServiceSpec setServiceSpec() {
    Mount mount = Mount.builder().type("Volume").source("controller-logs").target("/opt/pravega/logs").build();
    String zk = zkUri.getHost() + ":" + ZKSERVICE_ZKPORT;
    Map<String, String> stringBuilderMap = new HashMap<>();
    stringBuilderMap.put("controller.zk.connect.uri", zk);
    stringBuilderMap.put("controller.service.rpc.published.host.nameOrIp", serviceName);
    stringBuilderMap.put("controller.service.rpc.published.port", String.valueOf(controllerPort));
    stringBuilderMap.put("controller.service.rpc.listener.port", String.valueOf(controllerPort));
    stringBuilderMap.put("controller.service.rest.listener.port", String.valueOf(restPort));
    stringBuilderMap.put("log.level", "DEBUG");
    stringBuilderMap.put("curator-default-session-timeout", String.valueOf(10 * 1000));
    stringBuilderMap.put("controller.zk.connect.session.timeout.milliseconds", String.valueOf(30 * 1000));
    stringBuilderMap.put("controller.transaction.lease.count.max", String.valueOf(120 * 1000));
    stringBuilderMap.put("controller.retention.frequency.minutes", String.valueOf(2));
    StringBuilder systemPropertyBuilder = new StringBuilder();
    for (Map.Entry<String, String> entry : stringBuilderMap.entrySet()) {
        systemPropertyBuilder.append("-D").append(entry.getKey()).append("=").append(entry.getValue()).append(" ");
    }

    String controllerSystemProperties = systemPropertyBuilder.toString();
    String env1 = "PRAVEGA_CONTROLLER_OPTS=" + controllerSystemProperties;
    String env2 = "JAVA_OPTS=-Xmx512m";
    Map<String, String> labels = new HashMap<>();
    labels.put("com.docker.swarm.task.name", serviceName);

    final TaskSpec taskSpec = TaskSpec
            .builder()
            .networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build())
            .containerSpec(ContainerSpec.builder().image(IMAGE_PATH + IMAGE_PREFIX + PRAVEGA_IMAGE_NAME + PRAVEGA_VERSION)
                    .healthcheck(ContainerConfig.Healthcheck.builder().test(defaultHealthCheck(controllerPort)).build())
                    .mounts(Arrays.asList(mount))
                    .hostname(serviceName)
                    .labels(labels)
                    .env(Arrays.asList(env1, env2)).args("controller").build())
            .resources(ResourceRequirements.builder()
                    .reservations(Resources.builder()
                            .memoryBytes(setMemInBytes(mem)).nanoCpus(setNanoCpus(cpu)).build())
                    .build())
            .build();
    ServiceSpec spec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(ServiceMode.withReplicas(instances))
            .endpointSpec(EndpointSpec.builder()
                    .ports(Arrays.asList(PortConfig.builder()
                                    .publishedPort(controllerPort).targetPort(controllerPort).publishMode(PortConfig.PortConfigPublishMode.HOST).build(),
                            PortConfig.builder().publishedPort(restPort).targetPort(restPort).publishMode(PortConfig.PortConfigPublishMode.HOST).build())).
                            build())
            .build();
    return spec;
}
 
Example #8
Source File: PravegaSegmentStoreDockerService.java    From pravega with Apache License 2.0 4 votes vote down vote up
private ServiceSpec setServiceSpec() {
    Map<String, String> labels = new HashMap<>();
    labels.put("com.docker.swarm.task.name", serviceName);

    Mount mount = Mount.builder().type("volume").source("segmentstore-logs").target("/opt/pravega/logs").build();
    String zk = zkUri.getHost() + ":" + ZKSERVICE_ZKPORT;
    //System properties to configure SS service.
    Map<String, String> stringBuilderMap = new HashMap<>();
    StringBuilder systemPropertyBuilder = new StringBuilder();
    stringBuilderMap.put("autoScale.muteInSeconds", "120");
    stringBuilderMap.put("autoScale.cooldownInSeconds", "120");
    stringBuilderMap.put("autoScale.cacheExpiryInSeconds", "120");
    stringBuilderMap.put("autoScale.cacheCleanUpInSeconds", "120");
    stringBuilderMap.put("log.level", "DEBUG");
    stringBuilderMap.put("curator-default-session-timeout", String.valueOf(30 * 1000));
    stringBuilderMap.put("hdfs.replaceDataNodesOnFailure", "false");
    stringBuilderMap.put("bookkeeper.bkAckQuorumSize", "3");
    for (Map.Entry<String, String> entry : stringBuilderMap.entrySet()) {
        systemPropertyBuilder.append("-D").append(entry.getKey()).append("=").append(entry.getValue()).append(" ");
    }

    String hostSystemProperties = systemPropertyBuilder.toString();

    //set env
    String env1 = "PRAVEGA_SEGMENTSTORE_OPTS=" + hostSystemProperties;
    String env2 = "JAVA_OPTS=-Xmx2000m";
    List<String> envList = new ArrayList<>();
    envList.add(env1);
    envList.add(env2);
    getCustomEnvVars(envList, SEGMENTSTORE_EXTRA_ENV, hdfsUri);
    String env3 = "ZK_URL=" + zk;
    String env4 = "BK_ZK_URL=" + zk;
    String env5 = "CONTROLLER_URL=" + conUri.toString();
    envList.add(env3);
    envList.add(env4);
    envList.add(env5);

    final TaskSpec taskSpec = TaskSpec
            .builder()
            .networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).build())
            .containerSpec(ContainerSpec.builder().image(IMAGE_PATH + IMAGE_PREFIX + PRAVEGA_IMAGE_NAME + PRAVEGA_VERSION)
                    .hostname(serviceName)
                    .labels(labels)
                    .healthcheck(ContainerConfig.Healthcheck.builder().test(defaultHealthCheck(SEGMENTSTORE_PORT)).build())
                    .mounts(Arrays.asList(mount))
                    .env(envList).args("segmentstore").build())
            .resources(ResourceRequirements.builder()
                    .reservations(Resources.builder()
                            .memoryBytes(setMemInBytes(mem)).nanoCpus(setNanoCpus(cpu)).build())
                    .build())
            .build();
    ServiceSpec spec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(ServiceMode.withReplicas(instances))
            .endpointSpec(EndpointSpec.builder().ports(PortConfig.builder().
                    publishedPort(SEGMENTSTORE_PORT).targetPort(SEGMENTSTORE_PORT).publishMode(PortConfig.PortConfigPublishMode.HOST).build())
                    .build()).build();
    return spec;
}
 
Example #9
Source File: ContainerSpec.java    From docker-client with Apache License 2.0 4 votes vote down vote up
@Nullable
@JsonProperty("Mounts")
public abstract ImmutableList<Mount> mounts();
 
Example #10
Source File: ContainerSpec.java    From docker-client with Apache License 2.0 4 votes vote down vote up
@JsonCreator
static ContainerSpec create(
    @JsonProperty("Image") final String image,
    @JsonProperty("Labels") final Map<String, String> labels,
    @JsonProperty("Hostname") final String hostname,
    @JsonProperty("Command") final List<String> command,
    @JsonProperty("Args") final List<String> args,
    @JsonProperty("Env") final List<String> env,
    @JsonProperty("Dir") final String dir,
    @JsonProperty("User") final String user,
    @JsonProperty("Groups") final List<String> groups,
    @JsonProperty("TTY") final Boolean tty,
    @JsonProperty("Mounts") final List<Mount> mounts,
    @JsonProperty("StopGracePeriod") final Long stopGracePeriod,
    @JsonProperty("Healthcheck") final ContainerConfig.Healthcheck healthcheck,
    @JsonProperty("Hosts") final List<String> hosts,
    @JsonProperty("Secrets") final List<SecretBind> secrets,
    @JsonProperty("DNSConfig") final DnsConfig dnsConfig,
    @JsonProperty("Configs") final List<ConfigBind> configs) {
  final Builder builder = builder()
      .image(image)
      .hostname(hostname)
      .args(args)
      .env(env)
      .dir(dir)
      .user(user)
      .groups(groups)
      .tty(tty)
      .mounts(mounts)
      .stopGracePeriod(stopGracePeriod)
      .healthcheck(healthcheck)
      .hosts(hosts)
      .dnsConfig(dnsConfig)
      .command(command)
      .secrets(secrets)
      .configs(configs);

  if (labels != null) {
    builder.labels(labels);
  }

  return builder.build();
}