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

  alias NomadClient.Connection
  import NomadClient.RequestBuilder

  @doc """
  Forces a member of the gossip pool from the \"failed\" state into the \"left\" state.

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - node (String.t): the name of the node
  - 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 force_leave(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, nil} | {:error, Tesla.Env.t()}
  def force_leave(connection, node, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/agent/force-leave")
    |> add_param(:query, :node, node)
    |> add_optional_params(optional_params, opts)
    |> ensure_body()
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, false}
    ])
  end

  @doc """
  Performs a basic healthcheck

  ## 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
  ## Returns

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

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

  @doc """
  Queries for the known peers in the gossip pool

  ## 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
  ## Returns

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

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

  @doc """
  Queries for information about the agent we are connected to

  ## 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
  ## Returns

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

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

  @doc """
  Queries an agent in client mode for its list of known servers

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, [%String{}, ...]} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_servers(Tesla.Env.client(), keyword()) ::
          {:ok, list(String.t())} | {:error, Tesla.Env.t()}
  def get_servers(connection, _opts \\ []) do
    %{}
    |> method(:get)
    |> url("/agent/servers")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, []}
    ])
  end

  @doc """
  Causes the agent to join a cluster by joining the gossip pool at one of the given addresses

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - address ([String.t]): server address (ip:port)
  - 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.JoinResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec join(Tesla.Env.client(), list(String.t()), keyword()) ::
          {:ok, NomadClient.Model.JoinResponse.t()} | {:error, Tesla.Env.t()}
  def join(connection, address, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/agent/join")
    |> add_param(:query, :address, address)
    |> add_optional_params(optional_params, opts)
    |> ensure_body()
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.JoinResponse{}}
    ])
  end

  @doc """
  Streams logs from a specific Nomad server node

  ## 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
    - :log_level (String.t): log level
    - :node_id (String.t): node id
    - :server_id (String.t): server id
    - :json (boolean()): is json format
    - :plain (boolean()): is plain text format
  ## Returns

  {:ok, NomadClient.Model.StreamFrame.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec stream_logs(Tesla.Env.client(), keyword()) ::
          {:ok, NomadClient.Model.StreamFrame.t()} | {:error, Tesla.Env.t()}
  def stream_logs(connection, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query,
      :log_level => :query,
      :node_id => :query,
      :server_id => :query,
      :json => :query,
      :plain => :query
    }

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

  @doc """
  Updates the list of known servers to the given addresses, replacing all previous addresses

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - address ([String.t]): server address (ip:port)
  - 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, [%String{}, ...]} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec update_servers(Tesla.Env.client(), list(String.t()), keyword()) ::
          {:ok, list(String.t())} | {:error, Tesla.Env.t()}
  def update_servers(connection, address, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/agent/servers")
    |> add_param(:query, :address, address)
    |> add_optional_params(optional_params, opts)
    |> ensure_body()
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, []}
    ])
  end
end