2
# Copyright 2009-2013 MongoDB, Inc.
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
20
package MongoDBTest::Orchestrator;
24
use MongoDBTest::Server;
30
use Types::Standard qw/Str HashRef/;
31
use Types::Path::Tiny qw/AbsFile/;
34
with 'MooseX::Role::Logger';
41
coerce => AbsFile->coercion,
54
my ($config) = YAML::XS::LoadFile($self->config_file);
63
sub _build_cluster_type {
65
return $self->config->{type};
75
return $self->config->{setName} // 'rs0';
83
default => sub { {} },
91
for my $server ( @{ $self->config->{mongod} } ) {
92
$self->_mongod_set->{$server->{name}} = MongoDBTest::Server->new(
94
default_args => $self->default_args,
101
sub list_mongod_set {
103
return values %{ $self->_mongod_set }
108
for my $server ( $self->list_mongod_set ) {
109
$self->_logger->info("starting $server");
111
$self->_logger->info("$server is up on port " . $server->port);
114
$self->rs_initiate if $self->is_replicaset;
120
for my $server ( $self->list_mongod_set ) {
121
next unless $server->is_alive;
122
$self->_logger->info("stopping $server");
129
my $uri = "mongodb://" . join(",", map { $_->hostname . ":" . $_->port } $self->list_mongod_set);
135
my $default = $self->is_replicaset ? "--replSet " . $self->rs_name . " " : "";
136
$default .= $self->config->{default_args} if exists $self->config->{default_args};
142
return $self->cluster_type eq 'replicaset';
147
my ($first) = $self->list_mongod_set;
150
sort map {; { host => $_->as_host_port } } $self->list_mongod_set
153
for my $i (0 .. $#$members) {
154
$members->[$i]{_id} = $i;
158
_id => $self->rs_name,
162
my $client = MongoDB::MongoClient->new( host => $first->as_uri );
163
$client->get_database("admin")->run_command({replSetInitiate => $rs_config});
165
$self->_logger->debug("waiting for master");
167
until ( eval { MongoDB::MongoClient->new( host => $self->as_uri, find_master => 1 ) } ) {
169
$self->_logger->debug("waiting for master")