eventhub-command 0.7.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,8 @@
1
1
  class Net::SSH::Connection::Session
2
-
3
2
  def exec_sc!(command, verbose = false)
4
- stdout_data,stderr_data = "",""
5
- exit_code, exit_signal = nil,nil
6
- self.open_channel do |channel|
3
+ stdout_data, stderr_data = "", ""
4
+ exit_code, exit_signal = nil, nil
5
+ open_channel do |channel|
7
6
  channel.exec(command) do |_, success|
8
7
  raise "Command \"#{command}\" was unable to execute" unless success
9
8
 
@@ -22,31 +22,31 @@ class Deployer::RubyDeployer < Deployer::BaseDeployer
22
22
  log_deployment(executor, "Deploying #{processor_name} via #{deploy_via} from #{cached_copy_dir}")
23
23
 
24
24
  # stop old one
25
- cmd = inspector_command('stop', processor_name)
25
+ cmd = inspector_command("stop", processor_name)
26
26
  executor.execute(cmd, abort_on_error: false, comment: "Request to stop component")
27
27
 
28
28
  # unzip package
29
- target = deploy_dir('ruby')
30
- source = cached_copy_dir('ruby',"#{processor_name}.zip")
29
+ target = deploy_dir("ruby")
30
+ source = cached_copy_dir("ruby", "#{processor_name}.zip")
31
31
  executor.execute("rm -rf #{processor_dir(processor_name)} && unzip -o -d #{target} #{source}")
32
32
 
33
33
  # copy config
34
34
  executor.execute("if [[ -d #{config_source_dir(processor_name)} ]] ; then cp -r #{config_source_dir(processor_name)}/* #{processor_dir(processor_name)}; fi")
35
35
 
36
36
  # remove log dir if it exists
37
- executor.execute("if [[ -d #{processor_dir(processor_name, 'logs')} ]] ; then rm -rf #{processor_dir(processor_name, 'logs')}; fi")
37
+ executor.execute("if [[ -d #{processor_dir(processor_name, "logs")} ]] ; then rm -rf #{processor_dir(processor_name, "logs")}; fi")
38
38
 
39
39
  # symlink log dir
40
- executor.execute("ln -s #{logs_dir} #{processor_dir(processor_name, 'logs')}")
40
+ executor.execute("ln -s #{logs_dir} #{processor_dir(processor_name, "logs")}")
41
41
 
42
42
  # symlink pids dir
43
- executor.execute("ln -s #{pids_dir} #{processor_dir(processor_name, 'pids')}")
43
+ executor.execute("ln -s #{pids_dir} #{processor_dir(processor_name, "pids")}")
44
44
 
45
45
  # install gems
46
46
  executor.execute("cd #{processor_dir(processor_name)} && bundle install --without test")
47
47
 
48
48
  # start new one
49
- cmd = inspector_command('start', processor_name)
49
+ cmd = inspector_command("start", processor_name)
50
50
  executor.execute(cmd, abort_on_error: false, comment: "Request to stop component")
51
51
  end
52
52
  end
@@ -56,8 +56,8 @@ class Deployer::RubyDeployer < Deployer::BaseDeployer
56
56
 
57
57
  def update_cached_copy(executor)
58
58
  if via_scp?
59
- source = Eh::Settings.current.releases_dir('ruby', '*.zip')
60
- target_dir = File.join(cached_copy_dir, 'ruby')
59
+ source = Eh::Settings.current.releases_dir("ruby", "*.zip")
60
+ target_dir = File.join(cached_copy_dir, "ruby")
61
61
  executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
62
62
  executor.upload(source, target_dir)
63
63
  else
@@ -66,11 +66,11 @@ class Deployer::RubyDeployer < Deployer::BaseDeployer
66
66
  end
67
67
 
68
68
  def logs_dir
69
- File.join(shared_dir, 'logs')
69
+ File.join(shared_dir, "logs")
70
70
  end
71
71
 
72
72
  def pids_dir
73
- File.join(shared_dir, 'pids')
73
+ File.join(shared_dir, "pids")
74
74
  end
75
75
 
76
76
  def deploy_dir(*extra_paths)
@@ -78,23 +78,23 @@ class Deployer::RubyDeployer < Deployer::BaseDeployer
78
78
  end
79
79
 
80
80
  def processor_dir(*extra_paths)
81
- File.join(deploy_dir, 'ruby', *extra_paths)
81
+ File.join(deploy_dir, "ruby", *extra_paths)
82
82
  end
83
83
 
84
84
  def config_source_dir(processor_name)
85
- super('ruby', processor_name)
85
+ super("ruby", processor_name)
86
86
  end
87
87
 
88
88
  # Detect what processors to deploy
89
89
  #
90
90
  def resolve_processor_names(executor, options)
91
- available = remote_ls(executor, options, File.join(cached_copy_dir, 'ruby', '*.zip')).map do |name|
92
- File.basename(name, '.zip')
91
+ available = remote_ls(executor, options, File.join(cached_copy_dir, "ruby", "*.zip")).map do |name|
92
+ File.basename(name, ".zip")
93
93
  end
94
94
 
95
95
  fetched = Array(processor_names).map do |name|
96
- if name.include?('*') # resolve pattern on remote machine
97
- remote_ls(executor, options, File.join(cached_copy_dir, 'ruby', "#{name}.zip"))
96
+ if name.include?("*") # resolve pattern on remote machine
97
+ remote_ls(executor, options, File.join(cached_copy_dir, "ruby", "#{name}.zip"))
98
98
  else
99
99
  name
100
100
  end
@@ -104,7 +104,7 @@ class Deployer::RubyDeployer < Deployer::BaseDeployer
104
104
  end
105
105
 
106
106
  fetched = fetched.flatten.map do |name|
107
- File.basename(name, '.zip')
107
+ File.basename(name, ".zip")
108
108
  end
109
109
 
110
110
  verify_deployment_list!(fetched, available)
@@ -112,15 +112,13 @@ class Deployer::RubyDeployer < Deployer::BaseDeployer
112
112
  fetched
113
113
  end
114
114
 
115
-
116
115
  # custom ruby sorting makes sure dispatcher is always first if multiple go apps are given
117
116
  #
118
117
  def ruby_sorter
119
118
  ->(a, b) do
120
- return -1 if a =~ /dispatcher/i
121
- return 1 if b =~ /dispatcher/i
119
+ return -1 if /dispatcher/i.match?(a)
120
+ return 1 if /dispatcher/i.match?(b)
122
121
  a <=> b
123
122
  end
124
123
  end
125
-
126
124
  end
@@ -27,8 +27,8 @@ class Deployer::Stage
27
27
  data = YAML.load_file(file)
28
28
  data.map do |_, config|
29
29
  stage = Deployer::Stage.new(name)
30
- config['hosts'].each do |host|
31
- stage.host(host['host'], host['port'], host['user'])
30
+ config["hosts"].each do |host|
31
+ stage.host(host["host"], host["port"], host["user"])
32
32
  end
33
33
  stage
34
34
  end.first
data/lib/eh-commands.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  # All commands are required here
2
2
  if Eh::Settings.current.repository
3
- require 'eh/commands/generate'
4
- require 'eh/commands/package'
5
- require 'eh/commands/deploy'
6
- require 'eh/commands/stage'
7
- require 'eh/commands/proxy'
8
- require 'eh/commands/dump'
9
- require 'eh/commands/database'
10
- require 'eh/proxy/proxy'
3
+ require "eh/commands/generate"
4
+ require "eh/commands/package"
5
+ require "eh/commands/deploy"
6
+ require "eh/commands/stage"
7
+ require "eh/commands/proxy"
8
+ require "eh/commands/dump"
9
+ require "eh/commands/database"
10
+ require "eh/proxy/proxy"
11
11
  else
12
12
  # remove unused settings for this version
13
- Eh::Settings.current.data.delete('repository_root_dir')
13
+ Eh::Settings.current.data.delete("repository_root_dir")
14
14
  Eh::Settings.current.write
15
15
  puts "No current repository found."
16
16
  puts "You can configure other repositories by running 'eh repository add' and/or 'eh repository select'"
17
17
  end
18
18
 
19
- require 'eh/commands/repository'
19
+ require "eh/commands/repository"
data/lib/eh.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  module Eh
2
2
  end
3
3
 
4
- require 'zip'
5
- require 'pathname'
4
+ require "zip"
5
+ require "pathname"
6
6
 
7
- require 'eh/version'
8
- require 'eh/settings'
9
- require 'yaml'
7
+ require "eh/version"
8
+ require "eh/settings"
9
+ require "yaml"
10
10
 
11
- require_relative 'helper'
12
- require_relative 'deployer'
13
- require_relative 'packager'
11
+ require_relative "helper"
12
+ require_relative "deployer"
13
+ require_relative "packager"
@@ -1,15 +1,14 @@
1
- desc 'Database commands (run on local machine)'
1
+ desc "Database commands (run on local machine)"
2
2
  command :database do |database|
3
-
4
- database.flag([:user], default_value: 'event_hub_console', desc: 'DB User')
5
- database.flag([:db], default_value: 'event_hub_console', desc: 'DB name')
3
+ database.flag([:user], default_value: "event_hub_console", desc: "DB User")
4
+ database.flag([:db], default_value: "event_hub_console", desc: "DB name")
6
5
  database.flag([:file], desc: "Output Filename, last backup will be taken as default")
7
6
 
8
- database.desc 'Dump database from defined stage'
7
+ database.desc "Dump database from defined stage"
9
8
  database.command :dump do |dump|
10
9
  dump.action do |global_options, options, args|
11
10
  base = Eh::Settings.current.db_backups_dir
12
- stamp = Time.now.strftime('%Y%m%d%H%M%S')
11
+ stamp = Time.now.strftime("%Y%m%d%H%M%S")
13
12
  target = options[:file] || "#{stamp}-console-dump.sql.compressed"
14
13
 
15
14
  cmd = "mkdir -p #{base} && cd #{base} && pg_dump -Fc -U#{options[:user]} #{options[:db]} -f#{target}"
@@ -19,12 +18,12 @@ command :database do |database|
19
18
  end
20
19
  end
21
20
 
22
- database.desc 'Restore database to defined stage'
21
+ database.desc "Restore database to defined stage"
23
22
  database.command :restore do |restore|
24
23
  restore.action do |global_options, options, args|
25
24
  source = options[:file] || begin
26
25
  base = Eh::Settings.current.db_backups_dir
27
- pattern = File.join(base, '*')
26
+ pattern = File.join(base, "*")
28
27
  files = Dir.glob(pattern).sort
29
28
  files.last
30
29
  end
@@ -33,7 +32,7 @@ command :database do |database|
33
32
  end
34
33
  puts "This can destroy the contents of #{options[:db]}. Is this OK? [yes/NO]:"
35
34
  answer = $stdin.gets.chomp.downcase
36
- if answer == 'yes'
35
+ if answer == "yes"
37
36
  cmd = "pg_restore -Fc -U #{options[:user]} -d #{options[:db]} #{source}"
38
37
  puts "will execute '#{cmd}'" if global_options[:verbose]
39
38
  system cmd
@@ -44,15 +43,15 @@ command :database do |database|
44
43
  end
45
44
  end
46
45
 
47
- database.desc 'Cleanup dump files'
46
+ database.desc "Cleanup dump files"
48
47
  database.command :cleanup do |cleanup|
49
48
  cleanup.flag([:keep], type: Integer, desc: "How many dumps to keep", default_value: 25)
50
49
  cleanup.action do |global_options, options, args|
51
50
  keep = options[:keep]
52
51
  base = Eh::Settings.current.db_backups_dir
53
- pattern = File.join(base, '*')
52
+ pattern = File.join(base, "*")
54
53
  files = Dir.glob(pattern).sort.reverse # keep most recent
55
- to_delete = files[keep..-1] || []
54
+ to_delete = files[keep..] || []
56
55
 
57
56
  to_delete.each do |file|
58
57
  puts "will delete #{file}" if global_options[:verbose]
@@ -61,5 +60,4 @@ command :database do |database|
61
60
  puts "Deleted #{to_delete.size} file(s)".green
62
61
  end
63
62
  end
64
-
65
63
  end
@@ -1,14 +1,14 @@
1
- desc 'Deployment commands'
1
+ desc "Deployment commands"
2
2
  command :deploy do |deploy|
3
- deploy.flag([:stage], desc: 'stage', type: String, long_desc: 'Stage where processor is deployed to', default_value: Eh::Settings.current.default_stage)
4
- deploy.flag([:branch], desc: 'branch', type: String, long_desc: 'What branch to deploy. Only when deploy_via=scm', default_value: 'master')
5
- deploy.flag([:tag], desc: 'tag', type: String, long_desc: 'What tag to deploy. Only when deploy_via=scm', default_value: nil)
6
- deploy.flag([:deploy_via], desc: 'where to deploy from', type: String, long_desc: 'deploy via scm or scp. If you use scp then the working_dir is packaged and copied tot the servers', default_value: 'svn')
3
+ deploy.flag([:stage], desc: "stage", type: String, long_desc: "Stage where processor is deployed to", default_value: Eh::Settings.current.default_stage)
4
+ deploy.flag([:branch], desc: "branch", type: String, long_desc: "What branch to deploy. Only when deploy_via=scm", default_value: "master")
5
+ deploy.flag([:tag], desc: "tag", type: String, long_desc: "What tag to deploy. Only when deploy_via=scm", default_value: nil)
6
+ deploy.flag([:deploy_via], desc: "where to deploy from", type: String, long_desc: "deploy via scm or scp. If you use scp then the working_dir is packaged and copied tot the servers", default_value: "svn")
7
7
 
8
- deploy.desc 'Deploy all components'
8
+ deploy.desc "Deploy all components"
9
9
  deploy.command :all do |all|
10
10
  all.action do |global_options, options, args|
11
- forward_arguments = args.join(' ')
11
+ forward_arguments = args.join(" ")
12
12
  deploy_config(options, forward_arguments)
13
13
  deploy_console(options, forward_arguments)
14
14
  deploy_go(options, forward_arguments)
@@ -17,57 +17,45 @@ command :deploy do |deploy|
17
17
  end
18
18
  end
19
19
 
20
- deploy.desc 'Deploy configuration files'
20
+ deploy.desc "Deploy configuration files"
21
21
  deploy.command :config do |config|
22
22
  config.action do |global_options, options, args|
23
23
  Deployer::ConfigDeployer.new(options).deploy!
24
24
  end
25
25
  end
26
26
 
27
- deploy.desc 'Deploy rails console'
27
+ deploy.desc "Deploy rails console"
28
28
  deploy.command :console do |console|
29
- console.flag([:working_dir], desc: 'directory to execute commands in', type: String, default_value: '.')
29
+ console.flag([:working_dir], desc: "directory to execute commands in", type: String, default_value: ".")
30
30
 
31
31
  console.action do |global_options, options, args|
32
32
  Deployer::ConsoleDeployer.new(options).deploy!
33
33
  end
34
34
  end
35
35
 
36
- deploy.desc 'Deploy channel adapter(s)'
37
- deploy.arg_name '[NAME1[,NAME2,PATTERN*]]'
36
+ deploy.desc "Deploy channel adapter(s)"
37
+ deploy.arg_name "[NAME1[,NAME2,PATTERN*]]"
38
38
  deploy.command :mule do |mule|
39
39
  mule.action do |global_options, options, args|
40
- if args[0]
41
- adapter_names = args[0].split(',').map(&:strip)
42
- else
43
- adapter_names = nil
44
- end
40
+ adapter_names = args[0]&.split(",")&.map(&:strip)
45
41
  Deployer::MuleDeployer.new(adapter_names, options).deploy!
46
42
  end
47
43
  end
48
44
 
49
- deploy.desc 'Deploy ruby processor(s)'
50
- deploy.arg_name '[NAME1[,NAME2,PATTERN*]]'
45
+ deploy.desc "Deploy ruby processor(s)"
46
+ deploy.arg_name "[NAME1[,NAME2,PATTERN*]]"
51
47
  deploy.command :ruby do |ruby|
52
48
  ruby.action do |global_options, options, args|
53
- if args[0]
54
- processor_names = args[0].split(',').map(&:strip)
55
- else
56
- processor_names = nil
57
- end
49
+ processor_names = args[0]&.split(",")&.map(&:strip)
58
50
  Deployer::RubyDeployer.new(processor_names, options).deploy!
59
51
  end
60
52
  end
61
53
 
62
- deploy.desc 'Deploy go processor(s)'
63
- deploy.arg_name '[NAME1[,NAME2,PATTERN*]]'
54
+ deploy.desc "Deploy go processor(s)"
55
+ deploy.arg_name "[NAME1[,NAME2,PATTERN*]]"
64
56
  deploy.command :go do |go|
65
57
  go.action do |global_options, options, args|
66
- if args[0]
67
- processor_names = args[0].split(',').map(&:strip)
68
- else
69
- processor_names = nil
70
- end
58
+ processor_names = args[0]&.split(",")&.map(&:strip)
71
59
  Deployer::GoDeployer.new(processor_names, options).deploy!
72
60
  end
73
61
  end
@@ -75,23 +63,23 @@ command :deploy do |deploy|
75
63
  private
76
64
 
77
65
  def deploy_ruby(options, forward_arguments)
78
- system "#{extend_command('deploy ruby')} #{copy_options(options, :stage, :branch, :tag, :verbose)} #{forward_arguments}"
66
+ system "#{extend_command("deploy ruby")} #{copy_options(options, :stage, :branch, :tag, :verbose)} #{forward_arguments}"
79
67
  end
80
68
 
81
69
  def deploy_go(options, forward_arguments)
82
- system "#{extend_command('deploy go')} #{copy_options(options, :stage, :branch, :tag, :verbose)} #{forward_arguments}"
70
+ system "#{extend_command("deploy go")} #{copy_options(options, :stage, :branch, :tag, :verbose)} #{forward_arguments}"
83
71
  end
84
72
 
85
73
  def deploy_console(options, forward_arguments)
86
- system "#{extend_command('deploy console')} #{copy_options(options, :stage)} #{forward_arguments}"
74
+ system "#{extend_command("deploy console")} #{copy_options(options, :stage)} #{forward_arguments}"
87
75
  end
88
76
 
89
77
  def deploy_mule(options, forward_arguments)
90
- system "#{extend_command('deploy mule')} #{copy_options(options, :stage, :verbose)} #{forward_arguments}"
78
+ system "#{extend_command("deploy mule")} #{copy_options(options, :stage, :verbose)} #{forward_arguments}"
91
79
  end
92
80
 
93
81
  def deploy_config(options, forward_arguments)
94
- system "#{extend_command('deploy config')} #{copy_options(options, :stage, :branch, :tag, :verbose)} #{forward_arguments}"
82
+ system "#{extend_command("deploy config")} #{copy_options(options, :stage, :branch, :tag, :verbose)} #{forward_arguments}"
95
83
  end
96
84
 
97
85
  def copy_option(options, option)
@@ -103,11 +91,10 @@ command :deploy do |deploy|
103
91
  def copy_options(options, *selected)
104
92
  selected.map do |name|
105
93
  copy_option(options, name)
106
- end.compact.join(' ')
94
+ end.compact.join(" ")
107
95
  end
108
96
 
109
97
  def extend_command(command)
110
98
  "eh #{command}"
111
99
  end
112
-
113
100
  end
@@ -2,17 +2,15 @@ desc "Creating a dump from an eventhub environment with database, logfiles, fold
2
2
 
3
3
  command :dump do |command|
4
4
  command.desc "Create a backup"
5
- command.flag([:stage], desc: 'stage', type: String, long_desc: 'Stage where processor is deployed to', default_value: Eh::Settings.current.default_stage)
5
+ command.flag([:stage], desc: "stage", type: String, long_desc: "Stage where processor is deployed to", default_value: Eh::Settings.current.default_stage)
6
6
 
7
- command.desc('Download dumped database')
7
+ command.desc("Download dumped database")
8
8
  command.command :download do |command|
9
-
10
9
  command.action do |global_options, options, args|
11
- source = File.join('/tmp', "dump-#{args[0]}.zip")
12
- target = File.join('/tmp', "dump-#{args[0]}.zip")
13
- dir = File.join('/tmp', "dump-#{args[0]}")
10
+ source = File.join("/tmp", "dump-#{args[0]}.zip")
11
+ target = File.join("/tmp", "dump-#{args[0]}.zip")
12
+ dir = File.join("/tmp", "dump-#{args[0]}")
14
13
 
15
- cmds = []
16
14
  host = stage(options).single_host_stage.hosts[0]
17
15
 
18
16
  system "scp -P #{host[:port]} #{host[:user]}@#{host[:host]}:#{source} #{target}"
@@ -21,18 +19,17 @@ command :dump do |command|
21
19
  end
22
20
  end
23
21
 
24
- command.desc('Create dump file from database')
22
+ command.desc("Create dump file from database")
25
23
  command.command :create do |command|
26
-
27
24
  command.action do |global_options, options, args|
28
25
  stamp = Time.now.strftime("%Y%m%d-%H%M%S")
29
- dir = File.join('/tmp', "dump-#{stamp}")
30
- zip_target = File.join('/tmp', "dump-#{stamp}.zip")
31
- logstash_source = '~/apps/event_hub/shared/logs/logstash_output.log'
26
+ dir = File.join("/tmp", "dump-#{stamp}")
27
+ zip_target = File.join("/tmp", "dump-#{stamp}.zip")
28
+ logstash_source = "~/apps/event_hub/shared/logs/logstash_output.log"
32
29
  cmds = []
33
30
  cmds << "mkdir -p #{dir}"
34
31
  cmds << "cd #{dir} && pg_dump -Uevent_hub_console event_hub_console > console_pg.sql"
35
- cmds << "if [[ -f #{logstash_source} ]] ; then cp #{logstash_source} #{File.join(dir, 'logstash_output.log')} ; fi"
32
+ cmds << "if [[ -f #{logstash_source} ]] ; then cp #{logstash_source} #{File.join(dir, "logstash_output.log")} ; fi"
36
33
  cmds << "cd #{dir} && zip -r #{zip_target} ."
37
34
  cmds << "rm -rf #{dir}"
38
35
 
@@ -46,7 +43,6 @@ command :dump do |command|
46
43
  end
47
44
  end
48
45
 
49
-
50
46
  private
51
47
 
52
48
  def stage(options)