Class: UserAppClient
- Inherits:
-
Object
- Object
- UserAppClient
- Defined in:
- lib/user_app_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
- #add_instance(appname, host, port, retry_on_except = true) ⇒ Object
- #change_password(user, new_password, retry_on_except = true) ⇒ Object
- #commit_new_app(user, app_name, language, file_location) ⇒ Object
- #commit_new_app_name(user, app_name, language, retry_on_except = true) ⇒ Object
- #commit_new_user(user, encrypted_password, user_type = "xmpp_user", retry_on_except = true) ⇒ Object
- #commit_tar(app_name, file_location, retry_on_except = true) ⇒ Object
- #delete_app(app, retry_on_except = true) ⇒ Object
- #delete_instance(appname, host, port, retry_on_except = true) ⇒ Object
- #does_app_exist?(app, retry_on_except = true) ⇒ Boolean
- #does_user_exist?(user, retry_on_except = true) ⇒ Boolean
- #get_all_apps(retry_on_except = true) ⇒ Object
- #get_app_admin(appname, retry_on_except = true) ⇒ Object
- #get_app_data(appname, retry_on_except = true) ⇒ Object
- #get_tar(appname, retry_on_except = true) ⇒ Object
-
#initialize(ip, secret) ⇒ UserAppClient
constructor
A new instance of UserAppClient.
- #make_call(timeout, retry_on_except) ⇒ Object
- #set_capabilities(username, capabilities) ⇒ Object
- #set_cloud_admin_capabilities(username) ⇒ Object
- #set_cloud_admin_status(username, new_status) ⇒ Object
Constructor Details
#initialize(ip, secret) ⇒ UserAppClient
Returns a new instance of UserAppClient.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/user_app_client.rb', line 14 def initialize(ip, secret) @ip = ip @secret = secret @conn = SOAP::RPC::Driver.new("https://#{@ip}:4343") @conn.add_method("change_password", "user", "password", "secret") @conn.add_method("commit_new_user", "user", "passwd", "utype", "secret") @conn.add_method("commit_new_app", "user", "appname", "language", "secret") @conn.add_method("commit_tar", "app_name", "tar", "secret") @conn.add_method("delete_app", "appname", "secret") @conn.add_method("is_app_enabled", "appname", "secret") @conn.add_method("does_user_exist", "username", "secret") @conn.add_method("get_app_data", "appname", "secret") @conn.add_method("delete_instance", "appname", "host", "port", "secret") @conn.add_method("get_tar", "app_name", "secret") @conn.add_method("add_instance", "appname", "host", "port", "secret") @conn.add_method("set_cloud_admin_status", "username", "is_cloud_admin", "secret") @conn.add_method("set_capabilities", "username", "capabilities", "secret") end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
12 13 14 |
# File 'lib/user_app_client.rb', line 12 def conn @conn end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
12 13 14 |
# File 'lib/user_app_client.rb', line 12 def ip @ip end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
12 13 14 |
# File 'lib/user_app_client.rb', line 12 def secret @secret end |
Instance Method Details
#add_instance(appname, host, port, retry_on_except = true) ⇒ Object
215 216 217 218 219 220 221 222 |
# File 'lib/user_app_client.rb', line 215 def add_instance(appname, host, port, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.add_instance(appname, host, port, @secret) } return result end |
#change_password(user, new_password, retry_on_except = true) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/user_app_client.rb', line 114 def change_password(user, new_password, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.change_password(user, new_password, @secret) } if result == "true" puts "We successfully changed the password for the given user." elsif result == "Error: user not found" puts "We were unable to locate a user with the given username." else puts "[unexpected] Got this message back: [#{result}]" end end |
#commit_new_app(user, app_name, language, file_location) ⇒ Object
76 77 78 79 |
# File 'lib/user_app_client.rb', line 76 def commit_new_app(user, app_name, language, file_location) commit_new_app_name(user, app_name, language) commit_tar(app_name, file_location) end |
#commit_new_app_name(user, app_name, language, retry_on_except = true) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/user_app_client.rb', line 81 def commit_new_app_name(user, app_name, language, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.commit_new_app(user, app_name, language, @secret) } if result == "true" puts "We have reserved the name #{app_name} for your application." elsif result == "Error: appname already exist" puts "We are uploading a new version of the application #{app_name}." elsif result == "Error: User not found" abort("We were unable to reserve the name of your application. Please contact your cloud administrator for more information.") else puts "[unexpected] Commit new app says: [#{result}]" end end |
#commit_new_user(user, encrypted_password, user_type = "xmpp_user", retry_on_except = true) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/user_app_client.rb', line 61 def commit_new_user(user, encrypted_password, user_type="xmpp_user", retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.commit_new_user(user, encrypted_password, user_type, @secret) } if result == "true" puts "\nYour user account has been created successfully." elsif result == "false" abort("\nWe were unable to create your user account. Please contact your cloud administrator for further details.") else puts "\n[unexpected] Commit new user returned: [#{result}]" end end |
#commit_tar(app_name, file_location, retry_on_except = true) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/user_app_client.rb', line 98
def commit_tar(app_name, file_location, retry_on_except=true)
result = ""
make_call(10, retry_on_except) {
result = @conn.commit_tar(app_name, file_location, @secret)
if result == "true"
puts "#{app_name} was uploaded successfully."
elsif result == "Error: app does not exist"
abort("We were unable to upload your application. Please contact your cloud administrator for more information.")
else
puts "[unexpected] Commit new tar says: [#{result}]"
retry
end
}
end
|
#delete_app(app, retry_on_except = true) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/user_app_client.rb', line 129 def delete_app(app, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.delete_app(app, @secret) } if result == "true" return true else return result end end |
#delete_instance(appname, host, port, retry_on_except = true) ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/user_app_client.rb', line 188 def delete_instance(appname, host, port, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.delete_instance(appname, host, port, @secret) } return result end |
#does_app_exist?(app, retry_on_except = true) ⇒ Boolean
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/user_app_client.rb', line 142 def does_app_exist?(app, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.get_app_data(app, @secret) } begin num_hosts = Integer(result.scan(/num_ports:(\d+)/).flatten.to_s) rescue Exception num_hosts = 0 end if num_hosts > 0 return true else return false end end |
#does_user_exist?(user, retry_on_except = true) ⇒ Boolean
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/user_app_client.rb', line 161 def does_user_exist?(user, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.does_user_exist(user, @secret) } if result == "true" return true else return false end end |
#get_all_apps(retry_on_except = true) ⇒ Object
197 198 199 200 201 202 203 204 |
# File 'lib/user_app_client.rb', line 197 def get_all_apps(retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.get_all_apps(@secret) } return result end |
#get_app_admin(appname, retry_on_except = true) ⇒ Object
183 184 185 186 |
# File 'lib/user_app_client.rb', line 183 def get_app_admin(appname, retry_on_except=true) app_data = get_app_data(appname, retry_on_except) return app_data.scan(/app_owner:(.*)/).flatten.to_s end |
#get_app_data(appname, retry_on_except = true) ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'lib/user_app_client.rb', line 174 def get_app_data(appname, retry_on_except=true) result = "" make_call(10, retry_on_except) { result = @conn.get_app_data(appname, @secret) } return result end |
#get_tar(appname, retry_on_except = true) ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/user_app_client.rb', line 206 def get_tar(appname, retry_on_except=true) result = "" make_call(300, retry_on_except) { result = @conn.get_tar(appname, @secret) } return result end |
#make_call(timeout, retry_on_except) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/user_app_client.rb', line 34 def make_call(timeout, retry_on_except) result = "" begin Timeout::timeout(timeout) do begin yield if block_given? end end rescue OpenSSL::SSL::SSLError retry rescue Errno::ECONNREFUSED if retry_on_except sleep(1) retry else abort("We were unable to establish a connection with the UserAppServer at the designated location. Is AppScale currently running?") end rescue Exception => except if except.class == Interrupt abort end puts "An exception of type #{except.class} was thrown." retry if retry_on_except end end |
#set_capabilities(username, capabilities) ⇒ Object
233 234 235 236 237 238 239 240 |
# File 'lib/user_app_client.rb', line 233 def set_capabilities(username, capabilities) result = "" make_call(NO_TIMEOUT, RETRY_ON_FAIL) { result = @conn.set_capabilities(username, capabilities, @secret) } return result end |
#set_cloud_admin_capabilities(username) ⇒ Object
242 243 244 |
# File 'lib/user_app_client.rb', line 242 def set_cloud_admin_capabilities(username) return set_capabilities(username, ADMIN_CAPABILITIES) end |
#set_cloud_admin_status(username, new_status) ⇒ Object
224 225 226 227 228 229 230 231 |
# File 'lib/user_app_client.rb', line 224 def set_cloud_admin_status(username, new_status) result = "" make_call(NO_TIMEOUT, RETRY_ON_FAIL) { result = @conn.set_cloud_admin_status(username, new_status, @secret) } return result end |