superbot-cloud 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce8cd0ea8e957d1230ff3b9eb7e7afc6f46242ab2594dc28e33a2ae529abf580
4
- data.tar.gz: e16d490de4b68a548623af3a73805dedf3482b1906a50d64975dea579481bd20
3
+ metadata.gz: b7cf9f4ebda39c246a90a762bf76cb9101fa8f0a34abb8b4c87586fd77b09305
4
+ data.tar.gz: 3cf214ca9a1215afd9c76f87305da9ec7e647da163330d7a8fe447cd73d2fec6
5
5
  SHA512:
6
- metadata.gz: cbb070d510196297ef7ca9b1ade929db260b2cda17f411dfd49f80b8874f2aeaf2bc3a281b272e496e64b97b2c4882c3d44d40ad9f4274969a471e335ee7ec89
7
- data.tar.gz: 39a9203c7580e93f0ec883f12d335e0edceed2d54f604f61bb33622ed313bdefa04dbb78c52041d494a4e7253e40b02d212823344a9c31ab526de54e00aa5528
6
+ metadata.gz: 9516b4f2711a3b345b3e89707407653b0215edaf22f1f49507d1cb078f6d1ad68f8df0c58f524feeb7235757657d3c0739abc27550675e9ae97cc0e7db647554
7
+ data.tar.gz: 01a28235edf1bc534f1704bf6f142bf78b012b25c404ca639c481d3e69cc4ea6b78c4cd277e680c0419144813167cb06adb83bcc91f97b625aa36fd23f19e8ed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot-cloud (0.2.5)
4
+ superbot-cloud (0.2.6)
5
5
  marcel (= 0.3.3)
6
6
  multipart-post (= 2.0.0)
7
7
 
@@ -18,9 +18,14 @@ module Superbot
18
18
  cancel_schedule: { method: :delete, endpoint: 'schedules', required_param: :id },
19
19
  webdriver_session_list: { method: :get, endpoint: 'webdriver_sessions' },
20
20
  delete_webdriver_session: { method: :delete, endpoint: 'webdriver_sessions', required_param: :session_id },
21
- organization_members_list: { method: :get, endpoint: 'members' },
22
- organization_add_member: { method: :post, endpoint: 'members' },
23
- organization_remove_member: { method: :delete, endpoint: 'members', required_param: :username }
21
+ member_list: { method: :get, endpoint: 'members' },
22
+ add_member: { method: :post, endpoint: 'members' },
23
+ remove_member: { method: :delete, endpoint: 'members', required_param: :username },
24
+ create_interactive_run: { method: :post, endpoint: 'interactive_runs' },
25
+ abort_interactive_run: { method: :delete, endpoint: 'interactive_runs', required_param: :id },
26
+ update_interactive_run: { method: :patch, endpoint: 'interactive_runs', required_param: :id },
27
+ show_interactive_run: { method: :get, endpoint: 'interactive_runs', required_param: :id },
28
+ interactive_run_list: { method: :get, endpoint: 'interactive_runs' }
24
29
  }.freeze
25
30
 
26
31
  def self.request(type, params: {})
@@ -12,7 +12,7 @@ module Superbot
12
12
  end
13
13
 
14
14
  def add_member
15
- api_response = Superbot::Cloud::Api.request(:organization_add_member, params: { organization_name: organization, username: username })
15
+ api_response = Superbot::Cloud::Api.request(:add_member, params: { organization_name: organization, username: username })
16
16
  puts "Succesfully added %<username>s to %<organization>s organization" % api_response.slice(:username, :organization)
17
17
  end
18
18
  end
@@ -10,7 +10,7 @@ module Superbot
10
10
  end
11
11
 
12
12
  def list_members
13
- api_response = Superbot::Cloud::Api.request(:organization_members_list, params: { organization_name: @organization })
13
+ api_response = Superbot::Cloud::Api.request(:member_list, params: { organization_name: @organization })
14
14
  abort api_response[:error] if api_response[:error]
15
15
  puts "Organization: #{api_response[:organization]}"
16
16
  puts "Members:"
@@ -12,7 +12,7 @@ module Superbot
12
12
  end
13
13
 
14
14
  def remove_member
15
- api_response = Superbot::Cloud::Api.request(:organization_remove_member, params: { organization_name: organization, username: username })
15
+ api_response = Superbot::Cloud::Api.request(:remove_member, params: { organization_name: organization, username: username })
16
16
  puts "Member successfully removed from organization"
17
17
  end
18
18
  end
@@ -10,8 +10,8 @@ require_relative 'organization_command'
10
10
  require_relative 'test_command'
11
11
  require_relative 'webdriver_command'
12
12
  require_relative 'member_command'
13
- require_relative 'run_command'
14
13
  require_relative 'schedule_command'
14
+ require_relative 'run_command'
15
15
 
16
16
  module Superbot
17
17
  module Cloud
@@ -24,8 +24,8 @@ module Superbot
24
24
  subcommand ['test'], "Manage your tests", TestCommand
25
25
  subcommand ['webdriver'], "Manage your webdriver sessions", WebdriverCommand
26
26
  subcommand ['member'], "Manage your organization members", MemberCommand
27
- subcommand ['run'], "Schedule a cloud run", RunCommand
28
27
  subcommand ['schedule'], "Manage your schedules", ScheduleCommand
28
+ subcommand(['run'], "Schedule a cloud run", RunCommand) if ENV['SUPERBOT_FEAT_CLOUD_RUNS'] == 'true'
29
29
 
30
30
  option ['-v', '--version'], :flag, "Show version information" do
31
31
  puts Superbot::Cloud::VERSION
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Run
7
+ class AbortCommand < BaseCommand
8
+ parameter "ID ...", "the IDs of runs to abort", required: true
9
+
10
+ def execute
11
+ abort_run
12
+ end
13
+
14
+ def abort_run
15
+ id_list.each do |run_id|
16
+ Superbot::Cloud::Api.request(:abort_interactive_run, params: { id: run_id, organization_name: organization })
17
+ puts "Interactive run #{run_id} successfully aborted"
18
+ rescue SystemExit
19
+ p # skip to next run
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Run
7
+ class BaseCommand < OrganizationBasedCommand
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Run
7
+ class ConsoleCommand < BaseCommand
8
+ parameter "ID", "the ID of run to bots", required: true
9
+
10
+ def execute
11
+ abort "Run is not active anymore" if fetch_interaction[:status] == 'aborted'
12
+ loop do
13
+ printf '> '
14
+ input = $stdin.gets
15
+ exit if input.nil?
16
+ cmd, arg = input.rstrip.split(' ')
17
+ invoke_command(cmd, arg)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def invoke_command(command, argument)
24
+ return if empty_value?(command)
25
+
26
+ case command
27
+ when 'bots', 'loops' then positive_number?(argument) && send(command, argument)
28
+ when 'status', 'help', 'exit' then send(command)
29
+ when 'abort' then abort_run
30
+ else
31
+ puts "Unknow command: #{command}"
32
+ end
33
+ end
34
+
35
+ def common_request_params
36
+ {
37
+ id: id,
38
+ organization_name: organization
39
+ }
40
+ end
41
+
42
+ def bots(value)
43
+ return puts("bots: #{fetch_interaction[:parallel].to_i}") if empty_value?(value)
44
+
45
+ Superbot::Cloud::Api.request(:update_interactive_run, params: common_request_params.merge(parallel: value))
46
+ puts "Number of bots scaled to #{value}"
47
+ end
48
+
49
+ def loops(value)
50
+ return puts("loops: #{fetch_interaction[:loop].to_i}") if empty_value?(value)
51
+
52
+ Superbot::Cloud::Api.request(:update_interactive_run, params: common_request_params.merge(loop: value))
53
+ puts "Number of consecutive invocations scaled to #{value}"
54
+ end
55
+
56
+ def abort_run
57
+ Superbot::Cloud::Api.request(:abort_interactive_run, params: common_request_params)
58
+ abort "Abort requested"
59
+ end
60
+
61
+ def exit
62
+ abort
63
+ end
64
+
65
+ def status
66
+ puts(fetch_interaction.map { |arr| arr.join(': ') })
67
+ end
68
+
69
+ def fetch_interaction
70
+ Superbot::Cloud::Api.request(:show_interactive_run, params: common_request_params)
71
+ end
72
+
73
+ def empty_value?(value)
74
+ value.to_s.strip.empty?
75
+ end
76
+
77
+ def positive_number?(value)
78
+ return true if empty_value?(value) || value =~ /\A\d+\z/
79
+
80
+ puts("Incorrect argument value '#{value}', should be positive number or 0")
81
+ false
82
+ end
83
+
84
+ def help
85
+ puts "Interactive run commands:
86
+
87
+ bots Output number of active bots
88
+ loops Output number of consecutive invocations
89
+ bots [n] Scale number of active bots to [n]
90
+ loops [n] Scale number of consecutive invocations
91
+ status Show current run info
92
+ abort Abort current run and exit console
93
+ exit Exit from console"
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Run
7
+ class CreateCommand < OrganizationBasedCommand
8
+ parameter "NAME", "the name of the test to delete", required: true
9
+ option ['--region'], 'REGION', 'Region for remote webdriver'
10
+
11
+ def execute
12
+ Superbot::Cloud::Api.request(:create_interactive_run, params: run_params)
13
+ puts "Cloud interactive run has been created"
14
+ end
15
+
16
+ def run_params
17
+ {
18
+ organization_name: organization,
19
+ test_name: name,
20
+ region: region
21
+ }.compact
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Run
7
+ class ListCommand < BaseCommand
8
+ OUTPUT_HEADERS = {
9
+ id: { name: "ID", column_size: 10 },
10
+ test_name: { name: "Test", column_size: 25 },
11
+ region: { name: "Region", column_size: 20 },
12
+ status: { name: "Status", column_size: 10 },
13
+ parallel: { name: "Bots", column_size: 10 },
14
+ loop: { name: "Loop count", column_size: 10 }
15
+ }.freeze
16
+
17
+ option %w[-q --quiet], :flag, "Only show interactive run IDs"
18
+ option %w[-a --all], :flag, "Show all the interactive runs (including finished)"
19
+
20
+ def execute
21
+ list_interactive_runs
22
+ end
23
+
24
+ def list_interactive_runs
25
+ states = all? ? nil : %w[initial running]
26
+ api_response = Superbot::Cloud::Api.request(:interactive_run_list, params: { organization_name: organization, 'aasm_state[]': states })
27
+
28
+ abort api_response[:error] if api_response[:error]
29
+ abort "No active interactive runs found for organization #{api_response[:organization]}" if api_response[:interactive_runs].empty?
30
+
31
+ if quiet?
32
+ puts(api_response[:interactive_runs].map { |interactive_run| interactive_run[:id] })
33
+ else
34
+ puts "Organization: #{api_response[:organization]}"
35
+ puts "Interactive runs:"
36
+ puts OUTPUT_HEADERS.values.map { |header| header[:name].ljust(header[:column_size]) }.join
37
+ api_response[:interactive_runs].each do |interactive_run|
38
+ row = interactive_run.slice(*OUTPUT_HEADERS.keys).map do |key, value|
39
+ value.to_s.ljust(OUTPUT_HEADERS.dig(key, :column_size))
40
+ end.join
41
+ puts row
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Run
7
+ class ScaleCommand < BaseCommand
8
+ parameter "ID", "the ID of run to scale", required: true
9
+
10
+ option ['--bots'], 'BOTS', 'number of active bots' do |bots|
11
+ Integer(bots)
12
+ end
13
+
14
+ option ['--loop'], 'LOOP_COUNT', 'number of repeated invocations', attribute_name: :loop_count do |loop_count|
15
+ Integer(loop_count)
16
+ end
17
+
18
+ def execute
19
+ scale_run
20
+ end
21
+
22
+ def scale_run
23
+ api_response = Superbot::Cloud::Api.request(:update_interactive_run, params: { id: id, organization_name: organization, parallel: bots, loop: loop_count }.compact)
24
+ puts "Scaled"
25
+ puts "bots: #{api_response[:parallel]}"
26
+ puts "loop: #{api_response[:loop]}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,34 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'run/base_command'
4
+ require_relative 'run/create_command'
5
+ require_relative 'run/list_command'
6
+ require_relative 'run/abort_command'
7
+ require_relative 'run/scale_command'
8
+ require_relative 'run/console_command'
9
+
3
10
  module Superbot
4
11
  module Cloud
5
12
  module CLI
6
- class RunCommand < OrganizationBasedCommand
7
- parameter "NAME", "the name of the test to delete", required: true
8
- option ['--region'], 'REGION', 'Region for remote webdriver'
9
- option ['--when'], 'WHEN', "When to schedule a test (either asap or cron expression)", default: 'asap', attribute_name: :starts_at
10
- option ['--bots'], 'BOTS', 'Number of running cloud superbots', default: 1
11
- option ['--loop'], 'LOOP_COUNT', 'Number of runs for each bot', default: 1, attribute_name: :loop_count
12
-
13
- def execute
14
- schedule_test
15
- end
16
-
17
- def schedule_test
18
- Superbot::Cloud::Api.request(:schedule_test, params: schedule_params)
19
- puts "Cloud run has been scheduled"
20
- end
21
-
22
- def schedule_params
23
- {
24
- test_name: name,
25
- region: region,
26
- organization_name: organization,
27
- parallel: bots,
28
- starts_at: starts_at,
29
- loop: loop_count
30
- }.compact
31
- end
13
+ class RunCommand < LoginRequiredCommand
14
+ subcommand ['create'], "Create new interactive test run", Run::CreateCommand
15
+ subcommand ['list'], "List your interactive runs", Run::ListCommand
16
+ subcommand ['abort'], "Abort run", Run::AbortCommand
17
+ subcommand ['scale'], "Scale your interactive run", Run::ScaleCommand
18
+ subcommand ['console'], "Interactive run console", Run::ConsoleCommand
32
19
  end
33
20
  end
34
21
  end
@@ -13,12 +13,10 @@ module Superbot
13
13
 
14
14
  def delete_schedule
15
15
  id_list.each do |schedule_id|
16
- begin
17
- Superbot::Cloud::Api.request(:cancel_schedule, params: { id: schedule_id, organization_name: organization })
18
- puts "Test schedule #{schedule_id} successfully cancelled"
19
- rescue SystemExit
20
- p # skip to next schedule
21
- end
16
+ Superbot::Cloud::Api.request(:cancel_schedule, params: { id: schedule_id, organization_name: organization })
17
+ puts "Test schedule #{schedule_id} successfully cancelled"
18
+ rescue SystemExit
19
+ p # skip to next schedule
22
20
  end
23
21
  end
24
22
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Schedule
7
+ class CreateCommand < BaseCommand
8
+ parameter "NAME", "the name of the test to delete", required: true
9
+ option ['--region'], 'REGION', 'Region for remote webdriver'
10
+ option ['--when'], 'WHEN', "When to schedule a test (either asap or cron expression)", default: 'asap', attribute_name: :starts_at
11
+ option ['--bots'], 'BOTS', 'Number of running cloud superbots', default: 1
12
+ option ['--loop'], 'LOOP_COUNT', 'Number of runs for each bot', default: 1, attribute_name: :loop_count
13
+
14
+ def execute
15
+ schedule_test
16
+ end
17
+
18
+ def schedule_test
19
+ Superbot::Cloud::Api.request(:schedule_test, params: schedule_params)
20
+ puts "Cloud run has been scheduled"
21
+ end
22
+
23
+ def schedule_params
24
+ {
25
+ test_name: name,
26
+ region: region,
27
+ organization_name: organization,
28
+ parallel: bots,
29
+ starts_at: starts_at,
30
+ loop: loop_count
31
+ }.compact
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -3,11 +3,13 @@
3
3
  require_relative 'schedule/base_command'
4
4
  require_relative 'schedule/list_command'
5
5
  require_relative 'schedule/cancel_command'
6
+ require_relative 'schedule/create_command'
6
7
 
7
8
  module Superbot
8
9
  module Cloud
9
10
  module CLI
10
11
  class ScheduleCommand < LoginRequiredCommand
12
+ subcommand ['create'], "Create new scheduled run", Schedule::CreateCommand
11
13
  subcommand ['list'], "List your schedules", Schedule::ListCommand
12
14
  subcommand ['cancel'], "Cancel your schedule", Schedule::CancelCommand
13
15
  end
@@ -5,15 +5,19 @@ module Superbot
5
5
  module CLI
6
6
  module Test
7
7
  class DeleteCommand < BaseCommand
8
- parameter "NAME", "the name of the test to delete", required: true
8
+ parameter "NAME ...", "the name of the test to delete", required: true
9
9
 
10
10
  def execute
11
11
  delete_test
12
12
  end
13
13
 
14
14
  def delete_test
15
- Superbot::Cloud::Api.request(:delete_test, params: { name: name, organization_name: organization })
16
- puts "Tests successfully deleted"
15
+ name_list.each do |name|
16
+ Superbot::Cloud::Api.request(:delete_test, params: { name: name, organization_name: organization })
17
+ puts "Tests #{name} successfully deleted"
18
+ rescue SystemExit => e
19
+ puts "Test #{name} removal failed: #{e.message}"
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -5,17 +5,22 @@ module Superbot
5
5
  module CLI
6
6
  module Test
7
7
  class ListCommand < BaseCommand
8
+ option %w[-q --quiet], :flag, "Only show test names"
9
+
8
10
  def execute
9
11
  list_tests
10
12
  end
11
13
 
12
14
  def list_tests
13
15
  api_response = Superbot::Cloud::Api.request(:test_list, params: { organization_name: organization })
14
- abort api_response[:error] if api_response[:error]
15
- puts "Organization: #{api_response[:organization]}"
16
- puts "Tests:"
17
- api_response[:tests].each do |test|
18
- puts(test[:name], test[:files].map { |f| "- #{f[:filename]}" })
16
+ if quiet?
17
+ puts(api_response[:tests].map { |test| test[:name] })
18
+ else
19
+ puts "Organization: #{api_response[:organization]}"
20
+ puts "Tests:"
21
+ api_response[:tests].each do |test|
22
+ puts(test[:name], test[:files].map { |f| "- #{f[:filename]}" })
23
+ end
19
24
  end
20
25
  end
21
26
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Superbot
4
4
  module Cloud
5
- VERSION = "0.2.5"
5
+ VERSION = "0.2.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superbot-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Superbots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-15 00:00:00.000000000 Z
11
+ date: 2019-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -148,9 +148,16 @@ files:
148
148
  - lib/superbot/cloud/cli/organization_based_command.rb
149
149
  - lib/superbot/cloud/cli/organization_command.rb
150
150
  - lib/superbot/cloud/cli/root_command.rb
151
+ - lib/superbot/cloud/cli/run/abort_command.rb
152
+ - lib/superbot/cloud/cli/run/base_command.rb
153
+ - lib/superbot/cloud/cli/run/console_command.rb
154
+ - lib/superbot/cloud/cli/run/create_command.rb
155
+ - lib/superbot/cloud/cli/run/list_command.rb
156
+ - lib/superbot/cloud/cli/run/scale_command.rb
151
157
  - lib/superbot/cloud/cli/run_command.rb
152
158
  - lib/superbot/cloud/cli/schedule/base_command.rb
153
159
  - lib/superbot/cloud/cli/schedule/cancel_command.rb
160
+ - lib/superbot/cloud/cli/schedule/create_command.rb
154
161
  - lib/superbot/cloud/cli/schedule/list_command.rb
155
162
  - lib/superbot/cloud/cli/schedule_command.rb
156
163
  - lib/superbot/cloud/cli/test/base_command.rb