All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spotify.docker.client.messages.swarm.ContainerSpec Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
/*-
 * -\-\-
 * docker-client
 * --
 * Copyright (C) 2016 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * -/-/-
 */

package com.spotify.docker.client.messages.swarm;

import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.spotify.docker.client.messages.ContainerConfig;
import com.spotify.docker.client.messages.mount.Mount;

import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

@AutoValue
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
public abstract class ContainerSpec {

  @JsonProperty("Image")
  public abstract String image();

  /**
   * @since API 1.26
   */
  @Nullable
  @JsonProperty("Hostname")
  public abstract String hostname();

  @Nullable
  @JsonProperty("Labels")
  public abstract ImmutableMap labels();

  @Nullable
  @JsonProperty("Command")
  public abstract ImmutableList command();

  @Nullable
  @JsonProperty("Args")
  public abstract ImmutableList args();

  @Nullable
  @JsonProperty("Env")
  public abstract ImmutableList env();

  @Nullable
  @JsonProperty("Dir")
  public abstract String dir();

  @Nullable
  @JsonProperty("User")
  public abstract String user();

  @Nullable
  @JsonProperty("Groups")
  public abstract ImmutableList groups();

  @Nullable
  @JsonProperty("TTY")
  public abstract Boolean tty();

  @Nullable
  @JsonProperty("Mounts")
  public abstract ImmutableList mounts();

  @Nullable
  @JsonProperty("StopGracePeriod")
  public abstract Long stopGracePeriod();

  /**
   * @since API 1.26
   */
  @Nullable
  @JsonProperty("Healthcheck")
  public abstract ContainerConfig.Healthcheck healthcheck();

  /**
   * @since API 1.26
   */
  @Nullable
  @JsonProperty("Hosts")
  public abstract ImmutableList hosts();

  /**
   * @since API 1.26
   */
  @Nullable
  @JsonProperty("Secrets")
  public abstract ImmutableList secrets();

  /**
   * @since API 1.30
   */
  @Nullable
  @JsonProperty("Configs")
  public abstract ImmutableList configs();

  @Nullable
  @JsonProperty("DNSConfig")
  public abstract DnsConfig dnsConfig();


  @AutoValue.Builder
  public abstract static class Builder {

    public abstract Builder image(String image);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #image(String)}.
     */
    @Deprecated
    public Builder withImage(final String image) {
      image(image);
      return this;
    }

    abstract ImmutableMap.Builder labelsBuilder();

    public Builder addLabel(final String label, final String value) {
      labelsBuilder().put(label, value);
      return this;
    }

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #addLabel(String, String)} ()}.
     */
    @Deprecated
    public Builder withLabel(final String label, final String value) {
      addLabel(label, value);
      return this;
    }

    public abstract Builder hostname(String hostname);

    public abstract Builder labels(Map labels);

    public abstract Builder command(String... commands);

    public abstract Builder command(List commands);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #command(String...)}.
     */
    @Deprecated
    public Builder withCommands(final String... commands) {
      if (commands != null && commands.length > 0) {
        command(commands);
      }
      return this;
    }

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #command(List)}.
     */
    @Deprecated
    public Builder withCommands(final List commands) {
      if (commands != null && !commands.isEmpty()) {
        command(commands);
      }
      return this;
    }

    public abstract Builder args(String... args);

    public abstract Builder args(List args);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #args(String...)}.
     */
    @Deprecated
    public Builder withArgs(final String... args) {
      if (args != null && args.length > 0) {
        args(args);
      }
      return this;
    }

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #args(List)}.
     */
    @Deprecated
    public Builder withArgs(final List args) {
      if (args != null && !args.isEmpty()) {
        args(args);
      }
      return this;
    }

    public abstract Builder env(String... env);

    public abstract Builder env(List env);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #env(String...)}.
     */
    @Deprecated
    public Builder withEnv(final String... env) {
      if (env != null && env.length > 0) {
        env(env);
      }
      return this;
    }

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #env(List)}.
     */
    @Deprecated
    public Builder withEnv(final List env) {
      env(env);
      return this;
    }

    public abstract Builder dir(String dir);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #dir(String)}.
     */
    @Deprecated
    public Builder withDir(final String dir) {
      dir(dir);
      return this;
    }

    public abstract Builder user(String user);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #user(String)}.
     */
    @Deprecated
    public Builder withUser(final String user) {
      user(user);
      return this;
    }

    public abstract Builder groups(String... groups);

    public abstract Builder groups(List groups);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #groups(String...)}.
     */
    @Deprecated
    public Builder withGroups(final String... groups) {
      if (groups != null && groups.length > 0) {
        groups(groups);
      }
      return this;
    }

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #groups(List)}.
     */
    @Deprecated
    public Builder withGroups(final List groups) {
      if (groups != null && !groups.isEmpty()) {
        groups(groups);
      }
      return this;
    }

    public abstract Builder tty(Boolean tty);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #tty(Boolean)}
     */
    @Deprecated
    public Builder withTty() {
      tty(true);
      return this;
    }

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #tty(Boolean)}.
     */
    @Deprecated
    public Builder withTty(final boolean tty) {
      tty(tty);
      return this;
    }

    public abstract Builder mounts(Mount... mounts);

    public abstract Builder mounts(List mounts);

    /**
     * @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;
    }

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #mounts(List)}.
     */
    @Deprecated
    public Builder withMounts(final List mounts) {
      if (mounts != null && !mounts.isEmpty()) {
        mounts(mounts);
      }
      return this;
    }

    public abstract Builder stopGracePeriod(Long stopGracePeriod);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #stopGracePeriod(Long)}.
     */
    @Deprecated
    public Builder withStopGracePeriod(final long stopGracePeriod) {
      stopGracePeriod(stopGracePeriod);
      return this;
    }

    public abstract Builder dnsConfig(DnsConfig dnsConfig);

    public abstract Builder healthcheck(ContainerConfig.Healthcheck healthcheck);

    public abstract Builder hosts(List hosts);

    public abstract Builder secrets(List secrets);

    public abstract Builder configs(List configs);

    public abstract ContainerSpec build();
  }

  public static ContainerSpec.Builder builder() {
    return new AutoValue_ContainerSpec.Builder();
  }

  @JsonCreator
  static ContainerSpec create(
      @JsonProperty("Image") final String image,
      @JsonProperty("Labels") final Map labels,
      @JsonProperty("Hostname") final String hostname,
      @JsonProperty("Command") final List command,
      @JsonProperty("Args") final List args,
      @JsonProperty("Env") final List env,
      @JsonProperty("Dir") final String dir,
      @JsonProperty("User") final String user,
      @JsonProperty("Groups") final List groups,
      @JsonProperty("TTY") final Boolean tty,
      @JsonProperty("Mounts") final List mounts,
      @JsonProperty("StopGracePeriod") final Long stopGracePeriod,
      @JsonProperty("Healthcheck") final ContainerConfig.Healthcheck healthcheck,
      @JsonProperty("Hosts") final List hosts,
      @JsonProperty("Secrets") final List secrets,
      @JsonProperty("DNSConfig") final DnsConfig dnsConfig,
      @JsonProperty("Configs") final List 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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy