pi 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -75,14 +75,14 @@ _Copyright 2010-2012, Samsung.
75
75
  Project
76
76
  projects List created projects
77
77
  create-project [project] Create a new project
78
- delete-project [project] Delete the project
79
- project-events [project] List the event info for the project
80
- project-tags [project] List the tags for the project
81
- project-commits [project] List the commit log for the project
82
- upload [project][--path,--ver,--desc] Upload the war package for java project
78
+ delete-project [projectid] Delete the project
79
+ project-events [projectid] List the event info for the project
80
+ project-tags [projectid] List the tags for the project
81
+ project-commits [projectid] List the commit log for the project
82
+ upload [projectid][--path,--ver,--desc] Upload the war package for java project
83
83
 
84
84
  Application
85
- apps [--project,--target] List deployed applications for the project
85
+ apps [--projectid,--target] List deployed applications
86
86
  create-app [appname] Create a new application
87
87
  delete-app [appid] Delete the application
88
88
  delete-app <appname> <--target TARGET> Delete the application
@@ -131,7 +131,8 @@ _Copyright 2010-2012, Samsung.
131
131
  unmap-dns [appid] [--dns DNS] Unmap the urls for the application
132
132
  unmap-dns <appname> <--target TARGET> [--dns DNS] Unmap the urls for the application
133
133
  dns List the dns
134
- create-dns [dnsname] [--zoneid,--project,--desc] Create a new dns
134
+ zones List the dns zones
135
+ create-dns [dnsname] [--zoneid,--projectid,--desc] Create a new dns
135
136
  register-dns [dnsid] Register to target
136
137
  deregister-dns [dnsid] Deregister to target
137
138
  delete-dns [dnsid] Delete the dns
@@ -161,12 +162,12 @@ Github Account Email: ruanzhimin@gmail.com
161
162
 
162
163
  ubuntu@admin:~$ pi targets
163
164
 
164
- +------------+------------------------------------+
165
- | Name | URL |
166
- +------------+------------------------------------+
167
- | ap-ne-test | http://ap-ne-test.samsungcloud.org |
168
- | bst-dev | http://bst-dev.samsungcloud.org |
169
- +------------+------------------------------------+
165
+ +-----------+-----------------------------------+
166
+ | Name | URL |
167
+ +-----------+-----------------------------------+
168
+ | bst-dev | http://bst-dev.samsungcloud.org |
169
+ | target-hq | http://target-hq.samsungcloud.org |
170
+ +-----------+-----------------------------------+
170
171
 
171
172
  ubuntu@admin:~$ pi password
172
173
  Old Password: *******
@@ -226,14 +227,14 @@ Currently available pi commands are:
226
227
  Project
227
228
  projects List created projects
228
229
  create-project [project] Create a new project
229
- delete-project [project] Delete the project
230
- project-events [project] List the event info for the project
231
- project-tags [project] List the tags for the project
232
- project-commits [project] List the commit log for the project
233
- upload [project][--path,--ver,--desc] Upload the war package for java project
230
+ delete-project [projectid] Delete the project
231
+ project-events [projectid] List the event info for the project
232
+ project-tags [projectid] List the tags for the project
233
+ project-commits [projectid] List the commit log for the project
234
+ upload [projectid][--path,--ver,--desc] Upload the war package for java project
234
235
 
235
236
  Application
236
- apps [--project,--target] List deployed applications for the project
237
+ apps [--projectid,--target] List deployed applications
237
238
  create-app [appname] Create a new application
238
239
  delete-app [appid] Delete the application
239
240
  delete-app <appname> <--target TARGET> Delete the application
@@ -282,7 +283,8 @@ Currently available pi commands are:
282
283
  unmap-dns [appid] [--dns DNS] Unmap the urls for the application
283
284
  unmap-dns <appname> <--target TARGET> [--dns DNS] Unmap the urls for the application
284
285
  dns List the dns
285
- create-dns [dnsname] [--zoneid,--project,--desc] Create a new dns
286
+ zones List the dns zones
287
+ create-dns [dnsname] [--zoneid,--projectid,--desc] Create a new dns
286
288
  register-dns [dnsid] Register to target
287
289
  deregister-dns [dnsid] Deregister to target
288
290
  delete-dns [dnsid] Delete the dns
@@ -291,7 +293,6 @@ ubuntu@admin:~$ pi help options
291
293
 
292
294
  Available options:
293
295
 
294
- --url URL
295
296
  --user USER
296
297
  --password PASS
297
298
  --name NAME
@@ -299,7 +300,7 @@ Available options:
299
300
  --path PATH
300
301
  --ver VERSION
301
302
  --desc DESC
302
- --project PROJ
303
+ --projectid ID
303
304
  --target TARG
304
305
  --instance N
305
306
  --type TYPE
@@ -321,18 +322,20 @@ Usage: pi start-app [appid] or pi start-app <appname> <--target TARGET>
321
322
 
322
323
  ubuntu@admin:~$ pi projects
323
324
 
324
- +-------------+---------+-----------+----------+-------------------------------------------------------------------+-------------+
325
- | Name | Runtime | Framework | Git Type | GitUrl | Description |
326
- +-------------+---------+-----------+----------+-------------------------------------------------------------------+-------------+
327
- | javagithub | java | spring | github | https://ruanzhimin@github.com/ruanzhimin/javagithub.git | test |
328
- | javawj | java | spring | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/javawj.git | test |
329
- | railsgithub | ruby18 | rails3 | github | https://ruanzhimin@github.com/ruanzhimin/railsgithub.git | test |
330
- | railswj | ruby18 | rails3 | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/railswj.git | test |
331
- | sinatra | ruby18 | sinatra | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/sinatra.git | test |
332
- +-------------+---------+-----------+----------+-------------------------------------------------------------------+-------------+
325
+ +------+------------------+---------+-----------+----------+----------------------------------------------------------------------------+-------------+
326
+ | ID | Name | Runtime | Framework | Git Type | GitUrl | Description |
327
+ +------+------------------+---------+-----------+----------+----------------------------------------------------------------------------+-------------+
328
+ | 2131 | javagithub | java | spring | github | https://ruanzhimin@github.com/ruanzhimin/javagithub.git | test |
329
+ | 2193 | javawj | java | spring | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/javawj.git | test |
330
+ | 2132 | railsgithub | ruby18 | rails3 | github | https://ruanzhimin@github.com/ruanzhimin/railsgithub.git | test |
331
+ | 2028 | railswj | ruby18 | rails3 | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/railswj.git | test |
332
+ | 2271 | sinatra | ruby18 | sinatra | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/sinatra.git | test |
333
+ | 2414 | sinatra4rabbitmq | ruby18 | sinatra | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/sinatra4rabbitmq.git | test |
334
+ | 2416 | sinatra4redis | ruby18 | sinatra | cloudpi | http://wangjing@git-staging.samsungcloud.org/wangjing/sinatra4redis.git | test |
335
+ +------+------------------+---------+-----------+----------+----------------------------------------------------------------------------+-------------+
333
336
 
334
337
  ubuntu@admin:~$ pi create-project
335
- Project Name: javatest
338
+ Project Name: java
336
339
  1: java
337
340
  2: ruby18
338
341
  Select Runtime: 1
@@ -348,49 +351,48 @@ Please enter in the description: test
348
351
  2: github
349
352
  Select Repository Type: 1
350
353
  Selected Repository Type: cloudpi
351
- Creating project "javatest": ................OK
354
+ Creating project "java": ............OK
352
355
 
353
- ubuntu@admin:~$ pi upload
354
- 1: javagithub
355
- 2: javatest
356
+ ubuntu@admin:~$ pi upload
357
+ 1: java
358
+ 2: javagithub
356
359
  3: javawj
357
- Select Project: 2
358
- Selected Project: javatest
360
+ Select Project: 1
361
+ Selected Project: java
359
362
  Please enter the path of upload war file: /home/wangjing/paashelp.war
360
- Please enter the version: test
363
+ Please enter the version: paashelp
361
364
  Please enter in the description: test
362
- Uploading "paashelp.war": ..OK
365
+ Uploading "paashelp.war": .OK
363
366
 
364
367
  ubuntu@admin:~$ pi create-app
365
- 1: ap-ne-test
366
- 2: bst-dev
368
+ 1: bst-dev
369
+ 2: target-hq
367
370
  Select Target: 1
368
- Selected Target: ap-ne-test
369
- Available memory: 5952 M
370
- 1: javagithub
371
- 2: javatest
371
+ Selected Target: bst-dev
372
+ Available memory: 1856 M
373
+ 1: java
374
+ 2: javagithub
372
375
  3: javawj
373
376
  4: railsgithub
374
377
  5: railswj
375
378
  6: sinatra
376
- Select Project: 2
377
- Selected Project: javatest
379
+ 7: sinatra4rabbitmq
380
+ 8: sinatra4redis
381
+ Select Project: 1
382
+ Selected Project: java
378
383
  Application Name: java
379
- 1: test
384
+ 1: paashelp
380
385
  Select Version: 1
381
- Selected Version: test
382
- URL: java.wangjing.ap-ne-test.samsungpaas.com
386
+ Selected Version: paashelp
387
+ URL: java.wangjing.bst-dev.samsungpaas.com
383
388
  Memory reservation (64M, 128M, 256M, 512M, 1G, 2G) [64M]:
384
389
  How many instances? [1]:
385
390
  Need debug? [yN]:
386
391
  1: restart
387
392
  2: notify
388
- Reaction when service changed [notify]: 1
393
+ Reaction when service changed [notify]:
389
394
  Need monitor? [yN]:
390
- 1: master
391
- Select Branch [master]:
392
- Selected Branch: master
393
- Creating application "java": .........................OK
395
+ Creating application "java": .................................OK
394
396
 
395
397
  ubuntu@admin:~$ pi apps
396
398
  +------+------------+----------+----------------------------------------------+-------------+----------+---------+-----------+-------------------+
@@ -4,7 +4,15 @@ module PI::Cli
4
4
 
5
5
  YES_SET = Set.new(["y", "Y", "yes", "YES"])
6
6
  NO_SET = Set.new(["n", "N", "no", "NO"])
7
-
7
+ DEFAULTS = {
8
+ "mem" => "64M",
9
+ "instances" => 1,
10
+ "action_for_change" => "notify",
11
+ "graceful" => true,
12
+ "lazy" => true,
13
+ "isDebug" => false,
14
+ "needMonitor" => false
15
+ }
8
16
  def choose_project
9
17
  projects = client.projects
10
18
  err "No Projects" if projects.nil? || projects.empty?
@@ -159,28 +167,76 @@ module PI::Cli
159
167
  return dnsid
160
168
  end
161
169
 
162
- def check_status(target, appname, eventname)
163
- for i in 1..12 do
164
- result = client.app_message(target,appname,eventname)
165
- break result unless result[:text].empty?
166
- sleep(10)
167
- end
168
- return result
170
+ def get_graceful(app)
171
+ graceful = @options[:graceful]
172
+ if app[:action_for_change] == "restart"
173
+ graceful = ask "Need graceful?", :default => DEFAULTS["graceful"] unless graceful
174
+ else
175
+ graceful = false
176
+ end
177
+ graceful = (graceful == true ? "true" : "false")
178
+ end
179
+
180
+ def get_lazy(app)
181
+ lazy = @options[:lazy]
182
+ if app[:action_for_change] == "restart"
183
+ lazy = ask "Need lazy?", :default => DEFAULTS["lazy"] unless lazy
184
+ else
185
+ lazy = false
186
+ end
187
+ lazy = (lazy == true ? "true" : "false")
188
+ end
189
+
190
+ # def check_status(uuid)
191
+ # for i in 1..13 do
192
+ # result = client.app_message(uuid)
193
+ # break result unless result[:text].empty?
194
+ # sleep(10)
195
+ # end
196
+ # return result
197
+ # end
198
+
199
+ def check_status(uuid)
200
+ result = client.app_message(uuid)
201
+ if not result[:text].empty?
202
+ display "#{result[:text]}"
203
+ else
204
+ sleep(10)
205
+ check_status(uuid)
206
+ end
169
207
  end
170
208
 
171
209
  # only [a-zA-Z0-9] for project name and app name (size <=18)
172
210
  def check_name_valid?(name)
173
- (name =~ /^\w+$/ && name.size <= 18) ? true : false
211
+ (name =~ /^[a-zA-Z0-9]{1,18}$/) ? true : false
174
212
  end
175
213
 
176
- #not include number, and cannot be started with vcap_, vmc_ for env name (size <= 18)
214
+ #Env name can't start with 'vcap_', 'VCAP_', 'vmc_' & 'VMC_', and can include 'a-zA-Z`~!@#$%^&*()_+-{}' only. The max length of name is 18
177
215
  def check_envname_valid?(name)
178
- (name =~ /\b(?!vcap_|vmc_|VCAP_|VMC_)\D+\b/ && name.size <= 18) ? true : false
216
+ #(name =~ /\b(?!vcap_|vmc_|VCAP_|VMC_)\D+\b/ && name.size <= 18) ? true : false
217
+ if name =~ /[0-9]/
218
+ display "Digital cannot be included in Env name"
219
+ return false
220
+ end
221
+ if name =~ /^vcap_/i
222
+ display "Env name cannot be started with \"vcap_\" or \"VCAP_\""
223
+ return false
224
+ end
225
+ if name =~ /^vmc_/i
226
+ display "Env name cannot be started with \"vmc_\" or \"VMC_\""
227
+ return false
228
+ end
229
+ if not name =~ /^[a-zA-Z\`\~\!\@\#\$\%\^\&\*\(\)\_\+\-\{\}]{0,18}$/
230
+ display "the input is illegal!"
231
+ return false
232
+ end
233
+ return true
179
234
  end
180
235
 
181
- #not include number, ', ", \, and begin with vcap_, vmc_ for env name (size <= 18)
236
+ #not include number, ', ", \, and size <= 18
182
237
  def check_envvalue_valid?(value)
183
- (value =~ /^[^\'\"\\]+$/ && value.size <= 18) ? true : false
238
+ #(value =~ /^[^\'\"\\]+$/ && value.size <= 18) ? true : false
239
+ (value =~ /^[^\'\"\\=]{1,18}$/) ? true : false
184
240
  end
185
241
 
186
242
  end
@@ -5,11 +5,13 @@ module PI::Cli::Command
5
5
  include PI::Cli::ChooseHelper
6
6
  include PI::Cli::InteractHelper
7
7
  DEFAULTS = {
8
- "mem" => "64M",
9
- "instances" => 1,
8
+ "mem" => "64M",
9
+ "instances" => 1,
10
10
  "action_for_change" => "notify",
11
- "isDebug" => false,
12
- "needMonitor" => false
11
+ "graceful" => true,
12
+ "lazy" => true,
13
+ "isDebug" => false,
14
+ "needMonitor" => false
13
15
  }
14
16
 
15
17
  def apps
@@ -57,7 +59,7 @@ module PI::Cli::Command
57
59
  apps_table = table do |t|
58
60
  t.headings = 'ID', 'Target', 'App name', 'URL', 'Deploy Type','Version', 'Status', 'Instances', 'Running Instances'
59
61
  apps.each do |app|
60
- t << [app[:id], app[:targetName], app[:name] ,app[:url], app[:deployType], app[:tag], app[:status], app[:instances], app[:runInstances]]
62
+ t << [app[:id], app[:targetName], app[:name] ,app[:url], app[:deployType], app[:tag].empty? ? "Latest" : app[:tag], app[:status], app[:instances], app[:runInstances]]
61
63
  end
62
64
  end
63
65
  display apps_table
@@ -66,6 +68,13 @@ module PI::Cli::Command
66
68
  def create_app(appname=nil)
67
69
  client.check_login_status
68
70
  binarylist, deployType, instances = nil, nil, nil
71
+
72
+ if appname
73
+ if not check_name_valid?(appname)
74
+ err "Invalid application name '#{appname}'."
75
+ end
76
+ end
77
+
69
78
  # choose the target
70
79
  targets = client.targets
71
80
  err "No Targets!" if targets.nil? || targets.empty?
@@ -73,14 +82,7 @@ module PI::Cli::Command
73
82
  display "Selected Target: ",false
74
83
  display "#{target}"
75
84
  target_memory = client.target_memory(target)
76
- target_memory = target_memory[1]
77
- display ("Available memory: #{target_memory} M")
78
-
79
- # choose the project
80
- useproject = choose_project
81
- projectname = useproject[:name]
82
- projectid = useproject[:id]
83
-
85
+
84
86
  loop{
85
87
  appname = ask "Application Name" unless appname
86
88
  if not check_name_valid?(appname)
@@ -97,6 +99,11 @@ module PI::Cli::Command
97
99
  end
98
100
  }
99
101
 
102
+ # choose the project
103
+ useproject = choose_project
104
+ projectname = useproject[:name]
105
+ projectid = useproject[:id]
106
+
100
107
  # choose the tag
101
108
  if useproject[:runtime] =~ /^(ruby)/i
102
109
  deployType = "git"
@@ -134,24 +141,39 @@ module PI::Cli::Command
134
141
  mem = ask "Memory reservation", :default => DEFAULTS["mem"], :choices => ["64M", "128M", "256M", "512M", "1G", "2G"]
135
142
  # Set to MB number
136
143
  mem_quota = mem_choice_to_quota(mem)
137
-
144
+
145
+ target_memory = Integer(target_memory[1])
146
+ max_instance = (target_memory.to_f/mem.to_i).floor
147
+ display ("Available memory: #{target_memory} M, maximum instances: #{max_instance}")
138
148
  loop{
139
- instances = ask "How many instances?", :default => DEFAULTS["instances"]
140
- instances = instances.to_s
141
- if not instances =~ /^[1-9]\d*$/
149
+ instances = ask "How many instances(from 1 to #{max_instance})?", :default => DEFAULTS["instances"]
150
+ if not instances.to_s =~ /^[1-9]\d*$/
142
151
  display "Invalid Number!"
143
152
  instances =nil
144
- next
153
+ next
154
+ else if instances < 1 || instances > max_instance
155
+ display "Invalid Number! Please input number from 1 to #{max_instance}"
156
+ instances =nil
157
+ next
145
158
  else
146
159
  break
147
160
  end
161
+ end
148
162
  }
149
163
  isDebug = false
150
164
  isDebug = ask "Need debug?", :default => DEFAULTS["isDebug"] if deployType == "binary"
165
+ isDebug = (isDebug == false ? "no" : "yes")
166
+ graceful = false
167
+ lazy = false
151
168
  choices = ["restart", "notify"]
152
169
  action_for_change = ask"Reaction when service changed", :default => DEFAULTS["action_for_change"], :choices => choices, :indexed => true
153
- needMonitor = ask "Need monitor?", :default => DEFAULTS["needMonitor"]
154
- isDebug = (isDebug == false ? "no" : "yes")
170
+ if action_for_change == "restart"
171
+ graceful = ask "Need graceful?", :default => DEFAULTS["graceful"]
172
+ lazy = ask "Need lazy?", :default => DEFAULTS["lazy"]
173
+ end
174
+ graceful = (graceful == false ? "false" : "true")
175
+ lazy = (lazy == false ? "false" : "true")
176
+ needMonitor = ask "Need monitor?", :default => DEFAULTS["needMonitor"]
155
177
  needMonitor = (needMonitor == false ? "no" : "yes")
156
178
 
157
179
  manifest = {
@@ -167,6 +189,8 @@ module PI::Cli::Command
167
189
  :tag => tag,
168
190
  :isDebug => isDebug,
169
191
  :action_for_change => action_for_change,
192
+ :graceful => graceful,
193
+ :lazy => lazy,
170
194
  :needMonitor => needMonitor
171
195
  }
172
196
 
@@ -180,18 +204,10 @@ module PI::Cli::Command
180
204
  end
181
205
  end
182
206
 
183
- client.create_app(manifest)
184
- result = check_status(target, appname, "create")
207
+ tmp = client.create_app(manifest)
208
+ uuid = tmp[1]
209
+ result = check_status(uuid)
185
210
  Thread.kill(t)
186
- if result[:code] == 200
187
- if not result[:text].empty?
188
- display "OK".green
189
- else
190
- display "Time out"
191
- end
192
- else
193
- err result[:text]
194
- end
195
211
  end
196
212
 
197
213
  def delete_app(appid_or_appname=nil)
@@ -216,9 +232,9 @@ module PI::Cli::Command
216
232
 
217
233
  def start_app(appid_or_appname=nil)
218
234
  client.check_login_status
219
- target_not_all, app, appid = choose_app_help(appid_or_appname)
220
- appid = (appid == nil ? app[:id] : appid)
235
+ target_not_all, app, appid = choose_app_help(appid_or_appname)
221
236
  if target_not_all
237
+ appid = (appid == nil ? app[:id] : appid)
222
238
  return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already started.".yellow if app[:status] == "STARTED"
223
239
  do_start_app(app, appid)
224
240
  else
@@ -231,9 +247,9 @@ module PI::Cli::Command
231
247
 
232
248
  def stop_app(appid_or_appname=nil)
233
249
  client.check_login_status
234
- target_not_all, app, appid = choose_app_help(appid_or_appname)
235
- appid = (appid == nil ? app[:id] : appid)
250
+ target_not_all, app, appid = choose_app_help(appid_or_appname)
236
251
  if target_not_all
252
+ appid = (appid == nil ? app[:id] : appid)
237
253
  return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already stopped.".yellow if app[:status] == "STOPPED"
238
254
  do_stop_app(app, appid)
239
255
  else
@@ -246,38 +262,43 @@ module PI::Cli::Command
246
262
 
247
263
  def restart_app(appid_or_appname=nil)
248
264
  client.check_login_status
249
- target_not_all, app, appid = choose_app_help(appid_or_appname)
250
- appid = (appid == nil ? app[:id] : appid)
251
- if target_not_all
252
- do_stop_app(app, appid) if app[:status] == "STARTED"
253
- do_start_app(app, appid)
265
+ target_not_all, app, appid = choose_app_help(appid_or_appname)
266
+ if target_not_all
267
+ appid = (appid == nil ? app[:id] : appid)
268
+ do_restart_app(app, appid)
254
269
  else
255
270
  app.each do |a|
256
- do_stop_app(a, a[:id]) if a[:status] == "STARTED"
257
- do_start_app(a, a[:id])
271
+ do_restart_app(a, a[:id])
258
272
  end
259
273
  end
260
274
  end
261
275
 
262
276
  def scale_app(appid_or_appname=nil)
263
277
  client.check_login_status
264
- instance = @options[:instance]
278
+ instance = @options[:instance]
265
279
  app, appid = choose_app_help_target_not_all(appid_or_appname)
266
- appid = (appid == nil ? app[:id] : appid)
267
- loop{
268
- unless instance
269
- instance = ask "How many instances?", :default => app[:instances]
270
- instance = instance.to_s
271
- end
272
- if not instance =~ /^[1-9]\d*$/
280
+ appid = (appid == nil ? app[:id] : appid)
281
+ target_memory = client.target_memory(app[:targetName])
282
+ target_memory = Integer(target_memory[1])
283
+ max_instance = (target_memory.to_f/app[:memory].to_i).floor
284
+ display ("Available memory: #{target_memory} M, maximum instances: #{max_instance}")
285
+ loop{
286
+ instance = ask "Current instance: #{app[:instances]}, Instance number" unless instance
287
+ if not instance.to_s =~ /^[1-9]\d*$/
273
288
  display "Invalid Number!"
274
289
  instance =nil
275
290
  next
291
+ else if instance.to_i < 1 || instance.to_i > max_instance
292
+ display "Invalid Number! Please input number from 1 to #{max_instance}"
293
+ instance =nil
294
+ next
276
295
  else
277
296
  break
278
297
  end
298
+ end
279
299
  }
280
300
  err "Don't need scale application" if instance == app[:instances].to_s
301
+ graceful = get_graceful(app)
281
302
  display "Scaling application: ",false
282
303
 
283
304
  t = Thread.new do
@@ -288,18 +309,10 @@ module PI::Cli::Command
288
309
  end
289
310
  end
290
311
 
291
- client.scale_app(appid,instance)
292
- result = check_status(app[:targetName],app[:name], "scale")
293
- Thread.kill(t)
294
- if result[:code] == 200
295
- if not result[:text].empty?
296
- display "OK".green
297
- else
298
- display "Time out"
299
- end
300
- else
301
- err result[:text]
302
- end
312
+ tmp = client.scale_app(appid, instance, graceful)
313
+ uuid = tmp[1]
314
+ result = check_status(uuid)
315
+ Thread.kill(t)
303
316
  end
304
317
 
305
318
  def update_app(appid_or_appname=nil)
@@ -320,6 +333,8 @@ module PI::Cli::Command
320
333
  tag = ask "Select Version", :choices => tags.collect { |b| b[:versionName] }, :indexed => true unless tag
321
334
  err "Don't need update application!" if tag == app[:tag]
322
335
  end
336
+ graceful = get_graceful(app)
337
+ lazy = get_lazy(app)
323
338
  display "Updating application: ",false
324
339
 
325
340
  t = Thread.new do
@@ -330,18 +345,10 @@ module PI::Cli::Command
330
345
  end
331
346
  end
332
347
 
333
- client.update_app(appid,tag)
334
- result = check_status(app[:targetName], app[:name], "rollback")
335
- Thread.kill(t)
336
- if result[:code] == 200
337
- if not result[:text].empty?
338
- display "OK".green
339
- else
340
- display "Time out"
341
- end
342
- else
343
- err result[:text]
344
- end
348
+ tmp = client.update_app(appid,tag,graceful,lazy)
349
+ uuid = tmp[1]
350
+ result = check_status(uuid)
351
+ Thread.kill(t)
345
352
  end
346
353
 
347
354
  def status(appid_or_appname=nil)
@@ -387,7 +394,7 @@ module PI::Cli::Command
387
394
  loop{
388
395
  name = ask "Environment Name" unless name
389
396
  if not check_envname_valid?(name)
390
- display "Invalid environment name '#{name}'."
397
+ #display "Invalid environment name '#{name}'."
391
398
  name =nil
392
399
  next
393
400
  else if env_exists?(appid,name)
@@ -452,25 +459,44 @@ module PI::Cli::Command
452
459
 
453
460
  def app_log(appid_or_appname=nil)
454
461
  client.check_login_status
462
+ instanceindex = @options[:instanceid]
463
+ file = @options[:file]
455
464
  app, appid = choose_app_help_target_not_all(appid_or_appname)
456
- appid = (appid == nil ? app[:id] : appid)
457
-
465
+ appid = (appid == nil ? app[:id] : appid)
458
466
  max_index = app[:instances]-1
459
- instanceindex = ask "Select instance index(from 0 to #{max_index})", :default => 0
460
- filepath = "logs/"
461
- logs = client.app_log(appid,filepath,instanceindex)
462
- logs = logs[1].split("\n")
463
- file = ask "Select logs, indexed list?", :choices => logs, :indexed => true
464
- display "Selected logs: ",false
465
- file = file.split(' ')
466
- file = file[0]
467
- display "#{file}"
468
- filepath = "logs/#{file}"
467
+ instanceindex = ask "Select instance index(from 0 to #{max_index})", :default => 0 unless instanceindex
468
+ unless file
469
+ filepath = "logs/"
470
+ logs = client.app_log(appid,filepath,instanceindex)
471
+ logs = logs[1].split("\n")
472
+ file = ask "Select logs, indexed list?", :choices => logs, :indexed => true
473
+ display "Selected logs: ",false
474
+ file = file.split(' ')
475
+ file = file[0]
476
+ display "#{file}"
477
+ end
478
+ filepath = "logs/#{file}"
469
479
  logs = client.app_log(appid,filepath,instanceindex)
470
480
  display "\n"
471
481
  display logs[1]
472
482
  end
473
483
 
484
+ def app_debug(appid_or_appname=nil)
485
+ client.check_login_status
486
+ app, appid = choose_app_help_target_not_all(appid_or_appname)
487
+ appid = (appid == nil ? app[:id] : appid)
488
+ debug_info = client.app_debug_info(appid)
489
+ return display JSON.pretty_generate(debug_info) if @options[:json]
490
+ return display "No debug info" if debug_info.nil? || debug_info.empty?
491
+ debug_table = table do |t|
492
+ t.headings = 'Debug IP', 'Debug Port', 'State'
493
+ debug_info.each do |d|
494
+ t << [d[:debug_ip], d[:debug_port], d[:state]]
495
+ end
496
+ end
497
+ display debug_table
498
+ end
499
+
474
500
  private
475
501
 
476
502
  def app_exists?(target, appname)
@@ -492,25 +518,35 @@ module PI::Cli::Command
492
518
  break unless t.alive?
493
519
  end
494
520
  end
495
- client.start_app(appid)
496
- result = check_status(app[:targetName], app[:name], "start")
521
+ tmp = client.start_app(appid)
522
+ uuid = tmp[1]
523
+ result = check_status(uuid)
497
524
  Thread.kill(t)
498
- if result[:code] == 200
499
- if not result[:text].empty?
500
- display "OK".green
501
- else
502
- display "Time out"
503
- end
504
- else
505
- err result[:text]
506
- end
507
525
  end
508
526
 
509
527
  def do_stop_app(app, appid)
528
+ graceful = get_graceful(app)
510
529
  display "Stoping application '#{app[:name]}'(target:#{app[:targetName]}): ",false
511
- client.stop_app(appid)
530
+ client.stop_app(appid, graceful)
512
531
  display "OK".green
513
532
  end
533
+
534
+ def do_restart_app(app, appid)
535
+ graceful = get_graceful(app)
536
+ lazy = get_lazy(app)
537
+ display "Restart application '#{app[:name]}'(target:#{app[:targetName]}): ",false
538
+ t = Thread.new do
539
+ loop do
540
+ display '.', false
541
+ sleep (1)
542
+ break unless t.alive?
543
+ end
544
+ end
545
+ tmp = client.restart_app(appid, graceful,lazy)
546
+ uuid = tmp[1]
547
+ result = check_status(uuid)
548
+ Thread.kill(t)
549
+ end
514
550
 
515
551
  def mem_choice_to_quota(mem_choice)
516
552
  (mem_choice =~ /(\d+)M/i) ? mem_quota = $1.to_i : mem_quota = mem_choice.to_i * 1024