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

org.testifyproject.spotify.docker.client.messages.ContainerConfig Maven / Gradle / Ivy

The 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 org.testifyproject.testifyprojectpliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org.testifyproject/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 org.testifyproject.testifyproject.spotify.docker.client.messages;

import static org.testifyproject.testifyproject.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
import static org.testifyproject.testifyproject.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;

import org.testifyproject.testifyproject.fasterxml.jackson.annotation.JsonAutoDetect;
import org.testifyproject.testifyproject.fasterxml.jackson.annotation.JsonCreator;
import org.testifyproject.testifyproject.fasterxml.jackson.annotation.JsonProperty;
import org.testifyproject.testifyproject.google.auto.value.AutoValue;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.ImmutableList;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.ImmutableMap;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.ImmutableSet;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;

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

  @Nullable
  @JsonProperty("Hostname")
  public abstract String hostname();

  @Nullable
  @JsonProperty("Domainname")
  public abstract String domainname();

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

  @Nullable
  @JsonProperty("AttachStdin")
  public abstract Boolean attachStdin();

  @Nullable
  @JsonProperty("AttachStdout")
  public abstract Boolean attachStdout();

  @Nullable
  @JsonProperty("AttachStderr")
  public abstract Boolean attachStderr();

  @Nullable
  @JsonProperty("PortSpecs")
  public abstract ImmutableList portSpecs();

  @Nullable
  @JsonProperty("ExposedPorts")
  public abstract ImmutableSet exposedPorts();

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

  @Nullable
  @JsonProperty("OpenStdin")
  public abstract Boolean openStdin();

  @Nullable
  @JsonProperty("StdinOnce")
  public abstract Boolean stdinOnce();

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

  @Nullable
  @JsonProperty("Cmd")
  public abstract ImmutableList cmd();

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

  @SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
  public Set volumeNames() {
    //noinspection ConstantConditions
    return volumes() == null ? Collections.emptySet() : volumes().keySet();
  }

  @Nullable
  @JsonProperty("Volumes")
  public abstract ImmutableMap volumes();

  @Nullable
  @JsonProperty("WorkingDir")
  public abstract String workingDir();

  @Nullable
  @JsonProperty("Entrypoint")
  public abstract ImmutableList entrypoint();

  @Nullable
  @JsonProperty("NetworkDisabled")
  public abstract Boolean networkDisabled();

  @Nullable
  @JsonProperty("OnBuild")
  public abstract ImmutableList onBuild();

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

  @Nullable
  @JsonProperty("MacAddress")
  public abstract String macAddress();

  @Nullable
  @JsonProperty("HostConfig")
  public abstract HostConfig hostConfig();

  @Nullable
  @JsonProperty("StopSignal")
  public abstract String stopSignal();

  @Nullable
  @JsonProperty("Healthcheck")
  public abstract Healthcheck healthcheck();

  /**
   * @deprecated  As of release 7.0.0, replaced by {@link #stopSignal()}.
   */
  @Deprecated
  public String getStopSignal() {
    return stopSignal();
  }

  @Nullable
  @JsonProperty("NetworkingConfig")
  public abstract NetworkingConfig networkingConfig();

  @JsonCreator
  static ContainerConfig create(
      @JsonProperty("Hostname") final String hostname,
      @JsonProperty("Domainname") final String domainname,
      @JsonProperty("User") final String user,
      @JsonProperty("AttachStdin") final Boolean attachStdin,
      @JsonProperty("AttachStdout") final Boolean attachStdout,
      @JsonProperty("AttachStderr") final Boolean attachStderr,
      @JsonProperty("PortSpecs") final List portSpecs,
      @JsonProperty("ExposedPorts") final Set exposedPorts,
      @JsonProperty("Tty") final Boolean tty,
      @JsonProperty("OpenStdin") final Boolean openStdin,
      @JsonProperty("StdinOnce") final Boolean stdinOnce,
      @JsonProperty("Env") final List env,
      @JsonProperty("Cmd") final List cmd,
      @JsonProperty("Image") final String image,
      @JsonProperty("Volumes") final Map volumes,
      @JsonProperty("WorkingDir") final String workingDir,
      @JsonProperty("Entrypoint") final List entrypoint,
      @JsonProperty("NetworkDisabled") final Boolean networkDisabled,
      @JsonProperty("OnBuild") final List onBuild,
      @JsonProperty("Labels") final Map labels,
      @JsonProperty("MacAddress") final String macAddress,
      @JsonProperty("HostConfig") final HostConfig hostConfig,
      @JsonProperty("StopSignal") final String stopSignal,
      @JsonProperty("Healthcheck") final Healthcheck healthcheck,
      @JsonProperty("NetworkingConfig") final NetworkingConfig networkingConfig) {
    final Builder builder = builder()
        .hostname(hostname)
        .domainname(domainname)
        .user(user)
        .attachStdin(attachStdin)
        .attachStdout(attachStdout)
        .attachStderr(attachStderr)
        .tty(tty)
        .openStdin(openStdin)
        .stdinOnce(stdinOnce)
        .image(image)
        .workingDir(workingDir)
        .networkDisabled(networkDisabled)
        .macAddress(macAddress)
        .hostConfig(hostConfig)
        .stopSignal(stopSignal)
        .networkingConfig(networkingConfig);

    if (portSpecs != null) {
      builder.portSpecs(portSpecs);
    }
    if (exposedPorts != null) {
      builder.exposedPorts(exposedPorts);
    }
    if (env != null) {
      builder.env(env);
    }
    if (cmd != null) {
      builder.cmd(cmd);
    }
    if (volumes != null)  {
      builder.volumes(volumes);
    }
    if (entrypoint != null) {
      builder.entrypoint(entrypoint);
    }
    if (onBuild != null) {
      builder.onBuild(onBuild);
    }
    if (labels != null) {
      builder.labels(labels);
    }
    if (healthcheck != null) {
      builder.healthcheck(healthcheck);
    }

    return builder.build();
  }

  public abstract Builder toBuilder();

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

  @AutoValue.Builder
  public abstract static class Builder {

    public abstract Builder hostname(final String hostname);

    public abstract Builder domainname(final String domainname);

    public abstract Builder user(final String user);

    public abstract Builder attachStdin(final Boolean attachStdin);

    public abstract Builder attachStdout(final Boolean attachStdout);

    public abstract Builder attachStderr(final Boolean attachStderr);

    public abstract Builder portSpecs(final List portSpecs);

    public abstract Builder portSpecs(final String... portSpecs);

    public abstract Builder exposedPorts(final Set exposedPorts);

    public abstract Builder exposedPorts(final String... exposedPorts);

    public abstract Builder tty(final Boolean tty);

    public abstract Builder openStdin(final Boolean openStdin);

    public abstract Builder stdinOnce(final Boolean stdinOnce);

    public abstract Builder env(final List env);

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

    public abstract Builder cmd(final List cmd);

    public abstract Builder cmd(final String... cmd);

    public abstract Builder image(final String image);

    abstract ImmutableMap.Builder volumesBuilder();

    public Builder addVolume(final String volume) {
      volumesBuilder().put(volume, new HashMap());
      return this;
    }

    public Builder addVolumes(final String... volumes) {
      for (final String volume : volumes) {
        volumesBuilder().put(volume, new HashMap());
      }
      return this;
    }

    public abstract Builder volumes(final Map volumes);

    /**
     * @deprecated  As of release 7.0.0, replaced by {@link #volumes(Map)}.
     */
    @Deprecated
    public Builder volumes(final Set volumes) {
      if (volumes != null && !volumes.isEmpty()) {
        final ImmutableMap.Builder volumesBuilder = ImmutableMap.builder();
        for (final String volume : volumes) {
          volumesBuilder.put(volume, new HashMap());
        }
        volumes(volumesBuilder.build());
      }
      return this;
    }

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

    public abstract Builder workingDir(final String workingDir);

    public abstract Builder entrypoint(final List entrypoint);

    public abstract Builder entrypoint(final String... entrypoint);

    public abstract Builder networkDisabled(final Boolean networkDisabled);

    public abstract Builder onBuild(final List onBuild);

    public abstract Builder onBuild(final String... onBuild);

    public abstract Builder labels(final Map labels);

    public abstract Builder macAddress(final String macAddress);

    public abstract Builder hostConfig(final HostConfig hostConfig);

    public abstract Builder stopSignal(final String stopSignal);

    public abstract Builder healthcheck(final Healthcheck healthcheck);

    public abstract Builder networkingConfig(final NetworkingConfig networkingConfig);

    public abstract ContainerConfig build();
  }

  @AutoValue
  public abstract static class Healthcheck {
    @Nullable
    @JsonProperty("Test")
    public abstract ImmutableList test();

    /**
     * In nanoseconds.
     */
    @Nullable
    @JsonProperty("Interval")
    public abstract Long interval();

    /**
     * In nanoseconds.
     */
    @Nullable
    @JsonProperty("Timeout")
    public abstract Long timeout();

    @Nullable
    @JsonProperty("Retries")
    public abstract Integer retries();

    /**
     * In nanoseconds.
     * @since API 1.29
     */
    @Nullable
    @JsonProperty("StartPeriod")
    public abstract Long startPeriod();

    public static Healthcheck create(
            @JsonProperty("Test") final List test,
            @JsonProperty("Interval") final Long interval,
            @JsonProperty("Timeout") final Long timeout,
            @JsonProperty("Retries") final Integer retries) {
      return create(test, interval, timeout, retries, null);
    }

    @JsonCreator
    public static Healthcheck create(
            @JsonProperty("Test") final List test,
            @JsonProperty("Interval") final Long interval,
            @JsonProperty("Timeout") final Long timeout,
            @JsonProperty("Retries") final Integer retries,
            @JsonProperty("StartPeriod") final Long startPeriod) {
      return builder()
          .test(test)
          .interval(interval)
          .timeout(timeout)
          .retries(retries)
          .startPeriod(startPeriod)
          .build();
    }

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

    @AutoValue.Builder
    public abstract static class Builder {
      public abstract Builder test(final List test);

      public abstract Builder interval(final Long interval);

      public abstract Builder timeout(final Long timeout);

      public abstract Builder retries(final Integer retries);

      public abstract Builder startPeriod(final Long startPeriod);

      public abstract Healthcheck build();
    }
  }

  @AutoValue
  public abstract static class NetworkingConfig {
    @JsonProperty("EndpointsConfig")
    public abstract ImmutableMap endpointsConfig();

    @JsonCreator
    public static NetworkingConfig create(
            @JsonProperty("EndpointsConfig") final Map endpointsConfig) {
      final ImmutableMap endpointsConfigCopy =
              endpointsConfig == null
                      ? ImmutableMap.of()
                      : ImmutableMap.copyOf(endpointsConfig);
      return new AutoValue_ContainerConfig_NetworkingConfig(endpointsConfigCopy);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy