soajs.controller 4.2.18 → 4.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/mw/awareness/ha.js
CHANGED
|
@@ -24,7 +24,7 @@ let awarenessCache = {};
|
|
|
24
24
|
|
|
25
25
|
let lib = {
|
|
26
26
|
"getInfraToken": (envCode, cb) => {
|
|
27
|
-
registryModule.loadByEnv({envCode: envCode}, (err, envRecord) => {
|
|
27
|
+
registryModule.loadByEnv({ envCode: envCode }, (err, envRecord) => {
|
|
28
28
|
if (err) {
|
|
29
29
|
return cb(err);
|
|
30
30
|
}
|
|
@@ -55,7 +55,7 @@ let lib = {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
},
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
"getHostFromCache": function (serviceName, version) {
|
|
60
60
|
if (awarenessCache[serviceName] &&
|
|
61
61
|
awarenessCache[serviceName][version] &&
|
|
@@ -63,10 +63,10 @@ let lib = {
|
|
|
63
63
|
param.log.debug('Got ' + serviceName + ' - ' + version + ' - ' + awarenessCache[serviceName][version].host + ' from awareness cache');
|
|
64
64
|
return awarenessCache[serviceName][version].host;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
return null;
|
|
68
68
|
},
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
"getHostFromAPI": function (serviceName, version, cb) {
|
|
71
71
|
if (!version) {
|
|
72
72
|
lib.getInfraToken(regEnvironment, (error, configuration) => {
|
|
@@ -94,7 +94,7 @@ let lib = {
|
|
|
94
94
|
} else {
|
|
95
95
|
getHost(version);
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
function getHost(version) {
|
|
99
99
|
lib.getInfraToken(regEnvironment, (error, configuration) => {
|
|
100
100
|
if (error) {
|
|
@@ -105,7 +105,7 @@ let lib = {
|
|
|
105
105
|
let options = null;
|
|
106
106
|
let input = {
|
|
107
107
|
"configuration": configuration,
|
|
108
|
-
"item": {"name": serviceName, "version": version, "env": regEnvironment}
|
|
108
|
+
"item": { "name": serviceName, "version": version, "env": regEnvironment }
|
|
109
109
|
};
|
|
110
110
|
param.infraModule.kubernetes.get.host(param, input, options, (error, host) => {
|
|
111
111
|
if (error) {
|
|
@@ -126,7 +126,7 @@ let lib = {
|
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
"rebuildAwarenessCache": function () {
|
|
131
131
|
lib.getInfraToken(regEnvironment, (error, configuration) => {
|
|
132
132
|
if (error) {
|
|
@@ -155,11 +155,11 @@ let lib = {
|
|
|
155
155
|
if (oneService.metadata.labels && oneService.metadata.labels['soajs.service.version']) {
|
|
156
156
|
version = oneService.metadata.labels['soajs.service.version'];
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
|
|
159
159
|
if (oneService.metadata.labels && oneService.metadata.labels['soajs.service.name']) {
|
|
160
160
|
serviceName = oneService.metadata.labels['soajs.service.name'];
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
if (!serviceName) {
|
|
164
164
|
return callback();
|
|
165
165
|
}
|
|
@@ -177,7 +177,7 @@ let lib = {
|
|
|
177
177
|
awarenessCache = myCache;
|
|
178
178
|
param.log.debug("Awareness cache rebuilt successfully");
|
|
179
179
|
param.log.debug(JSON.stringify(awarenessCache));
|
|
180
|
-
|
|
180
|
+
|
|
181
181
|
let cacheTTL = registryModule.get().serviceConfig.awareness.cacheTTL;
|
|
182
182
|
if (cacheTTL) {
|
|
183
183
|
if (timeout) {
|
|
@@ -197,7 +197,7 @@ let ha = {
|
|
|
197
197
|
param = _param;
|
|
198
198
|
lib.rebuildAwarenessCache();
|
|
199
199
|
},
|
|
200
|
-
|
|
200
|
+
|
|
201
201
|
"getServiceHost": function () {
|
|
202
202
|
let env = regEnvironment;
|
|
203
203
|
let serviceName = param.serviceName, version = null, cb = arguments[arguments.length - 1];
|
|
@@ -206,20 +206,20 @@ let ha = {
|
|
|
206
206
|
case 2:
|
|
207
207
|
serviceName = arguments[0];
|
|
208
208
|
break;
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
//controller, 1, cb
|
|
211
211
|
case 3:
|
|
212
212
|
serviceName = arguments[0];
|
|
213
213
|
version = arguments[1];
|
|
214
214
|
break;
|
|
215
|
-
|
|
215
|
+
|
|
216
216
|
//controller, 1, dash, cb [dash is ignored]
|
|
217
217
|
case 4:
|
|
218
218
|
serviceName = arguments[0];
|
|
219
219
|
version = arguments[1];
|
|
220
220
|
break;
|
|
221
221
|
}
|
|
222
|
-
|
|
222
|
+
|
|
223
223
|
if (serviceName === param.serviceName) {
|
|
224
224
|
if (process.env.SOAJS_DEPLOY_HA === 'kubernetes') {
|
|
225
225
|
serviceName += "-v" + param.serviceVersion + "-service";
|
|
@@ -239,16 +239,21 @@ let ha = {
|
|
|
239
239
|
if (hostname) {
|
|
240
240
|
return cb(hostname);
|
|
241
241
|
} else {
|
|
242
|
-
|
|
242
|
+
if (process.env.SOAJS_DEPLOY_HA === 'kubernetes' && serviceName && version) {
|
|
243
|
+
serviceName += "-v" + version + "-service";
|
|
244
|
+
return cb(env + "-" + serviceName + "-v" + version + "-service");
|
|
245
|
+
} else {
|
|
246
|
+
lib.getHostFromAPI(serviceName, version, cb);
|
|
247
|
+
}
|
|
243
248
|
}
|
|
244
249
|
}
|
|
245
250
|
},
|
|
246
|
-
|
|
251
|
+
|
|
247
252
|
"getLatestVersion": function (name, cb) {
|
|
248
253
|
if (!awarenessCache[name]) {
|
|
249
254
|
return cb(null);
|
|
250
255
|
}
|
|
251
|
-
|
|
256
|
+
|
|
252
257
|
let serviceVersions = Object.keys(awarenessCache[name]);
|
|
253
258
|
if (serviceVersions.length === 0) {
|
|
254
259
|
return cb(null);
|
|
@@ -263,7 +268,7 @@ let ha = {
|
|
|
263
268
|
return cb(null);
|
|
264
269
|
}
|
|
265
270
|
},
|
|
266
|
-
|
|
271
|
+
|
|
267
272
|
"getLatestVersionFromCluster": function (name, cb) {
|
|
268
273
|
lib.getInfraToken(regEnvironment, (error, configuration) => {
|
|
269
274
|
if (error) {
|
|
@@ -41,13 +41,14 @@ module.exports = (configuration) => {
|
|
|
41
41
|
try {
|
|
42
42
|
let log_monitor = (doc) => {
|
|
43
43
|
let soamonitor = "soamonitor";
|
|
44
|
+
let soamonitorVersion = "1";
|
|
44
45
|
let port = get(["registry", "services", "soamonitor", "port"], req.soajs);
|
|
45
46
|
if (!port) {
|
|
46
47
|
port = "4050";
|
|
47
48
|
}
|
|
48
49
|
let api = "/monitor/item";
|
|
49
50
|
|
|
50
|
-
req.soajs.awareness.getHost(soamonitor, function (host) {
|
|
51
|
+
req.soajs.awareness.getHost(soamonitor, soamonitorVersion, function (host) {
|
|
51
52
|
if (!host) {
|
|
52
53
|
req.soajs.log.error('Unable to find any healthy host for service ' + soamonitor);
|
|
53
54
|
} else {
|
|
@@ -12,7 +12,7 @@ const coreLibs = require("soajs.core.libs");
|
|
|
12
12
|
|
|
13
13
|
module.exports = (configuration) => {
|
|
14
14
|
let core = configuration.core;
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
let return_SOAJS_keyACL = (req) => {
|
|
17
17
|
let ACL = null;
|
|
18
18
|
let ALLOWED_PACKAGES = null;
|
|
@@ -73,21 +73,47 @@ module.exports = (configuration) => {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
let urac = null;
|
|
78
|
+
if (req.soajs.uracDriver) {
|
|
79
|
+
let uracObj = req.soajs.uracDriver.getProfile();
|
|
80
|
+
if (uracObj) {
|
|
81
|
+
urac = {
|
|
82
|
+
"_id": uracObj._id
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let tenant = null;
|
|
88
|
+
let keyObj = req.soajs.controller.serviceParams.keyObj;
|
|
89
|
+
if (keyObj && keyObj.application && keyObj.application.package) {
|
|
90
|
+
tenant = {
|
|
91
|
+
"id": keyObj.tenant.id,
|
|
92
|
+
"name": keyObj.tenant.name,
|
|
93
|
+
"code": keyObj.tenant.code,
|
|
94
|
+
// "locked": keyObj.tenant.locked,
|
|
95
|
+
// "roaming": data.req.soajs.tenant.roaming,
|
|
96
|
+
"type": keyObj.tenant.type
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
76
100
|
let response = {
|
|
77
101
|
"acl": ACL,
|
|
78
102
|
"finalACL": finalACL,
|
|
79
|
-
"packages": ALLOWED_PACKAGES
|
|
103
|
+
"packages": ALLOWED_PACKAGES,
|
|
104
|
+
"urac": urac,
|
|
105
|
+
"tenant": tenant
|
|
80
106
|
};
|
|
81
107
|
return req.soajs.controllerResponse(response);
|
|
82
108
|
};
|
|
83
|
-
|
|
109
|
+
|
|
84
110
|
return (req, res, next) => {
|
|
85
|
-
|
|
111
|
+
|
|
86
112
|
//doesn't work without a key in the headers
|
|
87
113
|
if (!req.headers || !req.headers.key) {
|
|
88
114
|
return req.soajs.controllerResponse(core.error.getError(132));
|
|
89
115
|
}
|
|
90
|
-
|
|
116
|
+
|
|
91
117
|
//mimic a service named controller with route /key/permission/get
|
|
92
118
|
let serviceName = configuration.serviceName;
|
|
93
119
|
req.soajs.controller.serviceParams.registry = req.soajs.registry.services[serviceName];
|
|
@@ -112,10 +138,10 @@ module.exports = (configuration) => {
|
|
|
112
138
|
]
|
|
113
139
|
}
|
|
114
140
|
};
|
|
115
|
-
|
|
141
|
+
|
|
116
142
|
//assign the correct method to gotoservice in controller
|
|
117
143
|
req.soajs.controller.gotoservice = return_SOAJS_keyACL;
|
|
118
144
|
return next();
|
|
119
|
-
|
|
145
|
+
|
|
120
146
|
};
|
|
121
147
|
};
|
package/package.json
CHANGED