wakame 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/app_generators/wakame/templates/cluster/resources/markers/http_application_server.rb +3 -0
- data/app_generators/wakame/templates/cluster/resources/markers/http_asset_server.rb +2 -0
- data/app_generators/wakame/templates/cluster/resources/markers/http_server.rb +9 -0
- data/app_generators/wakame/templates/config/cluster.rb +36 -99
- data/app_generators/wakame/templates/config/init.d/wakame-agent +3 -3
- data/app_generators/wakame/templates/config/init.d/wakame-master +3 -3
- data/app_generators/wakame/wakame_generator.rb +5 -1
- data/contrib/imagesetup.sh +9 -5
- data/lib/ext/uri.rb +13 -0
- data/lib/wakame/action.rb +46 -21
- data/lib/wakame/{rule_engine.rb → action_manager.rb} +148 -36
- data/lib/wakame/actions/deploy_config.rb +35 -0
- data/lib/wakame/actions/launch_cluster.rb +8 -10
- data/lib/wakame/actions/launch_vm.rb +26 -20
- data/lib/wakame/actions/migrate_service.rb +30 -19
- data/lib/wakame/actions/notify_child_changed.rb +34 -0
- data/lib/wakame/actions/notify_parent_changed.rb +34 -0
- data/lib/wakame/actions/propagate_resource.rb +27 -0
- data/lib/wakame/actions/propagate_service.rb +27 -0
- data/lib/wakame/actions/reload_service.rb +21 -9
- data/lib/wakame/actions/shutdown_cluster.rb +3 -3
- data/lib/wakame/actions/shutdown_vm.rb +14 -5
- data/lib/wakame/actions/start_service.rb +53 -47
- data/lib/wakame/actions/stop_service.rb +35 -23
- data/lib/wakame/actor/system.rb +6 -3
- data/lib/wakame/agent.rb +29 -7
- data/lib/wakame/amqp_client.rb +26 -5
- data/lib/wakame/command/action_status.rb +7 -7
- data/lib/wakame/command/actor.rb +10 -10
- data/lib/wakame/command/import_cluster_config.rb +10 -0
- data/lib/wakame/command/launch_cluster.rb +2 -2
- data/lib/wakame/command/launch_vm.rb +3 -3
- data/lib/wakame/command/migrate_service.rb +7 -7
- data/lib/wakame/command/propagate_resource.rb +42 -0
- data/lib/wakame/command/propagate_service.rb +21 -19
- data/lib/wakame/command/reload_service.rb +3 -13
- data/lib/wakame/command/shutdown_cluster.rb +2 -2
- data/lib/wakame/command/start_service.rb +14 -0
- data/lib/wakame/command/status.rb +32 -10
- data/lib/wakame/command/stop_service.rb +27 -21
- data/lib/wakame/command.rb +19 -3
- data/lib/wakame/command_queue.rb +87 -67
- data/lib/wakame/configuration.rb +6 -0
- data/lib/wakame/event.rb +17 -0
- data/lib/wakame/event_dispatcher.rb +32 -23
- data/lib/wakame/graph.rb +2 -1
- data/lib/wakame/initializer.rb +11 -8
- data/lib/wakame/master.rb +327 -209
- data/lib/wakame/monitor/agent.rb +5 -1
- data/lib/wakame/monitor/service.rb +6 -5
- data/lib/wakame/packets.rb +13 -21
- data/lib/wakame/runner/administrator_command.rb +383 -264
- data/lib/wakame/runner/agent.rb +1 -5
- data/lib/wakame/runner/master.rb +0 -3
- data/lib/wakame/service.rb +817 -538
- data/lib/wakame/status_db.rb +383 -0
- data/lib/wakame/template.rb +27 -130
- data/lib/wakame/trigger.rb +10 -18
- data/lib/wakame/triggers/instance_count_update.rb +1 -1
- data/lib/wakame/triggers/load_history.rb +1 -1
- data/lib/wakame/triggers/maintain_ssh_known_hosts.rb +8 -5
- data/lib/wakame/triggers/shutdown_unused_vm.rb +1 -1
- data/lib/wakame/util.rb +64 -55
- data/lib/wakame.rb +4 -0
- data/tests/test_action_manager.rb +111 -0
- data/tests/test_service.rb +128 -23
- data/tests/test_status_db.rb +82 -0
- data/tests/test_uri_amqp.rb +10 -0
- data/wakame_generators/resource/templates/apache_app/apache_app.rb +19 -18
- data/wakame_generators/resource/templates/apache_app/conf/apache2.conf +14 -2
- data/wakame_generators/resource/templates/apache_app/conf/system-app.conf +1 -1
- data/wakame_generators/resource/templates/apache_app/conf/vh/aaa.test.conf +9 -0
- data/wakame_generators/resource/templates/apache_lb/apache_lb.rb +21 -20
- data/wakame_generators/resource/templates/apache_lb/conf/apache2.conf +14 -2
- data/wakame_generators/resource/templates/apache_lb/conf/system-lb.conf +17 -2
- data/wakame_generators/resource/templates/apache_lb/conf/vh/aaa.test.conf +37 -0
- data/wakame_generators/resource/templates/apache_www/apache_www.rb +20 -18
- data/wakame_generators/resource/templates/apache_www/conf/apache2.conf +14 -2
- data/wakame_generators/resource/templates/apache_www/conf/system-www.conf +1 -1
- data/wakame_generators/resource/templates/apache_www/conf/vh/aaa.test.conf +9 -0
- data/wakame_generators/resource/templates/ec2_elastic_ip/ec2_elastic_ip.rb +6 -8
- data/wakame_generators/resource/templates/ec2_elb/ec2_elb.rb +7 -6
- data/wakame_generators/resource/templates/memcached/conf/memcached.conf +47 -0
- data/wakame_generators/resource/templates/memcached/init.d/memcached +61 -0
- data/wakame_generators/resource/templates/memcached/memcached.rb +73 -0
- data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +5 -7
- data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +35 -34
- data/wakame_generators/resource/templates/mysql_slave/conf/my.cnf +6 -6
- data/wakame_generators/resource/templates/mysql_slave/mysql_slave.rb +21 -24
- data/wakame_generators/resource/templates/nginx/conf/nginx.conf +17 -27
- data/wakame_generators/resource/templates/nginx/conf/vh/aaa.test.conf +30 -0
- data/wakame_generators/resource/templates/nginx/nginx.rb +18 -18
- metadata +34 -21
- data/lib/wakame/actions/propagate_instances.rb +0 -70
- data/lib/wakame/manager/commands.rb +0 -134
- data/lib/wakame/rule.rb +0 -116
- data/lib/wakame/triggers/process_command.rb +0 -41
- data/tests/test_rule_engine.rb +0 -127
- data/wakame_generators/resource/templates/apache_app/conf/sites-app.conf +0 -23
- data/wakame_generators/resource/templates/apache_lb/conf/sites-lb.conf +0 -54
- data/wakame_generators/resource/templates/apache_www/conf/sites-www.conf +0 -23
@@ -2,17 +2,26 @@ module Wakame
|
|
2
2
|
module Actions
|
3
3
|
class ShutdownVM < Action
|
4
4
|
def initialize(agent)
|
5
|
+
raise ArgumentError unless agent.is_a?(Service::Agent)
|
5
6
|
@agent = agent
|
6
7
|
end
|
7
8
|
|
8
9
|
def run
|
10
|
+
#if @agent.id == master.master_local_agent_id
|
11
|
+
# Wakame.log.info("Skip to shutdown VM as the master is running on this node: #{@agent.agent_id}")
|
12
|
+
# return
|
13
|
+
#end
|
9
14
|
|
10
|
-
|
11
|
-
Wakame.log.info("Skip to shutdown VM as the master is running on this node: #{@agent.agent_id}")
|
12
|
-
return
|
13
|
-
end
|
15
|
+
shutdown_ec2_instance
|
14
16
|
|
15
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def shutdown_ec2_instance
|
21
|
+
require 'right_aws'
|
22
|
+
ec2 = RightAws::Ec2.new(Wakame.config.aws_access_key, Wakame.config.aws_secret_key, {:cache=>false})
|
23
|
+
|
24
|
+
res = ec2.terminate_instances([@agent.vm_attr[:instance_id]])
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
@@ -1,85 +1,91 @@
|
|
1
1
|
|
2
|
-
require 'wakame/rule'
|
3
|
-
|
4
2
|
module Wakame
|
5
3
|
module Actions
|
6
4
|
class StartService < Action
|
7
|
-
def initialize(service_instance
|
5
|
+
def initialize(service_instance)
|
8
6
|
@service_instance = service_instance
|
9
|
-
@target_agent = target_agent
|
10
7
|
end
|
11
8
|
|
12
9
|
def run
|
10
|
+
# Skip to act when the service is having below status.
|
11
|
+
if @service_instance.status == Service::STATUS_STARTING || @service_instance.status == Service::STATUS_ONLINE
|
12
|
+
Wakame.log.info("Ignore to start the service as is being or already Online: #{@service_instance.resource.class}")
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
acquire_lock { |lst|
|
17
|
+
lst << @service_instance.resource.class.to_s
|
18
|
+
}
|
19
|
+
|
13
20
|
if @service_instance.resource.require_agent
|
21
|
+
raise "The service is not bound cloud host object: #{@service_instance.id}" if @service_instance.cloud_host_id.nil?
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
23
|
+
unless @service_instance.cloud_host.mapped?
|
24
|
+
acquire_lock { |lst|
|
25
|
+
lst << Service::AgentPool.class.to_s
|
26
|
+
}
|
27
|
+
|
28
|
+
# Try to arrange agent from existing agent pool.
|
29
|
+
StatusDB.barrier {
|
30
|
+
next if Service::AgentPool.instance.group_active.empty?
|
31
|
+
agent2host = cluster.agents.invert
|
32
|
+
|
33
|
+
Service::AgentPool.instance.group_active.keys.each { |agent_id|
|
34
|
+
agent = Service::Agent.find(agent_id)
|
35
|
+
if !agent.has_resource_type?(@service_instance.resource) &&
|
36
|
+
agent2host[agent_id].nil? && # This agent is not mapped to any cloud hosts.
|
37
|
+
@service_instance.cloud_host.vm_spec.satisfy?(agent.vm_attr)
|
38
|
+
|
39
|
+
@service_instance.cloud_host.map_agent(agent)
|
40
|
+
break
|
41
|
+
end
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
# Start new VM when the target agent is still nil.
|
46
|
+
unless @service_instance.cloud_host.mapped?
|
18
47
|
inst_id_key = "new_inst_id_" + Wakame::Util.gen_id
|
19
|
-
trigger_action(LaunchVM.new(inst_id_key))
|
48
|
+
trigger_action(LaunchVM.new(inst_id_key, @service_instance.cloud_host.vm_spec))
|
20
49
|
flush_subactions
|
21
50
|
|
22
|
-
|
23
|
-
|
24
|
-
raise "Cound not find the specified VM instance \"#{notes[inst_id_key]}\"" if
|
25
|
-
|
51
|
+
StatusDB.barrier {
|
52
|
+
agent = Service::Agent.find(notes[inst_id_key])
|
53
|
+
raise "Cound not find the specified VM instance \"#{notes[inst_id_key]}\"" if agent.nil?
|
54
|
+
@service_instance.cloud_host.map_agent(agent)
|
26
55
|
}
|
27
56
|
end
|
57
|
+
|
58
|
+
raise "Could not find the agent to be assigned to : #{@service_instance.resource.class}" unless @service_instance.cloud_host.mapped?
|
28
59
|
|
29
|
-
|
30
|
-
@service_instance.bind_agent(@target_agent)
|
31
|
-
}
|
60
|
+
@service_instance.resource.on_enter_agent(@service_instance, self)
|
32
61
|
end
|
62
|
+
|
63
|
+
raise "The assigned agent \"#{@service_instance.cloud_host.agent_id}\" for the service instance #{@service_instance.id} is not online." unless @service_instance.cloud_host.status == Service::Agent::STATUS_ONLINE
|
33
64
|
|
34
|
-
|
35
|
-
raise "Agent is not bound on this service : #{@service_instance}" if @service_instance.agent.nil?
|
36
|
-
raise "The assigned agent for the service instance #{@service_instance.instance_id} is not online." unless @service_instance.agent.status == Service::Agent::STATUS_ONLINE
|
37
65
|
end
|
38
66
|
|
39
|
-
|
40
|
-
|
41
|
-
raise "Canceled as the service is being or already ONLINE: #{@service_instance.resource}"
|
42
|
-
end
|
43
|
-
EM.barrier {
|
67
|
+
|
68
|
+
StatusDB.barrier {
|
44
69
|
@service_instance.update_status(Service::STATUS_STARTING)
|
45
70
|
}
|
46
71
|
|
47
72
|
if @service_instance.resource.require_agent
|
48
|
-
|
73
|
+
trigger_action(DeployConfig.new(@service_instance))
|
74
|
+
flush_subactions
|
49
75
|
end
|
50
76
|
|
51
77
|
@service_instance.resource.start(@service_instance, self)
|
52
78
|
|
53
|
-
|
54
|
-
|
55
|
-
service_cluster.dg.children(@service_instance.resource.class).each { |svc_res|
|
56
|
-
Wakame.log.debug("Spreading DG child changed: #{@service_instance.resource.class} -> #{svc_res.class}")
|
57
|
-
trigger_action(Actions::CallChildChangeAction.new(svc_res))
|
58
|
-
}
|
59
|
-
}
|
79
|
+
trigger_action(NotifyParentChanged.new(@service_instance))
|
80
|
+
flush_subactions
|
60
81
|
|
61
82
|
end
|
62
83
|
|
63
84
|
def on_failed
|
64
|
-
|
85
|
+
StatusDB.barrier {
|
65
86
|
@service_instance.update_status(Service::STATUS_FAIL)
|
66
87
|
}
|
67
88
|
end
|
68
89
|
end
|
69
|
-
|
70
|
-
class CallChildChangeAction < Action
|
71
|
-
def initialize(resource)
|
72
|
-
@resource = resource
|
73
|
-
#@parent_instance = parent_instance
|
74
|
-
end
|
75
|
-
|
76
|
-
def run
|
77
|
-
Wakame.log.debug("CallChildChangeAction: run: #{@resource.class}")
|
78
|
-
service_cluster.each_instance(@resource.class) { |svc_inst|
|
79
|
-
next if svc_inst.status != Service::STATUS_ONLINE
|
80
|
-
@resource.on_parent_changed(svc_inst, self)
|
81
|
-
}
|
82
|
-
end
|
83
|
-
end
|
84
90
|
end
|
85
91
|
end
|
@@ -1,43 +1,55 @@
|
|
1
1
|
module Wakame
|
2
2
|
module Actions
|
3
3
|
class StopService < Action
|
4
|
-
def initialize(
|
5
|
-
|
6
|
-
@
|
4
|
+
def initialize(svc, do_terminate=true)
|
5
|
+
raise ArgumentError unless svc.is_a?(Service::ServiceInstance)
|
6
|
+
@svc = svc
|
7
|
+
@do_terminate = do_terminate
|
7
8
|
end
|
8
9
|
|
9
10
|
|
10
11
|
def run
|
11
|
-
raise "Agent is not bound on this service : #{@service_instance}" if @service_instance.property.require_agent && @service_instance.agent.nil?
|
12
|
-
|
13
12
|
# Skip to act when the service is having below status.
|
14
|
-
if @
|
15
|
-
|
13
|
+
if @svc.status == Service::STATUS_STOPPING || @svc.status == Service::STATUS_OFFLINE
|
14
|
+
Wakame.log.info("Ignore to stop the service as is being or already OFFLINE: #{@svc.resource.class}")
|
15
|
+
return
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
@
|
20
|
-
}
|
21
|
-
|
22
|
-
EM.barrier {
|
23
|
-
Wakame.log.debug("Child nodes: #{@service_instance.property.class}: " + service_cluster.dg.children(@service_instance.property.class).inspect)
|
24
|
-
service_cluster.dg.children(@service_instance.property.class).each { |svc_prop|
|
25
|
-
trigger_action(CallChildChangeAction.new(svc_prop))
|
26
|
-
}
|
18
|
+
acquire_lock { |lst|
|
19
|
+
lst << @svc.resource.class.to_s
|
27
20
|
}
|
28
21
|
|
29
|
-
|
22
|
+
if @svc.resource.require_agent && !@svc.cloud_host.mapped?
|
23
|
+
raise "Agent is not bound on this service : #{@svc}"
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
EM.barrier {
|
34
|
-
service_cluster.destroy(@service_instance.instance_id)
|
26
|
+
StatusDB.barrier {
|
27
|
+
@svc.update_status(Service::STATUS_STOPPING)
|
35
28
|
}
|
29
|
+
|
30
|
+
trigger_action(NotifyChildChanged.new(@svc))
|
31
|
+
flush_subactions
|
32
|
+
|
33
|
+
@svc.resource.stop(@svc, self)
|
34
|
+
|
35
|
+
if @do_terminate
|
36
|
+
if @svc.resource.require_agent
|
37
|
+
StatusDB.barrier {
|
38
|
+
@svc.update_status(Service::STATUS_QUITTING)
|
39
|
+
}
|
40
|
+
@svc.resource.on_quit_agent(@svc, self)
|
41
|
+
end
|
42
|
+
|
43
|
+
StatusDB.barrier {
|
44
|
+
@svc.update_status(Service::STATUS_TERMINATE)
|
45
|
+
cluster.destroy(@svc.id)
|
46
|
+
}
|
47
|
+
end
|
36
48
|
end
|
37
49
|
|
38
50
|
def on_failed
|
39
|
-
|
40
|
-
@
|
51
|
+
StatusDB.barrier {
|
52
|
+
@svc.update_status(Service::STATUS_FAIL)
|
41
53
|
}
|
42
54
|
end
|
43
55
|
|
data/lib/wakame/actor/system.rb
CHANGED
@@ -30,7 +30,7 @@ class Wakame::Actor::System
|
|
30
30
|
Wakame.log.debug("#{mount_point_dev}: #{dev}, /bin/mount | awk '$3==path {print $1}' path=\"#{path}\"")
|
31
31
|
if mount_point_dev != dev
|
32
32
|
Wakame.log.debug("Mounting volume: #{dev} as #{path} (with options: #{opts})")
|
33
|
-
Wakame::Util.exec("/bin/mount
|
33
|
+
Wakame::Util.exec("/bin/mount #{escape_mount_opts(opts)} '#{Shellwords.shellescape(dev)}' '#{Shellwords.shellescape(path)}'")
|
34
34
|
else
|
35
35
|
Wakame.log.debug("Mounting EBS volume: #{dev} as #{path} (with options: #{opts})")
|
36
36
|
end
|
@@ -45,11 +45,14 @@ class Wakame::Actor::System
|
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
48
|
-
def
|
48
|
+
def escape_mount_opts(opts)
|
49
|
+
return '' if opts.nil?
|
50
|
+
return "-o '#{Shellwords.shellescape(opts)}'" if opts.is_a? String
|
51
|
+
|
49
52
|
out = opts.collect { |k,v|
|
50
53
|
v.nil? ? k : "#{k}=#{v}"
|
51
54
|
}.join(',')
|
52
|
-
Shellwords.shellescape(out)
|
55
|
+
"-o #{Shellwords.shellescape(out)}"
|
53
56
|
end
|
54
57
|
|
55
58
|
end
|
data/lib/wakame/agent.rb
CHANGED
@@ -9,8 +9,8 @@ require 'thread'
|
|
9
9
|
require 'wakame'
|
10
10
|
require 'wakame/amqp_client'
|
11
11
|
require 'wakame/queue_declare'
|
12
|
-
require 'wakame/event'
|
13
|
-
require 'wakame/vm_manipulator'
|
12
|
+
#require 'wakame/event'
|
13
|
+
#require 'wakame/vm_manipulator'
|
14
14
|
|
15
15
|
|
16
16
|
module Wakame
|
@@ -31,14 +31,19 @@ module Wakame
|
|
31
31
|
determine_agent_id
|
32
32
|
@actor_registry = ActorRegistry.new
|
33
33
|
@monitor_registry = MonitorRegistry.new
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
# post_setup
|
37
|
+
def init
|
37
38
|
setup_monitors
|
38
39
|
setup_actors
|
39
40
|
setup_dispatcher
|
40
41
|
|
41
|
-
|
42
|
+
if Wakame.config.environment == :EC2
|
43
|
+
attrs = self.class.ec2_fetch_local_attrs
|
44
|
+
else
|
45
|
+
attrs = {}
|
46
|
+
end
|
42
47
|
publish_to('registry', Packets::Register.new(self, Wakame.config.root_path.to_s, attrs).marshal)
|
43
48
|
Wakame.log.info("Started agent process : WAKAME_ROOT=#{Wakame.config.root_path} WAKAME_ENV=#{Wakame.config.environment}, attrs=#{attrs.inspect}")
|
44
49
|
end
|
@@ -55,9 +60,9 @@ module Wakame
|
|
55
60
|
|
56
61
|
def determine_agent_id
|
57
62
|
if Wakame.config.environment == :EC2
|
58
|
-
@agent_id =
|
63
|
+
@agent_id = self.class.ec2_query_metadata_uri('instance-id')
|
59
64
|
else
|
60
|
-
@agent_id =
|
65
|
+
@agent_id = '__STAND_ALONE__'
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
@@ -114,6 +119,23 @@ module Wakame
|
|
114
119
|
}
|
115
120
|
end
|
116
121
|
|
122
|
+
def self.ec2_query_metadata_uri(key)
|
123
|
+
require 'open-uri'
|
124
|
+
open("http://169.254.169.254/2008-02-01/meta-data/#{key}") { |f|
|
125
|
+
return f.readline
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.ec2_fetch_local_attrs
|
130
|
+
attrs = {}
|
131
|
+
%w[instance-id instance-type local-ipv4 local-hostname public-hostname public-ipv4 ami-id].each { |key|
|
132
|
+
rkey = key.tr('-', '_')
|
133
|
+
attrs[rkey.to_sym]=ec2_query_metadata_uri(key)
|
134
|
+
}
|
135
|
+
attrs[:availability_zone] = ec2_query_metadata_uri('placement/availability-zone')
|
136
|
+
attrs
|
137
|
+
end
|
138
|
+
|
117
139
|
end
|
118
140
|
|
119
141
|
|
data/lib/wakame/amqp_client.rb
CHANGED
@@ -17,21 +17,28 @@ module Wakame
|
|
17
17
|
end
|
18
18
|
|
19
19
|
module ClassMethods
|
20
|
-
attr_reader :instance
|
21
20
|
attr_reader :defered_setup_calls
|
22
21
|
|
22
|
+
|
23
|
+
def instance
|
24
|
+
@instance
|
25
|
+
end
|
26
|
+
|
23
27
|
def start(*opts)
|
24
|
-
|
25
|
-
if
|
28
|
+
new_instance = proc {
|
29
|
+
if @instance.nil?
|
26
30
|
@instance = new(*opts)
|
31
|
+
@instance.connect(*opts) do
|
32
|
+
@instance.init
|
33
|
+
end
|
27
34
|
end
|
28
35
|
@instance
|
29
36
|
}
|
30
37
|
|
31
38
|
if EM.reactor_running?
|
32
|
-
return
|
39
|
+
return new_instance.call
|
33
40
|
else
|
34
|
-
EM.run
|
41
|
+
EM.run new_instance
|
35
42
|
end
|
36
43
|
end
|
37
44
|
|
@@ -107,9 +114,23 @@ module Wakame
|
|
107
114
|
|
108
115
|
attr_reader :mq, :amqp_client
|
109
116
|
|
117
|
+
def amqp_server_uri
|
118
|
+
raise "The connection is not established yet." unless @amqp_client && connected?
|
119
|
+
|
120
|
+
URI::AMQP.build(:host => @amqp_client.settings[:host],
|
121
|
+
:port => @amqp_client.settings[:port],
|
122
|
+
:path => @amqp_client.settings[:vhost]
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
110
126
|
def connect(*args)
|
111
127
|
close() unless connected?
|
112
128
|
@amqp_client = AMQP.connect(*args)
|
129
|
+
@amqp_client.instance_eval {
|
130
|
+
def settings
|
131
|
+
@settings
|
132
|
+
end
|
133
|
+
}
|
113
134
|
@mq = Thread.current[:mq] = MQ.new(@amqp_client)
|
114
135
|
|
115
136
|
run_defered_callbacks
|
@@ -1,10 +1,8 @@
|
|
1
1
|
|
2
|
-
require 'erb'
|
3
|
-
|
4
2
|
class Wakame::Command::ActionStatus
|
5
3
|
include Wakame::Command
|
6
4
|
|
7
|
-
def run
|
5
|
+
def run
|
8
6
|
walk_subactions = proc { |a, level|
|
9
7
|
res = a.dump_attrs
|
10
8
|
unless a.subactions.empty?
|
@@ -15,12 +13,14 @@ class Wakame::Command::ActionStatus
|
|
15
13
|
res
|
16
14
|
}
|
17
15
|
|
18
|
-
|
16
|
+
Wakame::StatusDB.barrier {
|
19
17
|
result = {}
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
master.action_manager.active_jobs.each { |id, v|
|
20
|
+
result[id]={}
|
21
|
+
(v.keys - [:root_action]).each { |k|
|
22
|
+
result[id][k]=v[k]
|
23
|
+
}
|
24
24
|
result[id][:root_action] = walk_subactions.call(v[:root_action], 0)
|
25
25
|
|
26
26
|
}
|
data/lib/wakame/command/actor.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
|
2
2
|
class Wakame::Command::Actor
|
3
3
|
include Wakame::Command
|
4
|
+
include Wakame::Service
|
4
5
|
|
5
|
-
command_name='
|
6
|
+
command_name='actor'
|
6
7
|
|
7
8
|
def parse(args)
|
8
9
|
raise "Not enugh number of arguments" if args.size < 2
|
9
|
-
@agent_id = args.shift
|
10
|
-
@path = args.shift
|
11
|
-
@args = *args
|
12
10
|
end
|
13
11
|
|
14
|
-
def run
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def run
|
13
|
+
agent = Agent.find(params[:agent_id])
|
14
|
+
raise "Unknown agent: #{params[:agent_id]}" if agent.nil?
|
15
|
+
raise "Invalid agent status (Not Online): #{agent.status} #{params[:agent_id]}" if agent.status != Agent::STATUS_ONLINE
|
18
16
|
|
17
|
+
raise "Invalid actor path: #{params[:path]}" if params[:path].nil? || params[:path] == ''
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
request = rule.master.actor_request(params[:agent_id], params[:path], *params[:args]).request
|
20
|
+
request.wait
|
22
21
|
end
|
22
|
+
|
23
23
|
end
|
@@ -4,8 +4,8 @@ class Wakame::Command::LaunchVm
|
|
4
4
|
|
5
5
|
command_name='launch_vm'
|
6
6
|
|
7
|
-
def run
|
7
|
+
def run
|
8
8
|
inst_id_key = "new_inst_id_" + Wakame::Util.gen_id
|
9
|
-
|
9
|
+
trigger_action(Wakame::Actions::LaunchVM.new(inst_id_key))
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -2,23 +2,23 @@
|
|
2
2
|
class Wakame::Command::MigrateService
|
3
3
|
include Wakame::Command
|
4
4
|
|
5
|
-
def run
|
5
|
+
def run
|
6
6
|
svc = nil
|
7
|
-
svc =
|
7
|
+
svc = service_cluster.find_service(options["service_id"])
|
8
8
|
if svc.nil?
|
9
|
-
raise "Unknown Service ID: #{
|
9
|
+
raise "Unknown Service ID: #{options["service_id"]}"
|
10
10
|
end
|
11
11
|
|
12
12
|
# Optional destination agent
|
13
13
|
agent = nil
|
14
|
-
if
|
15
|
-
agent =
|
14
|
+
if options["agent_id"]
|
15
|
+
agent = master.agent_monitor.agent_pool.find_agent(options["agent_id"])
|
16
16
|
if agent.nil?
|
17
|
-
raise "Unknown Agent ID: #{
|
17
|
+
raise "Unknown Agent ID: #{options["agent_id"]}"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
trigger_action(Wakame::Actions::MigrateService.new(svc, agent))
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
class Wakame::Command::PropagateResource
|
3
|
+
include Wakame::Command
|
4
|
+
include Wakame
|
5
|
+
|
6
|
+
command_name='propagate_resource'
|
7
|
+
|
8
|
+
def run
|
9
|
+
resname = @options["resource"]
|
10
|
+
|
11
|
+
resobj = Service::Resource.find(Service::Resource.id(resname))
|
12
|
+
if resobj.nil?
|
13
|
+
raise "Unknown Resource: #{resname}"
|
14
|
+
end
|
15
|
+
|
16
|
+
cloud_host_id = @options["cloud_host_id"]
|
17
|
+
if cloud_host_id.nil?
|
18
|
+
cloud_host = service_cluster.add_cloud_host { |h|
|
19
|
+
if @options["vm_attr"].is_a? Hash
|
20
|
+
h.vm_attr = @options["vm_attr"]
|
21
|
+
end
|
22
|
+
}
|
23
|
+
else
|
24
|
+
cloud_host = Service::CloudHost.find(cloud_host_id) || raise("Specified host was not found: #{cloud_host_id}")
|
25
|
+
raise "Same resouce type is already assigned: #{resobj.class} on #{cloud_host_id}" if cloud_host.has_resource_type?(resobj)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
num = options["number"] || 1
|
30
|
+
raise "Invalid format of number: #{num}" unless /^(\d+)$/ =~ num.to_s
|
31
|
+
num = num.to_i
|
32
|
+
|
33
|
+
if num < 1 || resobj.max_instances < service_cluster.instance_count(resobj) + num
|
34
|
+
raise "The number must be between 1 and #{resobj.max_instances - service_cluster.instance_count(resobj)} (max limit: #{resobj.max_instances})"
|
35
|
+
end
|
36
|
+
|
37
|
+
num.times {
|
38
|
+
trigger_action(Wakame::Actions::PropagateResource.new(resobj, cloud_host.id))
|
39
|
+
}
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -1,32 +1,34 @@
|
|
1
1
|
|
2
2
|
class Wakame::Command::PropagateService
|
3
3
|
include Wakame::Command
|
4
|
+
include Wakame
|
4
5
|
|
5
|
-
|
6
|
+
command_name='propagate_service'
|
6
7
|
|
7
|
-
def
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
def run(rule)
|
12
|
-
prop = nil
|
13
|
-
prop = rule.service_cluster.properties[@options["service"]]
|
14
|
-
if prop.nil?
|
15
|
-
raise "UnknownProperty: #{@options["service"]}"
|
8
|
+
def run
|
9
|
+
refsvc = service_cluster.find_service(@options["service_id"])
|
10
|
+
if refsvc.nil?
|
11
|
+
raise("Unknown ServiceInstance ID: #{@options["service_id"]}")
|
16
12
|
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
raise
|
14
|
+
cloud_host_id = @options["cloud_host_id"]
|
15
|
+
if cloud_host_id.nil? || cloud_host_id == ""
|
16
|
+
cloud_host_id = nil
|
17
|
+
else
|
18
|
+
cloud_host = Service::CloudHost.find(cloud_host_id) || raise("Specified cloud host was not found: #{cloud_host_id}")
|
19
|
+
raise "Same resouce type is already assigned: #{refsvc.resource.class} on #{cloud_host_id}" if cloud_host.has_resource_type?(refsvc.resource)
|
23
20
|
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
num = @options["number"] || 1
|
23
|
+
raise "Invalid format of number: #{num}" unless /^(\d+)$/ =~ num.to_s
|
24
|
+
num = num.to_i
|
25
|
+
|
26
|
+
if num < 1 || refsvc.resource.max_instances < service_cluster.instance_count(refsvc.resource) + num
|
27
|
+
raise "The number must be between 1 and #{refsvc.resource.max_instances - service_cluster.instance_count(refsvc.resource)} (max limit: #{refsvc.resource.max_instances})"
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
num.times {
|
31
|
+
trigger_action(Wakame::Actions::PropagateService.new(refsvc, cloud_host_id))
|
32
|
+
}
|
31
33
|
end
|
32
34
|
end
|
@@ -4,18 +4,8 @@ class Wakame::Command::ReloadService
|
|
4
4
|
|
5
5
|
command_name='reload_service'
|
6
6
|
|
7
|
-
def run
|
8
|
-
|
9
|
-
|
10
|
-
levels.reverse.each {|lv|
|
11
|
-
lv.each { |svc_prop|
|
12
|
-
if svc_prop.class.to_s == @options["service_name"].to_s
|
13
|
-
rule.service_cluster.each_instance(svc_prop.class) { |svc_inst|
|
14
|
-
rule.trigger_action(Wakame::Actions::ReloadService.new(svc_inst))
|
15
|
-
}
|
16
|
-
end
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
7
|
+
def run
|
8
|
+
svc = service_cluster.find_service(options['service_id'])
|
9
|
+
trigger_action(Wakame::Actions::ReloadService.new(svc))
|
20
10
|
end
|
21
11
|
end
|