@codiac.io/codiac-cli 1.2.234 → 1.2.236

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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/apis/codiac-relay/gen/client.d.ts +8 -1
  3. package/dist/apis/codiac-relay/gen/client.js +55 -13
  4. package/dist/apis/codiac-relay/gen/client.js.map +1 -1
  5. package/dist/apis/codiac-relay/gen/contracts.d.ts +233 -11
  6. package/dist/apis/codiac-relay/gen/contracts.js +55 -2
  7. package/dist/apis/codiac-relay/gen/contracts.js.map +1 -1
  8. package/dist/command-base-enterprise.d.ts +6 -0
  9. package/dist/command-base-enterprise.js +14 -0
  10. package/dist/command-base-enterprise.js.map +1 -1
  11. package/dist/commands/cluster/scaling/update.d.ts +1 -7
  12. package/dist/commands/cluster/scaling/update.js +46 -72
  13. package/dist/commands/cluster/scaling/update.js.map +1 -1
  14. package/dist/commands/config/add.d.ts +14 -0
  15. package/dist/commands/config/add.js +92 -3
  16. package/dist/commands/config/add.js.map +1 -1
  17. package/dist/commands/noc/cluster/create.d.ts +1 -0
  18. package/dist/commands/noc/cluster/create.js +7 -3
  19. package/dist/commands/noc/cluster/create.js.map +1 -1
  20. package/dist/commands/noc/cluster/forget.js +1 -1
  21. package/dist/commands/noc/cluster/forget.js.map +1 -1
  22. package/dist/relay/relay-container.js +1 -1
  23. package/dist/relay/wsclient/relay-queue-manager.d.ts +21 -0
  24. package/dist/relay/wsclient/relay-queue-manager.js +61 -0
  25. package/dist/relay/wsclient/relay-queue-manager.js.map +1 -0
  26. package/dist/uilogic/builtin-config-schemas.d.ts +12 -0
  27. package/dist/uilogic/builtin-config-schemas.js +96 -0
  28. package/dist/uilogic/builtin-config-schemas.js.map +1 -0
  29. package/dist/uilogic/config-ui-utils.d.ts +4 -1
  30. package/dist/uilogic/config-ui-utils.js +33 -10
  31. package/dist/uilogic/config-ui-utils.js.map +1 -1
  32. package/dist/uilogic/lrp-watcher-predef.d.ts +22 -0
  33. package/dist/uilogic/lrp-watcher-predef.js +157 -0
  34. package/dist/uilogic/lrp-watcher-predef.js.map +1 -0
  35. package/dist/uilogic/lrp-watcher-utils.d.ts +16 -0
  36. package/dist/uilogic/lrp-watcher-utils.js +30 -0
  37. package/dist/uilogic/lrp-watcher-utils.js.map +1 -0
  38. package/dist/uilogic/lrp-watcher.d.ts +22 -0
  39. package/dist/uilogic/lrp-watcher.js +143 -0
  40. package/dist/uilogic/lrp-watcher.js.map +1 -0
  41. package/oclif.manifest.json +14 -2
  42. package/package.json +4 -2
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LrpWatcherPredef = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const inversify_1 = require("inversify");
6
+ const listr2_1 = require("listr2");
7
+ const codiac_common_1 = require("@codiac.io/codiac-common");
8
+ const contracts_1 = require("@codiac.io/codiac-common/contracts");
9
+ const contracts_2 = require("../apis/codiac-relay/contracts");
10
+ const relay_websocket_client_1 = require("../relay/wsclient/relay-websocket-client");
11
+ const relay_queue_manager_1 = require("../relay/wsclient/relay-queue-manager");
12
+ const _ = require("lodash");
13
+ const lrp_watcher_utils_1 = require("./lrp-watcher-utils");
14
+ /** Triggers and renders real time status for a Long Running Process using a predefined call tree.
15
+ *
16
+ * That is, it fires an async request to trigger the process,
17
+ * then monitors a socket for real time status messages,
18
+ * and renders them in sequential order.
19
+ */
20
+ let LrpWatcherPredef = class LrpWatcherPredef {
21
+ constructor(relayWebSocket, logger) {
22
+ this.relayWebSocket = relayWebSocket;
23
+ this.logger = logger;
24
+ this.qmgr = new relay_queue_manager_1.QueueManager();
25
+ }
26
+ removeStatusListeners() {
27
+ let closed = false;
28
+ if (this.relayWebSocket) {
29
+ closed = closed && this.relayWebSocket.unlisten(lrp_watcher_utils_1.LrpWatcherUtils.STATUS_MSG_TYPE, this.statusHandlerId);
30
+ }
31
+ return closed;
32
+ }
33
+ triggerAndWatch(trigger) {
34
+ var _a, _b;
35
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
36
+ let result = new contracts_1.Result(false);
37
+ try {
38
+ let socketId = yield this.relayWebSocket.open();
39
+ this.statusHandlerId = this.relayWebSocket.listenFor(lrp_watcher_utils_1.LrpWatcherUtils.STATUS_MSG_TYPE, (msg) => {
40
+ // gotta queue these to prevent msg loss due to
41
+ // client-server latency in triggering each task watcher
42
+ // (server may send messages before the local client task starts listening).
43
+ let status = msg.payload;
44
+ this.qmgr.push(msg, status.opCode); // todo: consider prefixing with "<CorrelationId>."
45
+ });
46
+ // TODO: Make this the first task in the taskMap
47
+ let ack = yield this.invokeOperation(socketId, trigger);
48
+ let statusView = yield this.buildStatusView(ack.taskMap);
49
+ let finalCtx = yield statusView.run();
50
+ result = finalCtx.result;
51
+ }
52
+ catch (err) {
53
+ this.logger.error((_a = err.message) !== null && _a !== void 0 ? _a : err.stack);
54
+ result.error = err;
55
+ result.message = (_b = err.message) !== null && _b !== void 0 ? _b : "Error executing operation: See logs for details";
56
+ }
57
+ finally {
58
+ yield this.relayWebSocket.close();
59
+ return result;
60
+ }
61
+ });
62
+ }
63
+ /** Throws when not successful or when no ack is returned. */
64
+ invokeOperation(socketId, trigger) {
65
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
66
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
67
+ let ackResult = yield trigger(socketId);
68
+ if (ackResult.success != true) {
69
+ let logMsg = "Failed invoking operation ".concat("[CID ", (_b = (_a = ackResult.output) === null || _a === void 0 ? void 0 : _a.correlationId) !== null && _b !== void 0 ? _b : "none", "]: ", (_g = (_e = (_c = ackResult.message) !== null && _c !== void 0 ? _c : (_d = ackResult.error) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : (_f = ackResult.error) === null || _f === void 0 ? void 0 : _f.stack) !== null && _g !== void 0 ? _g : "no details available");
70
+ this.logger.error(logMsg, ackResult.error);
71
+ let friendlyMsg = "Failed invoking operation: ".concat((_k = (_h = ackResult.message) !== null && _h !== void 0 ? _h : (_j = ackResult.error) === null || _j === void 0 ? void 0 : _j.message) !== null && _k !== void 0 ? _k : "See logs for details");
72
+ throw new Error(friendlyMsg);
73
+ }
74
+ else if (ackResult.output == undefined) {
75
+ throw new Error("No acknowledgement received. ".concat((_l = ackResult.message) !== null && _l !== void 0 ? _l : "").trimEnd());
76
+ }
77
+ return ackResult.output;
78
+ });
79
+ }
80
+ buildStatusView(taskMap) {
81
+ // Set up the Listr control
82
+ if (taskMap == undefined) {
83
+ throw new Error("No TaskMap provided");
84
+ // TODO: Wire up a LrpWatcher instead.
85
+ }
86
+ else {
87
+ // PERFERRED: Predefined task map with completion statuses
88
+ let statusUi = new listr2_1.Listr({
89
+ title: taskMap.opIngTitle,
90
+ task: (taskMap.tasks) ? (ctx, task) => {
91
+ return task.newListr(taskMap.tasks.map(x => {
92
+ return {
93
+ title: x.opIngTitle,
94
+ rendererOptions: { outputBar: true },
95
+ task: (ctx, tx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
96
+ return new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
97
+ // subscribe to our queue
98
+ this.qmgr.subscribeTo(x.opCode, (msg) => {
99
+ if (msg.payload) {
100
+ let status = msg.payload;
101
+ if (status.state == contracts_2.OperationStateEnum.Completed) {
102
+ tx.task.complete();
103
+ // TODO: address status.completionCode and status.message
104
+ ctx.result = lrp_watcher_utils_1.LrpWatcherUtils.resultFromStatusMessage(status);
105
+ // Poor man's DRAIN
106
+ // TODO: drain the socket messages and the Listr tasks before we close up shop
107
+ setTimeout(() => {
108
+ this.removeStatusListeners();
109
+ if (ctx.result.error) {
110
+ reject(ctx.result.error);
111
+ }
112
+ else {
113
+ resolve();
114
+ }
115
+ }, 1000);
116
+ }
117
+ else {
118
+ if (status.message != undefined && !_.isEmpty(status.message)) {
119
+ tx.output = status.message;
120
+ }
121
+ }
122
+ }
123
+ else {
124
+ // no payload; ignore as a ping or heartbeat
125
+ }
126
+ }); // Perhaps this handler can be absorbed into the qmgr?
127
+ // pull any existing from our queue
128
+ // if complete, close the task
129
+ // else, render output
130
+ }));
131
+ // await delay(1500);
132
+ // return; }
133
+ })
134
+ };
135
+ }), {
136
+ concurrent: false,
137
+ rendererOptions: { collapseSubtasks: false }
138
+ });
139
+ } : /* no sub tasks */ (ctx, task) => tslib_1.__awaiter(this, void 0, void 0, function* () {
140
+ // TODO: subscribe to opCode queue
141
+ yield (0, listr2_1.delay)(1500);
142
+ return;
143
+ })
144
+ });
145
+ return statusUi;
146
+ // this._ui.userMessage(`Execution completed.`);
147
+ }
148
+ }
149
+ };
150
+ LrpWatcherPredef = tslib_1.__decorate([
151
+ (0, inversify_1.injectable)(),
152
+ tslib_1.__param(0, (0, inversify_1.inject)(relay_websocket_client_1.RelayWebsocketClient)),
153
+ tslib_1.__param(1, (0, inversify_1.inject)(codiac_common_1.INTERFACES.IBetterLogger)),
154
+ tslib_1.__metadata("design:paramtypes", [relay_websocket_client_1.RelayWebsocketClient, Object])
155
+ ], LrpWatcherPredef);
156
+ exports.LrpWatcherPredef = LrpWatcherPredef;
157
+ //# sourceMappingURL=lrp-watcher-predef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lrp-watcher-predef.js","sourceRoot":"","sources":["../../src/uilogic/lrp-watcher-predef.ts"],"names":[],"mappings":";;;;AAAA,yCAA+C;AAC/C,mCAAoD;AACpD,4DAAqE;AACrE,kEAA0E;AAC1E,8DAAqJ;AACrJ,qFAAgF;AAEhF,+EAAqE;AACrE,4BAA6B;AAC7B,2DAAuF;AAGvF;;;;;GAKG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAE3B,YACwC,cAAoC,EAChC,MAAqB;QADzB,mBAAc,GAAd,cAAc,CAAsB;QAChC,WAAM,GAAN,MAAM,CAAe;QAE/D,IAAI,CAAC,IAAI,GAAG,IAAI,kCAAY,EAAE,CAAC;IACjC,CAAC;IAOO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C,KAAK,CAAC,CAAC;qDAC1B;yDAAM;wDACL,OAAO,EAAE,CAAC;qDACX;gDACH,CAAC,EAAE,IAAI,CAAC,CAAC;6CAEV;iDAAM;gDACL,IAAI,MAAM,CAAC,OAAO,IAAI,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;oDAC7D,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;iDAC5B;6CACF;yCAEF;6CAAM;4CACL,4CAA4C;yCAC7C;oCAIH,CAAC,CAAC,CAAC,CAAE,sDAAsD;oCAE3D,mCAAmC;oCAEnC,8BAA8B;oCAC9B,sBAAsB;gCAGxB,CAAC,CAAA,CAAC,CAAC;gCACH,qBAAqB;gCACrB,yBAAyB;4BAC3B,CAAC,CAAA;yBACF,CAAA;oBACH,CAAC,CAAC,EAAE;wBACF,UAAU,EAAE,KAAK;wBACjB,eAAe,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE;qBAC7C,CAAC,CAAC;gBAEL,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAO,GAAG,EAAE,IAAI,EAAiB,EAAE;oBACxD,kCAAkC;oBAClC,MAAM,IAAA,cAAK,EAAC,IAAI,CAAC,CAAC;oBAClB,OAAO;gBACT,CAAC,CAAA;aACF,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC;YAChB,gDAAgD;SAEjD;IACH,CAAC;CACF,CAAA;AA1JY,gBAAgB;IAD5B,IAAA,sBAAU,GAAE;IAIR,mBAAA,IAAA,kBAAM,EAAC,6CAAoB,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAM,EAAC,0BAAU,CAAC,aAAa,CAAC,CAAA;6CADqB,6CAAoB;GAHjE,gBAAgB,CA0J5B;AA1JY,4CAAgB"}
@@ -0,0 +1,16 @@
1
+ import { Result, SingleResult } from "@codiac.io/codiac-common/contracts";
2
+ import { OperationStatus, AsyncAck } from "../apis/codiac-relay/contracts";
3
+ /** A function expression that invokes a long running process
4
+ * (without waiting for it to complete)
5
+ * and returns an immediate acknowledgement. */
6
+ export type AsyncTrigger = (socketId: string) => Promise<SingleResult<AsyncAck>>;
7
+ export type StatusViewContext<TResult extends Result> = {
8
+ values: any;
9
+ result: TResult;
10
+ };
11
+ /** Shared logic between LrpWatchers. */
12
+ export declare abstract class LrpWatcherUtils {
13
+ /** The value of the `action` field in a SocketAction for status messages. */
14
+ static readonly STATUS_MSG_TYPE = "operationStatus";
15
+ static resultFromStatusMessage(status: OperationStatus): Result;
16
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LrpWatcherUtils = void 0;
4
+ const contracts_1 = require("@codiac.io/codiac-common/contracts");
5
+ const contracts_2 = require("../apis/codiac-relay/contracts");
6
+ /** Shared logic between LrpWatchers. */
7
+ class LrpWatcherUtils {
8
+ static resultFromStatusMessage(status) {
9
+ var _a, _b;
10
+ let result = new contracts_1.Result(false);
11
+ // success
12
+ result.success = Boolean(status.completionCode == contracts_2.OperationCompletionCodeEnum.Success);
13
+ // message
14
+ if (status.completionCode != contracts_2.OperationCompletionCodeEnum.Success) {
15
+ result.message = status.opCode.concat(" ", (_a = status.completionCode) !== null && _a !== void 0 ? _a : "", ": ", (_b = status.message) !== null && _b !== void 0 ? _b : "").trimEnd();
16
+ }
17
+ else if (status.message) {
18
+ result.message = status.message;
19
+ }
20
+ // error
21
+ if (status.completionCode == contracts_2.OperationCompletionCodeEnum.Failed) {
22
+ result.error = new Error(result.message);
23
+ }
24
+ return result;
25
+ }
26
+ }
27
+ exports.LrpWatcherUtils = LrpWatcherUtils;
28
+ /** The value of the `action` field in a SocketAction for status messages. */
29
+ LrpWatcherUtils.STATUS_MSG_TYPE = "operationStatus";
30
+ //# sourceMappingURL=lrp-watcher-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lrp-watcher-utils.js","sourceRoot":"","sources":["../../src/uilogic/lrp-watcher-utils.ts"],"names":[],"mappings":";;;AAAA,kEAA0E;AAC1E,8DAAwG;AAWxG,wCAAwC;AACxC,MAAsB,eAAe;IAM5B,MAAM,CAAC,uBAAuB,CAAC,MAAuB;;QAC3D,IAAI,MAAM,GAAG,IAAI,kBAAM,CAAC,KAAK,CAAC,CAAC;QAE/B,UAAU;QACV,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,IAAI,uCAA2B,CAAC,OAAO,CAAC,CAAC;QACvF,UAAU;QACV,IAAI,MAAM,CAAC,cAAc,IAAI,uCAA2B,CAAC,OAAO,EAAE;YAChE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAA,MAAM,CAAC,cAAc,mCAAI,EAAE,EAAE,IAAI,EAAE,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SAC/G;aAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACzB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;SACjC;QACD,QAAQ;QACR,IAAI,MAAM,CAAC,cAAc,IAAI,uCAA2B,CAAC,MAAM,EAAE;YAC/D,MAAM,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC1C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;;AAvBH,0CA0BC;AAxBC,6EAA6E;AACtD,+BAAe,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { IBetterLogger } from "@codiac.io/codiac-common";
2
+ import { SingleResult, Result } from '@codiac.io/codiac-common/contracts';
3
+ import { AsyncAck } from '../apis/codiac-relay/contracts';
4
+ import { RelayWebsocketClient } from "../relay/wsclient/relay-websocket-client";
5
+ /** Triggers and renders real time status for Long Running Processes.
6
+ *
7
+ * That is, it fires an async request to trigger the process,
8
+ * then monitors a socket for real time status messages,
9
+ * and renders them in sequential order.
10
+ */
11
+ export declare class LrpWatcher {
12
+ private relayWebSocket;
13
+ private logger;
14
+ constructor(relayWebSocket: RelayWebsocketClient, logger: IBetterLogger);
15
+ private statusHandlerId;
16
+ private removeStatusListeners;
17
+ /** Opens and closes its own web socket.
18
+ * Throws any errors.
19
+ * Renders all real time status messages as logs off the main operation.
20
+ */
21
+ triggerAndWatch<TResult extends Result, TContext extends object>(mainOpCode: string, opIngTitle: string, trigger: (socketId: string) => Promise<SingleResult<AsyncAck>>): Promise<TResult>;
22
+ }
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LrpWatcher = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const inversify_1 = require("inversify");
6
+ const listr2_1 = require("listr2");
7
+ const codiac_common_1 = require("@codiac.io/codiac-common");
8
+ const contracts_1 = require("../apis/codiac-relay/contracts");
9
+ const relay_websocket_client_1 = require("../relay/wsclient/relay-websocket-client");
10
+ const lrp_watcher_utils_1 = require("./lrp-watcher-utils");
11
+ /** Triggers and renders real time status for Long Running Processes.
12
+ *
13
+ * That is, it fires an async request to trigger the process,
14
+ * then monitors a socket for real time status messages,
15
+ * and renders them in sequential order.
16
+ */
17
+ let LrpWatcher = class LrpWatcher {
18
+ constructor(relayWebSocket, logger) {
19
+ this.relayWebSocket = relayWebSocket;
20
+ this.logger = logger;
21
+ }
22
+ // private setStatusHandlers(): void {
23
+ // // this.spinners["operationStatus"] = ora("Cluster create interim status: ").start();
24
+ // this.statusHandlerId = this.relayWebSocket.listenFor("operationStatus", msg => {
25
+ // // this._ui.userMessage(`Cluster create interim status: ${JSON.stringify(msg.payload)}`);
26
+ // // this.spinners?.add({
27
+ // // title: "interim from relay",
28
+ // // task: async (ctx, task): Promise<void> => {
29
+ // // task.output = "payload: ".concat(JSON.stringify(msg.payload));
30
+ // // }
31
+ // // // , rendererOptions: { outputBar: 1 }
32
+ // // });
33
+ // });
34
+ // // this.completionHandlerId = this.relayWebSocket.listenFor("clusterCreateCompleted", msg => {
35
+ // // this.isCompleted = true;
36
+ // // // this.spinners["operationStatus"].succeed().suffixText = "Complete!";
37
+ // // this._ui.userMessage(`Cluster create completed ${JSON.stringify(msg.payload)}`);
38
+ // // this.removeStatusListeners();
39
+ // // });
40
+ // }
41
+ removeStatusListeners() {
42
+ let closed = false;
43
+ if (this.relayWebSocket) {
44
+ closed = closed && this.relayWebSocket.unlisten(lrp_watcher_utils_1.LrpWatcherUtils.STATUS_MSG_TYPE, this.statusHandlerId);
45
+ // closed = closed && this.relayWebSocket.unlisten("clusterCreateCompleted", this.completionHandlerId!);
46
+ }
47
+ return closed;
48
+ }
49
+ /** Opens and closes its own web socket.
50
+ * Throws any errors.
51
+ * Renders all real time status messages as logs off the main operation.
52
+ */
53
+ triggerAndWatch(mainOpCode, opIngTitle, trigger) {
54
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
55
+ let spinners = new listr2_1.Listr({
56
+ title: opIngTitle,
57
+ rendererOptions: { outputBar: Infinity, persistentOutput: true, timer: listr2_1.PRESET_TIMER },
58
+ task: (ctx, task) => tslib_1.__awaiter(this, void 0, void 0, function* () {
59
+ return new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
60
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
61
+ // 1. open real time status stream
62
+ let commChannel;
63
+ commChannel = {
64
+ socketId: yield this.relayWebSocket.open() // .start()
65
+ };
66
+ // this.setStatusHandlers();
67
+ this.statusHandlerId = this.relayWebSocket.listenFor(lrp_watcher_utils_1.LrpWatcherUtils.STATUS_MSG_TYPE, msg => {
68
+ var _a, _b, _c, _d, _e, _f;
69
+ if (msg.payload) {
70
+ let statusMsg = msg.payload;
71
+ // COMPLETION STATUS
72
+ if (statusMsg.opCode == mainOpCode && statusMsg.state == contracts_1.OperationStateEnum.Completed) {
73
+ task.output = "".concat((_b = (_a = statusMsg.completionCode) !== null && _a !== void 0 ? _a : statusMsg.message) !== null && _b !== void 0 ? _b : statusMsg.state, "!");
74
+ task.title = task.title.concat("...", (_c = statusMsg.completionCode) !== null && _c !== void 0 ? _c : statusMsg.state);
75
+ task.task.complete();
76
+ ctx.res = lrp_watcher_utils_1.LrpWatcherUtils.resultFromStatusMessage(statusMsg);
77
+ // Poor man's DRAIN
78
+ // TODO: drain the socket messages and the Listr tasks before we close up shop
79
+ setTimeout(() => {
80
+ this.removeStatusListeners();
81
+ if (result.error) {
82
+ reject(result.error);
83
+ }
84
+ else {
85
+ resolve();
86
+ }
87
+ }, 1000);
88
+ }
89
+ else {
90
+ if (statusMsg.state == contracts_1.OperationStateEnum.Completed) {
91
+ task.output = statusMsg.opIngTitle.concat("...", (_d = statusMsg.completionCode) !== null && _d !== void 0 ? _d : statusMsg.state, " ", (_e = statusMsg.message) !== null && _e !== void 0 ? _e : "").trimEnd();
92
+ }
93
+ else {
94
+ task.output = statusMsg.opIngTitle.concat("...", (_f = statusMsg.message) !== null && _f !== void 0 ? _f : "").trimEnd();
95
+ }
96
+ }
97
+ }
98
+ else {
99
+ // No payload - ignore as a ping/heartbeat
100
+ task.output = JSON.stringify(msg);
101
+ }
102
+ });
103
+ // 2. Fire off the async cluster create
104
+ // this._ui.userMessage(`(CLI says, Starting cluster create...`);
105
+ task.output = "Invoking operation...";
106
+ let result = yield trigger(commChannel.socketId);
107
+ if (result.success) {
108
+ // 3. listen for real time status (and wait for final result)
109
+ // await this.monitorExecution(result.output?.taskMap);
110
+ }
111
+ else {
112
+ let logMsg = "Failed invoking operation ".concat(mainOpCode, " [CID ", (_b = (_a = result.output) === null || _a === void 0 ? void 0 : _a.correlationId) !== null && _b !== void 0 ? _b : "none", "]: ", (_g = (_e = (_c = result.message) !== null && _c !== void 0 ? _c : (_d = result.error) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : (_f = result.error) === null || _f === void 0 ? void 0 : _f.stack) !== null && _g !== void 0 ? _g : "no details available");
113
+ this.logger.error(logMsg, result.error);
114
+ let friendlyMsg = "Failed invoking operation: ".concat((_k = (_h = result.message) !== null && _h !== void 0 ? _h : (_j = result.error) === null || _j === void 0 ? void 0 : _j.message) !== null && _k !== void 0 ? _k : "See logs for details");
115
+ // Close up shop and throw
116
+ // task.output = friendlyMsg;
117
+ task.task.complete();
118
+ result.message = friendlyMsg;
119
+ ctx.res = result;
120
+ this.removeStatusListeners();
121
+ reject(result); // <-- result is getting treated like an Error. Ok, cuz we want to send out the friendly message
122
+ }
123
+ }));
124
+ })
125
+ }, {
126
+ renderer: 'default',
127
+ rendererOptions: { timer: listr2_1.PRESET_TIMER }
128
+ });
129
+ let taskResult = yield (spinners === null || spinners === void 0 ? void 0 : spinners.run()); // we're not going to await because we cant block execution (we havent fired the actual task yet)
130
+ // this._ui.userMessage("CLI says, spinner task ended. ".concat(JSON.stringify(taskResult)));
131
+ yield this.relayWebSocket.close();
132
+ // return <TResult>{ success: true, message: "Process execution completed" }; // TODO: Capture the result from the completion status message
133
+ return taskResult.res;
134
+ });
135
+ }
136
+ };
137
+ LrpWatcher = tslib_1.__decorate([
138
+ (0, inversify_1.injectable)(),
139
+ tslib_1.__param(1, (0, inversify_1.inject)(codiac_common_1.INTERFACES.IBetterLogger)),
140
+ tslib_1.__metadata("design:paramtypes", [relay_websocket_client_1.RelayWebsocketClient, Object])
141
+ ], LrpWatcher);
142
+ exports.LrpWatcher = LrpWatcher;
143
+ //# sourceMappingURL=lrp-watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lrp-watcher.js","sourceRoot":"","sources":["../../src/uilogic/lrp-watcher.ts"],"names":[],"mappings":";;;;AAAA,yCAA+C;AAC/C,mCAA6C;AAC7C,4DAAqE;AAErE,8DAA4I;AAC5I,qFAAgF;AAChF,2DAAsD;AAGtD;;;;;GAKG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAU;IAErB,YACU,cAAoC,EACF,MAAqB;QADvD,mBAAc,GAAd,cAAc,CAAsB;QACF,WAAM,GAAN,MAAM,CAAe;IAGjE,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AC,MAAiB,CAAC,CAAC,CAAC,iGAAiG;yBAC7H;oBAEH,CAAC,CAAA,CAAC,CAAC;gBAEL,CAAC,CAAA;aACF,EAED;gBACE,QAAQ,EAAE,SAAS;gBACnB,eAAe,EAAE,EAAE,KAAK,EAAE,qBAAY,EAAE;aACzC,CACF,CAAC;YACF,IAAI,UAAU,GAAG,MAAM,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,GAAG,EAAE,CAAA,CAAC,CAAE,iGAAiG;YAE1I,6FAA6F;YAC7F,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;YAElC,6IAA6I;YAC7I,OAAO,UAAU,CAAC,GAAI,CAAC;QACzB,CAAC;KAAA;CACF,CAAA;AAnJY,UAAU;IADtB,IAAA,sBAAU,GAAE;IAKR,mBAAA,IAAA,kBAAM,EAAC,0BAAU,CAAC,aAAa,CAAC,CAAA;6CADT,6CAAoB;GAHnC,UAAU,CAmJtB;AAnJY,gCAAU"}
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.234",
2
+ "version": "1.2.236",
3
3
  "commands": {
4
4
  "branch": {
5
5
  "id": "branch",
@@ -4916,6 +4916,7 @@
4916
4916
  "pluginName": "@codiac.io/codiac-cli",
4917
4917
  "pluginAlias": "@codiac.io/codiac-cli",
4918
4918
  "pluginType": "core",
4919
+ "hidden": true,
4919
4920
  "aliases": [],
4920
4921
  "flags": {
4921
4922
  "help": {
@@ -5447,6 +5448,17 @@
5447
5448
  "required": false,
5448
5449
  "multiple": false
5449
5450
  },
5451
+ "provider": {
5452
+ "name": "provider",
5453
+ "type": "option",
5454
+ "description": "Cloud service provider on which to provision the cluster",
5455
+ "required": false,
5456
+ "multiple": false,
5457
+ "options": [
5458
+ "azure",
5459
+ "aws"
5460
+ ]
5461
+ },
5450
5462
  "providerSubscription": {
5451
5463
  "name": "providerSubscription",
5452
5464
  "type": "option",
@@ -5697,7 +5709,7 @@
5697
5709
  },
5698
5710
  "noc:cluster:forget": {
5699
5711
  "id": "noc:cluster:forget",
5700
- "description": "Permanently removes the record of a cluster. This command does NOT affect any infrastructure; it simply removes the cluster from the Codiac consciousness. Use `cod cluster capture` to re-acquire an existing but forgotten cluster. You must remove all cabinets and environments in a cluster before forgetting it.",
5712
+ "description": "Permanently removes the record of a cluster. This command does NOT affect any infrastructure; it simply removes the cluster from the Codiac consciousness. You must remove all cabinets and environments in a cluster before forgetting it.",
5701
5713
  "strict": true,
5702
5714
  "pluginName": "@codiac.io/codiac-cli",
5703
5715
  "pluginAlias": "@codiac.io/codiac-cli",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codiac.io/codiac-cli",
3
3
  "description": "Local command line interface for registering and maintaining enterprise assets and pipelines",
4
- "version": "1.2.234",
4
+ "version": "1.2.236",
5
5
  "author": "Codiac",
6
6
  "bin": {
7
7
  "codiac": "./bin/run",
@@ -30,7 +30,7 @@
30
30
  "@codiac.io/api-client-base": "^1.1.15",
31
31
  "@codiac.io/cli-tools": "^1.1.10",
32
32
  "@codiac.io/codiac-common": "^1.1.76",
33
- "@codiac.io/codiac-domain": "^1.3.23",
33
+ "@codiac.io/codiac-domain": "^1.3.28",
34
34
  "@codiac.io/codiac-ops-common": "^1.1.87",
35
35
  "@codiac.io/codiac-relay-contracts": "^1.2.17",
36
36
  "@codiac.io/jwt-lib": "^1.1.6",
@@ -60,7 +60,9 @@
60
60
  "inversify": "^5.1.1",
61
61
  "json-stringify-safe": "^5.0.1",
62
62
  "jsonpath-plus": "^5.0.7",
63
+ "jsonschema": "^1.4.1",
63
64
  "kubernetes-client": "^8.3.7",
65
+ "listr2": "^7.0.2",
64
66
  "lodash": "^4.17.21",
65
67
  "log-update": "^4.0.0",
66
68
  "log4js": "^6.7.0",