@conduitplatform/module-tools 0.16.0-alpha.20 → 0.16.0-alpha.21
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/dist/ManagedModule.js +154 -371
- package/dist/ManagedModule.js.map +1 -1
- package/dist/classes/ConduitActiveSchema.js +30 -48
- package/dist/classes/ConduitActiveSchema.js.map +1 -1
- package/dist/classes/ConduitServiceModule.js +55 -131
- package/dist/classes/ConduitServiceModule.js.map +1 -1
- package/dist/classes/ConfigController.js +10 -17
- package/dist/classes/ConfigController.js.map +1 -1
- package/dist/classes/GrpcServer.js +93 -187
- package/dist/classes/GrpcServer.js.map +1 -1
- package/dist/helpers/GrpcHelper.js +11 -11
- package/dist/helpers/GrpcHelper.js.map +1 -1
- package/dist/helpers/GrpcToParsedRouterRequest.js +1 -1
- package/dist/helpers/GrpcToParsedRouterRequest.js.map +1 -1
- package/dist/helpers/TypeHelpers.js +57 -119
- package/dist/helpers/TypeHelpers.js.map +1 -1
- package/dist/helpers/wrapGrpcFunctions.js +14 -15
- package/dist/helpers/wrapGrpcFunctions.js.map +1 -1
- package/dist/logging/index.js +80 -180
- package/dist/logging/index.js.map +1 -1
- package/dist/metrics/MetricsServer.js +25 -70
- package/dist/metrics/MetricsServer.js.map +1 -1
- package/dist/metrics/clientMiddleware.js +76 -225
- package/dist/metrics/clientMiddleware.js.map +1 -1
- package/dist/metrics/config/defaults.js +1 -1
- package/dist/metrics/config/defaults.js.map +1 -1
- package/dist/metrics/index.js +53 -89
- package/dist/metrics/index.js.map +1 -1
- package/dist/routing/ProxyRouteBuilder.js +21 -24
- package/dist/routing/ProxyRouteBuilder.js.map +1 -1
- package/dist/routing/RouteBuilder.js +31 -34
- package/dist/routing/RouteBuilder.js.map +1 -1
- package/dist/routing/RoutingController.js +8 -9
- package/dist/routing/RoutingController.js.map +1 -1
- package/dist/routing/RoutingManager.js +61 -104
- package/dist/routing/RoutingManager.js.map +1 -1
- package/dist/routing/RoutingUtilities.js +3 -3
- package/dist/routing/RoutingUtilities.js.map +1 -1
- package/dist/routing/wrapRouterFunctions.js +28 -37
- package/dist/routing/wrapRouterFunctions.js.map +1 -1
- package/dist/utilities/convictConfigParser.js +2 -2
- package/dist/utilities/convictConfigParser.js.map +1 -1
- package/dist/utilities/initializeSdk.js +9 -11
- package/dist/utilities/initializeSdk.js.map +1 -1
- package/dist/utilities/linearBackoffTimeout.js +28 -92
- package/dist/utilities/linearBackoffTimeout.js.map +1 -1
- package/dist/utilities/merge.js +2 -2
- package/dist/utilities/merge.js.map +1 -1
- package/package.json +3 -3
package/dist/ManagedModule.js
CHANGED
|
@@ -1,213 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
4
|
};
|
|
56
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
6
|
exports.ManagedModule = void 0;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
function ManagedModule(moduleName) {
|
|
72
|
-
var _this = this;
|
|
7
|
+
const classes_1 = require("./classes");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
10
|
+
const convict_1 = __importDefault(require("convict"));
|
|
11
|
+
const grpc_sdk_1 = __importDefault(require("@conduitplatform/grpc-sdk"));
|
|
12
|
+
const utilities_1 = require("./utilities");
|
|
13
|
+
const convictConfigParser_1 = require("./utilities/convictConfigParser");
|
|
14
|
+
const initializeSdk_1 = require("./utilities/initializeSdk");
|
|
15
|
+
const routing_1 = require("./routing");
|
|
16
|
+
const RoutingController_1 = require("./routing/RoutingController");
|
|
17
|
+
const ModuleLifecycleStage_1 = require("./interfaces/ModuleLifecycleStage");
|
|
18
|
+
class ManagedModule extends classes_1.ConduitServiceModule {
|
|
19
|
+
constructor(moduleName) {
|
|
73
20
|
var _a;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
21
|
+
super(moduleName);
|
|
22
|
+
this.configOverride = false;
|
|
23
|
+
this._moduleState = ModuleLifecycleStage_1.ModuleLifecycleStage.CREATE_GRPC;
|
|
77
24
|
if (!process.env.CONDUIT_SERVER) {
|
|
78
25
|
throw new Error('CONDUIT_SERVER is undefined, specify Conduit server URL');
|
|
79
26
|
}
|
|
80
|
-
|
|
81
|
-
|
|
27
|
+
this.servicePort = (_a = process.env.GRPC_PORT) !== null && _a !== void 0 ? _a : '5000';
|
|
28
|
+
this.serviceAddress =
|
|
82
29
|
// @compat (v0.15): SERVICE_IP -> SERVICE_URL
|
|
83
|
-
process.env.SERVICE_URL || process.env.SERVICE_IP || '0.0.0.0:' +
|
|
30
|
+
process.env.SERVICE_URL || process.env.SERVICE_IP || '0.0.0.0:' + this.servicePort;
|
|
84
31
|
try {
|
|
85
|
-
|
|
86
|
-
return
|
|
32
|
+
this.grpcSdk = (0, initializeSdk_1.initializeSdk)(process.env.CONDUIT_SERVER, this.name, true, () => {
|
|
33
|
+
return this.healthState;
|
|
87
34
|
});
|
|
88
35
|
}
|
|
89
36
|
catch (e) {
|
|
90
37
|
throw new Error('Failed to initialize grpcSdk');
|
|
91
38
|
}
|
|
92
|
-
return _this;
|
|
93
39
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.initialize(this.serviceAddress, this.servicePort);
|
|
117
|
-
_a.label = 2;
|
|
118
|
-
case 2:
|
|
119
|
-
_a.trys.push([2, 5, , 6]);
|
|
120
|
-
return [4 /*yield*/, this.preRegisterLifecycle()];
|
|
121
|
-
case 3:
|
|
122
|
-
_a.sent();
|
|
123
|
-
return [4 /*yield*/, this.grpcSdk.config.registerModule(this.name, this.address, this.healthState)];
|
|
124
|
-
case 4:
|
|
125
|
-
_a.sent();
|
|
126
|
-
return [3 /*break*/, 6];
|
|
127
|
-
case 5:
|
|
128
|
-
err_1 = _a.sent();
|
|
129
|
-
grpc_sdk_1.default.Logger.error('Failed to initialize server');
|
|
130
|
-
grpc_sdk_1.default.Logger.error(err_1);
|
|
131
|
-
process.exit(-1);
|
|
132
|
-
return [3 /*break*/, 6];
|
|
133
|
-
case 6: return [4 /*yield*/, this.postRegisterLifecycle().catch(function (err) {
|
|
134
|
-
grpc_sdk_1.default.Logger.error('Failed to activate module');
|
|
135
|
-
grpc_sdk_1.default.Logger.error(err);
|
|
136
|
-
process.exit(-1);
|
|
137
|
-
})];
|
|
138
|
-
case 7:
|
|
139
|
-
_a.sent();
|
|
140
|
-
return [2 /*return*/];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
40
|
+
get name() {
|
|
41
|
+
return this._moduleName;
|
|
42
|
+
}
|
|
43
|
+
get address() {
|
|
44
|
+
return this._address;
|
|
45
|
+
}
|
|
46
|
+
async start() {
|
|
47
|
+
await this.grpcSdk.initialize();
|
|
48
|
+
this.initialize(this.serviceAddress, this.servicePort);
|
|
49
|
+
try {
|
|
50
|
+
await this.preRegisterLifecycle();
|
|
51
|
+
await this.grpcSdk.config.registerModule(this.name, this.address, this.healthState);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
grpc_sdk_1.default.Logger.error('Failed to initialize server');
|
|
55
|
+
grpc_sdk_1.default.Logger.error(err);
|
|
56
|
+
process.exit(-1);
|
|
57
|
+
}
|
|
58
|
+
await this.postRegisterLifecycle().catch((err) => {
|
|
59
|
+
grpc_sdk_1.default.Logger.error('Failed to activate module');
|
|
60
|
+
grpc_sdk_1.default.Logger.error(err);
|
|
61
|
+
process.exit(-1);
|
|
143
62
|
});
|
|
144
|
-
}
|
|
63
|
+
}
|
|
145
64
|
/**
|
|
146
65
|
* This is the first function triggered on module spin up.
|
|
147
66
|
* @param address {string} external address:port of service (LoadBalancer)
|
|
148
67
|
* @param port {string} port to bring up gRPC service
|
|
149
68
|
*/
|
|
150
|
-
|
|
69
|
+
initialize(address, port) {
|
|
151
70
|
this._address = address;
|
|
152
71
|
this._port = port;
|
|
153
72
|
if (this.configSchema) {
|
|
154
73
|
this.config = (0, convict_1.default)(this.configSchema);
|
|
155
74
|
}
|
|
156
|
-
}
|
|
75
|
+
}
|
|
157
76
|
/**
|
|
158
77
|
* This is triggered before spinning up the Grpc Server
|
|
159
78
|
* of the module. On this stage, the redis bus and state have
|
|
160
79
|
* not yet been initialized, and only communications with Conduit core
|
|
161
80
|
* have been established.
|
|
162
81
|
*/
|
|
163
|
-
|
|
164
|
-
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
165
|
-
return [2 /*return*/];
|
|
166
|
-
}); });
|
|
167
|
-
};
|
|
82
|
+
async preServerStart() { }
|
|
168
83
|
/**
|
|
169
84
|
* This is triggered right after Grpc Server start.
|
|
170
85
|
* At this stage the core module will communicate with your service
|
|
171
86
|
* for health checks, and the Bus and State management mechanics
|
|
172
87
|
* are online and available.
|
|
173
88
|
*/
|
|
174
|
-
|
|
175
|
-
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
176
|
-
return [2 /*return*/];
|
|
177
|
-
}); });
|
|
178
|
-
};
|
|
89
|
+
async onServerStart() { }
|
|
179
90
|
/**
|
|
180
91
|
* Triggers right before registering the module with Conduit Core.
|
|
181
92
|
*/
|
|
182
|
-
|
|
183
|
-
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
184
|
-
return [2 /*return*/];
|
|
185
|
-
}); });
|
|
186
|
-
};
|
|
93
|
+
async preRegister() { }
|
|
187
94
|
/**
|
|
188
95
|
* Triggers when module has been registered with Conduit Core
|
|
189
96
|
* This is the step where you should initialize your
|
|
190
97
|
* module's general routing (admin or client) and any other operation,
|
|
191
98
|
* that would require other modules being able to reach you
|
|
192
99
|
*/
|
|
193
|
-
|
|
194
|
-
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
195
|
-
return [2 /*return*/];
|
|
196
|
-
}); });
|
|
197
|
-
};
|
|
100
|
+
async onRegister() { }
|
|
198
101
|
/**
|
|
199
102
|
* This is triggered when the module receives new configuration.
|
|
200
103
|
* At this step the configuration has not been checked yet,
|
|
201
104
|
* and has only been parsed.
|
|
202
105
|
* @param config
|
|
203
106
|
*/
|
|
204
|
-
|
|
205
|
-
return
|
|
206
|
-
|
|
207
|
-
return [2 /*return*/, config];
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
};
|
|
107
|
+
async preConfig(config) {
|
|
108
|
+
return config;
|
|
109
|
+
}
|
|
211
110
|
/**
|
|
212
111
|
* This is triggered when new configuration has been applied.
|
|
213
112
|
* This happens either when changes are being made on the configuration,
|
|
@@ -215,232 +114,116 @@ var ManagedModule = /** @class */ (function (_super) {
|
|
|
215
114
|
* In either case the configuration is now available through the
|
|
216
115
|
* Config Controller of the sdk.
|
|
217
116
|
*/
|
|
218
|
-
|
|
219
|
-
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
220
|
-
return [2 /*return*/];
|
|
221
|
-
}); });
|
|
222
|
-
};
|
|
117
|
+
async onConfig() { }
|
|
223
118
|
/**
|
|
224
119
|
* Registers common and module-specific metric types.
|
|
225
120
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
return [2 /*return*/];
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
};
|
|
121
|
+
async registerMetrics() {
|
|
122
|
+
if (grpc_sdk_1.default.Metrics) {
|
|
123
|
+
grpc_sdk_1.default.Metrics.initializeDefaultMetrics();
|
|
124
|
+
if (this.metricsSchema) {
|
|
125
|
+
Object.values(this.metricsSchema).forEach(metric => {
|
|
126
|
+
grpc_sdk_1.default.Metrics.registerMetric(metric.type, metric.config);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
241
131
|
/**
|
|
242
132
|
* Initializes metric startup values.
|
|
243
133
|
* Implemented by individual modules.
|
|
244
134
|
*/
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
ManagedModule.prototype.startGrpcServer = function () {
|
|
267
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
268
|
-
return __generator(this, function (_a) {
|
|
269
|
-
switch (_a.label) {
|
|
270
|
-
case 0:
|
|
271
|
-
if (!this.service) return [3 /*break*/, 2];
|
|
272
|
-
this._serviceName = this.service.protoDescription.substring(this.service.protoDescription.indexOf('.') + 1);
|
|
273
|
-
return [4 /*yield*/, this.grpcServer.addService(this.service.protoPath, this.service.protoDescription, this.service.functions)];
|
|
274
|
-
case 1:
|
|
275
|
-
_a.sent();
|
|
276
|
-
_a.label = 2;
|
|
277
|
-
case 2:
|
|
278
|
-
routing_1.RoutingManager.ClientController = new RoutingController_1.RoutingController();
|
|
279
|
-
routing_1.RoutingManager.AdminController = new RoutingController_1.RoutingController();
|
|
280
|
-
return [4 /*yield*/, this.addHealthCheckService()];
|
|
281
|
-
case 3:
|
|
282
|
-
_a.sent();
|
|
283
|
-
return [4 /*yield*/, this.addModuleService()];
|
|
284
|
-
case 4:
|
|
285
|
-
_a.sent();
|
|
286
|
-
return [4 /*yield*/, this.grpcServer.start()];
|
|
287
|
-
case 5:
|
|
288
|
-
_a.sent();
|
|
289
|
-
grpc_sdk_1.default.Logger.log('gRPC server listening on ' + this._port);
|
|
290
|
-
return [2 /*return*/];
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
};
|
|
295
|
-
ManagedModule.prototype.setConfig = function (call, callback) {
|
|
135
|
+
async initializeMetrics() { }
|
|
136
|
+
async createGrpcServer() {
|
|
137
|
+
this.grpcServer = new classes_1.GrpcServer(this._port);
|
|
138
|
+
this._port = (await this.grpcServer.createNewServer()).toString();
|
|
139
|
+
}
|
|
140
|
+
async startGrpcServer() {
|
|
141
|
+
if (this.service) {
|
|
142
|
+
this._serviceName = this.service.protoDescription.substring(this.service.protoDescription.indexOf('.') + 1);
|
|
143
|
+
await this.grpcServer.addService(this.service.protoPath, this.service.protoDescription, this.service.functions);
|
|
144
|
+
}
|
|
145
|
+
routing_1.RoutingManager.ClientController = new RoutingController_1.RoutingController();
|
|
146
|
+
routing_1.RoutingManager.AdminController = new RoutingController_1.RoutingController();
|
|
147
|
+
await this.addHealthCheckService();
|
|
148
|
+
await this.addModuleService();
|
|
149
|
+
await this.grpcServer.start();
|
|
150
|
+
grpc_sdk_1.default.Logger.log('gRPC server listening on ' + this._port);
|
|
151
|
+
}
|
|
152
|
+
async setConfig(call, callback) {
|
|
296
153
|
var _a;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return [4 /*yield*/, this.onConfig()];
|
|
332
|
-
case 2:
|
|
333
|
-
_b.sent();
|
|
334
|
-
(_a = this.grpcSdk.bus) === null || _a === void 0 ? void 0 : _a.publish((0, lodash_1.kebabCase)(this.name) + ':config:update', JSON.stringify(config));
|
|
335
|
-
return [3 /*break*/, 4];
|
|
336
|
-
case 3:
|
|
337
|
-
e_1 = _b.sent();
|
|
338
|
-
return [2 /*return*/, callback({ code: grpc_js_1.status.INTERNAL, message: e_1.message })];
|
|
339
|
-
case 4: return [2 /*return*/];
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
};
|
|
154
|
+
try {
|
|
155
|
+
if (!this.config) {
|
|
156
|
+
return callback({
|
|
157
|
+
code: grpc_js_1.status.INVALID_ARGUMENT,
|
|
158
|
+
message: 'Module is not configurable',
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
let config = JSON.parse(call.request.newConfig);
|
|
162
|
+
config = (0, utilities_1.merge)(this.config.getProperties(), config);
|
|
163
|
+
config = await this.preConfig(config);
|
|
164
|
+
const previousConfig = this.config.getProperties();
|
|
165
|
+
try {
|
|
166
|
+
this.config.load(config).validate({
|
|
167
|
+
allowed: 'warn',
|
|
168
|
+
});
|
|
169
|
+
config = this.config.getProperties();
|
|
170
|
+
callback(null, { updatedConfig: JSON.stringify(config) });
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
this.config = (0, convict_1.default)(this.configSchema);
|
|
174
|
+
this.config.load(previousConfig);
|
|
175
|
+
return callback({
|
|
176
|
+
code: grpc_js_1.status.INVALID_ARGUMENT,
|
|
177
|
+
message: 'Invalid configuration values: ' + e.message,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
classes_1.ConfigController.getInstance().config = config;
|
|
181
|
+
await this.onConfig();
|
|
182
|
+
(_a = this.grpcSdk.bus) === null || _a === void 0 ? void 0 : _a.publish((0, lodash_1.kebabCase)(this.name) + ':config:update', JSON.stringify(config));
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
return callback({ code: grpc_js_1.status.INTERNAL, message: e.message });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
344
188
|
/** Used to update the module's configuration on initial Redis/DB reconciliation. */
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.grpcSdk.bus.subscribe("".concat(this.name, ":config:update"), function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
352
|
-
var _a;
|
|
353
|
-
return __generator(this, function (_b) {
|
|
354
|
-
switch (_b.label) {
|
|
355
|
-
case 0:
|
|
356
|
-
_a = classes_1.ConfigController.getInstance();
|
|
357
|
-
return [4 /*yield*/, this.preConfig(JSON.parse(message))];
|
|
358
|
-
case 1:
|
|
359
|
-
_a.config = _b.sent();
|
|
360
|
-
return [4 /*yield*/, this.onConfig()];
|
|
361
|
-
case 2:
|
|
362
|
-
_b.sent();
|
|
363
|
-
return [2 /*return*/];
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}); });
|
|
367
|
-
return [2 /*return*/];
|
|
368
|
-
});
|
|
189
|
+
async handleConfigSyncUpdate() {
|
|
190
|
+
if (!this.config)
|
|
191
|
+
return;
|
|
192
|
+
this.grpcSdk.bus.subscribe(`${this.name}:config:update`, async (message) => {
|
|
193
|
+
classes_1.ConfigController.getInstance().config = await this.preConfig(JSON.parse(message));
|
|
194
|
+
await this.onConfig();
|
|
369
195
|
});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return [4 /*yield*/, this.preRegister()];
|
|
403
|
-
case 9:
|
|
404
|
-
_a.sent();
|
|
405
|
-
return [2 /*return*/];
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
};
|
|
410
|
-
ManagedModule.prototype.postRegisterLifecycle = function () {
|
|
411
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
412
|
-
var configSchema, config;
|
|
413
|
-
return __generator(this, function (_a) {
|
|
414
|
-
switch (_a.label) {
|
|
415
|
-
case 0:
|
|
416
|
-
this._moduleState = ModuleLifecycleStage_1.ModuleLifecycleStage.POST_REGISTER;
|
|
417
|
-
this.registered = true;
|
|
418
|
-
return [4 /*yield*/, this.onRegister()];
|
|
419
|
-
case 1:
|
|
420
|
-
_a.sent();
|
|
421
|
-
if (!this.config) return [3 /*break*/, 5];
|
|
422
|
-
configSchema = this.config.getSchema();
|
|
423
|
-
config = this.config.getProperties();
|
|
424
|
-
return [4 /*yield*/, this.preConfig(config)];
|
|
425
|
-
case 2:
|
|
426
|
-
config = _a.sent();
|
|
427
|
-
return [4 /*yield*/, this.grpcSdk.config.configure(config, (0, convictConfigParser_1.convictConfigParser)(configSchema), this.configOverride)];
|
|
428
|
-
case 3:
|
|
429
|
-
config = _a.sent();
|
|
430
|
-
classes_1.ConfigController.getInstance();
|
|
431
|
-
if (config)
|
|
432
|
-
classes_1.ConfigController.getInstance().config = config;
|
|
433
|
-
if (!(!config || config.active || !config.hasOwnProperty('active'))) return [3 /*break*/, 5];
|
|
434
|
-
return [4 /*yield*/, this.onConfig()];
|
|
435
|
-
case 4:
|
|
436
|
-
_a.sent();
|
|
437
|
-
_a.label = 5;
|
|
438
|
-
case 5: return [2 /*return*/];
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
};
|
|
443
|
-
return ManagedModule;
|
|
444
|
-
}(classes_1.ConduitServiceModule));
|
|
196
|
+
}
|
|
197
|
+
async preRegisterLifecycle() {
|
|
198
|
+
await this.createGrpcServer();
|
|
199
|
+
this._moduleState = ModuleLifecycleStage_1.ModuleLifecycleStage.PRE_SERVER_START;
|
|
200
|
+
await this.preServerStart();
|
|
201
|
+
await this.grpcSdk.initializeEventBus();
|
|
202
|
+
await this.handleConfigSyncUpdate();
|
|
203
|
+
await this.registerMetrics();
|
|
204
|
+
await this.startGrpcServer();
|
|
205
|
+
this._moduleState = ModuleLifecycleStage_1.ModuleLifecycleStage.SERVER_STARTED;
|
|
206
|
+
await this.onServerStart();
|
|
207
|
+
await this.initializeMetrics();
|
|
208
|
+
this._moduleState = ModuleLifecycleStage_1.ModuleLifecycleStage.PRE_REGISTER;
|
|
209
|
+
await this.preRegister();
|
|
210
|
+
}
|
|
211
|
+
async postRegisterLifecycle() {
|
|
212
|
+
this._moduleState = ModuleLifecycleStage_1.ModuleLifecycleStage.POST_REGISTER;
|
|
213
|
+
this.registered = true;
|
|
214
|
+
await this.onRegister();
|
|
215
|
+
if (this.config) {
|
|
216
|
+
const configSchema = this.config.getSchema();
|
|
217
|
+
let config = this.config.getProperties();
|
|
218
|
+
config = await this.preConfig(config);
|
|
219
|
+
config = await this.grpcSdk.config.configure(config, (0, convictConfigParser_1.convictConfigParser)(configSchema), this.configOverride);
|
|
220
|
+
classes_1.ConfigController.getInstance();
|
|
221
|
+
if (config)
|
|
222
|
+
classes_1.ConfigController.getInstance().config = config;
|
|
223
|
+
if (!config || config.active || !config.hasOwnProperty('active'))
|
|
224
|
+
await this.onConfig();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
445
228
|
exports.ManagedModule = ManagedModule;
|
|
446
229
|
//# sourceMappingURL=ManagedModule.js.map
|