tengine_resource 0.5.15 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -27
- data/Gemfile.lock +60 -73
- data/README.rdoc +2 -2
- data/bin/create_indexes_for_tengine_resource +18 -0
- data/lib/tengine/resource/config/resource.rb +0 -3
- data/lib/tengine/resource/credential.rb +16 -17
- data/lib/tengine/resource/net_ssh.rb +22 -10
- data/lib/tengine/resource/physical_server.rb +8 -0
- data/lib/tengine/resource/provider.rb +206 -35
- data/lib/tengine/resource/server.rb +3 -3
- data/lib/tengine/resource/virtual_server.rb +1 -1
- data/lib/tengine/resource/virtual_server_image.rb +8 -8
- data/lib/tengine/resource/virtual_server_type.rb +2 -2
- data/lib/tengine/resource/watcher.rb +39 -9
- data/tmp/.gitkeep +0 -0
- metadata +92 -141
- data/.document +0 -5
- data/.rspec +0 -1
- data/Rakefile +0 -42
- data/VERSION +0 -1
- data/config/.gitignore +0 -2
- data/lib/tengine/resource/credential/ec2.rb +0 -5
- data/lib/tengine/resource/credential/ec2/dummy.rb +0 -148
- data/lib/tengine/resource/credential/ec2/launch_options.rb +0 -179
- data/lib/tengine/resource/provider/ec2.rb +0 -187
- data/lib/tengine/resource/provider/wakame.rb +0 -638
- data/spec/fixtures/goku_at_ec2_ap_northeast.rb +0 -177
- data/spec/mongoid.yml +0 -35
- data/spec/mongoid_en.yml +0 -48
- data/spec/spec_helper.rb +0 -43
- data/spec/support/ec2.rb +0 -129
- data/spec/support/mongo_index_key_log.rb +0 -91
- data/spec/tengine/resource/bugfix/watcher_for_wakame_spec.rb +0 -232
- data/spec/tengine/resource/credential_spec.rb +0 -205
- data/spec/tengine/resource/drivers/resource_control_driver_spec.rb +0 -84
- data/spec/tengine/resource/net_ssh_spec.rb +0 -148
- data/spec/tengine/resource/physical_server_spec.rb +0 -47
- data/spec/tengine/resource/provider/ec2_spec.rb +0 -473
- data/spec/tengine/resource/provider/test_files/describe_host_nodes.json +0 -22
- data/spec/tengine/resource/provider/test_files/describe_images.json +0 -23
- data/spec/tengine/resource/provider/test_files/describe_instance_specs.json +0 -23
- data/spec/tengine/resource/provider/test_files/describe_instances.json +0 -56
- data/spec/tengine/resource/provider/test_files/run_instances.json +0 -30
- data/spec/tengine/resource/provider/test_files/terminate_instances.json +0 -3
- data/spec/tengine/resource/provider/wakame/00_describe_host_nodes_0_physical_servers.json +0 -8
- data/spec/tengine/resource/provider/wakame/01_describe_host_nodes_10_physical_servers.json +0 -139
- data/spec/tengine/resource/provider/wakame/02_describe_host_nodes_60_physical_servers.json +0 -795
- data/spec/tengine/resource/provider/wakame/10_describe_instances_0_virtual_servers.json +0 -8
- data/spec/tengine/resource/provider/wakame/11_describe_instances_10_virtual_servers.json +0 -469
- data/spec/tengine/resource/provider/wakame/12_describe_instances_after_run_instances.json +0 -280
- data/spec/tengine/resource/provider/wakame/13_describe_instances_after_terminate_instances.json +0 -279
- data/spec/tengine/resource/provider/wakame/20_describe_images_0_virtual_server_images.json +0 -8
- data/spec/tengine/resource/provider/wakame/21_describe_images_5_virtual_server_images.json +0 -84
- data/spec/tengine/resource/provider/wakame/22_describe_images_60_virtual_server_images.json +0 -856
- data/spec/tengine/resource/provider/wakame/30_describe_instance_specs_0_virtual_server_specs.json +0 -8
- data/spec/tengine/resource/provider/wakame/31_describe_instance_specs_4_virtual_server_specs.json +0 -66
- data/spec/tengine/resource/provider/wakame/40_run_instances_0_virtual_servers.json +0 -1
- data/spec/tengine/resource/provider/wakame/41_run_instances_1_virtual_servers.json +0 -22
- data/spec/tengine/resource/provider/wakame/42_run_instances_5_virtual_servers.json +0 -106
- data/spec/tengine/resource/provider/wakame/50_terminate_instances_0_virtual_servers.json +0 -1
- data/spec/tengine/resource/provider/wakame/51_terminate_instances_3_virtual_servers.json +0 -5
- data/spec/tengine/resource/provider/wakame/sync_physical_servers_spec.rb +0 -114
- data/spec/tengine/resource/provider/wakame/sync_virtual_server_images_spec.rb +0 -116
- data/spec/tengine/resource/provider/wakame/sync_virtual_server_types_spec.rb +0 -116
- data/spec/tengine/resource/provider/wakame/sync_virtual_servers_spec.rb +0 -216
- data/spec/tengine/resource/provider/wakame_api_spec.rb +0 -319
- data/spec/tengine/resource/provider/wakame_spec.rb +0 -339
- data/spec/tengine/resource/provider_spec.rb +0 -252
- data/spec/tengine/resource/server_spec.rb +0 -195
- data/spec/tengine/resource/test_files/.gitignore +0 -6
- data/spec/tengine/resource/test_files/00_describe_host_nodes_0_physical_servers.json +0 -8
- data/spec/tengine/resource/test_files/01_describe_host_nodes_10_physical_servers.json +0 -139
- data/spec/tengine/resource/test_files/02_describe_host_nodes_60_physical_servers.json +0 -795
- data/spec/tengine/resource/test_files/10_describe_instances_0_virtual_servers.json +0 -8
- data/spec/tengine/resource/test_files/11_describe_instances_10_virtual_servers.json +0 -469
- data/spec/tengine/resource/test_files/12_describe_instances_after_run_instances.json +0 -280
- data/spec/tengine/resource/test_files/13_describe_instances_after_terminate_instances.json +0 -279
- data/spec/tengine/resource/test_files/14_describe_instances_after_run_1_instance.json +0 -55
- data/spec/tengine/resource/test_files/20_describe_images_0_virtual_server_images.json +0 -8
- data/spec/tengine/resource/test_files/21_describe_images_5_virtual_server_images.json +0 -84
- data/spec/tengine/resource/test_files/22_describe_images_60_virtual_server_images.json +0 -856
- data/spec/tengine/resource/test_files/30_describe_instance_specs_0_virtual_server_specs.json +0 -8
- data/spec/tengine/resource/test_files/31_describe_instance_specs_4_virtual_server_specs.json +0 -66
- data/spec/tengine/resource/test_files/40_run_instances_0_virtual_servers.json +0 -1
- data/spec/tengine/resource/test_files/41_run_instances_1_virtual_servers.json +0 -22
- data/spec/tengine/resource/test_files/42_run_instances_5_virtual_servers.json +0 -106
- data/spec/tengine/resource/test_files/43_run_instances_1_virtual_servers_without_aws_availability_zone.json +0 -22
- data/spec/tengine/resource/test_files/50_terminate_instances_0_virtual_servers.json +0 -1
- data/spec/tengine/resource/test_files/51_terminate_instances_3_virtual_servers.json +0 -5
- data/spec/tengine/resource/virtual_server_image_spec.rb +0 -94
- data/spec/tengine/resource/virtual_server_spec.rb +0 -116
- data/spec/tengine/resource/virtual_server_type_spec.rb +0 -4
- data/spec/tengine/resource/watcher_spec.rb +0 -1027
- data/spec/tengine_resource_spec.rb +0 -5
- data/tengine_resource.gemspec +0 -172
- data/tmp/log/.gitignore +0 -1
@@ -1,177 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
class GokuAtEc2ApNortheast
|
4
|
-
# # memoize については http://wota.jp/ac/?date=20081025#p11 などを参照してください
|
5
|
-
# extend ActiveSupport::Memoizable
|
6
|
-
|
7
|
-
def provider
|
8
|
-
Tengine::Resource::Provider::Ec2.find_or_create_by_name!({
|
9
|
-
:name => "goku_at_ec2_ap-northeast-1",
|
10
|
-
:connection_settings => {
|
11
|
-
:access_key => '12345',
|
12
|
-
:secret_access_key => '1234567',
|
13
|
-
:default_region => 'ap-northeast-1',
|
14
|
-
}
|
15
|
-
})
|
16
|
-
end
|
17
|
-
|
18
|
-
def goku_ssh_pw
|
19
|
-
Tengine::Resource::Credential.find_or_create_by_name!(
|
20
|
-
:name => "goku_ssh_pw",
|
21
|
-
:auth_type_key => :ssh_password,
|
22
|
-
:auth_values => {
|
23
|
-
:username => 'goku',
|
24
|
-
:password => 'dragonball'
|
25
|
-
})
|
26
|
-
end
|
27
|
-
|
28
|
-
def gohan_ssh_pk
|
29
|
-
Tengine::Resource::Credential.find_or_create_by_name!(
|
30
|
-
:name => "gohan_ssh_pk",
|
31
|
-
:auth_type_key => :ssh_public_key,
|
32
|
-
:auth_values => {
|
33
|
-
:username => 'gohan',
|
34
|
-
:private_keys => "1234567890",
|
35
|
-
:passphrase => 'dragonball'
|
36
|
-
})
|
37
|
-
end
|
38
|
-
|
39
|
-
def physical_servers
|
40
|
-
[availability_zone(1), availability_zone(2)]
|
41
|
-
end
|
42
|
-
|
43
|
-
def availability_zone(idx)
|
44
|
-
name = "ap-notrheast-1" + ("a".ord - 1 + idx).chr
|
45
|
-
Tengine::Resource::PhysicalServer.find_or_create_by_name!(
|
46
|
-
:provider_id => provider.id,
|
47
|
-
:name => name, :provided_id => name, :status => "available")
|
48
|
-
end
|
49
|
-
|
50
|
-
def virtual_server_images
|
51
|
-
[
|
52
|
-
hadoop_image,
|
53
|
-
mysql_image,
|
54
|
-
rails_image
|
55
|
-
]
|
56
|
-
end
|
57
|
-
|
58
|
-
def hadoop_image
|
59
|
-
Tengine::Resource::VirtualServerImage.find_or_create_by_name!(
|
60
|
-
:provider_id => provider.id,
|
61
|
-
:name => "hadoop_image1",
|
62
|
-
:provided_id => "ami-10000001")
|
63
|
-
end
|
64
|
-
|
65
|
-
def mysql_image
|
66
|
-
Tengine::Resource::VirtualServerImage.find_or_create_by_name!(
|
67
|
-
:provider_id => provider.id,
|
68
|
-
:name => "mysql_image1",
|
69
|
-
:provided_id => "ami-10000002")
|
70
|
-
end
|
71
|
-
|
72
|
-
def rails_image
|
73
|
-
Tengine::Resource::VirtualServerImage.find_or_create_by_name!(
|
74
|
-
:provider_id => provider.id,
|
75
|
-
:name => "rails_image1",
|
76
|
-
:provided_id => "ami-10000003")
|
77
|
-
end
|
78
|
-
|
79
|
-
def virtual_server_types
|
80
|
-
[
|
81
|
-
m1_small,
|
82
|
-
m1_large,
|
83
|
-
m1_xlarge,
|
84
|
-
t1_micro,
|
85
|
-
]
|
86
|
-
end
|
87
|
-
|
88
|
-
def m1_small
|
89
|
-
Tengine::Resource::VirtualServerType.find_or_create_by(:provider_id => provider.id,
|
90
|
-
:caption => "m1.small", :provided_id => "m1.small", :cpu_cores => 1, :memory_size => 17 * (10 ** 8))
|
91
|
-
end
|
92
|
-
|
93
|
-
def m1_large
|
94
|
-
Tengine::Resource::VirtualServerType.find_or_create_by(:provider_id => provider.id,
|
95
|
-
:caption => "m1.large", :provided_id => "m1.large", :cpu_cores => 4, :memory_size => 75 * (10 ** 8))
|
96
|
-
end
|
97
|
-
|
98
|
-
def m1_xlarge
|
99
|
-
Tengine::Resource::VirtualServerType.find_or_create_by(:provider_id => provider.id,
|
100
|
-
:caption => "m1.xlarge", :provided_id => "m1.xlarge", :cpu_cores => 8, :memory_size => 15 * (10 ** 9))
|
101
|
-
end
|
102
|
-
|
103
|
-
def t1_micro
|
104
|
-
Tengine::Resource::VirtualServerType.find_or_create_by(:provider_id => provider.id,
|
105
|
-
:caption => "t1.micro", :provided_id => "t1.micro", :cpu_cores => 2, :memory_size => 613 * (10 ** 6))
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
def virtual_servers
|
110
|
-
[
|
111
|
-
hadoop_master_node,
|
112
|
-
hadoop_slave_node(1),
|
113
|
-
hadoop_slave_node(2),
|
114
|
-
hadoop_slave_node(3),
|
115
|
-
mysql_master,
|
116
|
-
mysql_slave(1),
|
117
|
-
mysql_slave(2),
|
118
|
-
rails_server(1)
|
119
|
-
]
|
120
|
-
end
|
121
|
-
|
122
|
-
def hadoop_master_node
|
123
|
-
Tengine::Resource::VirtualServer.find_or_create_by_name!(
|
124
|
-
:addresses => hostnames_and_ips(1),
|
125
|
-
:provider_id => provider.id,
|
126
|
-
:provided_image_id => hadoop_image.provided_id,
|
127
|
-
:host_server_id => availability_zone(1).id, :status => "available",
|
128
|
-
:name => "hadoop_master_node", :provided_id => "i-10000001")
|
129
|
-
end
|
130
|
-
|
131
|
-
def hadoop_slave_node(idx)
|
132
|
-
Tengine::Resource::VirtualServer.find_or_create_by_name!(
|
133
|
-
:addresses => hostnames_and_ips(idx + 10),
|
134
|
-
:provider_id => provider.id,
|
135
|
-
:provided_image_id => hadoop_image.provided_id,
|
136
|
-
:host_server_id => availability_zone(1).id, :status => "available",
|
137
|
-
:name => "hadoop_slave_node#{idx}", :provided_id => "i-1000001#{idx}")
|
138
|
-
end
|
139
|
-
|
140
|
-
def mysql_master
|
141
|
-
Tengine::Resource::VirtualServer.find_or_create_by_name!(
|
142
|
-
:addresses => hostnames_and_ips(20),
|
143
|
-
:provider_id => provider.id,
|
144
|
-
:provided_image_id => mysql_image.provided_id,
|
145
|
-
:host_server_id => availability_zone(1).id, :status => "available",
|
146
|
-
:name => "mysql_master", :provided_id => "i-10000020")
|
147
|
-
end
|
148
|
-
|
149
|
-
def mysql_slave(idx)
|
150
|
-
Tengine::Resource::VirtualServer.find_or_create_by_name!(
|
151
|
-
:addresses => hostnames_and_ips(idx + 20),
|
152
|
-
:provider_id => provider.id,
|
153
|
-
:provided_image_id => mysql_image.provided_id,
|
154
|
-
:host_server_id => availability_zone(1).id, :status => "available",
|
155
|
-
:name => "mysql_slave#{idx}", :provided_id => "i-1000002#{idx}")
|
156
|
-
end
|
157
|
-
|
158
|
-
def rails_server(idx)
|
159
|
-
Tengine::Resource::VirtualServer.find_or_create_by_name!(
|
160
|
-
:addresses => hostnames_and_ips(idx + 30),
|
161
|
-
:provider_id => provider.id,
|
162
|
-
:provided_image_id => rails_image.provided_id,
|
163
|
-
:host_server_id => availability_zone(1).id, :status => "available",
|
164
|
-
:name => "rails#{idx}", :provided_id => "i-1000003#{idx}")
|
165
|
-
end
|
166
|
-
|
167
|
-
private
|
168
|
-
def hostnames_and_ips(idx)
|
169
|
-
{
|
170
|
-
'dns_name' => "ec2-184-72-20-#{idx}.ap-northeast-1.compute.amazonaws.com",
|
171
|
-
'ip_address' => "184.72.20.#{idx}",
|
172
|
-
'private_dns_name' => "ip-10-162-153-#{idx}.ap-northeast-1.compute.internal",
|
173
|
-
'private_ip_address' => "10.162.153.#{idx}",
|
174
|
-
}
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
data/spec/mongoid.yml
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
defaults: &defaults
|
2
|
-
# mongoid defaults for configurable settings
|
3
|
-
# autocreate_indexes: false
|
4
|
-
# allow_dynamic_fields: true
|
5
|
-
# include_root_in_json: false
|
6
|
-
# parameterize_keys: true
|
7
|
-
persist_in_safe_mode: true
|
8
|
-
# raise_not_found_error: true
|
9
|
-
# reconnect_time: 3
|
10
|
-
logger: false
|
11
|
-
|
12
|
-
development:
|
13
|
-
<<: *defaults
|
14
|
-
host: localhost
|
15
|
-
database: tengine_resource_development
|
16
|
-
|
17
|
-
test:
|
18
|
-
<<: *defaults
|
19
|
-
host: localhost
|
20
|
-
database: tengine_resource_test
|
21
|
-
autocreate_indexes: true
|
22
|
-
|
23
|
-
# set these environment variables on your prod server
|
24
|
-
production:
|
25
|
-
<<: *defaults
|
26
|
-
host: <%= ENV['MONGOID_HOST'] %>
|
27
|
-
port: <%= ENV['MONGOID_PORT'] %>
|
28
|
-
username: <%= ENV['MONGOID_USERNAME'] %>
|
29
|
-
password: <%= ENV['MONGOID_PASSWORD'] %>
|
30
|
-
database: <%= ENV['MONGOID_DATABASE'] %>
|
31
|
-
# slaves:
|
32
|
-
# - host: slave1.local
|
33
|
-
# port: 27018
|
34
|
-
# - host: slave2.local
|
35
|
-
# port: 27019
|
data/spec/mongoid_en.yml
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
mongoid:
|
3
|
-
errors:
|
4
|
-
messages:
|
5
|
-
taken:
|
6
|
-
is already taken
|
7
|
-
document_not_found:
|
8
|
-
Document not found for class %{klass} with id(s) %{identifiers}.
|
9
|
-
invalid_database:
|
10
|
-
"Database should be a Mongo::DB, not %{name}."
|
11
|
-
invalid_options:
|
12
|
-
"Invalid option :%{invalid} provided to relation :%{name}. Valid options
|
13
|
-
are: %{valid}."
|
14
|
-
invalid_type:
|
15
|
-
Field was defined as a(n) %{klass}, but received a %{other} with
|
16
|
-
the value %{value}.
|
17
|
-
unsupported_version:
|
18
|
-
MongoDB %{version} not supported, please upgrade
|
19
|
-
to %{mongo_version}.
|
20
|
-
validations:
|
21
|
-
Validation failed - %{errors}.
|
22
|
-
invalid_collection:
|
23
|
-
Access to the collection for %{klass} is not allowed since it
|
24
|
-
is an embedded document, please access a collection from
|
25
|
-
the root document.
|
26
|
-
invalid_field:
|
27
|
-
Defining a field named %{name} is not allowed. Do not define
|
28
|
-
fields that conflict with Mongoid internal attributes or method
|
29
|
-
names. Use Mongoid.destructive_fields to see what names this includes.
|
30
|
-
too_many_nested_attribute_records:
|
31
|
-
Accepting nested attributes for %{association} is limited
|
32
|
-
to %{limit} records.
|
33
|
-
embedded_in_must_have_inverse_of:
|
34
|
-
Options for embedded_in association must include inverse_of.
|
35
|
-
dependent_only_references_one_or_many:
|
36
|
-
The dependent => destroy|delete option that was supplied
|
37
|
-
is only valid on references_one or references_many associations.
|
38
|
-
association_cant_have_inverse_of:
|
39
|
-
Defining an inverse_of on this association is not allowed. Only
|
40
|
-
use this option on embedded_in or references_many as array.
|
41
|
-
calling_document_find_with_nil_is_invalid:
|
42
|
-
Calling Document#find with nil is invalid
|
43
|
-
unsaved_document:
|
44
|
-
"You cannot call create or create! through a relational association
|
45
|
-
relation (%{document}) who's parent (%{base}) is not already saved."
|
46
|
-
mixed_relations:
|
47
|
-
Referencing a(n) %{embedded} document from the %{root} document via a
|
48
|
-
relational association is not allowed since the %{embedded} is embedded.
|
data/spec/spec_helper.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
ENV["RACK_ENV"] ||= "test" # Mongoid.load!で参照しています
|
3
|
-
|
4
|
-
require 'simplecov'
|
5
|
-
SimpleCov.start if ENV["COVERAGE"]
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
-
require 'rspec'
|
10
|
-
# require 'factory_girl'
|
11
|
-
|
12
|
-
require 'tengine_resource'
|
13
|
-
require 'mongoid'
|
14
|
-
Mongoid.load!(File.expand_path('mongoid.yml', File.dirname(__FILE__)))
|
15
|
-
Mongoid.database.connection.drop_database(Mongoid.database.name)
|
16
|
-
|
17
|
-
I18n.backend = I18n::Backend::Simple.new
|
18
|
-
I18n.backend.load_translations(File.expand_path('mongoid_en.yml', File.dirname(__FILE__)))
|
19
|
-
|
20
|
-
# Requires supporting files with custom matchers and macros, etc,
|
21
|
-
# in ./support/ and its subdirectories.
|
22
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
23
|
-
|
24
|
-
# Requires fixtures files in ./fixtures/ and its subdirectories.
|
25
|
-
Dir["#{File.dirname(__FILE__)}/fixtures/**/*.rb"].each {|f| require f}
|
26
|
-
|
27
|
-
Tengine::Core::MethodTraceable.disabled = true
|
28
|
-
require 'logger'
|
29
|
-
log_path = File.expand_path("../tmp/log/test.log", File.dirname(__FILE__))
|
30
|
-
Tengine.logger = Logger.new(log_path)
|
31
|
-
Tengine.logger.level = Logger::DEBUG
|
32
|
-
Tengine::Core.stdout_logger = Logger.new(log_path)
|
33
|
-
Tengine::Core.stdout_logger.level = Logger::DEBUG
|
34
|
-
Tengine::Core.stderr_logger = Logger.new(log_path)
|
35
|
-
Tengine::Core.stderr_logger.level = Logger::DEBUG
|
36
|
-
|
37
|
-
Tengine::Core::Kernel.event_exception_reporter = :raise_all
|
38
|
-
|
39
|
-
RSpec.configure do |config|
|
40
|
-
# config.include Factory::Syntax::Methods
|
41
|
-
end
|
42
|
-
|
43
|
-
# Dir["#{File.expand_path('factories', File.dirname(__FILE__))}/**/*.rb"].each {|f| require f}
|
data/spec/support/ec2.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
def setup_ec2_images
|
3
|
-
klass = Tengine::Resource::VirtualServerImage
|
4
|
-
Tengine::Resource::VirtualServerImage.delete_all
|
5
|
-
result = [
|
6
|
-
# us-west-1
|
7
|
-
klass.create!(:name => "ami-10101010mysql", :provided_id => "ami-10101000", :description => "MySQL server"), # *1 同じAMI ID
|
8
|
-
klass.create!(:name => "ami-10101010rails", :provided_id => "ami-10101000", :description => "Rails App Server"), # *1 同じAMI ID
|
9
|
-
klass.create!(:name => "ami-10102000" , :provided_id => "ami-10102000", :description => "Nginx Server"),
|
10
|
-
# us-west-2
|
11
|
-
klass.create!(:name => "ami-10103000" , :provided_id => "ami-10103000", :description => "APP1 servers"),
|
12
|
-
klass.create!(:name => "ami-10104000" , :provided_id => "ami-10104000", :description => "APP2 servers"),
|
13
|
-
]
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
def setup_ec2_stub(images = setup_ec2_images)
|
18
|
-
mock_ec2 = mock(:ec2)
|
19
|
-
mock_ec2.stub!(:describe_regions).and_return([
|
20
|
-
"eu-west-1", "us-east-1", "us-west-1", "ap-southeast-1"
|
21
|
-
])
|
22
|
-
mock_ec2.stub!(:describe_availability_zones).and_return([
|
23
|
-
{:region_name=>"us-west-1", :zone_name=>"us-west-1a", :zone_state=>"available"},
|
24
|
-
{:region_name=>"us-west-1", :zone_name=>"us-west-1b", :zone_state=>"available"},
|
25
|
-
])
|
26
|
-
mock_ec2.stub!(:describe_key_pairs).and_return([
|
27
|
-
{:aws_key_name=>"goku" , :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:97"},
|
28
|
-
{:aws_key_name=>"dev" , :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:98"},
|
29
|
-
{:aws_key_name=>"default", :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:99"},
|
30
|
-
])
|
31
|
-
mock_ec2.stub!(:describe_security_groups).and_return([
|
32
|
-
{ :aws_owner=>"892601002221", :aws_group_name=>"default", :aws_description=>"default group",
|
33
|
-
:aws_perms=>[{:owner=>"892601002221", :group=>"default"}, {:from_port=>"22", :to_port=>"22", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
|
34
|
-
{ :aws_owner=>"892601002221", :aws_group_name=>"hadoop-dev", :aws_description=>"for developmewnt with hadoop",
|
35
|
-
:aws_perms=>[{:from_port=>"80", :to_port=>"80", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
|
36
|
-
{ :aws_owner=>"892601002221", :aws_group_name=>"ruby-dev", :aws_description=>"for developmewnt with ruby",
|
37
|
-
:aws_perms=>[{:from_port=>"80", :to_port=>"80", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
|
38
|
-
])
|
39
|
-
mock_ec2.stub!(:describe_images).
|
40
|
-
with(images.map(&:provided_id).uniq).
|
41
|
-
and_return([
|
42
|
-
{
|
43
|
-
:aws_id=>images[0].provided_id, # "ami-012b7a44",
|
44
|
-
:aws_architecture=>"i386", :root_device_type=>"instance-store",
|
45
|
-
:aws_kernel_id=>"aki-f70657b2", :aws_ramdisk_id=>"ari-ff0657ba",
|
46
|
-
:root_device_name=>"/dev/sda5",
|
47
|
-
:aws_location=>"zeus-technology-us-west-1/zeus-load-balancer-60r2-v2-100tps-100mbps-32bit.manifest.xml",
|
48
|
-
:aws_image_type=>"machine", :aws_state=>"available",
|
49
|
-
:aws_owner=>"106430830294", :aws_is_public=>true,
|
50
|
-
:aws_product_codes=>["F6F58AC9"]
|
51
|
-
},
|
52
|
-
{
|
53
|
-
:aws_id=>images[2].provided_id, # "ami-05530240",
|
54
|
-
:aws_architecture=>"x86_64", :root_device_type=>"ebs",
|
55
|
-
:aws_kernel_id=>"aki-6f3c6d2a", :aws_ramdisk_id=>"ari-693c6d2c",
|
56
|
-
:root_device_name=>"/dev/sda1",
|
57
|
-
:aws_location=>"063491364108/ubuntu-8.04.3-hardy-server-amd64-20091130",
|
58
|
-
:aws_image_type=>"machine",
|
59
|
-
:description=>"Ubuntu 8.04.3 Hardy server amd64 20091130", :aws_state=>"available",
|
60
|
-
:aws_owner=>"063491364108", :aws_is_public=>true,
|
61
|
-
:block_device_mappings=>[{:ebs_volume_size=>15, :ebs_delete_on_termination=>true, :device_name=>"/dev/sda1", :ebs_snapshot_id=>"snap-ea54fb82"}],
|
62
|
-
:name=>"ubuntu-8.04.3-hardy-server-amd64-20091130"
|
63
|
-
}
|
64
|
-
])
|
65
|
-
|
66
|
-
mock_ec2.stub!(:describe_images_by_owner).with("amazon").and_return([
|
67
|
-
# kernels = conn.describe_images_by_owner('amazon').select{|i| i[:aws_image_type] == "kernel"}
|
68
|
-
# kernels.select{|k| h[:aws_architecture] == "i386"} の中から抜粋
|
69
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/vmlinuz-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-00000000", :aws_architecture=>"i386"},
|
70
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/vmlinuz-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-11111111", :aws_architecture=>"i386"},
|
71
|
-
# kernels.select{|k| h[:aws_architecture] == "x86_64"} の中から抜粋
|
72
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/ec2-vmlinuz-2.6.21.7-2.fc8xen.x86_64.manifest.xml", :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-22222222", :aws_architecture=>"x86_64"},
|
73
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/pv-grub-hd0-V1.01-x86_64.gz.manifest.xml" , :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-33333333", :aws_architecture=>"x86_64"},
|
74
|
-
|
75
|
-
# ramdisks = conn.describe_images_by_owner('amazon').select{|i| i[:aws_image_type] == "ramdisk"}
|
76
|
-
# ramdisks.select{|k| h[:aws_architecture] == "i386"} の中から抜粋
|
77
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/initrd-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"ari-00000000", :aws_architecture=>"i386"},
|
78
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/initrd-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"ari-11111111", :aws_architecture=>"i386"},
|
79
|
-
# ramdisks.select{|k| h[:aws_architecture] == "x86_64"} の中から抜粋
|
80
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/ec2-initrd-2.6.21.7-2.fc8xen.x86_64.manifest.xml" , :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"ari-22222222", :aws_architecture=>"x86_64"},
|
81
|
-
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/initrd-2.6.21.7-2.ec2.v1.1.fc8xen-x86_64-lvm-rootVG-rootFS.manifest.xml", :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :name=>"initrd-2.6.21.7-2.ec2.v1.1.fc8xen-x86_64-lvm-rootVG-rootFS", :image_owner_alias=>"amazon", :aws_id=>"ari-33333333", :aws_architecture=>"x86_64"},
|
82
|
-
])
|
83
|
-
|
84
|
-
# http://rightscale.rubyforge.org/right_aws_gem_doc/classes/RightAws/Ec2.html#M000285
|
85
|
-
mock_ec2.stub!(:run_instances).with("ami-e444444d", 1, 1, ["my_awesome_group"], "my_awesome_key", "", nil, "m1.small", "aki-9905e0f0", "ari-8605e0ef", "us-east-1b", nil).and_return([
|
86
|
-
{
|
87
|
-
:aws_image_id => "ami-e444444d",
|
88
|
-
:aws_reason => "",
|
89
|
-
:aws_state_code => "0",
|
90
|
-
:aws_owner => "000000000888",
|
91
|
-
:aws_instance_id => "i-123f1234",
|
92
|
-
:aws_reservation_id => "r-aabbccdd",
|
93
|
-
:aws_state => "pending",
|
94
|
-
:dns_name => "",
|
95
|
-
:ssh_key_name => "my_awesome_key",
|
96
|
-
:aws_groups => ["my_awesome_group"],
|
97
|
-
:private_dns_name => "",
|
98
|
-
:aws_instance_type => "m1.small",
|
99
|
-
:aws_launch_time => "2008-1-1T00:00:00.000Z",
|
100
|
-
:aws_ramdisk_id => "ari-8605e0ef",
|
101
|
-
:aws_kernel_id => "aki-9905e0f0",
|
102
|
-
:ami_launch_index => "0",
|
103
|
-
:aws_availability_zone => "us-east-1b",
|
104
|
-
}
|
105
|
-
])
|
106
|
-
|
107
|
-
# http://rightscale.rubyforge.org/right_aws_gem_doc/classes/RightAws/Ec2.html#M000287
|
108
|
-
mock_ec2.stub!(:terminate_instances).with(['i-f222222d','i-f222222e']).and_return(
|
109
|
-
[{:aws_shutdown_state => "shutting-down",
|
110
|
-
:aws_instance_id => "i-f222222d",
|
111
|
-
:aws_shutdown_state_code => 32,
|
112
|
-
:aws_prev_state => "running",
|
113
|
-
:aws_prev_state_code => 16},
|
114
|
-
{:aws_shutdown_state => "shutting-down",
|
115
|
-
:aws_instance_id => "i-f222222e",
|
116
|
-
:aws_shutdown_state_code => 32,
|
117
|
-
:aws_prev_state => "running",
|
118
|
-
:aws_prev_state_code => 16}]
|
119
|
-
)
|
120
|
-
mock_ec2.stub!(:terminate_instances).with(['i-f222222d']).and_return(
|
121
|
-
[{:aws_shutdown_state => "shutting-down",
|
122
|
-
:aws_instance_id => "i-f222222d",
|
123
|
-
:aws_shutdown_state_code => 32,
|
124
|
-
:aws_prev_state => "running",
|
125
|
-
:aws_prev_state_code => 16},]
|
126
|
-
)
|
127
|
-
|
128
|
-
mock_ec2
|
129
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# 使い方
|
3
|
-
# テスト実行時に 環境変数MONGO_INDEX_KEY_LOGにログの出力先のファイル名を指定しておくと、
|
4
|
-
# そこにmongoに対してどんな検索条件やソート、ヒントなどをどのように指定しているのかを出力できます
|
5
|
-
#
|
6
|
-
# この出力された結果のファイルに対して sort と uniq をかけることにより、どんなインデックスを
|
7
|
-
# 作れば良いのか判断する材料となります。
|
8
|
-
#
|
9
|
-
# export MONGO_INDEX_KEY_LOG=$HOME/tmp/mongo_index_key.log
|
10
|
-
# cd tenigne_core && rake spec
|
11
|
-
# cd tenigne_resource && rake spec
|
12
|
-
# cd tenigne_job && rake spec
|
13
|
-
# cd tenigne_console && rake spec
|
14
|
-
# cd $HOME/tmp
|
15
|
-
# cat mongo_index_key.log | sort | uniq > mongo_index_key_summary.log
|
16
|
-
#
|
17
|
-
# これで $HOME/tmp/mongo_index_key_summary.log にどのようなキーが使われているのかがまとめられます
|
18
|
-
#
|
19
|
-
if ENV['MONGO_INDEX_KEY_LOG']
|
20
|
-
file_path = File.expand_path(ENV['MONGO_INDEX_KEY_LOG'])
|
21
|
-
STDOUT.puts("MONGO_INDEX_KEY_LOG enable logging key infomation for index to #{file_path}")
|
22
|
-
|
23
|
-
Mongo::Collection.class_eval do
|
24
|
-
def index_key_log_file
|
25
|
-
unless defined?(@@index_key_log_file)
|
26
|
-
file_path = File.expand_path(ENV['MONGO_INDEX_KEY_LOG'])
|
27
|
-
@@index_key_log_file = File.open(file_path, "a")
|
28
|
-
end
|
29
|
-
@@index_key_log_file
|
30
|
-
end
|
31
|
-
|
32
|
-
def find_with_index_key_log(selector={}, opts={}, &block)
|
33
|
-
result = find_without_index_key_log(selector, opts, &block)
|
34
|
-
index_key_log_file.puts("#{self.name}.find({#{_hash_keys_(selector)}}, {#{_hash_keys_(opts.dup)}}): #{_explain_summary_(result.explain)}")
|
35
|
-
result
|
36
|
-
end
|
37
|
-
alias_method :find_without_index_key_log, :find
|
38
|
-
alias_method :find, :find_with_index_key_log
|
39
|
-
|
40
|
-
|
41
|
-
def find_and_modify_with_index_key_log(opts={}, &block)
|
42
|
-
o = opts.dup
|
43
|
-
query = o.delete(:query)
|
44
|
-
index_key_log_file.puts("#{self.name}.find_and_modify({#{_hash_keys_(query)}}, {#{_hash_keys_(o)}})")
|
45
|
-
find_and_modify_without_index_key_log(opts, &block)
|
46
|
-
end
|
47
|
-
alias_method :find_and_modify_without_index_key_log, :find_and_modify
|
48
|
-
alias_method :find_and_modify, :find_and_modify_with_index_key_log
|
49
|
-
|
50
|
-
def _hash_keys_(hash)
|
51
|
-
res = []
|
52
|
-
[:sort, :hint, :limit].each do |key|
|
53
|
-
if value = hash.delete(key)
|
54
|
-
res << "#{key.inspect} => #{value.inspect}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
res += hash.keys.map(&:inspect)
|
58
|
-
res.join(',')
|
59
|
-
end
|
60
|
-
|
61
|
-
def _explain_summary_(hash)
|
62
|
-
case cursor = hash['cursor']
|
63
|
-
when /^BtreeCursor/ then
|
64
|
-
res = []
|
65
|
-
%w[cursor].each do |key|
|
66
|
-
if value = hash.delete(key)
|
67
|
-
res << "#{key.inspect} => #{value.inspect}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
res += hash.keys.map(&:inspect)
|
71
|
-
"{" << res.join(',') << "}"
|
72
|
-
else
|
73
|
-
res = []
|
74
|
-
res << "'cursor' => #{hash.delete('cursor').inspect}"
|
75
|
-
{"nscanned" => 1, "nscannedObjects" => 1, "n" => 1, "millis" => 0, "nYields"=>0, "nChunkSkips"=>0 }.each do |key, border|
|
76
|
-
if value = hash.delete(key)
|
77
|
-
if value > border
|
78
|
-
res << "#{key.inspect} => '>#{border.inspect}'"
|
79
|
-
else
|
80
|
-
res << "#{key.inspect} => #{value.inspect}"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
res += hash.keys.map(&:inspect)
|
85
|
-
"{" << res.join(',') << "}"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|