lib/nomad_client/api/deployments.ex

# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# https://openapi-generator.tech
# Do not edit the class manually.

defmodule NomadClient.Api.Deployments do
  @moduledoc """
  API calls for all endpoints tagged `Deployments`.
  """

  alias NomadClient.Connection
  import NomadClient.RequestBuilder

  @doc """
  mark a deployment as failed. This should be done to force the scheduler to stop creating allocations as part of the deployment or to cause a rollback to a previous job version. This endpoint only triggers a rollback if the most recent stable version of the job has a different specification than the job being reverted

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - deployment_id (String.t): Specifies the UUID of the deployment. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, NomadClient.Model.DeploymentUpdateResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec fail_deployment(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, NomadClient.Model.DeploymentUpdateResponse.t()} | {:error, Tesla.Env.t()}
  def fail_deployment(connection, deployment_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/deployment/fail/#{deployment_id}")
    |> add_optional_params(optional_params, opts)
    |> ensure_body()
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.DeploymentUpdateResponse{}}
    ])
  end

  @doc """
  lists the allocations created or modified for the given deployment

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - deployment_id (String.t): Specifies the UUID of the deployment. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, [%AllocationListStub{}, ...]} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_allocations_for_deployment(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, list(NomadClient.Model.AllocationListStub.t())} | {:error, Tesla.Env.t()}
  def get_allocations_for_deployment(connection, deployment_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:get)
    |> url("/deployment/allocations/#{deployment_id}")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, [%NomadClient.Model.AllocationListStub{}]}
    ])
  end

  @doc """
  reads information about a specific deployment by ID

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - deployment_id (String.t): Specifies the UUID of the deployment. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, NomadClient.Model.Deployment.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_deployment(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, NomadClient.Model.Deployment.t()} | {:error, Tesla.Env.t()}
  def get_deployment(connection, deployment_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:get)
    |> url("/deployment/#{deployment_id}")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.Deployment{}}
    ])
  end

  @doc """
  lists all deployments

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
    - :prefix (String.t): Specifies a string to filter jobs on based on an index prefix. This is specified as a query string parameter
  ## Returns

  {:ok, [%Deployment{}, ...]} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_deployments(Tesla.Env.client(), keyword()) ::
          {:ok, list(NomadClient.Model.Deployment.t())} | {:error, Tesla.Env.t()}
  def get_deployments(connection, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query,
      :prefix => :query
    }

    %{}
    |> method(:get)
    |> url("/deployments")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, [%NomadClient.Model.Deployment{}]}
    ])
  end

  @doc """
  pause or unpause a deployment. This is done to pause a rolling upgrade or resume it

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - deployment_id (String.t): Specifies the UUID of the deployment. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - deployment_pause_request (DeploymentPauseRequest): 
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, NomadClient.Model.DeploymentUpdateResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec pause_deployment(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.DeploymentPauseRequest.t(),
          keyword()
        ) :: {:ok, NomadClient.Model.DeploymentUpdateResponse.t()} | {:error, Tesla.Env.t()}
  def pause_deployment(connection, deployment_id, deployment_pause_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/deployment/pause/#{deployment_id}")
    |> add_param(:body, :body, deployment_pause_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.DeploymentUpdateResponse{}}
    ])
  end

  @doc """
  promote task groups that have canaries for a deployment. This should be done when the placed canaries are healthy and the rolling upgrade of the remaining allocations should begin

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - deployment_id (String.t): Specifies the UUID of the deployment. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - deployment_promote_request (DeploymentPromoteRequest): 
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, NomadClient.Model.DeploymentUpdateResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec promote_deployment(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.DeploymentPromoteRequest.t(),
          keyword()
        ) :: {:ok, NomadClient.Model.DeploymentUpdateResponse.t()} | {:error, Tesla.Env.t()}
  def promote_deployment(connection, deployment_id, deployment_promote_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/deployment/promote/#{deployment_id}")
    |> add_param(:body, :body, deployment_promote_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.DeploymentUpdateResponse{}}
    ])
  end

  @doc """
  set the health of an allocation that is in the deployment manually
  In some use cases, automatic detection of allocation health may not be desired. As such those task groups can be marked with an upgrade policy that uses health_check = \"manual\". Those allocations must have their health marked manually using this endpoint. Marking an allocation as healthy will allow the rolling upgrade to proceed. Marking it as failed will cause the deployment to fail. This endpoint only triggers a rollback if the most recent stable version of the job has a different specification than the job being reverted

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - deployment_id (String.t): Specifies the UUID of the deployment. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - deployment_alloc_health_request (DeploymentAllocHealthRequest): 
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, NomadClient.Model.DeploymentUpdateResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec set_allocation_health_in_deployment(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.DeploymentAllocHealthRequest.t(),
          keyword()
        ) :: {:ok, NomadClient.Model.DeploymentUpdateResponse.t()} | {:error, Tesla.Env.t()}
  def set_allocation_health_in_deployment(
        connection,
        deployment_id,
        deployment_alloc_health_request,
        opts \\ []
      ) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/deployment/allocation-health/#{deployment_id}")
    |> add_param(:body, :body, deployment_alloc_health_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.DeploymentUpdateResponse{}}
    ])
  end
end