Class: KineticSdk::Agent

Inherits:
Object
  • Object
show all
Includes:
Utils::KineticHttpUtils
Defined in:
lib/kinetic_sdk/agent/agent-sdk.rb,
lib/kinetic_sdk/agent/lib/bridges.rb,
lib/kinetic_sdk/agent/lib/handler.rb,
lib/kinetic_sdk/agent/lib/filestores.rb

Overview

Agent is a Ruby class that acts as a wrapper for the Kinetic Agent System REST API without having to make explicit HTTP requests. This is not to be confused with the Kinetic Agent Space REST API, which must go through the Kinetic Core Proxy API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::KineticHttpUtils

#default_headers, default_headers, #default_jwt_headers, default_jwt_headers, #delete, #encode, #gateway_retry_delay, #gateway_retry_limit, #get, #head, #header_accept_json, header_accept_json, #header_basic_auth, header_basic_auth, header_bearer_auth, #header_bearer_auth, #header_content_json, header_content_json, header_user_agent, #header_user_agent, #max_redirects, #mimetype, #patch, #post, #post_multipart, #put, #redirect_url, #stream_download_to_file

Constructor Details

#initialize(opts) ⇒ Agent

Initalize the Agent SDK with the web server URL and configuration user credentials, along with any custom option values.

Example: using a configuration file

KineticSdk::Agent.new({
  config_file: "/opt/config1.yaml"
})

Example: using a properties hash

KineticSdk::Agent.new({
  app_server_url: "http://localhost:8080/kinetic-agent",
  username: "admin",
  password: "admin",
  options: {
    log_level: "debug",
    ssl_verify_mode: "peer",
    ssl_ca_file: "/usr/local/self_signing_ca.pem"
  }
})

If the +config_file+ option is present, it will be loaded first, and any additional options will overwrite any values in the config file

Parameters:

  • opts (Hash)

    Kinetic Agent properties

Options Hash (opts):

  • :config_file (String)

    optional - path to the YAML configuration file

    • Ex: /opt/config/agent-configuration1.yaml
  • :app_server_url (String)

    the URL to the Kinetic Agent web application.

  • :username (String)

    the username for the user

  • :password (String)

    the password for the user

  • :options (Hash<Symbol, Object>) — default: {}

    optional settings

    • :gateway_retry_limit (FixNum) (defaults to: 5) max number of times to retry a bad gateway
    • :gateway_retry_delay (Float) (defaults to: 1.0) number of seconds to delay before retrying a bad gateway
    • :log_level (String) (defaults to: off) level of logging - off | error | warn | info | debug
    • :log_output (String) (defaults to: STDOUT) where to send output - STDOUT | STDERR
    • :max_redirects (Fixnum) (defaults to: 5) maximum number of redirects to follow
    • :ssl_ca_file (String) full path to PEM certificate used to verify the server
    • :ssl_verify_mode (String) (defaults to: none) - none | peer


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 63

def initialize(opts)
  # initialize any variables
  options = {}

  # process the configuration file if it was provided
  unless opts[:config_file].nil?
    options.merge!(YAML::load_file opts[:config_file])
  end

  # process the configuration hash if it was provided
  options.merge!(opts)

  # process any individual options
  @options = options.delete(:options) || {}
  # setup logging
  log_level = @options[:log_level] || @options["log_level"]
  log_output = @options[:log_output] || @options["log_output"]
  @logger = KineticSdk::Utils::KLogger.new(log_level, log_output)

  @username = options[:username]
  @password = options[:password]
  @server = options[:app_server_url].chomp('/')
  @api_url = "#{@server}/app/api/v1"
  @version = 1
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



15
16
17
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 15

def api_url
  @api_url
end

#loggerObject (readonly)

Returns the value of attribute logger.



15
16
17
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 15

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 15

def options
  @options
end

#passwordObject (readonly)

Returns the value of attribute password.



15
16
17
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 15

def password
  @password
end

#serverObject (readonly)

Returns the value of attribute server.



15
16
17
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 15

def server
  @server
end

#usernameObject (readonly)

Returns the value of attribute username.



15
16
17
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 15

def username
  @username
end

#versionObject (readonly)

Returns the value of attribute version.



15
16
17
# File 'lib/kinetic_sdk/agent/agent-sdk.rb', line 15

def version
  @version
end

Instance Method Details

#add_bridge(space, body, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add Bridge

Parameters:

  • space (String)

    slug of the space

  • body (Hash)

    properties associated to the Bridge

    • +adapterClass+
    • +name+
    • +slug+
    • +properties+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



14
15
16
17
# File 'lib/kinetic_sdk/agent/lib/bridges.rb', line 14

def add_bridge(space, body, headers=default_headers)
  @logger.info("Adding the \"#{body['name']}\" bridge in the \"#{space}\" space.")
  post("#{@api_url}/spaces/#{space}/bridges", body, headers)
end

#add_filestore(space, body, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add Filestore

Parameters:

  • space (String)

    slug of the space

  • body (Hash)

    properties associated to the Filestore

    • +adapterClass+
    • +name+
    • +slug+
    • +properties+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



14
15
16
17
# File 'lib/kinetic_sdk/agent/lib/filestores.rb', line 14

def add_filestore(space, body, headers=default_headers)
  @logger.info("Adding the \"#{body['name']}\" filestore in the \"#{space}\" space.")
  post("#{@api_url}/spaces/#{space}/filestores", body, headers)
end

#add_handler(space, body, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add Handler

Parameters:

  • space (String)

    slug of the space

  • body (Hash)

    properties associated to the Handler

    • +adapterClass+
    • +name+
    • +slug+
    • +properties+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



14
15
16
17
# File 'lib/kinetic_sdk/agent/lib/handler.rb', line 14

def add_handler(space, body, headers=default_headers)
  @logger.info("Adding the \"#{body['name']}\" handler in the \"#{space}\" space.")
  post("#{@api_url}/spaces/#{space}/handlers", body, headers)
end

#add_space_bridge(body, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add Bridge to Space

Parameters:

  • body (Hash)

    properties associated to the Bridge

    • +space+
    • +adapterClass+
    • +name+
    • +slug+
    • +properties+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



75
76
77
78
# File 'lib/kinetic_sdk/agent/lib/bridges.rb', line 75

def add_space_bridge(body, headers=default_headers)
  @logger.info("Adding the \"#{body['name']}\" bridge in the \"#{body['space']}\" space.")
  post("#{@api_url}/bridges", body, headers)
end

#add_space_filestore(body, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add Filestore to Space

Parameters:

  • body (Hash)

    properties associated to the Filestore

    • +space+
    • +adapterClass+
    • +slug+
    • +properties+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



74
75
76
77
# File 'lib/kinetic_sdk/agent/lib/filestores.rb', line 74

def add_space_filestore(body, headers=default_headers)
  @logger.info("Adding the \"#{body['name']}\" filestore in the \"#{body['space']}\" space.")
  post("#{@api_url}/filestores", body, headers)
end

#add_space_handler(body, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add Handler to Space

Parameters:

  • body (Hash)

    properties associated to the Handler

    • +space+
    • +definitionId+
    • +slug+
    • +properties+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



74
75
76
77
# File 'lib/kinetic_sdk/agent/lib/handler.rb', line 74

def add_space_handler(body, headers=default_headers)
  @logger.info("Adding the \"#{body['name']}\" handler in the \"#{body['space']}\" space.")
  post("#{@api_url}/handlers", body, headers)
end

#delete_bridge(space, slug, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete a Bridge

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the Bridge

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



25
26
27
28
# File 'lib/kinetic_sdk/agent/lib/bridges.rb', line 25

def delete_bridge(space, slug, headers=default_headers)
  @logger.info("Deleting the \"#{slug}\" bridge in the \"#{space}\" space.")
  delete("#{@api_url}/spaces/#{space}/bridges/#{slug}", headers)
end

#delete_filestore(space, slug, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete a Filestore

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the Filestore

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



25
26
27
28
# File 'lib/kinetic_sdk/agent/lib/filestores.rb', line 25

def delete_filestore(space, slug, headers=default_headers)
  @logger.info("Deleting the \"#{slug}\" filestore in the \"#{space}\" space.")
  delete("#{@api_url}/spaces/#{space}/filestores/#{slug}", headers)
end

#delete_handler(space, slug, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete a Handler

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the Handler

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



25
26
27
28
# File 'lib/kinetic_sdk/agent/lib/handler.rb', line 25

def delete_handler(space, slug, headers=default_headers)
  @logger.info("Deleting the \"#{slug}\" handler in the \"#{space}\" space.")
  delete("#{@api_url}/spaces/#{space}/handlers/#{slug}", headers)
end

#find_all_bridges(params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find all bridges in the system

Parameters:

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



85
86
87
88
# File 'lib/kinetic_sdk/agent/lib/bridges.rb', line 85

def find_all_bridges(params={}, headers=default_headers)
  @logger.info("Find all bridges.")
  get("#{@api_url}/bridges", params, headers)
end

#find_all_filestores(params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find all filestores in the system

Parameters:

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



84
85
86
87
# File 'lib/kinetic_sdk/agent/lib/filestores.rb', line 84

def find_all_filestores(params={}, headers=default_headers)
  @logger.info("Find all filestores.")
  get("#{@api_url}/filestores", params, headers)
end

#find_all_handlers(params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find all handlers in the system

Parameters:

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



84
85
86
87
# File 'lib/kinetic_sdk/agent/lib/handler.rb', line 84

def find_all_handlers(params={}, headers=default_headers)
  @logger.info("Find all handlers.")
  get("#{@api_url}/handlers", params, headers)
end

#find_bridge(space, slug, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find a bridge

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the bridge

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



37
38
39
40
# File 'lib/kinetic_sdk/agent/lib/bridges.rb', line 37

def find_bridge(space, slug, params={}, headers=default_headers)
  @logger.info("Finding the \"#{slug}\" bridge in the \"#{space}\" space.")
  get("#{@api_url}/spaces/#{space}/bridges/#{slug}", params, headers)
end

#find_bridges(space, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find all bridges in a space

Parameters:

  • space (String)

    slug of the space

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



60
61
62
63
# File 'lib/kinetic_sdk/agent/lib/bridges.rb', line 60

def find_bridges(space, params={}, headers=default_headers)
  @logger.info("Find all bridges in the \"#{space}\" space.")
  get("#{@api_url}/spaces/#{space}/bridges", params, headers)
end

#find_filestore(space, slug, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find a filestore

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the filestore

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



37
38
39
40
# File 'lib/kinetic_sdk/agent/lib/filestores.rb', line 37

def find_filestore(space, slug, params={}, headers=default_headers)
  @logger.info("Finding the \"#{slug}\" filestore in the \"#{space}\" space.")
  get("#{@api_url}/spaces/#{space}/filestores/#{slug}", params, headers)
end

#find_filestores(space, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find all filestores in a space

Parameters:

  • space (String)

    slug of the space

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



60
61
62
63
# File 'lib/kinetic_sdk/agent/lib/filestores.rb', line 60

def find_filestores(space, params={}, headers=default_headers)
  @logger.info("Find all filestores in the \"#{space}\" space.")
  get("#{@api_url}/spaces/#{space}/filestores", params, headers)
end

#find_handler(space, slug, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find a handler

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the handler

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



37
38
39
40
# File 'lib/kinetic_sdk/agent/lib/handler.rb', line 37

def find_handler(space, slug, params={}, headers=default_headers)
  @logger.info("Finding the \"#{slug}\" handler in the \"#{space}\" space.")
  get("#{@api_url}/spaces/#{space}/handlers/#{slug}", params, headers)
end

#find_handlers(space, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find all handlers in a space

Parameters:

  • space (String)

    slug of the space

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



60
61
62
63
# File 'lib/kinetic_sdk/agent/lib/handler.rb', line 60

def find_handlers(space, params={}, headers=default_headers)
  @logger.info("Find all handlers in the \"#{space}\" space.")
  get("#{@api_url}/spaces/#{space}/handlers", params, headers)
end

#update_bridge(space, slug, body = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a bridge

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the bridge

  • body (Hash) (defaults to: {})

    properties of the bridge to update

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



49
50
51
52
# File 'lib/kinetic_sdk/agent/lib/bridges.rb', line 49

def update_bridge(space, slug, body={}, headers=default_headers)
  @logger.info("Updating the \"#{slug}\" bridge in the \"#{space}\" space.")
  put("#{@api_url}/spaces/#{space}/bridges/#{slug}", body, headers)
end

#update_filestore(space, slug, body = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a filestore

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the filestore

  • body (Hash) (defaults to: {})

    properties of the filestore to update

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



49
50
51
52
# File 'lib/kinetic_sdk/agent/lib/filestores.rb', line 49

def update_filestore(space, slug, body={}, headers=default_headers)
  @logger.info("Updating the \"#{slug}\" filestore in the \"#{space}\" space.")
  put("#{@api_url}/spaces/#{space}/filestores/#{slug}", body, headers)
end

#update_handler(space, slug, body = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a handler

Parameters:

  • space (String)

    slug of the space

  • slug (String)

    slug of the handler

  • body (Hash) (defaults to: {})

    properties of the handler to update

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



49
50
51
52
# File 'lib/kinetic_sdk/agent/lib/handler.rb', line 49

def update_handler(space, slug, body={}, headers=default_headers)
  @logger.info("Updating the \"#{slug}\" handler in the \"#{space}\" space.")
  put("#{@api_url}/spaces/#{space}/handlers/#{slug}", body, headers)
end