a4tools 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/install.log +38 -0
  3. data/.gitignore +2 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +38 -0
  6. data/a4tools.gemspec +38 -0
  7. data/bin/deploy_latest_clients +32 -0
  8. data/bin/devsite_config_server +48 -0
  9. data/bin/netshell +23 -0
  10. data/bin/update_server +101 -0
  11. data/bin/usher +54 -0
  12. data/lib/a4tools.rb +61 -0
  13. data/lib/a4tools/version.rb +3 -0
  14. data/lib/acres_client.rb +376 -0
  15. data/lib/clients/caching_client.rb +151 -0
  16. data/lib/clients/deployment_client.rb +53 -0
  17. data/lib/clients/kai_config_client.rb +39 -0
  18. data/lib/clients/usher_client.rb +72 -0
  19. data/lib/clients/usher_mgmt_client.rb +201 -0
  20. data/lib/event_manager.rb +24 -0
  21. data/lib/events.json +1 -0
  22. data/lib/net_shell/builtin_command.rb +312 -0
  23. data/lib/net_shell/builtin_commands/build.rb +251 -0
  24. data/lib/net_shell/builtin_commands/cd.rb +12 -0
  25. data/lib/net_shell/builtin_commands/connect.rb +122 -0
  26. data/lib/net_shell/builtin_commands/deploy.rb +280 -0
  27. data/lib/net_shell/builtin_commands/disconnect.rb +15 -0
  28. data/lib/net_shell/builtin_commands/excerpt.rb +97 -0
  29. data/lib/net_shell/builtin_commands/exit.rb +7 -0
  30. data/lib/net_shell/builtin_commands/get.rb +38 -0
  31. data/lib/net_shell/builtin_commands/help.rb +40 -0
  32. data/lib/net_shell/builtin_commands/host.rb +126 -0
  33. data/lib/net_shell/builtin_commands/inject.rb +42 -0
  34. data/lib/net_shell/builtin_commands/jsoncache.rb +80 -0
  35. data/lib/net_shell/builtin_commands/kai_event.rb +151 -0
  36. data/lib/net_shell/builtin_commands/persist.rb +24 -0
  37. data/lib/net_shell/builtin_commands/pwd.rb +6 -0
  38. data/lib/net_shell/builtin_commands/recap.rb +188 -0
  39. data/lib/net_shell/builtin_commands/references.rb +63 -0
  40. data/lib/net_shell/builtin_commands/select.rb +36 -0
  41. data/lib/net_shell/builtin_commands/send.rb +74 -0
  42. data/lib/net_shell/builtin_commands/set.rb +29 -0
  43. data/lib/net_shell/builtin_commands/show.rb +183 -0
  44. data/lib/net_shell/builtin_commands/site.rb +122 -0
  45. data/lib/net_shell/builtin_commands/ssh.rb +62 -0
  46. data/lib/net_shell/builtin_commands/talk.rb +90 -0
  47. data/lib/net_shell/builtin_commands/translate.rb +45 -0
  48. data/lib/net_shell/builtin_commands/unset.rb +14 -0
  49. data/lib/net_shell/builtin_commands/usher.rb +55 -0
  50. data/lib/net_shell/builtin_commands/usher_device.rb +39 -0
  51. data/lib/net_shell/builtin_commands/usher_site.rb +245 -0
  52. data/lib/net_shell/builtin_commands/usherm_connect.rb +21 -0
  53. data/lib/net_shell/colors.rb +149 -0
  54. data/lib/net_shell/command.rb +97 -0
  55. data/lib/net_shell/io.rb +132 -0
  56. data/lib/net_shell/net_shell.rb +396 -0
  57. data/lib/net_shell/prompt.rb +335 -0
  58. data/lib/object_builder/definitions/app_info_for_script.rb +83 -0
  59. data/lib/object_builder/definitions/connection_request.rb +28 -0
  60. data/lib/object_builder/definitions/device_info_for_system.rb +37 -0
  61. data/lib/object_builder/object_builder.rb +145 -0
  62. data/lib/talk.json +1 -0
  63. data/lib/talk_consumer.rb +235 -0
  64. metadata +279 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87934bdee4cc20d861cc2a45da0e136b01256354
4
+ data.tar.gz: 3adde1944193b10a499b76332f4766d5b3b2616b
5
+ SHA512:
6
+ metadata.gz: db5d98c78740f0ccde2529424355612b695f3fed430f32a8609b6e942e56c5c2122849fc92d79954cba293f1797025d98c15ae1bca532c233f0fce886b649a8b
7
+ data.tar.gz: 5641f20d70b92f74b32ec2bdaced9aa79ca3e8d8c6aea87b62a2ba6febaaf62d2017ff9a18d935ed5a4e2dfe682b3f43ee226f04325bb5d7f755c3c939cad9df
@@ -0,0 +1,38 @@
1
+ # Logfile created on 2014-05-03 13:43:05 -0700 by logger.rb/41954
2
+ I, [2014-05-03T13:43:05.858635 #40222] INFO -- : 0: colorize (0.7.2) from /Library/Ruby/Gems/2.0.0/specifications/colorize-0.7.2.gemspec
3
+ I, [2014-05-03T13:43:05.860612 #40222] INFO -- : 0: daemons (1.1.9) from /Library/Ruby/Gems/2.0.0/specifications/daemons-1.1.9.gemspec
4
+ I, [2014-05-03T13:43:05.861131 #40222] INFO -- : 0: eventmachine (1.0.3) from /Library/Ruby/Gems/2.0.0/specifications/eventmachine-1.0.3.gemspec
5
+ I, [2014-05-03T13:43:06.944464 #40222] INFO -- : 0: websocket-driver (0.3.3) from /Library/Ruby/Gems/2.0.0/specifications/websocket-driver-0.3.3.gemspec
6
+ I, [2014-05-03T13:43:07.466626 #40222] INFO -- : 0: faye-websocket (0.7.3) from /Library/Ruby/Gems/2.0.0/specifications/faye-websocket-0.7.3.gemspec
7
+ I, [2014-05-03T13:43:07.471196 #40222] INFO -- : 0: json (1.8.1) from /Library/Ruby/Gems/2.0.0/specifications/json-1.8.1.gemspec
8
+ I, [2014-05-03T13:43:07.471576 #40222] INFO -- : 0: logger (1.2.8) from /Library/Ruby/Gems/2.0.0/specifications/logger-1.2.8.gemspec
9
+ I, [2014-05-03T13:43:08.291533 #40222] INFO -- : 0: mime-types (2.2) from /Library/Ruby/Gems/2.0.0/specifications/mime-types-2.2.gemspec
10
+ I, [2014-05-03T13:43:08.297221 #40222] INFO -- : 0: mysql2 (0.3.15) from /Library/Ruby/Gems/2.0.0/specifications/mysql2-0.3.15.gemspec
11
+ I, [2014-05-03T13:43:08.297725 #40222] INFO -- : 0: rack (1.5.2) from /Library/Ruby/Gems/2.0.0/specifications/rack-1.5.2.gemspec
12
+ I, [2014-05-03T13:43:08.773343 #40222] INFO -- : 0: rack-protection (1.5.3) from /Library/Ruby/Gems/2.0.0/specifications/rack-protection-1.5.3.gemspec
13
+ I, [2014-05-03T13:43:08.779107 #40222] INFO -- : 0: rest-client (1.6.7) from /Library/Ruby/Gems/2.0.0/specifications/rest-client-1.6.7.gemspec
14
+ I, [2014-05-03T13:43:08.779646 #40222] INFO -- : 0: tilt (1.4.1) from /Library/Ruby/Gems/2.0.0/specifications/tilt-1.4.1.gemspec
15
+ I, [2014-05-03T13:43:09.697722 #40222] INFO -- : 0: sinatra (1.4.5) from /Library/Ruby/Gems/2.0.0/specifications/sinatra-1.4.5.gemspec
16
+ I, [2014-05-03T13:43:11.348151 #40222] INFO -- : 0: thin (1.6.2) from /Library/Ruby/Gems/2.0.0/specifications/thin-1.6.2.gemspec
17
+ I, [2014-05-03T13:43:11.355564 #40222] INFO -- : 0: trollop (2.0) from /Library/Ruby/Gems/2.0.0/specifications/trollop-2.0.gemspec
18
+ I, [2014-05-03T13:43:11.355943 #40222] INFO -- : 0: bundler (1.5.1) from /Library/Ruby/Gems/2.0.0/specifications/bundler-1.5.1.gemspec
19
+ I, [2014-05-03T21:33:21.366737 #931] INFO -- : 0: addressable (2.3.6) from /Library/Ruby/Gems/2.0.0/specifications/addressable-2.3.6.gemspec
20
+ I, [2014-05-03T21:33:21.367787 #931] INFO -- : 0: colorize (0.7.2) from /Library/Ruby/Gems/2.0.0/specifications/colorize-0.7.2.gemspec
21
+ I, [2014-05-03T21:33:21.807561 #931] INFO -- : 0: cookiejar (0.3.2) from /Library/Ruby/Gems/2.0.0/specifications/cookiejar-0.3.2.gemspec
22
+ I, [2014-05-03T21:33:21.807872 #931] INFO -- : 0: daemons (1.1.9) from /Library/Ruby/Gems/2.0.0/specifications/daemons-1.1.9.gemspec
23
+ I, [2014-05-03T21:33:21.808134 #931] INFO -- : 0: eventmachine (1.0.3) from /Library/Ruby/Gems/2.0.0/specifications/eventmachine-1.0.3.gemspec
24
+ I, [2014-05-03T21:33:22.207461 #931] INFO -- : 0: em-socksify (0.3.0) from /Library/Ruby/Gems/2.0.0/specifications/em-socksify-0.3.0.gemspec
25
+ I, [2014-05-03T21:33:22.207768 #931] INFO -- : 0: http_parser.rb (0.6.0) from /Library/Ruby/Gems/2.0.0/specifications/http_parser.rb-0.6.0.gemspec
26
+ I, [2014-05-03T21:33:23.041419 #931] INFO -- : 0: em-http-request (1.1.2) from /Library/Ruby/Gems/2.0.0/specifications/em-http-request-1.1.2.gemspec
27
+ I, [2014-05-03T21:33:23.041918 #931] INFO -- : 0: json (1.8.1) from /Library/Ruby/Gems/2.0.0/specifications/json-1.8.1.gemspec
28
+ I, [2014-05-03T21:33:23.042181 #931] INFO -- : 0: logger (1.2.8) from /Library/Ruby/Gems/2.0.0/specifications/logger-1.2.8.gemspec
29
+ I, [2014-05-03T21:33:23.042442 #931] INFO -- : 0: mime-types (2.2) from /Library/Ruby/Gems/2.0.0/specifications/mime-types-2.2.gemspec
30
+ I, [2014-05-03T21:33:23.042716 #931] INFO -- : 0: mysql2 (0.3.15) from /Library/Ruby/Gems/2.0.0/specifications/mysql2-0.3.15.gemspec
31
+ I, [2014-05-03T21:33:23.043009 #931] INFO -- : 0: rack (1.5.2) from /Library/Ruby/Gems/2.0.0/specifications/rack-1.5.2.gemspec
32
+ I, [2014-05-03T21:33:23.043296 #931] INFO -- : 0: rack-protection (1.5.3) from /Library/Ruby/Gems/2.0.0/specifications/rack-protection-1.5.3.gemspec
33
+ I, [2014-05-03T21:33:23.043590 #931] INFO -- : 0: rest-client (1.6.7) from /Library/Ruby/Gems/2.0.0/specifications/rest-client-1.6.7.gemspec
34
+ I, [2014-05-03T21:33:23.043855 #931] INFO -- : 0: tilt (1.4.1) from /Library/Ruby/Gems/2.0.0/specifications/tilt-1.4.1.gemspec
35
+ I, [2014-05-03T21:33:23.044119 #931] INFO -- : 0: sinatra (1.4.5) from /Library/Ruby/Gems/2.0.0/specifications/sinatra-1.4.5.gemspec
36
+ I, [2014-05-03T21:33:23.044413 #931] INFO -- : 0: thin (1.6.2) from /Library/Ruby/Gems/2.0.0/specifications/thin-1.6.2.gemspec
37
+ I, [2014-05-03T21:33:23.044703 #931] INFO -- : 0: trollop (2.0) from /Library/Ruby/Gems/2.0.0/specifications/trollop-2.0.gemspec
38
+ I, [2014-05-03T21:33:23.044972 #931] INFO -- : 0: bundler (1.5.1) from /Library/Ruby/Gems/2.0.0/specifications/bundler-1.5.1.gemspec
@@ -0,0 +1,2 @@
1
+ _env
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ a4tools (1.2.1)
5
+ colorize (= 0.7)
6
+ eventmachine (~> 1.0)
7
+ faye-websocket (= 0.7)
8
+ io
9
+ io-console
10
+ jebediah (~> 1.0)
11
+ json (~> 1.7)
12
+ logger (~> 1.2)
13
+ trollop (~> 2.0)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ colorize (0.7.0)
19
+ eventmachine (1.0.3)
20
+ faye-websocket (0.7.0)
21
+ eventmachine (>= 0.12.0)
22
+ websocket-driver (>= 0.3.0)
23
+ io (0.0.1)
24
+ io-console (0.4.2)
25
+ jebediah (1.0.4)
26
+ json (1.8.1)
27
+ logger (1.2.8)
28
+ rake (10.1.0)
29
+ trollop (2.0)
30
+ websocket-driver (0.3.3)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ a4tools!
37
+ bundler (~> 1.5)
38
+ rake
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'a4tools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "a4tools"
8
+ spec.version = A4Tools::VERSION
9
+ spec.authors = ["Jonas Acres"]
10
+ spec.email = ["jonas.acres@acres4.com"]
11
+ spec.summary = %q{It's dangerous to go alone! Take this.}
12
+ spec.description = %q{A series of tools to make life better at Acres 4.0.}
13
+ spec.homepage = "http://github.com/acres4/a4tools"
14
+ spec.license = "Proprietary"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency 'io'
25
+ spec.add_runtime_dependency 'io-console'
26
+ spec.add_runtime_dependency 'json', "~> 1.7"
27
+ spec.add_runtime_dependency 'logger', "~> 1.2"
28
+ #spec.add_runtime_dependency 'rest-client', "~> 1.6"
29
+ #spec.add_runtime_dependency 'sinatra', "~> 1.4"
30
+ #spec.add_runtime_dependency 'thin', "~> 1.6"
31
+ spec.add_runtime_dependency 'trollop', "~> 2.0"
32
+ #spec.add_runtime_dependency 'mysql2', "~> 0.3"
33
+ spec.add_runtime_dependency 'eventmachine', "~> 1.0"
34
+ spec.add_runtime_dependency 'colorize', "0.7"
35
+ spec.add_runtime_dependency 'jebediah', "~> 1.0"
36
+ spec.add_runtime_dependency 'faye-websocket', "0.7"
37
+ spec.add_runtime_dependency 'talk'
38
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby
2
+
3
+ basepath = File.expand_path(File.dirname(__FILE__) + '/..')
4
+ lib = File.join(basepath, 'lib')
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
+
7
+ require 'acres_client'
8
+ require 'trollop'
9
+
10
+ opts = Trollop::options do
11
+ opt :username, "Usher username", :type => :string
12
+ opt :password, "Usher password", :type => :string
13
+ opt :site, "Site ID", :type => :integer
14
+ opt :milestone, "Milestone", :type => :integer
15
+ end
16
+
17
+ Trollop::die :site, "must be supplied" if opts[:site].nil?
18
+ Trollop::die :system, "must be supplied" if opts[:system].nil?
19
+ Trollop::die :username, "must be supplied" if opts[:username].nil?
20
+ Trollop::die :password, "must be supplied" if opts[:password].nil?
21
+
22
+ puts "Syncing #{opt[:milestone]} onto site #{opt[:site]}"
23
+
24
+ usher = A4Tools::UsherClient.new()
25
+ usher.list_servers
26
+
27
+ deployment = A4Tools::DeploymentClient.new(usher.locate_service("Deployment"), opts[:username], opts[:password])
28
+
29
+ deployment.builds_for_milestone(opt[:milestone]).each do |build|
30
+ puts "Publishing #{build["appId"]} build \"#{build["buildId"]}\" to site #{opt[:site]}..."
31
+ puts "\tFailed!" unless deployment.publish_build(build, opt[:site])
32
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/ruby
2
+
3
+ basepath = File.expand_path(File.dirname(__FILE__) + '/..')
4
+ lib = File.join(basepath, 'lib')
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
+
7
+ require 'sinatra'
8
+ require 'a4tools'
9
+
10
+ if ENV["USHER_USERNAME"].nil? or ENV["USHER_PASSWORD"].nil? then
11
+ puts "Must set USHER_USERNAME and USHER_PASSWORD environment variables"
12
+ exit 1
13
+ end
14
+
15
+ def usherm_client
16
+ A4Tools::UsherMgmtClient.new(nil, ENV["USHER_USERNAME"], ENV["USHER_PASSWORD"])
17
+ end
18
+
19
+ get '/sites' do
20
+ info = usherm_client.system_info["usherSites"]
21
+ dev_sites = info.select { |s| s["idSite"] < 10000 }
22
+ filtered_sites = dev_sites.map { |s| { idSite:s["idSite"], name:s["name"], siteDescription:s["siteDescription"] } }
23
+ sorted = filtered_sites.sort { |a,b| a[:idSite] <=> b[:idSite] }
24
+ sorted.to_json
25
+ end
26
+
27
+ get '/:serial' do |serial|
28
+ device = usherm_client.find_device_in_info(serial)
29
+ halt 404 if device.nil?
30
+
31
+ device.to_json
32
+ end
33
+
34
+ get '/:serial/delete' do |serial|
35
+ result = usherm_client.delete_device(serial)
36
+ halt 500 if result.nil?
37
+
38
+ result.to_json
39
+ end
40
+
41
+ get '/:serial/:site' do |serial, site|
42
+ halt 400 unless site.match(/^[0-9]+$/)
43
+ halt 400 if site.to_i >= 10000
44
+ result = usherm_client.update_device(serial, params[:desc], site)
45
+ halt 500 if result.nil?
46
+
47
+ result.to_json
48
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby
2
+
3
+
4
+ basepath = File.expand_path(File.dirname(__FILE__) + '/..')
5
+ lib = File.join(basepath, 'lib')
6
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
7
+
8
+ require 'a4tools'
9
+ require 'trollop'
10
+
11
+ opts = Trollop::options do
12
+ opt :exec, "Execute a command", :type => :string
13
+ end
14
+
15
+ if opts[:exec] then
16
+ A4Tools::NetShell.new.exec(opts[:exec])
17
+ elsif $stdin.isatty then
18
+ A4Tools::NetShell.new.enter
19
+ else
20
+ while (line = STDIN.gets)
21
+ A4Tools::NetShell.new.exec(line.chomp)
22
+ end
23
+ end
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/ruby
2
+
3
+
4
+ basepath = File.expand_path(File.dirname(__FILE__) + '/..')
5
+ lib = File.join(basepath, 'lib')
6
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
7
+
8
+ require 'sinatra'
9
+ require 'a4tools'
10
+ require 'mysql2'
11
+ require 'json'
12
+ require 'rest-client'
13
+
14
+ $usher = { username: ENV["USHER_USERNAME"], password: ENV["USHER_PASSWORD"] }
15
+ $script_root = ENV["SCRIPT_DIRECTORY"] || "~/scripts"
16
+ $milestone = ENV["MILESTONE"]
17
+ $site = ENV["SITE_ID"]
18
+ $mailgun = { key: ENV["MAILGUN_KEY"], domain: ENV["MAILGUN_DOMAIN"], from: ENV["MAILGUN_FROM"] }
19
+ $dbfile = ENV["DATABASE_FILE"] || "/var/storage/acres4/snapshots/current.sql.gz"
20
+
21
+ $db_client = Mysql2::Client.new(:host => ENV["DATABASE_HOST"], :username => ENV["DATABASE_USERNAME"], :password => ENV["DATABASE_PASSWORD"])
22
+ $db_client.query_options.merge!(:symbolize_keys => true)
23
+
24
+ def sendEmail(subject, body, recipients)
25
+ url = "https://api:#{$mailgun[:key]}@api.mailgun.net/v2/#{$mailgun[:domain]}/messages"
26
+ RestClient.post url,
27
+ :from => $mailgun[:from],
28
+ :to => recipients.join(", "),
29
+ :subject => subject,
30
+ :html => body
31
+ end
32
+
33
+ def run_script(script, args="")
34
+ path = File.join($script_root, script)
35
+ command = path
36
+ command += args if args.length > 0
37
+
38
+ pid = Process.fork do
39
+ output = `cd #{$script_root} ; #{command}`
40
+ if $?.exitstatus != 0 then
41
+ max_length = 64*1024
42
+ trimmed = output
43
+ trimmed = "[trimmed to #{max_length} bytes]\n" + trimmed[-max_length .. -1] if trimmed.length > max_length
44
+ sendEmail("Script failed: #{script}", "<p><b>#{command}</b><br />\nExit status: #{$?.exitstatus}</p><pre>#{trimmed}</pre>", ["jonas.acres@acres4.com"])
45
+ end
46
+ end
47
+
48
+ Process.detach(pid)
49
+ end
50
+
51
+ def refresh_mercury
52
+ run_script("refresh_mercury.sh ")
53
+ end
54
+
55
+ def refresh_database
56
+ run_script("refresh_database.sh", $dbfile)
57
+ end
58
+
59
+ def refresh_clients
60
+ usher = A4Tools::UsherClient.new()
61
+ usher.list_servers
62
+ deployment = A4Tools::DeploymentClient.new(usher.locate_service("Deployment"), $usher[:username], $usher[:password])
63
+ deployment.builds_for_milestone($milestone).each { |build| deployment.publish_build(build, $site) }
64
+ end
65
+
66
+ def refresh_all
67
+ refresh_clients
68
+ run_script("refresh_all.sh", $dbfile)
69
+ end
70
+
71
+ def list_users
72
+ sql = "select r.id_role, r.description, e.login_name, e.first_name, e.last_name, pg.description from rt.role r \
73
+ inner join rt.role_employee_link rel on r.id_role = rel.id_role \
74
+ inner join rt.employee e on rel.id_employee = e.id_employee \
75
+ inner join rt.permission_group_employee_link pgel on pgel.id_employee = e.id_employee \
76
+ inner join rt.permission_group pg on pg.id_permission_group = pgel.id_permission_group \
77
+ and e.deleted = 0 \
78
+ order by r.description, login_name"
79
+ $db_client.query(sql)
80
+ end
81
+
82
+ get '/users' do
83
+ list_users.to_a.to_json
84
+ end
85
+
86
+ post '/update/all' do
87
+ refresh_all
88
+ end
89
+
90
+ post '/update/mercury' do
91
+ refresh_mercury
92
+ end
93
+
94
+ post '/update/database' do
95
+ refresh_database
96
+ end
97
+
98
+ post '/update/client' do
99
+ refresh_clients
100
+ "OK"
101
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/ruby
2
+
3
+
4
+ basepath = File.expand_path(File.dirname(__FILE__) + '/..')
5
+ lib = File.join(basepath, 'lib')
6
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
7
+
8
+ require 'a4tools'
9
+ require 'trollop'
10
+ require 'pp'
11
+
12
+ opts = Trollop::options do
13
+ opt :url, "Usher server URL", :type => :string
14
+ opt :serial, "Device serial number", :type => :string
15
+ opt :ip, "Device IP address", :type => :string
16
+ opt :full, "Show all addresses for each product"
17
+ end
18
+
19
+ def die_with_error(errmsg)
20
+ puts errmsg
21
+ exit 1
22
+ end
23
+
24
+ def render_result(result)
25
+ s = " Site ID: #{result["siteID"]}\n"
26
+ s += " Site name: #{result["siteName"]}\n"
27
+ s += "Remote address: #{result["remoteAddr"]}\n\n"
28
+
29
+ result["hosts"].each do |host|
30
+ s += "Product: #{host["product"]} (#{host["host"]}:#{host["port"]})\n\t#{host["url"]}, #{host["ctx"]}, System #{host["systemId"]}\n\n"
31
+ end
32
+
33
+ s
34
+ end
35
+
36
+ params = {}
37
+ [:ip, :serial, :full].each { |key| params[key] = opts[key] unless opts[key].nil? }
38
+
39
+ result = A4Tools::UsherClient.new(opts[:url]).list_servers_raw(params)
40
+
41
+ die_with_error("Unable to contact usher") if result.nil?
42
+ die_with_error("Unable to contact usher") if result.nil?
43
+ die_with_error("Usher returned status #{result.code}") if result.code.to_i < 200 or result.code.to_i >= 300
44
+ begin
45
+ payload = JSON.parse(result.body)
46
+ die_with_error("Usher returned non-JSON RPC response") unless payload["jsonrpc"] == "2.0"
47
+ die_with_error("Usher returned error: \"#{payload["error"]}\"") unless payload["error"].nil?
48
+ die_with_error("Usher did not include result") if payload["result"].nil?
49
+ die_with_error("Usher server returned non-usher response") unless payload["result"]["className"] == "com.acres4.common.info.usher.UsherResponse"
50
+ die_with_error("Usher response did not include body") if payload["result"]["body"].nil?
51
+ puts render_result(payload["result"]["body"])
52
+ rescue JSON::ParserError
53
+ die_with_error("Usher returned non-JSON response")
54
+ end
@@ -0,0 +1,61 @@
1
+ require 'acres_client'
2
+ require 'talk_consumer'
3
+ require 'net_shell/net_shell'
4
+ require 'event_manager.rb'
5
+ require 'object_builder/object_builder'
6
+ require "a4tools/version"
7
+
8
+ def symbolify(item)
9
+ if item.is_a? Array
10
+ return item.map! { |value| symbolify value }
11
+ elsif not item.is_a? Hash
12
+ return item
13
+ end
14
+
15
+ new_hash = {}
16
+ item.each { |key, value| new_hash[key.to_sym] = symbolify value }
17
+ new_hash
18
+ end
19
+
20
+ def talk
21
+ $talk ||= A4Tools::TalkConsumer.new(talk_file)
22
+ end
23
+
24
+ def refresh_talk
25
+ $talk = A4Tools::TalkConsumer.new(talk_file)
26
+ end
27
+
28
+ def talk_file
29
+ return $localtalk if not $localtalk.nil? and File.exists?($localtalk)
30
+ A4Tools::TalkConsumer.new(File.join(File.dirname(__FILE__), "talk.json"))
31
+ end
32
+
33
+ def events
34
+ $events ||= A4Tools::EventManager.new
35
+ end
36
+
37
+ def try_connection(hostname, port)
38
+ s = TCPSocket.new(hostname, port) rescue false
39
+ s != false
40
+ end
41
+
42
+ # array of { :host, :port }
43
+ def try_connection_options(options, timeout=2)
44
+ mutex = Mutex.new
45
+ condition = ConditionVariable.new
46
+ result = nil
47
+
48
+ mutex.synchronize do
49
+ options.each do |opt|
50
+ Thread.new do
51
+ if try_connection(opt[:host], opt[:port]) then
52
+ result = opt
53
+ mutex.synchronize { condition.signal }
54
+ end
55
+ end
56
+ end
57
+
58
+ condition.wait(mutex, timeout)
59
+ end
60
+ result
61
+ end