Net-Amazon-HadoopEC2

 view release on metacpan or  search on metacpan

lib/Net/Amazon/HadoopEC2/Cluster.pm  view on Meta::CPAN

}

sub terminate_slaves {
    my ($self, $args) = @_;
    my $existing = scalar @{$self->slave_instances};
    my $count = $args->{slaves} || $existing;
    $count = $existing if $count > $existing;
    my @instances = map { $_->instance_id } @{$self->slave_instances}[ 0 .. $count - 1 ];
    my $result = $self->_ec2->terminate_instances(
        InstanceId => [ @instances ],
    );
    if (ref $result eq 'Net::Amazon::EC2::Errors') {
        croak $result->errors->[0]->message;
    }
    $self->_find_slaves;
    return $result;
}

1;
__END__

=pod

=head1 NAME

Net::Amazon::HadoopEC2::Cluster - Representation of Hadoop-EC2 cluster

=head1 SYNOPSIS

    my $hadoop = Net::Amazon::HadoopEC2->new(
        {
            aws_account_id => 'my account',
            aws_access_key_id => 'my key',
            aws_secret_access_key => 'my secret',
        }
    );
    my $cluster = $hadoop->launch_cluster(
        {
            naem => 'hadoop-ec2-cluster',
            image_id => 'ami-b0fe1ad9' # hadoop-ec2 official image
            slaves => 2,
            key_name => 'gsg-keypair',
            key_file => "$ENV{HOME}/.ssh/id_rsa-gsg-keypair',
        }
    );
    $cluster->push_file(
        {
            files => ['map.pl', 'reduce.pl'],
            destination => '/root/',
        }
    );
    my $option = join(' ', qw(
            -mapper map.pl
            -reducer reduce.pl
            -file map.pl
            -file reduce.pl
        )
    );
    my $result = $cluster->execute(
        {
            command => "$hadoop jar $streaming $option",
        }
    );


=head1 DESCRIPTION

A class Representing Hadoop-EC2 cluster

=head1 METHODS

=head2 new

Constructor. Normally L<Net::Amazon::HadoopEC2> calls this 
so you won't need to think about this.

=head2 launch_cluster ($hashref)

Launches hadoop-ec2 cluster. Returns L<Net::Amazon::HadoopEC2::Cluster> instance itself
when succeeded.

=over 4

=item image_id (required)

The image id (ami) of the cluster.

=item key_name (optional)

The key name to use when launching cluster. the default is 'gsg-keypair'.

=item key_file (required)

Location of the private key file associated with key_name.

=item slaves (optional)

The number of slaves. The default is 2.

=back

=head2 find_cluster

Finds hadoop-ec2 cluster. Returns L<Net::Hadoop::EC2::Cluster> instance itself if found.

=head2 launch_slave ($hashref)

Launches hadoop-ec2 slave instance for this cluster. Returns L<Net::Hadoop::EC2::Cluster> instance itself
if succeeded. Arguments are:

=over 4

=item slaves (optional)

The number of slaves to launch. default is 1.

=back

=head2 terminate_cluster

Terminates all EC2 instances of this cluster. Returns L<Net::Amazon::EC2::TerminateInstancesResponse>



( run in 0.912 second using v1.01-cache-2.11-cpan-39bf76dae61 )