Class: Dag::Client::API

Inherits:
Object
  • Object
show all
Includes:
Cluster, Database, Job, Storage, Table
Defined in:
lib/dag/client/api.rb,
lib/dag/client/api/job.rb,
lib/dag/client/api/table.rb,
lib/dag/client/api/cluster.rb,
lib/dag/client/api/storage.rb,
lib/dag/client/api/database.rb,
lib/dag/client/api/list_params.rb,
lib/dag/client/api/rest_parameter.rb,
lib/dag/client/api/storage_result.rb

Defined Under Namespace

Modules: Cluster, Database, Job, ListParams, Storage, Table Classes: BucketsResult, ObjectsResult, RestParameter, StorageResult

Constant Summary

Constants included from ClusterValidation

ClusterValidation::VALID_WHERE_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Storage

#buckets, #create_bucket, #create_multipart_object, #create_object, #delete_bucket, #delete_object, #get_object, #import, #objects

Methods included from Job

#query, #query_cancel, #query_info, #query_info_list, #query_log

Methods included from ListParams

#list_params

Methods included from Table

#create_table, #delete_table, #split_table, #table, #table_info_list

Methods included from Database

#create_database, #database_list, #delete_database

Methods included from Cluster

#cluster_export_log, #cluster_info, #cluster_info_list, #cluster_restart, #statistics

Methods included from ClusterValidation

#cluster_norm?, #cluster_norm_or_ptfailed?, #cluster_restart_status?, #cluster_status, #valid_cluster_info_list_status?, #valid_cluster_status?, #validate_cluster, #validate_cluster_param_keys

Constructor Details

#initialize(apikey, secret, analysis_api: Dag::Settings.analysis_api, storage_api: Dag::Settings.storage_api, force_path_style: Dag::Settings.force_path_style, debug: Dag::Settings.debug) ⇒ API

Returns a new instance of API.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dag/client/api.rb', line 15

def initialize(apikey, secret,
               analysis_api: Dag::Settings.analysis_api,
               storage_api: Dag::Settings.storage_api,
               force_path_style: Dag::Settings.force_path_style,
               debug: Dag::Settings.debug)

  require 'time'
  require 'base64'
  require 'oj'
  require 'rexml/document'
  require 'erb'
  require 'net/http'
  require 'xmlsimple'
  require 'ipaddr'
  require 'httpclient'
  require 'stringio'

  @apikey = apikey
  @secret = secret

  unless [TrueClass, FalseClass].any? { |c| force_path_style.kind_of?(c) }
     raise Dag::Client::APIOptionInvalid.new("force_path_style is not boolean:#{force_path_style}")
  end

  unless [TrueClass, FalseClass].any? { |c| debug.kind_of?(c) }
    raise Dag::Client::APIOptionInvalid.new("debug is not boolean:#{debug}")
  end

  @analysis_api = analysis_api
  @storage_api = storage_api
  @force_path_style = force_path_style
  @debug = debug

  Oj.default_options = { mode: :compat }

  @http_client = HTTPClient.new
  @http_client.connect_timeout = 300
  @http_client.send_timeout    = 300
  @http_client.receive_timeout = 300
  @http_client.debug_dev = STDERR if @debug
end

Instance Attribute Details

#analysis_apiObject (readonly)

Returns the value of attribute analysis_api.



57
58
59
# File 'lib/dag/client/api.rb', line 57

def analysis_api
  @analysis_api
end

#apikeyObject (readonly)

Returns the value of attribute apikey.



57
58
59
# File 'lib/dag/client/api.rb', line 57

def apikey
  @apikey
end

#storage_apiObject (readonly)

Returns the value of attribute storage_api.



57
58
59
# File 'lib/dag/client/api.rb', line 57

def storage_api
  @storage_api
end

Instance Method Details

#download_signature(expire_at, bucket, output_object) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/dag/client/api.rb', line 119

def download_signature(expire_at, bucket, output_object)
  http_verb = "GET\n"
  content_md5 = "\n"
  content_type = "\n"
  expire = "#{expire_at}\n"

  string_to_sign = http_verb + content_md5 + content_type + expire +
      canonicalized_resource(bucket, output_object)

  digest = OpenSSL::HMAC::digest(OpenSSL::Digest::SHA1.new, @secret, string_to_sign)
  Base64.encode64(digest).strip
end

#execute(rest_parameter) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dag/client/api.rb', line 63

def execute(rest_parameter)
  response = handle_api_failure(rest_parameter) do
    rest_client(:dag_gw, rest_parameter)
  end

  if response.present?
    STDERR.print "\n\n" if @debug

    if response.body == ''
      data = ''
    else
      data = Oj.load(response.body) || ''
    end
    
    data.instance_eval {
      class << self
        attr_accessor :headers
      end
    }
    data.headers = response.header
    return data.freeze
  end
end

#execute_storage(rest_parameter, &block) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/dag/client/api.rb', line 87

def execute_storage(rest_parameter, &block)
  response = handle_api_failure(rest_parameter) do
    rest_client(:storage, rest_parameter, &block)
  end

  if response.present?
    data = if rest_parameter.raw_data?
             response.body
           else
             REXML::Document.new(response.body)
           end || ''

    if data.present?
      STDERR.print "\n\n" if @debug
    end

    data.instance_eval {
      class << self
        attr_accessor :headers
      end
    }
    data.headers = response.header
    return data.freeze
  end
end

#force_path_style?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/dag/client/api.rb', line 59

def force_path_style?
  @force_path_style
end