root/lang/perl/Net-Amazon-HadoopEC2/trunk/lib/Net/Amazon/HadoopEC2.pm @ 21796

Revision 21796, 4.9 kB (checked in by lopnor, 5 years ago)

additional user_data support

Line 
1package Net::Amazon::HadoopEC2;
2use Moose;
3use Net::Amazon::EC2;
4use Net::Amazon::HadoopEC2::Cluster;
5use Net::Amazon::HadoopEC2::Group;
6our $VERSION = '0.01';
7
8has aws_access_key_id => ( is => 'ro', isa => 'Str', required => 1 );
9has aws_secret_access_key => ( is => 'ro', isa => 'Str', required => 1 );
10has aws_account_id => ( is => 'ro', isa => 'Str', required => 1 );
11
12has _ec2 => (
13    is => 'ro',
14    isa => 'Net::Amazon::EC2',
15    required => 1,
16    lazy => 1,
17    default => sub {
18        Net::Amazon::EC2->new(
19            AWSAccessKeyId => $_[0]->aws_access_key_id,
20            SecretAccessKey => $_[0]->aws_secret_access_key,
21        );
22    }
23);
24
25no Moose;
26
27sub launch_cluster {
28    my ($self, $args) = @_;
29    my $name = delete $args->{name};
30    my $key_file = delete $args->{key_file};
31    my $image_id = delete $args->{image_id};
32    my $slaves = delete $args->{slaves};
33    my $key_name = delete $args->{key_name} || 'gsg-keypair';
34    Net::Amazon::HadoopEC2::Group->new(
35        {
36            _ec2           => $self->_ec2,
37            name           => $name,
38            aws_account_id => $self->aws_account_id,
39        }
40    )->ensure or return;
41    my $cluster = Net::Amazon::HadoopEC2::Cluster->new(
42        {
43            _ec2         => $self->_ec2,
44            name         => $name,
45            key_file     => $key_file,
46            %{$args},
47        }
48    );
49    $cluster->launch_cluster(
50        {
51            slaves => defined $slaves ? $slaves : 2 ,
52            image_id => $image_id,
53            key_name => $key_name,
54        }
55    ) or return;
56    return $cluster;
57}
58
59sub find_cluster {
60    my ($self, $args) = @_;
61    my $name = delete $args->{name};
62    my $key_file = delete $args->{key_file};
63    Net::Amazon::HadoopEC2::Group->new(
64        {
65            _ec2           => $self->_ec2,
66            name           => $name,
67            aws_account_id => $self->aws_account_id,
68        }
69    )->find or return;
70    my $cluster = Net::Amazon::HadoopEC2::Cluster->new(
71        {
72            _ec2 => $self->_ec2,
73            name => $name,
74            key_file => $key_file,
75        }
76    );
77    $cluster->find_cluster or return;
78    return $cluster;
79}
80
811;
82
83=pod
84
85=head1 NAME
86
87Net::Amazon::HadoopEC2 - perl interface to work with Hadoop-EC2
88
89=head1 SYNOPSYS
90
91    my $hadoop = Net::Amazon::HadoopEC2->new(
92        {
93            aws_account_id => 'your_aws_account',
94            aws_access_key_id => 'your_key',
95            aws_secret_access_key => 'your_secret',
96        }
97    );
98
99    my $cluster = $hadoop->launch_cluster(
100        {
101            name           => 'hadoop',
102            image_id       => 'ami-b0fe1ad9',
103            slaves         => 2,
104        }
105    );
106
107    my $result = $cluster->execute({command => 'ls'});
108    warn $result->stdout;
109
110    $cluster->terminate_cluster;
111
112=head1 DESCRIPTION
113
114This module is perl interface to work with Hadoop-EC2.
115
116=head1 METHODS
117
118=head2 new($hashref)
119
120Constructor. Arguments are:
121
122=over 4
123
124=item aws_access_key_id (required)
125
126Your aws access key.
127
128=item aws_secret_access_key (required)
129
130Your aws secret key.
131
132=item aws_account_id (required)
133
134Your aws account id.
135
136=back
137
138=head2 launch_cluster($hashref)
139
140launchs hadoop-ec2 cluster. Returns L<Net::Amazon::HadoopEC2::Cluster> instance
141if launch process succeeded. Arguments are:
142
143=over 4
144
145=item name (required)
146
147Name of the cluster.
148
149=item image_id (required)
150
151The image id (ami) of the cluster.
152
153=item key_name (optional)
154
155The key name to use when launching cluster. the default is 'gsg-keypair'.
156
157=item key_file (required)
158
159Location of the private key file associated with key_name.
160
161=item slaves (optional)
162
163The number of slaves. The default is 2.
164
165=item retry (optional)
166
167Boolean whether EC2 api request retry or not. The default is 1.
168
169=item map_tasks (optional)
170
171MAX_MAP_TASKS to pass to the instances when boot. The default is 2.
172
173=item reduce_tasks (optional)
174
175MAX_REDUCE_TASKS to pass to the instances when boot. The default is 2.
176
177=item compress (optional)
178
179COMPRESS to pass to the instances when boot. The default is 1.
180
181=back
182
183=head2 find_cluster($hashref)
184
185finds running cluster satisfying the conditions given by the arguments.
186Returns L<Net::Amazon::HadoopEC2::Cluster> instance if found.
187Arguments are:
188
189=over 4
190
191=item name (required)
192
193Name of the cluster.
194
195=item key_file (required)
196
197Location of the private key file to login to the cluster instances.
198
199=back
200
201=head1 AUTHOR
202
203Nobuo Danjou <nobuo.danjou@gmail.com>
204
205=head1 SEE ALSO
206
207L<Net::Amazon::HadoopEC2>
208
209L<Net::Amazon::EC2>
210
211Hadoop - L<http://hadoop.apache.org/>
212
213Hadoop Wiki, AmazonEC2 L<http://wiki.apache.org/hadoop/AmazonEC2>
214
215=head1 REPOSITORY
216
217  svn co http://svn.coderepos.org/share/lang/perl/Net-Amazon-HadoopEC2/trunk Net-Amazon-HadoopEC2
218
219The svn repository of this module is hosted at L<http://coderepos.org/share/>.
220Patches and commits are welcome.
221
222=head1 LICENSE
223
224This library is free software; you can redistribute it and/or modify
225it under the same terms as Perl itself.
226
227=cut
Note: See TracBrowser for help on using the browser.