Class: App42::Command::App

Inherits:
Base
  • Object
show all
Defined in:
lib/app42/command/app.rb

Constant Summary

Constants included from Base

Base::APP42_COMMAND

Instance Method Summary collapse

Instance Method Details

#add_custom_urlObject

Add custom URL to app



306
307
308
309
310
311
# File 'lib/app42/command/app.rb', line 306

def add_custom_url
  @options[:name] = get_app_name if @options[:name].nil?
  custom_url = get_custom_url if is_app_exist? @options[:name]
  custom_url_res = custom_url_operation "addcustomurl", @options[:name], custom_url
  exit! if custom_url_res
end

#appsObject

List deployed applications



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/app42/command/app.rb', line 286

def apps
  response = build_get_request params, 'app', nil
  rows, rows_header_final, rows_header = [], [], nil
  unless response['apps'].nil? 
    response['apps'].each do |e|
      rows_header = e.keys 
      rows << e.values
    end
  else
    message "#{Message::NO_APP}", true, 'red'
    exit!  
  end   
  
  rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) }

  table = Terminal::Table.new  :title => Paint["=== My Apps ===", :green], :headings => rows_header_final, :rows => rows
  puts table
end

#ask_app_source(app_source_type) ⇒ Object

Returns upload type.

Parameters:

  • app_source_url

Returns:

  • upload type



115
116
117
# File 'lib/app42/command/app.rb', line 115

def ask_app_source app_source_type
  input "Choose Upload Type", app_source_type, true
end

#ask_existing_app_urlObject

ask existing app url for deploy



109
110
111
# File 'lib/app42/command/app.rb', line 109

def ask_existing_app_url
  input "Enter App URL", [], true
end

#ask_scale_typeObject



119
120
121
# File 'lib/app42/command/app.rb', line 119

def ask_scale_type
  input "Choose Scale Type", App42::SCALE_TYPE, true
end

#assignObject

Assign static IP to App



341
342
343
344
345
# File 'lib/app42/command/app.rb', line 341

def assign
  @options[:name] = get_app_name if @options[:name].nil?
  response = assign_release_static_ip "assignstaticip", @options[:name] if is_app_exist? @options[:name]
  exit! if response
end

#collect_vm_details(app_name, iaas, vm_type) ⇒ Object

Returns host name.

Parameters:

  • app_name
  • iaas
  • vm_type

Returns:

  • host name



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/app42/command/app.rb', line 72

def collect_vm_details app_name, iaas, vm_type
  runtime = get_runtime iaas, vm_type
  framework = get_framework iaas, vm_type, runtime
  webserver = get_webserver iaas, vm_type, runtime, framework
  os = get_os_for_app iaas, vm_type, runtime, framework, webserver
  # FIXME, may be configure out later
  # instance = get_instance 'new_vm'
  if vm_type == "Shared"
    kontena = get_vmconfig
  else
    kontena = App42::Command::Gpaas.new.get_instance_config iaas, vm_type
  end
  setup_infra_res = App42::Command::Base.new.create_infrastructure app_name, iaas, vm_type, runtime, framework, webserver, os, kontena
  exit! if setup_infra_res
end

#deleteObject

app42 delete

delete the app, return true or error code/message



279
280
281
282
283
# File 'lib/app42/command/app.rb', line 279

def delete
  @options[:name] = get_app_name if @options[:name].nil?
  app_operation_req = app_operation __method__, @options[:name] if is_app_exist? @options[:name]
  exit! if app_operation_req
end

#deployObject

collect all required attributes for app deploy



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/app42/command/app.rb', line 19

def deploy
  @options[:name] = get_app_name if @options[:name].nil?
  response = interactive_get 'info', 'app/uploadtypes' if is_app_exist? @options[:name]
  app_source_type = response['sourceTypes']
   
  if response['sourceTypes'].count > 1
    source_type = ask_app_source response['sourceTypes']
    if source_type == 'Source'
      git_url = get_git_url
      status = upload_binary @options[:name], source_type, git_url if validate_git_url git_url
    else
      status = get_binary_url @options[:name]
    end
  else
    status = get_binary_url @options[:name]
  end
  exit! if status
end

#descaleObject

read app name and number of instance from user then descale app by no of instance



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/app42/command/app.rb', line 173

def descale
  @options[:name] = get_app_name if @options[:name].nil?

  app_info = app_information 'app', @options[:name]
  descale_dedicated_app @options[:name] if app_info["appInfo"]["vmType"] && app_info["appInfo"]["vmType"] == "Dedicated"

  scale_type = ask_scale_type
  if scale_type == App42::SCALE_TYPE.first
    hdescale @options[:name]
  else
    vdescale @options[:name]
  end
end

#descale_dedicated_app(app_name) ⇒ Object



158
159
160
161
162
163
# File 'lib/app42/command/app.rb', line 158

def descale_dedicated_app app_name
  iaas, vm_type = get_iaas_and_vm_type_of_app app_name
  vm_config = App42::Command::Gpaas.new.get_instance_config iaas, vm_type
  scale_or_descal_res = scale_or_descale_app "descale", vm_config, app_name, "vm"
  exit! if scale_or_descal_res
end

#get_binary_url(app_name) ⇒ Object

collect app source type

pass app name, app source and source url to binary upload methods

Parameters:

  • app_name


62
63
64
65
66
# File 'lib/app42/command/app.rb', line 62

def get_binary_url app_name
  app_source, source_url = collect_app_source app_name
  status = upload_binary app_name, app_source, source_url
  return status
end

#get_git_url(prompt = ) ⇒ Object

collect git URL from user



131
132
133
# File 'lib/app42/command/app.rb', line 131

def get_git_url(prompt = Paint["Enter Git URL?", :cyan])
  ask(prompt) {|q| q.each = true}
end

#get_iaas_and_vm_type_of_app(app_name) ⇒ Object

return setup details



166
167
168
169
# File 'lib/app42/command/app.rb', line 166

def get_iaas_and_vm_type_of_app app_name
   app_details = App42::Command::Config.new.get_app_details app_name
   return app_details['iaas'], app_details['containerType'] if app_details['success']
end

#get_source_path(app_source) ⇒ Object

Returns path.

Parameters:

  • binary/git

Returns:

  • path



125
126
127
128
# File 'lib/app42/command/app.rb', line 125

def get_source_path app_source
  path = ask(Paint["#{app_source.capitalize} Deployment Path", :cyan])
  return path.strip 
end

#hdescale(app_name) ⇒ Object

read app name and number of instance from user then descale app by no of instance



197
198
199
200
201
# File 'lib/app42/command/app.rb', line 197

def hdescale app_name
  @options[:instance] = get_instance "Horizontal descale" if is_app_exist? app_name and @options[:instance].nil?
  scale_or_descal_res = scale_or_descale_app "descale", @options[:instance], app_name
  exit! if scale_or_descal_res
end

#hscale(app_name) ⇒ Object

read app name and number of instance from user then scale app by no of instance



189
190
191
192
193
# File 'lib/app42/command/app.rb', line 189

def hscale app_name
  @options[:instance] = get_instance "Horizontal scale" if is_app_exist? app_name and @options[:instance].nil?
  scale_or_descal_res = scale_or_descale_app "scale", @options[:instance], app_name
  exit! if scale_or_descal_res
end

#is_binary_exist?(source_url, app_name) ⇒ Boolean

Returns binary name.

Parameters:

  • deployment

    path

  • app_name

Returns:

  • (Boolean)

    binary name



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/app42/command/app.rb', line 91

def is_binary_exist? source_url, app_name
  path = escape_path(source_url)
  app_file_name = nil
  @binary_retry ||= 1
  no_of_file = []
  Dir["#{path}/*"].collect {|f| app_file_name = f and no_of_file << f  if f.include?('.zip') || f.include?('.war') || f.include?('.tar.gz') || f.include?('.gzip') }
  if no_of_file.count > 1
    message "#{Message::MORE_THAN_ONE_BINARY}", true, 'red'
    app_file_name = input "Please Select Binary", no_of_file, true
  elsif app_file_name.nil?
    message "#{Message::NO_BINARY}", true, 'red'
    exit! if (@binary_retry +=1 ) >= 4
    get_binary_url app_name
  end
  return app_file_name
end

#releaseObject

Release static IP of App



348
349
350
351
352
# File 'lib/app42/command/app.rb', line 348

def release
  @options[:name] = get_app_name if @options[:name].nil?
  response = assign_release_static_ip "releasestaticip", @options[:name] if is_app_exist? @options[:name]
  exit! if response
end

#remove_custom_urlObject

Remove custom URL of app



314
315
316
317
318
319
# File 'lib/app42/command/app.rb', line 314

def remove_custom_url
  @options[:name] = get_app_name if @options[:name].nil?
  custom_url = get_custom_url if is_app_exist? @options[:name]
  custom_url_res = custom_url_operation "removecustomurl", @options[:name], custom_url
  exit! if custom_url_res
end

#restartObject

app42 restart

restart the app, return true or error code/message



261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/app42/command/app.rb', line 261

def restart 
  @options[:name] = get_app_name if @options[:name].nil?
  app_info = app_information 'app', @options[:name]

  action_type_id = nil
  if app_info["appInfo"]["name"] && app_info["appInfo"]["vmType"] == "Dedicated"
    action_type = input "App Start Type", APP_RESTART.values, true

    APP_RESTART.each_pair{|action| action_type_id = action[0] if action[1] == action_type}
  end
  app_operation_req = app_operation __method__, @options[:name], action_type_id if is_app_exist? @options[:name]
  exit! if app_operation_req
end

#scaleObject

read app name and number of instance from user then scale app by no of instance



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/app42/command/app.rb', line 137

def scale
  @options[:name] = get_app_name if @options[:name].nil?

  app_info = app_information 'app', @options[:name]
  scale_dedicated_app @options[:name] if app_info["appInfo"]["vmType"] && app_info["appInfo"]["vmType"] == "Dedicated"

  scale_type = ask_scale_type
  if scale_type == App42::SCALE_TYPE.first
    hscale @options[:name]
  else
    vscale @options[:name]
  end
end

#scale_dedicated_app(app_name) ⇒ Object



151
152
153
154
155
156
# File 'lib/app42/command/app.rb', line 151

def scale_dedicated_app app_name
  iaas, vm_type = get_iaas_and_vm_type_of_app app_name
  vm_config = App42::Command::Gpaas.new.get_instance_config iaas, vm_type
  scale_or_descal_res = scale_or_descale_app "scale", vm_config, app_name, "vm"
  exit! if scale_or_descal_res
end

#setup_infraObject

collect all required attributes for new VM spawn



11
12
13
14
15
16
# File 'lib/app42/command/app.rb', line 11

def setup_infra
  app_name = get_app_name_and_check_app_url_availability
  vm_type = get_vm_types "app"
  iaas = get_iaas_providers vm_type
  app_name, source_url = get_app_source app_name, iaas, vm_type
end

#startObject

app42 start

start the app, return true or error code/message



223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/app42/command/app.rb', line 223

def start
  @options[:name] = get_app_name if @options[:name].nil?
  app_info = app_information 'app', @options[:name]

  action_type_id = nil
  if app_info["appInfo"]["name"] && app_info["appInfo"]["vmType"] == "Dedicated"
    action_type = input "App Start Type", APP_START.values, true

    APP_START.each_pair{|action| action_type_id = action[0] if action[1] == action_type}
  end

  app_operation_req = app_operation __method__, @options[:name], action_type_id if is_app_exist? @options[:name]
  exit! if app_operation_req
end

#stopObject

app42 stop

stop the app, return true or error code/message



242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/app42/command/app.rb', line 242

def stop
  @options[:name] = get_app_name if @options[:name].nil?
  app_info = app_information 'app', @options[:name]

  action_type_id = nil
  if app_info["appInfo"]["name"] && app_info["appInfo"]["vmType"] == "Dedicated"
    action_type = input "App Stop Type", APP_STOP.values, true

    APP_STOP.each_pair{|action| action_type_id = action[0] if action[1] == action_type}
  end

  app_operation_req = app_operation __method__, @options[:name], action_type_id if is_app_exist? @options[:name]
  exit! if app_operation_req
end

#updateObject

collect all required attributes for app update



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/app42/command/app.rb', line 39

def update
  @options[:name] = get_app_name if @options[:name].nil?
  response = interactive_get 'info', 'app/uploadtypes' if is_app_exist? @options[:name]
  app_source_type = response['sourceTypes']
   
  if response['sourceTypes'].count > 1
    source_type = ask_app_source response['sourceTypes']
    if source_type == 'Source'
      status = update_binary @options[:name]
    else
      status = get_binary_url @options[:name]
    end
  else
    status = get_binary_url @options[:name]
  end
  exit! if status
end

#urlsObject

List all custom urls of apps



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/app42/command/app.rb', line 322

def urls
  @options[:name] = get_app_name if @options[:name].nil?

  rows, rows_header_final, rows_header = [], [], nil
  custom_url_info = custom_url_information @options[:name]
  if custom_url_info && custom_url_info['urls']
    custom_url_info['urls'].each do |e|
      rows_header = e.keys 
      rows << e.values
    end

    rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } 

    table = Terminal::Table.new  :title => Paint["=== #{@options[:name]} Custom URLs Details ===", :green], :headings => rows_header_final, :rows => rows
    puts table
  end
end

#vdescale(app_name) ⇒ Object

read app name and number of instance from user then vertically descale app by no of instance



213
214
215
216
217
# File 'lib/app42/command/app.rb', line 213

def vdescale app_name
  @options[:kontena] = get_kontena "Vertical descale" if is_app_exist? app_name and @options[:kontena].nil?
  vscale_or_vdescal_res = vscale_or_vdescale_app __method__, @options[:kontena], app_name
  exit! if vscale_or_vdescal_res
end

#vscale(app_name) ⇒ Object

read app name and number of instance from user then vertically scale app by no of instance



205
206
207
208
209
# File 'lib/app42/command/app.rb', line 205

def vscale app_name
  @options[:kontena] = get_kontena "Vertical scale" if is_app_exist? app_name and @options[:kontena].nil?
  vscale_or_vdescal_res = vscale_or_vdescale_app __method__, @options[:kontena], app_name
  exit! if vscale_or_vdescal_res
end