Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit fc98a53

Browse files
committed
Add cloud url check in cluster manager
1 parent c2810a8 commit fc98a53

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

source/cluster_manager/clusterManager.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ var ClusterManager = function (clusterName, selfId, spec) {
3434

3535
var data_synchronizer;
3636

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+
3748
var send = function (method, resource, body) {
38-
if (spec.url === "none") {
39-
log.info("No cloud url specified");
40-
return;
41-
}
4249
log.info("send info to url:", spec.url);
4350
const data = JSON.stringify(body);
4451
var url = Url.parse(spec.url + "/" + resource);
@@ -103,8 +110,10 @@ var ClusterManager = function (clusterName, selfId, spec) {
103110
capacity: purpose
104111
}
105112
}
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+
}
108117
}
109118
clusterInfo[purpose].add(worker);
110119
data_synchronizer && data_synchronizer({type: 'worker_join', payload: {purpose: purpose, worker: worker, info: info}});
@@ -132,8 +141,10 @@ var ClusterManager = function (clusterName, selfId, spec) {
132141
capacity: purpose
133142
}
134143
}
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+
}
137148
}
138149
}
139150
};
@@ -263,8 +274,10 @@ var ClusterManager = function (clusterName, selfId, spec) {
263274
serviceid: info.serviceid
264275
}
265276
}
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+
}
268281
};
269282

270283
var leaveConference = function (info, on_ok) {
@@ -274,17 +287,21 @@ var ClusterManager = function (clusterName, selfId, spec) {
274287
region: spec.region,
275288
conferenceId: info
276289
}
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+
}
279294
};
280295

281296
var unregisterCluster = function () {
282297
var data = {
283298
clusterID: spec.clusterID,
284299
region: spec.region
285300
}
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+
}
288305
};
289306

290307
that.stopCluster = function () {

0 commit comments

Comments
 (0)