cluster_management 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake_ext'
2
2
 
3
3
  project(
4
4
  name: "cluster_management",
5
- version: "0.6",
5
+ version: "0.7",
6
6
  summary: "Simple Cluster Management Tools",
7
7
 
8
8
  author: "Alexey Petrushin",
@@ -6,6 +6,8 @@ require 'class_loader'
6
6
  # require 'micon'
7
7
  # require 'micon/rad'
8
8
 
9
+ module ClusterManagement
10
+ end
9
11
 
10
12
  #
11
13
  # Classes
@@ -1,56 +1,54 @@
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
1
+ class ClusterManagement::Cluster
2
+ attr_accessor :config, :logger
3
+ attr_reader :boxes
4
+
5
+ def services &b
6
+ b ? @services.instance_eval(&b) : @services
7
+ end
8
+
9
+ class Services < BasicObject
10
+ def initialize
11
+ @h = ::Hash.new do |h, service_name|
12
+ h[service_name] = ::ClusterManagement::Service.service_class(service_name).new
13
+ end
8
14
  end
9
15
 
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
16
+ def [] service_name
17
+ service_name.must_be.a ::Symbol
18
+ @h[service_name.to_sym]
19
+ end
20
+
21
+ protected
22
+ def p msg
23
+ ::Object.send :p, msg
15
24
  end
16
25
 
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
26
+ def method_missing m, *a, &b
27
+ super unless a.blank? and b.blank?
28
+ @h[m]
40
29
  end
30
+ end
31
+
32
+ def initialize
33
+ @services = Services.new
34
+
35
+ @boxes = Hash.new do |h, host|
36
+ box = config.ssh? ? Box.new(host.to_s, config.ssh.to_h) : Box.new(host.to_s)
37
+ box.open
38
+ h[host] = box
41
39
  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
40
  end
41
+
42
+ def configure runtime_dir
43
+ config.merge_file! "#{runtime_dir}/config/config.yml"
44
+ config.set! :config_path, "#{runtime_dir}/config"
45
+
46
+ r = {}
47
+ config.boxes!.to_h.each do |box, tags|
48
+ tags.each do |tag|
49
+ (r[tag.to_sym] ||= []) << box
50
+ end
51
+ end
52
+ config.set! :tags, r
53
+ end
56
54
  end
@@ -1,17 +1,10 @@
1
- module ClusterManagement
2
- class Config < SafeHash
3
- def merge_file! file_path
4
- raise("config file must have .yml extension (#{file_path})!") unless file_path.end_with? '.yml'
5
- data = ::YAML.load_file file_path
6
- if data
7
- data.must_be.a ::Hash
8
- self.merge! data, override: true
9
- end
1
+ class ClusterManagement::Config < SafeHash
2
+ def merge_file! file_path
3
+ raise("config file must have .yml extension (#{file_path})!") unless file_path.end_with? '.yml'
4
+ data = ::YAML.load_file file_path
5
+ if data
6
+ data.must_be.a ::Hash
7
+ self.merge! data, override: true
10
8
  end
11
-
12
- # def self.load file
13
- # @config = Config.new
14
- # @config.merge_file! file
15
- # end
16
- end
9
+ end
17
10
  end
@@ -1,4 +0,0 @@
1
- # module Vfs
2
- # class File
3
- # end
4
- # end
@@ -1,27 +1,25 @@
1
- module Vos
2
- class Box
3
- include Helpers::Ubuntu
1
+ class Vos::Box
2
+ include Vos::Helpers::Ubuntu
3
+
4
+ # alias_method :mark_without_service!, :mark!
5
+ # def mark! key
6
+ # key = key.respond_to(:marker) || key
7
+ # mark_without_service! key
8
+ # end
9
+ #
10
+ # alias_method :has_mark_without_service?, :has_mark?
11
+ # def has_mark? key
12
+ # key = key.respond_to(:marker) || key
13
+ # has_mark_without_service? key
14
+ # end
4
15
 
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
16
-
17
- def apply_once key, &block
18
- unless has_mark? key
19
- block.call self
20
- mark! key
21
- end
22
- end
23
-
24
- end
16
+ def apply_once key, &block
17
+ unless has_mark? key
18
+ block.call self
19
+ mark! key
20
+ end
21
+ end
22
+
25
23
  end
26
24
 
27
25
  # module Vos
@@ -1,26 +1,15 @@
1
1
  require 'logger'
2
2
 
3
- module ClusterManagement
4
- class CustomLogger < Logger
5
- def info msg
6
- super "#{msg}\n"
7
- end
8
-
9
- def warn msg
10
- super "#{msg}\n"
11
- end
12
-
13
- def error msg
14
- super "#{msg}\n"
15
- end
3
+ class ClusterManagement::CustomLogger < Logger
4
+ def info msg
5
+ super "#{msg}\n"
16
6
  end
17
7
 
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
8
+ def warn msg
9
+ super "#{msg}\n"
10
+ end
11
+
12
+ def error msg
13
+ super "#{msg}\n"
14
+ end
26
15
  end
@@ -1,85 +1,83 @@
1
- module ClusterManagement
2
- class Service
3
- class << self
4
- def version version = nil
5
- if version
6
- @version = version
7
- else
8
- @version ||= 1
9
- end
10
- end
11
-
12
- def tag tag = nil
13
- if tag
14
- @tag = tag
15
- else
16
- @tag || raise("service :#{service_name} not tagged!")
17
- end
1
+ class ClusterManagement::Service
2
+ class << self
3
+ def version version = nil
4
+ if version
5
+ @version = version
6
+ else
7
+ @version ||= 1
18
8
  end
19
-
20
- def marker extra_mark = nil
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__)
9
+ end
10
+
11
+ def tag tag = nil
12
+ if tag
13
+ @tag = tag
14
+ else
15
+ @tag || raise("service :#{service_name} not tagged!")
27
16
  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
32
17
  end
33
18
 
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
19
+ def marker extra_mark = nil
20
+ %(#{service_name}:#{version}#{":#{extra_mark}" if extra_mark})
21
+ end
40
22
 
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
23
+ def service_class name
24
+ # dont'use constantize, it works wrong, and returns ::File instead of ::Services::File for example.
25
+ eval("::Services::#{name.to_s.camelize}", TOPLEVEL_BINDING, __FILE__, __LINE__)
26
+ end
27
+ cache_method_with_params :service_class
28
+
29
+ def service_name; name.split('::').last.underscore end
30
+ cache_method_with_params :service_name
31
+ end
32
+
33
+ protected
34
+ def config; cluster.config end
35
+ def logger; cluster.logger end
36
+ def services &b; cluster.services &b end
37
+
38
+ def service_name; self.class.service_name end
39
+
40
+ def apply_once key, &block
41
+ boxes{|box| box.apply_once self.class.marker(key), &block}
42
+ end
43
+
44
+ def boxes &b
45
+ if b
46
+ boxes.each &b
47
+ else
48
+ unless @boxes
49
+ hosts = config.tags!["#{self.class.tag}", nil] || []
50
+ @boxes = hosts.collect{|host| cluster.boxes[host]}
54
51
  end
52
+ @boxes
55
53
  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
84
- end
54
+ end
55
+
56
+ def single_box
57
+ boxes.size.must_be == 1
58
+ boxes.first
59
+ end
60
+
61
+ # def require options
62
+ # # if args.size == 1 and args.first.is_a?(Hash)
63
+ # # services = args.first
64
+ # # elsif args.size == 2 and args.first.is_a?(Array)
65
+ # # services = {}
66
+ # # args.first.each{|klass| services[klass] = args.last}
67
+ # # else
68
+ # # raise 'invalid arguments'
69
+ # # end
70
+ #
71
+ # options.each do |service_name, method|
72
+ # key = "#{service_name}.#{method}"
73
+ # unless box.already_required_services.include? key
74
+ # klass.new(box).send method if klass.method_defined? method
75
+ # box.already_required_services << key
76
+ # end
77
+ # end
78
+ # end
79
+ #
80
+ # def already_required_services
81
+ #
82
+ # end
85
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cluster_management
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: '0.7'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-11 00:00:00.000000000 +04:00
12
+ date: 2011-06-24 00:00:00.000000000 +04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: tilt
17
- requirement: &3055160 !ruby/object:Gem::Requirement
17
+ requirement: &2738130 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *3055160
25
+ version_requirements: *2738130
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: ruby_ext
28
- requirement: &3054950 !ruby/object:Gem::Requirement
28
+ requirement: &2737850 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *3054950
36
+ version_requirements: *2737850
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: vos
39
- requirement: &3054750 !ruby/object:Gem::Requirement
39
+ requirement: &2737650 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *3054750
47
+ version_requirements: *2737650
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: class_loader
50
- requirement: &3054550 !ruby/object:Gem::Requirement
50
+ requirement: &2737450 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *3054550
58
+ version_requirements: *2737450
59
59
  description:
60
60
  email:
61
61
  executables: []