class StatsCloud::ClusterClient
statscloud.io cluster-api service client.
Attributes
environment[R]
host[R]
Public Class Methods
new(env, host)
click to toggle source
Constructs cluster-api service client instance.
@param [String
] env
cluster api environment
@param [String
] host
cluster api host.
@api public
# File lib/statscloud/cluster_client.rb, line 25 def initialize(env, host) @environment = env @host = host || "https://cluster-api-v1.statscloud.statscloud.io" end
Public Instance Methods
deploy_cluster(token, app, configuration)
click to toggle source
Schedules cluster to be (re)deployed.
@param [String
] token
authorization token.
@param [String
] app
cluster name.
@param [String
] configuration
cluster configuration
@api public
# File lib/statscloud/cluster_client.rb, line 54 def deploy_cluster(token, app, configuration) url = "#{host}/users/current/clusters/#{app}/#{environment}" body = body_hash_parameters(configuration) response = http_client.put(url, body.to_json, headers(token)) get_parsed_response(response) rescue RestClient::ExceptionWithResponse => error error_info = convert_to_pretty_json(error.http_body) logger($stdout).error error_info raise statscloud_client_error(error_info) end
get_cluster(token, app)
click to toggle source
Schedules cluster instance to be retrieved.
@param [String
] token
authorization token.
@param [String
] app
cluster name.
@api public
# File lib/statscloud/cluster_client.rb, line 38 def get_cluster(token, app) url = "#{host}/users/current/clusters/#{app}/#{environment}" response = http_client.get(url, headers(token)) get_parsed_response(response) end
register_statscloud_connection(token, app, tags)
click to toggle source
Register statscloud client connection. @param [String
] token
authorization token
@param [String
] app
cluster name
@param [Array
] tags
statscloud client tags
# File lib/statscloud/cluster_client.rb, line 85 def register_statscloud_connection(token, app, tags) url = "#{host}/users/current/clusters/#{app}/#{environment}/register-statscloud-connection" body = { tags: tags }.to_json response = http_client.post(url, body, headers(token)) get_parsed_response(response) end
undeploy_cluster(token, app)
click to toggle source
Schedules cluster to be undeployed. @param [String
] token
authorization token.
@param [String
] app
cluster name.
@api public
# File lib/statscloud/cluster_client.rb, line 72 def undeploy_cluster(token, app) url = "#{host}/users/current/clusters/#{app}/#{environment}/undeploy" response = http_client.post(url, nil, headers(token)) get_parsed_response(response) end
Private Instance Methods
auth_headers(token)
click to toggle source
# File lib/statscloud/cluster_client.rb, line 107 def auth_headers(token) { "auth-token" => token } end
body_hash_parameters(configuration)
click to toggle source
# File lib/statscloud/cluster_client.rb, line 113 def body_hash_parameters(configuration) { configuration: configuration.to_json } end
default_headers()
click to toggle source
# File lib/statscloud/cluster_client.rb, line 100 def default_headers { content_type: :json, accept: :json } end
get_parsed_response(response)
click to toggle source
# File lib/statscloud/cluster_client.rb, line 123 def get_parsed_response(response) StatsCloud::ParsedResponseHelper.new(response) end
headers(token)
click to toggle source
# File lib/statscloud/cluster_client.rb, line 96 def headers(token) default_headers.merge(auth_headers(token)) end
http_client()
click to toggle source
# File lib/statscloud/cluster_client.rb, line 127 def http_client RestClient end
statscloud_client_error(message)
click to toggle source
# File lib/statscloud/cluster_client.rb, line 119 def statscloud_client_error(message) StatsCloud::ClientError.new(message) end