1
1
<?php
2
- require __DIR__ . "/ " . "../tests/utils/orchestration.php " ;
2
+ $ SERVERS = array ();
3
+ $ FILENAME = sys_get_temp_dir () . "/PHONGO-SERVERS.json " ;
3
4
4
5
function lap () {
5
6
static $ then = 0 ;
@@ -11,47 +12,132 @@ function lap() {
11
12
return $ ret ;
12
13
}
13
14
14
- if (!($ host = getenv ("MONGODB_ORCHESTRATION " ))) {
15
- $ host = "http://192.168.112.10:8889 " ;
15
+
16
+ if (!($ HOST = getenv ("MONGODB_ORCHESTRATION_HOST " ))) {
17
+ $ HOST = "192.168.112.10 " ;
18
+ }
19
+
20
+ if (!($ PORT = getenv ("MONGODB_ORCHESTRATION_PORT " ))) {
21
+ $ PORT = "8889 " ;
22
+ }
23
+
24
+ if (!($ BASE = getenv ("mongodb_orchestration_base " ))) {
25
+ $ BASE = "/phongo/ " ;
26
+ }
27
+
28
+ $ MO = "http:// $ HOST : $ PORT " ;
29
+
30
+ $ PRESETS = [
31
+ "standalone " => [
32
+ "scripts/presets/standalone.json " ,
33
+ "scripts/presets/standalone-ssl.json " ,
34
+ "scripts/presets/standalone-auth.json " ,
35
+ "scripts/presets/standalone-x509.json " ,
36
+ "scripts/presets/standalone-plain.json " ,
37
+ ],
38
+ "replicasets " => [
39
+ "scripts/presets/replicaset.json " ,
40
+ ],
41
+ ];
42
+
43
+ function make_ctx ($ preset , $ method = "POST " ) {
44
+ $ opts = [
45
+ "http " => [
46
+ "timeout " => 30 ,
47
+ "method " => $ method ,
48
+ "header " => "Accept: application/json \r\n" .
49
+ "Content-type: application/x-www-form-urlencoded " ,
50
+ "content " => json_encode (array ("preset " => $ preset )),
51
+ "ignore_errors " => true ,
52
+ ],
53
+ ];
54
+ $ ctx = stream_context_create ($ opts );
55
+ return $ ctx ;
16
56
}
17
57
18
- $ orch = new Mongo \Orchestration ($ host , getenv ("MONGODB_ORCHESTRATION_PRESETS_ROOT " ));
19
- if (!$ orch ->ping ()) {
20
- var_dump ($ host );
21
- system ("pwd " );
22
- system ("wget -O - $ host " );
23
- echo file_get_contents ("server.log " );
24
- echo "Failed starting MO \n" ;
25
- exit (3 );
58
+ function failed ($ result ) {
59
+ echo "\n\n" ;
60
+ echo join ("\n" , $ result );
61
+ exit ();
26
62
}
27
63
64
+
65
+
66
+ printf ("Cleaning out previous processes, if any " );
28
67
lap ();
29
- $ orch ->stopAll ();
68
+ /* Remove all pre-existing ReplicaSets */
69
+ $ replicasets = file_get_contents ($ MO . "/replica_sets " , false , make_ctx ($ BASE , "GET " ));
70
+ $ replicasets = json_decode ($ replicasets , true );
71
+ foreach ($ replicasets ["replica_sets " ] as $ replicaset ) {
72
+ $ uri = $ MO . "/replica_sets/ " . $ replicaset ["id " ];
73
+ file_get_contents ($ uri , false , make_ctx ($ BASE , "DELETE " ));
74
+ echo ". " ;
75
+ }
76
+ echo " " ;
77
+ /* Remove all pre-existing servers */
78
+ $ servers = file_get_contents ($ MO . "/servers " , false , make_ctx ($ BASE , "GET " ));
79
+ $ servers = json_decode ($ servers , true );
80
+ foreach ($ servers ["servers " ] as $ server ) {
81
+ $ uri = $ MO . "/servers/ " . $ server ["id " ];
82
+ file_get_contents ($ uri , false , make_ctx ($ BASE , "DELETE " ));
83
+ echo ". " ;
84
+ }
85
+ printf ("\t(took: %.2f secs) \n" , lap ());
86
+
87
+ foreach ($ PRESETS ["standalone " ] as $ preset ) {
88
+ lap ();
89
+ $ json = json_decode (file_get_contents ($ preset ), true );
90
+ printf ("Starting %-20s ... " , $ json ["id " ]);
30
91
31
- $ res = $ orch ->start ("standalone.json " );
32
- if ($ res ) {
33
- printf ("Standalone running on: \t\t\t(took: %.2f secs) \t%s \n" , lap (), $ res );
34
- } else {
35
- printf ("Failed starting standalone.json after %.2f secs \n" , lap ());
36
- exit (1 );
92
+ $ result = file_get_contents ($ MO . "/servers " , false , make_ctx ($ BASE . $ preset ));
93
+ $ decode = json_decode ($ result , true );
94
+ if (!isset ($ decode ["id " ])) {
95
+ failed ($ decode );
96
+ }
97
+
98
+ $ SERVERS [$ decode ["id " ]] = isset ($ decode ["mongodb_auth_uri " ]) ? $ decode ["mongodb_auth_uri " ] : $ decode ["mongodb_uri " ];
99
+ printf ("'%s' \t(took: %.2f secs) \n" , $ SERVERS [$ decode ["id " ]], lap ());
37
100
}
101
+ echo "--- \n" ;
102
+
103
+ foreach ($ PRESETS ["replicasets " ] as $ preset ) {
104
+ lap ();
105
+ $ json = json_decode (file_get_contents ($ preset ), true );
106
+ printf ("Starting %-20s ... " , $ json ["id " ]);
38
107
39
- if (getenv ("TRAVIS " )) {
40
- echo "Skipping special nodes on travis \n" ;
41
- exit ;
108
+ $ result = file_get_contents ($ MO . "/replica_sets " , false , make_ctx ($ BASE . $ preset ));
109
+ $ decode = json_decode ($ result , true );
110
+ if (!isset ($ decode ["id " ])) {
111
+ failed ($ decode );
112
+ }
113
+ $ SERVERS [$ decode ["id " ]] = isset ($ decode ["mongodb_auth_uri " ]) ? $ decode ["mongodb_auth_uri " ] : $ decode ["mongodb_uri " ];
114
+ printf ("'%s' \t(took: %.2f secs) \n" , $ SERVERS [$ decode ["id " ]], lap ());
42
115
}
43
- $ res = $ orch ->start ("standalone-ssl.json " );
44
- printf ("Standalone SSL running on: \t\t(took: %.2f secs) \t%s \n" , lap (), $ res );
45
116
46
- $ res = $ orch ->start ("standalone-auth.json " );
47
- printf ("Standalone Auth running on: \t\t(took: %.2f secs) \t%s \n" , lap (), $ res );
117
+ file_put_contents ($ FILENAME , json_encode ($ SERVERS , JSON_PRETTY_PRINT ));
48
118
49
- $ res = $ orch ->start ("standalone-x509.json " );
50
- printf ("Standalone X509 Auth running on: \t(took: %.2f secs) \t%s \n" , lap (), $ res );
119
+ /*
120
+ wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
121
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-AUTH
122
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE
123
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/RS-two
124
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/RS-arbiter
125
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-PLAIN
126
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-X509
127
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/RS-one
128
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers/STANDALONE-SSL
51
129
52
- $ res = $ orch -> start ( " standalone-plain. json" );
53
- printf ( " Standalone PLAIN Auth running on: \t (took: %.2f secs) \t %s \n" , lap (), $ res );
130
+ wget --body-data='' --method='GET' --header='Accept: application/ json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets
131
+ wget --body-data='' --method='DELETE' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets/REPLICASET
54
132
55
- $ res = $ orch ->startRS ("replicaset.json " );
56
- printf ("ReplicaSet running on: \t\t\t(took: %.2f secs) \t%s \n" , lap (), $ res );
133
+ wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/
134
+ wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
135
+ wget --body-data='' --method='GET' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets
57
136
137
+ wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
138
+ wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-ssl.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
139
+ wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-auth.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
140
+ wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-x509.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
141
+ wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/standalone-plain.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/servers
142
+ wget --body-data='{"preset":"\/phongo\/\/scripts\/presets\/replicaset.json"}' --method='POST' --header='Accept: application/json' --header='Content-type: application/x-www-form-urlencoded' http://192.168.112.10:8889/replica_sets
143
+ */
0 commit comments