proctor 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.rspec +1 -0
  2. data/TODO +28 -0
  3. data/bin/proctor +55 -85
  4. data/bin/showlog +5 -0
  5. data/bin/showtime +5 -0
  6. data/lib/proctor/command/asset_list_cmd.rb +56 -0
  7. data/lib/proctor/{presenter/show.rb → command/asset_show_cmd.rb} +7 -2
  8. data/lib/proctor/command/file_cleanup_cmd.rb +81 -0
  9. data/lib/proctor/command/file_export_cmd.rb +79 -0
  10. data/lib/proctor/command/helpers/command.rb +27 -0
  11. data/lib/proctor/command/render_group_cmd.rb +39 -0
  12. data/lib/proctor/command/render_service_cmd.rb +34 -0
  13. data/lib/proctor/command/start_cmd.rb +70 -0
  14. data/lib/proctor/config/app_file.rb +54 -0
  15. data/lib/proctor/config/app_files.rb +50 -0
  16. data/lib/proctor/config/env.rb +35 -0
  17. data/lib/proctor/config/template_file.rb +41 -0
  18. data/lib/proctor/config/template_files.rb +39 -0
  19. data/lib/proctor/manager.rb +36 -3
  20. data/lib/proctor/managers.rb +38 -0
  21. data/lib/proctor/node.rb +26 -0
  22. data/lib/proctor/nodes.rb +38 -0
  23. data/lib/proctor/resource/erb.rb +95 -0
  24. data/lib/proctor/resource/lookup.rb +82 -0
  25. data/lib/proctor/service.rb +28 -3
  26. data/lib/proctor/services.rb +38 -0
  27. data/lib/proctor/util/helpers.rb +13 -0
  28. data/lib/proctor/util/version.rb +3 -0
  29. data/proctor.gemspec +2 -1
  30. data/proctor/Proctorfile +35 -34
  31. data/proctor/templates/foreman_default_g.erb +3 -0
  32. data/proctor/templates/monit_default_s.erb +3 -6
  33. data/proctor/templates/monit_faye_s.erb +3 -3
  34. data/proctor/templates/upstart_default_g.erb +1 -0
  35. data/proctor/templates/upstart_default_s.erb +1 -3
  36. data/proctor/templates/upstart_passenger_s.erb +3 -0
  37. data/spec/acceptance/asset_list_spec.rb +16 -0
  38. data/spec/acceptance/asset_show_spec.rb +16 -0
  39. data/spec/acceptance/file_cleanup_spec.rb +16 -0
  40. data/spec/acceptance/file_export_spec.rb +16 -0
  41. data/spec/acceptance/render_group_spec.rb +15 -0
  42. data/spec/acceptance/render_service_spec.rb +16 -0
  43. data/spec/acceptance/start_spec.rb +16 -0
  44. data/spec/spec_helper.rb +22 -0
  45. data/spec/unit/command/file_export_cmd_spec.rb +46 -0
  46. data/spec/unit/command/file_list_cmd_spec.rb +30 -0
  47. data/spec/unit/command/render_group_cmd_spec.rb +44 -0
  48. data/spec/unit/command/render_service_cmd_spec.rb +42 -0
  49. data/spec/unit/{app_file_spec.rb → config/app_file_spec.rb} +27 -7
  50. data/spec/unit/config/app_files_spec.rb +55 -0
  51. data/spec/unit/config/env_spec.rb +37 -0
  52. data/spec/unit/config/template_file_spec.rb +55 -0
  53. data/spec/unit/config/template_files_spec.rb +32 -0
  54. data/spec/unit/manager_spec.rb +30 -10
  55. data/spec/unit/managers_spec.rb +40 -0
  56. data/spec/unit/node_spec.rb +34 -0
  57. data/spec/unit/nodes_spec.rb +36 -0
  58. data/spec/unit/service_spec.rb +31 -10
  59. data/spec/unit/services_spec.rb +34 -0
  60. metadata +86 -31
  61. data/Proctorfile +0 -4
  62. data/lib/proctor/app_config.rb +0 -23
  63. data/lib/proctor/app_file.rb +0 -44
  64. data/lib/proctor/cmd_state.rb +0 -39
  65. data/lib/proctor/presenter/list.rb +0 -67
  66. data/lib/proctor/presenter/render.rb +0 -39
  67. data/lib/proctor/template.rb +0 -5
  68. data/lib/proctor/template_config.rb +0 -22
  69. data/lib/proctor/template_file.rb +0 -44
  70. data/lib/proctor/util.rb +0 -12
  71. data/lib/proctor/version.rb +0 -3
  72. data/proctor/templates/foreman_default_n.erb +0 -9
  73. data/proctor/templates/monit_web_s.erb +0 -0
  74. data/proctor/templates/upstart_default_n.erb +0 -0
  75. data/spec/acceptance/help_spec.rb +0 -36
  76. data/spec/acceptance/list_spec.rb +0 -17
  77. data/spec/unit/app_config_spec.rb +0 -30
  78. data/spec/unit/template_config_spec.rb +0 -12
  79. data/spec/unit/template_file_spec.rb +0 -16
  80. data/spec/unit/template_spec.rb +0 -8
data/Proctorfile DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- managers:
3
- upstart:
4
- export_directory: '/tmp/test'
@@ -1,23 +0,0 @@
1
- require 'hash_deep_merge'
2
-
3
- module Proctor
4
- class AppConfig
5
-
6
- def self.load(global_options = {:f => "Proctorfile"})
7
- app_files = self.app_files(global_options).map {|f| AppFile.new(f)}
8
- app_files.reduce({}) { |a,v| a.deep_merge(v.config_data) }
9
- end
10
-
11
- def self.app_files(global_options)
12
- proctorfile = global_options[:f]
13
- ["#{base_dir}/proctor/Proctorfile", "#{Dir.pwd}/#{proctorfile}", ]
14
- end
15
-
16
- private
17
-
18
- def self.base_dir
19
- File.expand_path(File.dirname(File.expand_path(__FILE__)) + '/../..')
20
- end
21
-
22
- end
23
- end
@@ -1,44 +0,0 @@
1
- require 'yaml'
2
-
3
- module Proctor
4
- class AppFile
5
- attr_reader :config_data
6
-
7
- def initialize(filename)
8
- check_file_existence(filename)
9
- @config_data = load_data(filename)
10
- check_data_format(filename)
11
- end
12
-
13
- private
14
-
15
- def load_data(file)
16
- begin
17
- @config_data = YAML.load_file(file)
18
- rescue Psych::SyntaxError
19
- error_msg = "invalid file format (expecting YAML - #{file})"
20
- raise InvalidYamlException.new, error_msg
21
- end
22
- end
23
-
24
- def check_data_format(file)
25
- raise InvalidDataType, "expecting hash data (#{file})" unless @config_data.is_a?(Hash)
26
- end
27
-
28
- def check_file_existence(file)
29
- error_msg = "missing app file (#{file})"
30
- raise MissingFileException, error_msg unless File.exist?(file)
31
- end
32
-
33
- end
34
-
35
- class MissingFileException < RuntimeError
36
- end
37
-
38
- class InvalidYamlException < RuntimeError
39
- end
40
-
41
- class InvalidDataType < RuntimeError
42
- end
43
-
44
- end
@@ -1,39 +0,0 @@
1
- module Proctor
2
-
3
- class CmdState
4
-
5
- def self.app_files(global, options, args)
6
- AppConfig.app_files(global)
7
- end
8
-
9
- def self.templates(global, options, args)
10
- options[:templates].values.sort
11
- end
12
-
13
- def self.nodes(global, options, args)
14
- options[:app_config]['nodes']
15
- end
16
-
17
- def self.node_names(global, options, args)
18
- options[:app_config]['nodes'].keys
19
- end
20
-
21
- def self.services(global, options, args)
22
- options[:app_config]['services']
23
- end
24
-
25
- def self.service_names(global, options, args)
26
- options[:app_config]['services'].keys
27
- end
28
-
29
- def self.managers(global, options, args)
30
- options[:app_config]['managers']
31
- end
32
-
33
- def self.manager_names(global, options, args)
34
- options[:app_config]['managers'].keys
35
- end
36
-
37
- end
38
-
39
- end
@@ -1,67 +0,0 @@
1
- require 'digest/md5'
2
-
3
- module Proctor
4
- module Presenter
5
- class List
6
-
7
- def initialize(global, options, args)
8
- @global = global
9
- @options = options
10
- @args = args
11
- end
12
-
13
- def render
14
- case @options[:type]
15
- when "appfiles" then render_appfiles
16
- when "managers" then render_managers
17
- when "services" then render_services
18
- when "templates" then render_templates
19
- when "node" then render_node
20
- when "all" then render_all
21
- end
22
- end
23
-
24
- def handle(string)
25
- Digest::MD5.hexdigest(string)[0..2]
26
- end
27
-
28
- def puts_handle(string)
29
- puts "#{handle(string)}: #{string}"
30
- end
31
-
32
- def render_templates
33
- puts "[Templates]"
34
- CmdState.templates(@global, @options, @args).each {|v| puts_handle(v)}
35
- end
36
-
37
- def render_appfiles
38
- puts "[AppFiles]"
39
- CmdState.app_files(@global, @options, @args).each { |f| puts "#{handle(f)}: #{f}" }
40
- end
41
-
42
- def render_managers
43
- puts "[Managers]"
44
- CmdState.managers(@global, @options, @args).keys.each {|k| puts_handle(k)}
45
- end
46
-
47
- def render_services
48
- puts "[Services]"
49
- CmdState.services(@global, @options, @args).keys.each {|k| puts_handle(k)}
50
- end
51
-
52
- def render_node
53
- puts "[Nodes]"
54
- CmdState.nodes(@global, @options, @args).keys.each {|k| puts_handle(k)}
55
- end
56
-
57
- def render_all
58
- render_templates
59
- render_appfiles
60
- render_managers
61
- render_services
62
- render_node
63
- end
64
-
65
- end
66
- end
67
- end
@@ -1,39 +0,0 @@
1
- module Proctor
2
- module Presenter
3
- class Render
4
-
5
- def initialize(global, options, args)
6
- @global = global
7
- @options = options
8
- @args = args
9
- @role = args[0]
10
- @manager = args[1]
11
- check_for_valid_role(@role)
12
- check_for_valid_manager(@manager)
13
- end
14
-
15
- def check_for_valid_role(role)
16
- roles = CmdState.roles(@global, @options, @args) + ["manifest"]
17
- unless roles.include? role
18
- raise "Invalid ROLE (#{role}) - use one of [#{roles.join('|')}]"
19
- end
20
- end
21
-
22
- def check_for_valid_manager(manager)
23
- managers = CmdState.manager_names(@global, @options, @args)
24
- unless managers.include? manager
25
- raise "Invalid MANAGER (#{manager}) - use one of [#{managers.join('|')}]"
26
- end
27
- end
28
-
29
- def render_template
30
- puts "# Template #{@role} #{@manager}"
31
- end
32
-
33
- def render
34
- render_template
35
- end
36
-
37
- end
38
- end
39
- end
@@ -1,5 +0,0 @@
1
- module Proctor
2
- module Template
3
-
4
- end
5
- end
@@ -1,22 +0,0 @@
1
- module Proctor
2
- class TemplateConfig
3
-
4
- def self.load(global_options = {})
5
- template_files = self.files(global_options)
6
- template_files.reduce({}) do |a, v|
7
- a.merge({File.basename(v) => v})
8
- end
9
- end
10
-
11
- private
12
-
13
- def self.files(global_options)
14
- Dir.glob('proctor/templates/*').map {|f| File.expand_path(f)}
15
- end
16
-
17
- #def self.base_dir
18
- # File.expand_path(File.dirname(File.expand_path(__FILE__)) + '/../..')
19
- #end
20
-
21
- end
22
- end
@@ -1,44 +0,0 @@
1
- require 'yaml'
2
-
3
- module Proctor
4
- class TemplateFile
5
- attr_reader :config_data
6
-
7
- def initialize(filename)
8
- check_file_existence(filename)
9
- @config_data = load_data(filename)
10
- check_data_format(filename)
11
- end
12
-
13
- private
14
-
15
- def load_data(file)
16
- begin
17
- @config_data = YAML.load_file(file)
18
- rescue Psych::SyntaxError
19
- error_msg = "invalid file format (expecting YAML - #{file})"
20
- raise InvalidYamlException.new, error_msg
21
- end
22
- end
23
-
24
- def check_data_format(file)
25
- raise InvalidDataType, "expecting hash data (#{file})" unless @config_data.is_a?(Hash)
26
- end
27
-
28
- def check_file_existence(file)
29
- error_msg = "missing app file (#{file})"
30
- raise MissingFileException, error_msg unless File.exist?(file)
31
- end
32
-
33
- end
34
-
35
- class MissingFileException < RuntimeError
36
- end
37
-
38
- class InvalidYamlException < RuntimeError
39
- end
40
-
41
- class InvalidDataType < RuntimeError
42
- end
43
-
44
- end
data/lib/proctor/util.rb DELETED
@@ -1,12 +0,0 @@
1
- # 1.9 adds realpath to resolve symlinks; 1.8 doesn't
2
- # have this method, so we add it so we get resolved symlinks
3
- # and compatibility
4
- unless File.respond_to? :realpath
5
- class File #:nodoc:
6
- def self.realpath path
7
- return realpath(File.readlink(path)) if symlink?(path)
8
- path
9
- end
10
- end
11
- end
12
- #$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
@@ -1,3 +0,0 @@
1
- module Proctor
2
- VERSION = "0.0.3"
3
- end
@@ -1,9 +0,0 @@
1
- # Generated by Proctor at <%= Time.now %>
2
-
3
- start on reboot
4
- expect daemon
5
- respawn
6
- pre-start script
7
- emit starting_faye
8
- end
9
- exec <%= @start_command %> --port <%= port %>
File without changes
File without changes
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'start/help', :acceptance do
4
-
5
- it 'returns text' do
6
- start_simple
7
- all_output.should include('proctor')
8
- end
9
-
10
- it 'does not have an error' do
11
- start_simple
12
- last_exit_status.should == 0
13
- all_output.should_not include('Error')
14
- end
15
-
16
- it 'takes the help command' do
17
- start_simple "help start"
18
- all_output.should include('start')
19
- end
20
-
21
- end
22
-
23
- describe "checking existence of App file" do
24
- it "returns an error w/o the app file" do
25
- clear_app_file do
26
- start_simple "list", false
27
- last_exit_status.should_not == 0
28
- all_output.should include('error: missing app file')
29
- end
30
- end
31
- it "returns an error when specifying an alternative proctorfile" do
32
- start_simple "list -f Nofile", false
33
- last_exit_status.should_not == 0
34
- all_output.should include('error: missing app file')
35
- end
36
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'list', :acceptance do
4
-
5
- it 'returns help text' do
6
- start_simple "help list"
7
- all_output.should include('list')
8
- end
9
-
10
- it 'raises an error with an unknown type' do
11
- start_simple "list -t whatexxver", false
12
- last_exit_status.should_not == 0
13
- all_output.should include('error')
14
- end
15
-
16
- end
17
-
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require_relative "../../lib/proctor/app_config"
3
-
4
- include Proctor
5
-
6
- describe AppConfig do
7
- it "loads data and generates a hash" do
8
- result = AppConfig.load
9
- result.should_not be_nil
10
- result.should be_a(Hash)
11
- end
12
- it "has default values" do
13
- app_data = "---\nmanagers:\n newstart:\n export_directory: '/tmp/test'"
14
- clear_app_file do
15
- File.open("Proctorfile", 'w') {|f| f.puts "#{app_data}"}
16
- result = AppConfig.load
17
- tst_value = result["managers"]["upstart"]["export_directory"]
18
- tst_value.should == "/etc/init"
19
- end
20
- end
21
- it "overwrites default values with local values" do
22
- app_data = "---\nmanagers:\n upstart:\n export_directory: '/tmp/test'"
23
- clear_app_file do
24
- File.open("Proctorfile", 'w') {|f| f.puts "#{app_data}"}
25
- result = AppConfig.load
26
- tst_value = result["managers"]["upstart"]["export_directory"]
27
- tst_value.should == "/tmp/test"
28
- end
29
- end
30
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require_relative "../../lib/proctor/template_config"
3
-
4
- include Proctor
5
-
6
- describe TemplateConfig do
7
- it "loads data and generates a hash" do
8
- result = TemplateConfig.load
9
- result.should_not be_nil
10
- result.should be_a(Hash)
11
- end
12
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
- require_relative "../../lib/proctor/template_file"
3
-
4
- include Proctor
5
-
6
- describe TemplateFile do
7
-
8
- describe "#new" do
9
-
10
- end
11
-
12
- #it "should have a list of valid object types"
13
- #it "should raise warnings for invalid objects"
14
- #it "should handle embedded ERB tags"
15
- #it "reports if there is an ERB rendering error"
16
- end