Permalink
Browse files

Merge pull request #856

  • Loading branch information...
jmikola committed Jun 21, 2018
2 parents d08b54e + d4c2e33 commit 4a56dfe57da17f48beaa16bca7c76519def2baaa
Showing with 37 additions and 18 deletions.
  1. +3 −3 scripts/presets/replicaset-30.json
  2. +1 −1 scripts/presets/standalone-30.json
  3. +33 −14 scripts/start-servers.php
@@ -11,7 +11,7 @@
"journal": true,
"nssize": 1,
"port": 3100,
- "bind_ip": "0.0.0.0,::",
+ "bind_ip": "::,0.0.0.0",
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
@@ -33,7 +33,7 @@
"journal": true,
"nssize": 1,
"port": 3101,
- "bind_ip": "0.0.0.0,::",
+ "bind_ip": "::,0.0.0.0",
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
@@ -55,7 +55,7 @@
"journal": true,
"nssize": 1,
"port": 3102,
- "bind_ip": "0.0.0.0,::",
+ "bind_ip": "::,0.0.0.0",
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
@@ -9,7 +9,7 @@
"journal": true,
"nssize": 1,
"port": 2700,
- "bind_ip": "0.0.0.0,::",
+ "bind_ip": "::,0.0.0.0",
"smallfiles": true,
"setParameter": {"enableTestCommands": 1}
},
View
@@ -47,11 +47,10 @@ function make_ctx($preset, $method = "POST") {
return $ctx;
}
-function failed($result) {
- echo "\n\n";
- echo join("\n", $result);
- printf("Last operation took: %.2f secs\n", lap());
- exit();
+function failed()
+{
+ printf("\nLast operation took: %.2f secs\n", lap());
+ exit(1);
}
function mo_http_request($uri, $context) {
@@ -60,17 +59,32 @@ function mo_http_request($uri, $context) {
$result = file_get_contents($uri, false, $context);
if ($result === false) {
- failed($http_response_header);
+ printf("HTTP request to %s failed:\n", $uri);
+ var_dump($http_response_header);
+ failed();
}
return $result;
}
+function json_decode_or_fail(...$args)
+{
+ $decoded = json_decode(...$args);
+
+ if ($decoded === NULL && json_last_error() !== JSON_ERROR_NONE) {
+ printf("\njson_decode() failed: %s\n", json_last_error_msg());
+ var_dump(func_get_arg(0));
+ failed();
+ }
+
+ return $decoded;
+}
+
printf("Cleaning out previous processes, if any ");
lap();
/* Remove all pre-existing ReplicaSets */
$replicasets = mo_http_request(getMOUri() . "/replica_sets", make_ctx(getMOPresetBase(), "GET"));
-$replicasets = json_decode($replicasets, true);
+$replicasets = json_decode_or_fail($replicasets, true);
foreach($replicasets["replica_sets"] as $replicaset) {
$uri = getMOUri() . "/replica_sets/" . $replicaset["id"];
mo_http_request($uri, make_ctx(getMOPresetBase(), "DELETE"));
@@ -79,7 +93,7 @@ function mo_http_request($uri, $context) {
echo " ";
/* Remove all pre-existing servers */
$servers = mo_http_request(getMOUri() . "/servers", make_ctx(getMOPresetBase(), "GET"));
-$servers = json_decode($servers, true);
+$servers = json_decode_or_fail($servers, true);
foreach($servers["servers"] as $server) {
$uri = getMOUri() . "/servers/" . $server["id"];
mo_http_request($uri, make_ctx(getMOPresetBase(), "DELETE"));
@@ -89,13 +103,15 @@ function mo_http_request($uri, $context) {
foreach($PRESETS["standalone"] as $preset) {
lap();
- $json = json_decode(file_get_contents($preset), true);
+ $json = json_decode_or_fail(file_get_contents($preset), true);
printf("Starting %-20s ... ", $json["id"]);
$result = mo_http_request(getMOUri() . "/servers", make_ctx(getMOPresetBase() . $preset));
- $decode = json_decode($result, true);
+ $decode = json_decode_or_fail($result, true);
+
if (!isset($decode["id"])) {
- failed($decode);
+ printf("\"id\" field not found in server response:\n%s\n", $decode);
+ failed();
}
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];
@@ -105,14 +121,17 @@ function mo_http_request($uri, $context) {
foreach($PRESETS["replicasets"] as $preset) {
lap();
- $json = json_decode(file_get_contents($preset), true);
+ $json = json_decode_or_fail(file_get_contents($preset), true);
printf("Starting %-20s ... ", $json["id"]);
$result = mo_http_request(getMOUri() . "/replica_sets", make_ctx(getMOPresetBase() . $preset));
- $decode = json_decode($result, true);
+ $decode = json_decode_or_fail($result, true);
+
if (!isset($decode["id"])) {
- failed($decode);
+ printf("\"id\" field not found in replica set response:\n%s\n", $decode);
+ failed();
}
+
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];
printf("'%s'\t(took: %.2f secs)\n", $SERVERS[$decode["id"]], lap());
}

0 comments on commit 4a56dfe

Please sign in to comment.