lib/nomad_client/api/allocations.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.Allocations do
  @moduledoc """
  API calls for all endpoints tagged `Allocations`.
  """

  alias NomadClient.Connection
  import NomadClient.RequestBuilder

  @doc """
  reads information about a specific allocation

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - alloc_id (String.t): Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one
  - 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.Allocation.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_allocation(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, NomadClient.Model.Allocation.t()} | {:error, Tesla.Env.t()}
  def get_allocation(connection, alloc_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

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

  @doc """
  query for and interact with allocations

  ## 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, [%AllocationListStub{}, ...]} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_allocations(Tesla.Env.client(), keyword()) ::
          {:ok, list(NomadClient.Model.AllocationListStub.t())} | {:error, Tesla.Env.t()}
  def get_allocations(connection, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query,
      :prefix => :query
    }

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

  @doc """
  restarts an allocation or task in-place

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - alloc_id (String.t): Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one
  - allocation_restart_request (AllocationRestartRequest): 
  - 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, nil} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec restart_allocation(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.AllocationRestartRequest.t(),
          keyword()
        ) :: {:ok, nil} | {:error, Tesla.Env.t()}
  def restart_allocation(connection, alloc_id, allocation_restart_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/allocation/#{alloc_id}/restart")
    |> add_param(:body, :body, allocation_restart_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, false}
    ])
  end

  @doc """
  sends a signal to an allocation or task

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - alloc_id (String.t): Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one
  - alloc_signal_request (AllocSignalRequest): 
  - 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, nil} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec signal_allocation(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.AllocSignalRequest.t(),
          keyword()
        ) :: {:ok, nil} | {:error, Tesla.Env.t()}
  def signal_allocation(connection, alloc_id, alloc_signal_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/allocation/#{alloc_id}/signal")
    |> add_param(:body, :body, alloc_signal_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, false}
    ])
  end

  @doc """
  stops and reschedules a specific allocation

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - alloc_id (String.t): Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one
  - 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.AllocStopResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec stop_allocation(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, NomadClient.Model.AllocStopResponse.t()} | {:error, Tesla.Env.t()}
  def stop_allocation(connection, alloc_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

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