Class SaltClient


  • public class SaltClient
    extends java.lang.Object
    Salt API client.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private AsyncHttpClient asyncHttpClient
      The async connection factory object
      private com.google.gson.Gson gson  
      private java.net.URI uri  
    • Constructor Summary

      Constructors 
      Constructor Description
      SaltClient​(java.net.URI url, AsyncHttpClient asyncHttpClient)
      Constructor for connecting to a given URL.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <R> java.util.concurrent.CompletionStage<R> call​(Call<?> call, Client client, java.util.Optional<Target<?>> target, java.util.Map<java.lang.String,​java.lang.Object> custom, com.google.gson.reflect.TypeToken<R> type, AuthMethod auth)  
      WebSocketEventStream events​(Token token, long sessionIdleTimeout, long idleTimeout, int maxMsgSize, EventListener... listeners)
      Returns a WebSocket @ClientEndpoint annotated object connected to the /ws ServerEndpoint.
      java.util.concurrent.CompletionStage<Token> login​(java.lang.String username, java.lang.String password, AuthModule eauth)
      Non-blocking version of login() returning a CompletionStage with the token.
      java.util.concurrent.CompletionStage<java.lang.Boolean> logout()
      Perform logout and clear the session token from the config.
      <T> java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,​java.lang.Object>> run​(java.lang.String username, java.lang.String password, AuthModule eauth, java.lang.String client, Target<T> target, java.lang.String function, java.util.List<java.lang.Object> args, java.util.Map<java.lang.String,​java.lang.Object> kwargs)
      Generic interface to start any execution command bypassing normal session handling.
      <T> java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,​Result<SSHRawResult>>> runRawSSHCommand​(java.lang.String command, Target<T> target, SaltSSHConfig cfg)
      Calls salt-ssh with a command in raw shell mode (commands bypass Salt and gets executed as shell commands).
      java.util.concurrent.CompletionStage<Stats> stats()
      Query statistics from the CherryPy Server.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • asyncHttpClient

        private final AsyncHttpClient asyncHttpClient
        The async connection factory object
      • uri

        private final java.net.URI uri
      • gson

        private final com.google.gson.Gson gson
    • Constructor Detail

      • SaltClient

        public SaltClient​(java.net.URI url,
                          AsyncHttpClient asyncHttpClient)
        Constructor for connecting to a given URL.
        Parameters:
        asyncHttpClient - http client to use for the salt api
        url - the Salt API URL
    • Method Detail

      • login

        public java.util.concurrent.CompletionStage<Token> login​(java.lang.String username,
                                                                 java.lang.String password,
                                                                 AuthModule eauth)
        Non-blocking version of login() returning a CompletionStage with the token.

        POST /login

        Parameters:
        username - the username
        password - the password
        eauth - the eauth type
        Returns:
        CompletionStage holding the authentication token
      • logout

        public java.util.concurrent.CompletionStage<java.lang.Boolean> logout()
        Perform logout and clear the session token from the config.

        POST /logout

        Returns:
        true if the logout was successful, otherwise false
      • run

        public <T> java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,​java.lang.Object>> run​(java.lang.String username,
                                                                                                                    java.lang.String password,
                                                                                                                    AuthModule eauth,
                                                                                                                    java.lang.String client,
                                                                                                                    Target<T> target,
                                                                                                                    java.lang.String function,
                                                                                                                    java.util.List<java.lang.Object> args,
                                                                                                                    java.util.Map<java.lang.String,​java.lang.Object> kwargs)
        Generic interface to start any execution command bypassing normal session handling.

        POST /run

        Type Parameters:
        T - type of the tgt property for this command
        Parameters:
        username - the username
        password - the password
        eauth - the eauth type
        client - the client
        target - the target
        function - the function to execute
        args - list of non-keyword arguments
        kwargs - map containing keyword arguments
        Returns:
        Map key: minion id, value: command result from that minion
      • runRawSSHCommand

        public <T> java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,​Result<SSHRawResult>>> runRawSSHCommand​(java.lang.String command,
                                                                                                                                     Target<T> target,
                                                                                                                                     SaltSSHConfig cfg)
        Calls salt-ssh with a command in raw shell mode (commands bypass Salt and gets executed as shell commands).
        Type Parameters:
        T - type of the tgt property for this command
        Parameters:
        command - to be executed
        target - glob type, targets to be reached by the command
        cfg - SaltSSH config holder
        Returns:
        a map in which every key is a host associated to the result of the raw command
      • stats

        public java.util.concurrent.CompletionStage<Stats> stats()
        Query statistics from the CherryPy Server.

        GET /stats

        Returns:
        the stats
      • events

        public WebSocketEventStream events​(Token token,
                                           long sessionIdleTimeout,
                                           long idleTimeout,
                                           int maxMsgSize,
                                           EventListener... listeners)
                                    throws SaltException
        Returns a WebSocket @ClientEndpoint annotated object connected to the /ws ServerEndpoint.

        The stream object supports the WebSocketEventStream interface which allows the caller to register/unregister for stream event notifications as well as close the event stream.

        Note: login(String, String, AuthModule) or must be called prior to calling this method.

        GET /events

        Parameters:
        listeners - event listeners to be added before the stream is initialized
        idleTimeout - idle timeout to pass to the http client config
        maxMsgSize - maximum event data size to accept
        sessionIdleTimeout - session idle timeout to pass to the http client config
        token - salt session token to use for authentication
        Returns:
        the event stream
        Throws:
        SaltException - in case of an error during websocket stream initialization
      • call

        public <R> java.util.concurrent.CompletionStage<R> call​(Call<?> call,
                                                                Client client,
                                                                java.util.Optional<Target<?>> target,
                                                                java.util.Map<java.lang.String,​java.lang.Object> custom,
                                                                com.google.gson.reflect.TypeToken<R> type,
                                                                AuthMethod auth)