@@ -34,11 +34,18 @@ var ClusterManager = function (clusterName, selfId, spec) {
34
34
35
35
var data_synchronizer ;
36
36
37
+ function validateUrl ( url ) {
38
+ try {
39
+ new Url . URL ( url ) ;
40
+ return true ;
41
+ } catch {
42
+ return false ;
43
+ }
44
+ }
45
+
46
+ var sendRequest = validateUrl ( spec . url ) ;
47
+
37
48
var send = function ( method , resource , body ) {
38
- if ( spec . url === "none" ) {
39
- log . info ( "No cloud url specified" ) ;
40
- return ;
41
- }
42
49
log . info ( "send info to url:" , spec . url ) ;
43
50
const data = JSON . stringify ( body ) ;
44
51
var url = Url . parse ( spec . url + "/" + resource ) ;
@@ -103,8 +110,10 @@ var ClusterManager = function (clusterName, selfId, spec) {
103
110
capacity : purpose
104
111
}
105
112
}
106
- log . info ( "Send updateCapacity event add to cloud with data:" , data ) ;
107
- send ( 'POST' , 'updateCapacity' , data )
113
+ if ( sendRequest ) {
114
+ log . info ( "Send updateCapacity event add to cloud with data:" , data ) ;
115
+ send ( 'POST' , 'updateCapacity' , data ) ;
116
+ }
108
117
}
109
118
clusterInfo [ purpose ] . add ( worker ) ;
110
119
data_synchronizer && data_synchronizer ( { type : 'worker_join' , payload : { purpose : purpose , worker : worker , info : info } } ) ;
@@ -132,8 +141,10 @@ var ClusterManager = function (clusterName, selfId, spec) {
132
141
capacity : purpose
133
142
}
134
143
}
135
- log . info ( "Send updateCapacity event remove to cloud with data:" , data ) ;
136
- send ( 'POST' , 'updateCapacity' , data )
144
+ if ( sendRequest ) {
145
+ log . info ( "Send updateCapacity event remove to cloud with data:" , data ) ;
146
+ send ( 'POST' , 'updateCapacity' , data ) ;
147
+ }
137
148
}
138
149
}
139
150
} ;
@@ -263,8 +274,10 @@ var ClusterManager = function (clusterName, selfId, spec) {
263
274
serviceid : info . serviceid
264
275
}
265
276
}
266
- log . info ( "Send registerCluster event to cloud with data:" , data ) ;
267
- send ( 'POST' , 'registerCluster' , data )
277
+ if ( sendRequest ) {
278
+ log . info ( "Send registerCluster event to cloud with data:" , data ) ;
279
+ send ( 'POST' , 'registerCluster' , data ) ;
280
+ }
268
281
} ;
269
282
270
283
var leaveConference = function ( info , on_ok ) {
@@ -274,17 +287,21 @@ var ClusterManager = function (clusterName, selfId, spec) {
274
287
region : spec . region ,
275
288
conferenceId : info
276
289
}
277
- log . info ( "Send conference leave event to cloud with data:" , data ) ;
278
- send ( 'POST' , 'leaveConference' , data )
290
+ if ( sendRequest ) {
291
+ log . info ( "Send conference leave event to cloud with data:" , data ) ;
292
+ send ( 'POST' , 'leaveConference' , data ) ;
293
+ }
279
294
} ;
280
295
281
296
var unregisterCluster = function ( ) {
282
297
var data = {
283
298
clusterID : spec . clusterID ,
284
299
region : spec . region
285
300
}
286
- log . info ( "Send unregister cluster event to cloud with data:" , data ) ;
287
- send ( 'POST' , 'unregisterCluster' , data )
301
+ if ( sendRequest ) {
302
+ log . info ( "Send unregister cluster event to cloud with data:" , data ) ;
303
+ send ( 'POST' , 'unregisterCluster' , data ) ;
304
+ }
288
305
} ;
289
306
290
307
that . stopCluster = function ( ) {
0 commit comments