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



248
249
250
251
252
253
# File 'lib/app42/command/app.rb', line 248

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



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/app42/command/app.rb', line 228

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



111
112
113
# File 'lib/app42/command/app.rb', line 111

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



105
106
107
# File 'lib/app42/command/app.rb', line 105

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

#ask_scale_typeObject



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

def ask_scale_type
  input "Choose Scale Type", App42::SCALE_TYPE, true
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
# File 'lib/app42/command/app.rb', line 72

def collect_vm_details app_name, iaas, vm_type
  runtime = get_runtime
  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'
  kontena = get_vmconfig
  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



221
222
223
224
225
# File 'lib/app42/command/app.rb', line 221

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



145
146
147
148
149
150
151
152
153
# File 'lib/app42/command/app.rb', line 145

def descale
  @options[:name] = get_app_name if @options[:name].nil?
  scale_type = ask_scale_type
  if scale_type == App42::SCALE_TYPE.first
    hdescale @options[:name]
  else
    vdescale @options[:name]
  end
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



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

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

#get_source_path(app_source) ⇒ Object

Returns path.

Parameters:

  • binary/git

Returns:

  • path



121
122
123
124
# File 'lib/app42/command/app.rb', line 121

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



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

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



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

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/app42/command/app.rb', line 87

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

#remove_custom_urlObject

Remove custom URL of app



256
257
258
259
260
261
# File 'lib/app42/command/app.rb', line 256

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



211
212
213
214
215
# File 'lib/app42/command/app.rb', line 211

def restart 
  @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

#scaleObject

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



133
134
135
136
137
138
139
140
141
# File 'lib/app42/command/app.rb', line 133

def scale
  @options[:name] = get_app_name if @options[:name].nil?
  scale_type = ask_scale_type
  if scale_type == App42::SCALE_TYPE.first
    hscale @options[:name]
  else
    vscale @options[:name]
  end
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
  iaas = get_iaas_providers
  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



191
192
193
194
195
# File 'lib/app42/command/app.rb', line 191

def start
  @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

#stopObject

app42 stop

stop the app, return true or error code/message



201
202
203
204
205
# File 'lib/app42/command/app.rb', line 201

def stop
  @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

#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



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/app42/command/app.rb', line 264

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



181
182
183
184
185
# File 'lib/app42/command/app.rb', line 181

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



173
174
175
176
177
# File 'lib/app42/command/app.rb', line 173

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