cluster_management 0.5.2 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,8 +2,8 @@ require 'rake_ext'
2
2
 
3
3
  project(
4
4
  name: "cluster_management",
5
- version: "0.5.2",
6
- summary: "Simple cluster management tools",
5
+ version: "0.6",
6
+ summary: "Simple Cluster Management Tools",
7
7
 
8
8
  author: "Alexey Petrushin",
9
9
  homepage: "http://github.com/alexeypetrushin/cluster_management"
@@ -2,11 +2,36 @@ require 'ruby_ext'
2
2
  require 'vos'
3
3
  require 'yaml'
4
4
  require 'tilt'
5
+ require 'class_loader'
6
+ # require 'micon'
7
+ # require 'micon/rad'
5
8
 
9
+
10
+ #
11
+ # Classes
12
+ #
6
13
  %w(
14
+ support/exception
7
15
  config
8
16
  logger
9
17
  service
10
18
  integration/vfs
11
19
  integration/vos
12
- ).each{|f| require "cluster_management/#{f}"}
20
+ cluster
21
+ ).each{|f| require "cluster_management/#{f}"}
22
+
23
+
24
+ #
25
+ # Cluster
26
+ #
27
+ CLUSTER = ClusterManagement::Cluster.new
28
+ def cluster; ::CLUSTER end
29
+
30
+
31
+ #
32
+ # Config & Logger
33
+ #
34
+ cluster.logger = ClusterManagement::CustomLogger.new STDOUT
35
+ cluster.logger.formatter = -> severity, datetime, progname, msg {msg}
36
+
37
+ cluster.config = ClusterManagement::Config.new
@@ -0,0 +1,56 @@
1
+ module ClusterManagement
2
+ class Cluster
3
+ attr_accessor :config, :logger
4
+ attr_reader :boxes
5
+
6
+ def services &b
7
+ b ? @services.instance_eval(&b) : @services
8
+ end
9
+
10
+ class Services < BasicObject
11
+ def initialize
12
+ @h = ::Hash.new do |h, service_name|
13
+ h[service_name] = ::ClusterManagement::Service.service_class(service_name).new
14
+ end
15
+ end
16
+
17
+ def [] service_name
18
+ service_name.must_be.a ::Symbol
19
+ @h[service_name.to_sym]
20
+ end
21
+
22
+ protected
23
+ def p msg
24
+ ::Object.send :p, msg
25
+ end
26
+
27
+ def method_missing m, *a, &b
28
+ super unless a.blank? and b.blank?
29
+ @h[m]
30
+ end
31
+ end
32
+
33
+ def initialize
34
+ @services = Services.new
35
+
36
+ @boxes = Hash.new do |h, host|
37
+ box = config.ssh? ? Box.new(host.to_s, config.ssh.to_h) : Box.new(host.to_s)
38
+ box.open
39
+ h[host] = box
40
+ end
41
+ end
42
+
43
+ def configure runtime_dir
44
+ config.merge_file! "#{runtime_dir}/config/config.yml"
45
+ config.set! :config_path, "#{runtime_dir}/config"
46
+
47
+ r = {}
48
+ config.boxes!.to_h.each do |box, tags|
49
+ tags.each do |tag|
50
+ (r[tag.to_sym] ||= []) << box
51
+ end
52
+ end
53
+ config.set! :tags, r
54
+ end
55
+ end
56
+ end
@@ -1,21 +1,17 @@
1
1
  module ClusterManagement
2
2
  class Config < SafeHash
3
- def merge_config! file_path
3
+ def merge_file! file_path
4
4
  raise("config file must have .yml extension (#{file_path})!") unless file_path.end_with? '.yml'
5
- data = ::YAML.load_file file_path
5
+ data = ::YAML.load_file file_path
6
6
  if data
7
- data.must_be.a ::Hash
8
- self.deep_merge! data
7
+ data.must_be.a ::Hash
8
+ self.merge! data, override: true
9
9
  end
10
10
  end
11
- end
12
-
13
- def self.load_config file
14
- @config = Config.new
15
- @config.merge_config! file
16
- end
17
-
18
- def self.config
19
- @config || raise("config nod defined (use ClusterManagement.load_config to use config)!")
20
- end
11
+
12
+ # def self.load file
13
+ # @config = Config.new
14
+ # @config.merge_file! file
15
+ # end
16
+ end
21
17
  end
@@ -3,4 +3,5 @@ gem 'tilt'
3
3
  if respond_to? :fake_gem
4
4
  fake_gem 'ruby_ext'
5
5
  fake_gem 'vos'
6
+ fake_gem 'class_loader'
6
7
  end
@@ -1,8 +1,4 @@
1
- module Vfs
2
- class File
3
- def render *args
4
- args.unshift Object.new if args.size == 1 and args.first.is_a?(Hash)
5
- Tilt::ERBTemplate.new(path).render *args
6
- end
7
- end
8
- end
1
+ # module Vfs
2
+ # class File
3
+ # end
4
+ # end
@@ -1,38 +1,64 @@
1
1
  module Vos
2
- class ServicesHelper < BasicObject
3
- def initialize box, class_namespace
4
- @box, @class_namespace = box, class_namespace
5
- end
2
+ class Box
3
+ include Helpers::Ubuntu
6
4
 
7
- class ServiceCallback < BasicObject
8
- def initialize box, class_namespace, class_name
9
- @box, @class_namespace, @class_name = box, class_namespace, class_name
10
- end
5
+ # alias_method :mark_without_service!, :mark!
6
+ # def mark! key
7
+ # key = key.respond_to(:marker) || key
8
+ # mark_without_service! key
9
+ # end
10
+ #
11
+ # alias_method :has_mark_without_service?, :has_mark?
12
+ # def has_mark? key
13
+ # key = key.respond_to(:marker) || key
14
+ # has_mark_without_service? key
15
+ # end
11
16
 
12
- protected
13
- def method_missing m, *a, &b
14
- klass = "::#{@class_namespace.to_s.camelize}::#{@class_name.to_s.camelize}".constantize
15
- klass.new(@box).send m, *a, &b
16
- end
17
- end
18
-
19
- protected
20
- def method_missing class_name
21
- ServiceCallback.new(@box, @class_namespace, class_name)
22
- end
23
- end
24
-
25
- class Box
26
- def self.define_service_namespace class_namespace
27
- define_method class_namespace do
28
- ServicesHelper.new self, class_namespace
17
+ def apply_once key, &block
18
+ unless has_mark? key
19
+ block.call self
20
+ mark! key
29
21
  end
30
- end
31
- define_service_namespace :services
32
- define_service_namespace :projects
22
+ end
33
23
 
34
- def already_required_services
35
- @already_required_services ||= Set.new
36
- end
37
24
  end
38
- end
25
+ end
26
+
27
+ # module Vos
28
+ # class ServicesHelper < BasicObject
29
+ # def initialize box, class_namespace
30
+ # @box, @class_namespace = box, class_namespace
31
+ # end
32
+ #
33
+ # class ServiceCallback < BasicObject
34
+ # def initialize box, class_namespace, class_name
35
+ # @box, @class_namespace, @class_name = box, class_namespace, class_name
36
+ # end
37
+ #
38
+ # protected
39
+ # def method_missing m, *a, &b
40
+ # klass = "::#{@class_namespace.to_s.camelize}::#{@class_name.to_s.camelize}".constantize
41
+ # klass.new(@box).send m, *a, &b
42
+ # end
43
+ # end
44
+ #
45
+ # protected
46
+ # def method_missing class_name
47
+ # ServiceCallback.new(@box, @class_namespace, class_name)
48
+ # end
49
+ # end
50
+ #
51
+ # # class Box
52
+ # # def self.define_service_namespace class_namespace
53
+ # # define_method class_namespace do
54
+ # # ServicesHelper.new self, class_namespace
55
+ # # end
56
+ # # end
57
+ # # define_service_namespace :services
58
+ # # define_service_namespace :projects
59
+ # #
60
+ # # def already_required_services
61
+ # # @already_required_services ||= Set.new
62
+ # # end
63
+ # # end
64
+ # end
@@ -15,12 +15,12 @@ module ClusterManagement
15
15
  end
16
16
  end
17
17
 
18
- attr_writer :logger
19
- def self.logger
20
- unless @logger
21
- @logger = CustomLogger.new STDOUT
22
- @logger.formatter = -> severity, datetime, progname, msg {msg}
23
- end
24
- @logger
25
- end
18
+ # attr_writer :logger
19
+ # def self.logger
20
+ # unless @logger
21
+ # @logger = CustomLogger.new STDOUT
22
+ # @logger.formatter = -> severity, datetime, progname, msg {msg}
23
+ # end
24
+ # @logger
25
+ # end
26
26
  end
@@ -1,55 +1,5 @@
1
1
  module ClusterManagement
2
2
  class Service
3
- attr_reader :box
4
-
5
- #
6
- # Helpers
7
- #
8
- def logger; ClusterManagement.logger end
9
- def config; ClusterManagement.config end
10
-
11
-
12
- #
13
- # Business Logic
14
- #
15
- def initialize box
16
- @box = box
17
- end
18
-
19
- def mark! extra_mark = nil
20
- box.mark! self.class.marker(extra_mark)
21
- end
22
-
23
- def has_mark? extra_mark = nil
24
- box.has_mark? self.class.marker(extra_mark)
25
- end
26
-
27
- def apply_once extra_mark = nil, &block
28
- unless has_mark? extra_mark
29
- block.call
30
- mark! extra_mark
31
- end
32
- end
33
-
34
- def require *args
35
- if args.size == 1 and args.first.is_a?(Hash)
36
- services = args.first
37
- elsif args.size == 2 and args.first.is_a?(Array)
38
- services = {}
39
- args.first.each{|klass| services[klass] = args.last}
40
- else
41
- raise 'invalid arguments'
42
- end
43
-
44
- services.each do |klass, method|
45
- key = "#{klass}.#{method}"
46
- unless box.already_required_services.include? key
47
- klass.new(box).send method if klass.method_defined? method
48
- box.already_required_services << key
49
- end
50
- end
51
- end
52
-
53
3
  class << self
54
4
  def version version = nil
55
5
  if version
@@ -58,10 +8,78 @@ module ClusterManagement
58
8
  @version ||= 1
59
9
  end
60
10
  end
61
-
11
+
12
+ def tag tag = nil
13
+ if tag
14
+ @tag = tag
15
+ else
16
+ @tag || raise("service :#{service_name} not tagged!")
17
+ end
18
+ end
19
+
62
20
  def marker extra_mark = nil
63
- %(#{name}:#{version}#{":#{extra_mark}" if extra_mark})
21
+ %(#{service_name}:#{version}#{":#{extra_mark}" if extra_mark})
22
+ end
23
+
24
+ def service_class name
25
+ # dont'use constantize, it works wrong, and returns ::File instead of ::Services::File for example.
26
+ eval("::Services::#{name.to_s.camelize}", TOPLEVEL_BINDING, __FILE__, __LINE__)
64
27
  end
28
+ cache_method_with_params :service_class
29
+
30
+ def service_name; name.split('::').last.underscore end
31
+ cache_method_with_params :service_name
65
32
  end
33
+
34
+ protected
35
+ def config; cluster.config end
36
+ def logger; cluster.logger end
37
+ def services &b; cluster.services &b end
38
+
39
+ def service_name; self.class.service_name end
40
+
41
+ def apply_once key, &block
42
+ boxes{|box| box.apply_once self.class.marker(key), &block}
43
+ end
44
+
45
+ def boxes &b
46
+ if b
47
+ boxes.each &b
48
+ else
49
+ unless @boxes
50
+ hosts = config.tags!["#{self.class.tag}", nil] || []
51
+ @boxes = hosts.collect{|host| cluster.boxes[host]}
52
+ end
53
+ @boxes
54
+ end
55
+ end
56
+
57
+ def single_box
58
+ boxes.size.must_be == 1
59
+ boxes.first
60
+ end
61
+
62
+ # def require options
63
+ # # if args.size == 1 and args.first.is_a?(Hash)
64
+ # # services = args.first
65
+ # # elsif args.size == 2 and args.first.is_a?(Array)
66
+ # # services = {}
67
+ # # args.first.each{|klass| services[klass] = args.last}
68
+ # # else
69
+ # # raise 'invalid arguments'
70
+ # # end
71
+ #
72
+ # options.each do |service_name, method|
73
+ # key = "#{service_name}.#{method}"
74
+ # unless box.already_required_services.include? key
75
+ # klass.new(box).send method if klass.method_defined? method
76
+ # box.already_required_services << key
77
+ # end
78
+ # end
79
+ # end
80
+ #
81
+ # def already_required_services
82
+ #
83
+ # end
66
84
  end
67
85
  end
@@ -0,0 +1,36 @@
1
+ warn 'stack trace filtering enabled'
2
+
3
+ Exception.metaclass_eval do
4
+ attr_accessor :filters
5
+ end
6
+ Exception.filters = [
7
+ "/gems/haml",
8
+ "/gems/tilt",
9
+ "/gems/facets",
10
+ "/gems/rspec",
11
+
12
+ "/timeout.rb",
13
+
14
+ 'lib/fake_gem',
15
+ 'rubygems/custom_require',
16
+
17
+ 'lib/ruby_ext',
18
+
19
+ 'lib/cluster_management',
20
+
21
+ 'bin/rake',
22
+ 'lib/rake',
23
+
24
+ "/monitor",
25
+ "/synchronize",
26
+ "/class_loader",
27
+ "/micon"
28
+ ]
29
+ # Exception.filters = []
30
+
31
+ Exception.class_eval do
32
+ alias_method :set_backtrace_without_filter, :set_backtrace
33
+ def set_backtrace array
34
+ set_backtrace_without_filter array.sfilter(::Exception.filters)
35
+ end
36
+ end
metadata CHANGED
@@ -1,96 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cluster_management
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.6'
4
5
  prerelease:
5
- version: 0.5.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Alexey Petrushin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-02-16 00:00:00 +03:00
12
+ date: 2011-04-11 00:00:00.000000000 +04:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: tilt
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &3055160 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: ruby_ext
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *3055160
26
+ - !ruby/object:Gem::Dependency
27
+ name: ruby_ext
28
+ requirement: &3054950 !ruby/object:Gem::Requirement
31
29
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
36
34
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ version_requirements: *3054950
37
+ - !ruby/object:Gem::Dependency
39
38
  name: vos
39
+ requirement: &3054750 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
40
46
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
47
+ version_requirements: *3054750
48
+ - !ruby/object:Gem::Dependency
49
+ name: class_loader
50
+ requirement: &3054550 !ruby/object:Gem::Requirement
42
51
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
47
56
  type: :runtime
48
- version_requirements: *id003
57
+ prerelease: false
58
+ version_requirements: *3054550
49
59
  description:
50
60
  email:
51
61
  executables: []
52
-
53
62
  extensions: []
54
-
55
63
  extra_rdoc_files: []
56
-
57
- files:
64
+ files:
58
65
  - Rakefile
59
66
  - readme.md
67
+ - lib/cluster_management/cluster.rb
60
68
  - lib/cluster_management/config.rb
61
69
  - lib/cluster_management/gems.rb
62
70
  - lib/cluster_management/integration/vfs.rb
63
71
  - lib/cluster_management/integration/vos.rb
64
72
  - lib/cluster_management/logger.rb
65
73
  - lib/cluster_management/service.rb
74
+ - lib/cluster_management/support/exception.rb
66
75
  - lib/cluster_management.rb
67
76
  has_rdoc: true
68
77
  homepage: http://github.com/alexeypetrushin/cluster_management
69
78
  licenses: []
70
-
71
79
  post_install_message:
72
80
  rdoc_options: []
73
-
74
- require_paths:
81
+ require_paths:
75
82
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
83
+ required_ruby_version: !ruby/object:Gem::Requirement
77
84
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
90
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: "0"
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
88
95
  requirements: []
89
-
90
96
  rubyforge_project:
91
97
  rubygems_version: 1.5.1
92
98
  signing_key:
93
99
  specification_version: 3
94
- summary: Simple cluster management tools
100
+ summary: Simple Cluster Management Tools
95
101
  test_files: []
96
-