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 +1 -1
- data/lib/cluster_management.rb +2 -0
- data/lib/cluster_management/cluster.rb +46 -48
- data/lib/cluster_management/config.rb +8 -15
- data/lib/cluster_management/integration/vfs.rb +0 -4
- data/lib/cluster_management/integration/vos.rb +21 -23
- data/lib/cluster_management/logger.rb +10 -21
- data/lib/cluster_management/service.rb +75 -77
- metadata +10 -10
data/Rakefile
CHANGED
data/lib/cluster_management.rb
CHANGED
@@ -1,56 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
18
|
-
|
19
|
-
@h[
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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,27 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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.
|
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-
|
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: &
|
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: *
|
25
|
+
version_requirements: *2738130
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: ruby_ext
|
28
|
-
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: *
|
36
|
+
version_requirements: *2737850
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: vos
|
39
|
-
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: *
|
47
|
+
version_requirements: *2737650
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: class_loader
|
50
|
-
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: *
|
58
|
+
version_requirements: *2737450
|
59
59
|
description:
|
60
60
|
email:
|
61
61
|
executables: []
|