Class: StatsCloud::ClusterClient

Inherits:
Object
  • Object
show all
Includes:
JsonParser, LoggerHelper
Defined in:
lib/statscloud/cluster_client.rb

Overview

statscloud.io cluster-api service client.

Instance Method Summary collapse

Methods included from LoggerHelper

#log_error, #log_info, #logger

Methods included from JsonParser

#convert_to_pretty_json, #parse_json

Constructor Details

#initialize(env, host) ⇒ ClusterClient

Constructs cluster-api service client instance.

Parameters:

  • env (+String+)

    cluster api environment

  • host (+String+)

    cluster api host.



25
26
27
28
# File 'lib/statscloud/cluster_client.rb', line 25

def initialize(env, host)
  @environment = env
  @host = host || "https://cluster-api-v1.statscloud.statscloud.io"
end

Instance Method Details

#deploy_cluster(token, app, configuration) ⇒ Object

Schedules cluster to be (re)deployed.

Parameters:

  • token (+String+)

    authorization token.

  • app (+String+)

    cluster name.

  • configuration (+String+)

    cluster configuration



54
55
56
57
58
59
60
61
62
63
# 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) ⇒ Object

Schedules cluster instance to be retrieved.

Parameters:

  • token (+String+)

    authorization token.

  • app (+String+)

    cluster name.



38
39
40
41
42
# 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) ⇒ Object

Register statscloud client connection.

Parameters:

  • token (+String+)

    authorization token

  • app (+String+)

    cluster name

  • tags (+Array+)

    statscloud client tags



85
86
87
88
89
90
# 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) ⇒ Object

Schedules cluster to be undeployed.

Parameters:

  • token (+String+)

    authorization token.

  • app (+String+)

    cluster name.



72
73
74
75
76
# 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