Class: AppControllerClient
- Inherits:
-
Object
- Object
- AppControllerClient
- Defined in:
- lib/app_controller_client.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #app_is_running?(appname) ⇒ Boolean
- #done_uploading(appname, location) ⇒ Object
- #get_all_public_ips ⇒ Object
-
#get_role_info ⇒ Object
Asks the AppController to see what roles each node is running in AppScale.
- #get_status ⇒ Object
- #get_userappserver_ip(verbose_level = "low") ⇒ Object
-
#initialize(ip, secret) ⇒ AppControllerClient
constructor
A new instance of AppControllerClient.
- #is_done_initializing? ⇒ Boolean
- #is_done_loading? ⇒ Boolean
- #is_live? ⇒ Boolean
- #kill ⇒ Object
- #make_call(time, retry_on_except, want_output = true) ⇒ Object
- #set_parameters(locations, creds, apps_to_start) ⇒ Object
- #status ⇒ Object
- #stop_app(app_name) ⇒ Object
- #update(app_names) ⇒ Object
Constructor Details
#initialize(ip, secret) ⇒ AppControllerClient
Returns a new instance of AppControllerClient.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/app_controller_client.rb', line 23 def initialize(ip, secret) @ip = ip @secret = secret @conn = SOAP::RPC::Driver.new("https://#{@ip}:17443") @conn.add_method("set_parameters", "djinn_locations", "database_credentials", "app_names", "secret") @conn.add_method("status", "secret") @conn.add_method("update", "app_names", "secret") @conn.add_method("done_uploading", "appname", "location", "secret") @conn.add_method("is_done_initializing", "secret") @conn.add_method("is_done_loading", "secret") @conn.add_method("is_app_running", "appname", "secret") @conn.add_method("stop_app", "app_name", "secret") @conn.add_method("get_all_public_ips", "secret") @conn.add_method("kill", "secret") @conn.add_method("get_role_info", "secret") end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
21 22 23 |
# File 'lib/app_controller_client.rb', line 21 def conn @conn end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
21 22 23 |
# File 'lib/app_controller_client.rb', line 21 def ip @ip end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
21 22 23 |
# File 'lib/app_controller_client.rb', line 21 def secret @secret end |
Instance Method Details
#app_is_running?(appname) ⇒ Boolean
164 165 166 167 168 |
# File 'lib/app_controller_client.rb', line 164 def app_is_running?(appname) make_call(NO_TIMEOUT, RETRY_ON_FAIL) { @conn.is_app_running(appname, @secret) } end |
#done_uploading(appname, location) ⇒ Object
157 158 159 160 161 |
# File 'lib/app_controller_client.rb', line 157 def done_uploading(appname, location) make_call(NO_TIMEOUT, RETRY_ON_FAIL) { @conn.done_uploading(appname, location, @secret) } end |
#get_all_public_ips ⇒ Object
139 140 141 |
# File 'lib/app_controller_client.rb', line 139 def get_all_public_ips() make_call(30, RETRY_ON_FAIL) { @conn.get_all_public_ips(@secret) } end |
#get_role_info ⇒ Object
Asks the AppController to see what roles each node is running in AppScale. The result is an Array, where each item is a Hash that contains information about the given node.
174 175 176 177 178 |
# File 'lib/app_controller_client.rb', line 174 def get_role_info() make_call(NO_TIMEOUT, ABORT_ON_FAIL) { @conn.get_role_info(@secret) } end |
#get_status ⇒ Object
127 128 129 |
# File 'lib/app_controller_client.rb', line 127 def get_status() make_call(10, RETRY_ON_FAIL) { @conn.status(@secret) } end |
#get_userappserver_ip(verbose_level = "low") ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/app_controller_client.rb', line 89 def get_userappserver_ip(verbose_level="low") userappserver_ip, status, state, new_state = "", "", "", "" loop { status = get_status() new_state = status.scan(/Current State: ([\w\s\d\.,]+)\n/).flatten.to_s.chomp if verbose_level == LOGS_VERBOSE and new_state != state puts new_state state = new_state end if status == "false: bad secret" abort("\nWe were unable to verify your secret key with the head node specified in your locations file. Are you sure you have the correct secret key and locations file?\n\nSecret provided: [#{@secret}]\nHead node IP address: [#{@ip}]\n") end if status =~ /Database is at (#{IP_OR_FQDN})/ and $1 != "not-up-yet" userappserver_ip = $1 break end sleep(10) } return userappserver_ip end |
#is_done_initializing? ⇒ Boolean
147 148 149 150 151 |
# File 'lib/app_controller_client.rb', line 147 def is_done_initializing?() make_call(NO_TIMEOUT, RETRY_ON_FAIL) { @conn.is_done_initializing(@secret) } end |
#is_done_loading? ⇒ Boolean
153 154 155 |
# File 'lib/app_controller_client.rb', line 153 def is_done_loading?() make_call(NO_TIMEOUT, RETRY_ON_FAIL) { @conn.is_done_loading(@secret) } end |
#is_live? ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/app_controller_client.rb', line 76 def is_live? uri = "https://#{@ip}:17443" begin Timeout::timeout(5) { make_call(1, ABORT_ON_FAIL, want_output=false) { @conn.status(@secret) } } return true rescue Exception return false end end |
#kill ⇒ Object
143 144 145 |
# File 'lib/app_controller_client.rb', line 143 def kill() make_call(NO_TIMEOUT, RETRY_ON_FAIL) { @conn.kill(@secret) } end |
#make_call(time, retry_on_except, want_output = true) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/app_controller_client.rb', line 41 def make_call(time, retry_on_except, want_output=true) refused_count = 0 max = 10 begin Timeout::timeout(time) { yield if block_given? } rescue Errno::ECONNREFUSED if refused_count > max if want_output abort("Connection with #{@ip} was refused. Is the AppController running?") else raise Exception end else refused_count += 1 Kernel.sleep(1) retry end rescue OpenSSL::SSL::SSLError, NotImplementedError, Errno::EPIPE, Timeout::Error, Errno::ECONNRESET retry rescue Exception => except if retry_on_except retry else if want_output abort("We saw an unexpected error of the type #{except.class} with the following message:\n#{except}.") else raise except end end end end |
#set_parameters(locations, creds, apps_to_start) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/app_controller_client.rb', line 115 def set_parameters(locations, creds, apps_to_start) result = "" make_call(10, ABORT_ON_FAIL) { result = conn.set_parameters(locations, creds, apps_to_start, @secret) } abort(result) if result =~ /Error:/ end |
#status ⇒ Object
123 124 125 |
# File 'lib/app_controller_client.rb', line 123 def status() return "Status of node at #{ip}:\n" + get_status() end |
#stop_app(app_name) ⇒ Object
131 132 133 |
# File 'lib/app_controller_client.rb', line 131 def stop_app(app_name) make_call(30, RETRY_ON_FAIL) { @conn.stop_app(app_name, @secret) } end |
#update(app_names) ⇒ Object
135 136 137 |
# File 'lib/app_controller_client.rb', line 135 def update(app_names) make_call(30, RETRY_ON_FAIL) { @conn.update(app_names, @secret) } end |