@kumori/aurora-backend-handler 1.0.52 → 1.0.54
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/api/service-api-service.ts +47 -0
- package/backend-handler.ts +8 -0
- package/event-helper.ts +12 -3
- package/event-names.ts +3 -0
- package/helpers/revision-helper.ts +4 -26
- package/package.json +1 -1
|
@@ -839,4 +839,51 @@ function getLatestRevision(revisions: Revision[]): number | null {
|
|
|
839
839
|
}
|
|
840
840
|
|
|
841
841
|
return Math.max(...revisions.map((revision) => Number(revision.id)));
|
|
842
|
+
}
|
|
843
|
+
export async function restartInstance(service: Service, roleId: string, instanceId: string, token: string) {
|
|
844
|
+
try {
|
|
845
|
+
await initializeGlobalWebSocketClient(token);
|
|
846
|
+
const status = getWebSocketStatus();
|
|
847
|
+
const revisionBody = {
|
|
848
|
+
tenant: service.tenant,
|
|
849
|
+
service: service.name,
|
|
850
|
+
role: roleId,
|
|
851
|
+
instance: instanceId === "all" ? undefined : instanceId,
|
|
852
|
+
};
|
|
853
|
+
const revisionResponse = await makeGlobalWebSocketRequest(
|
|
854
|
+
"service:restart",
|
|
855
|
+
revisionBody,
|
|
856
|
+
30000,
|
|
857
|
+
"RESTART_INSTANCE",
|
|
858
|
+
service.name
|
|
859
|
+
);
|
|
860
|
+
const notification: Notification = {
|
|
861
|
+
type: "success",
|
|
862
|
+
subtype: "instance-restarted",
|
|
863
|
+
date: Date.now().toString(),
|
|
864
|
+
status: "unread",
|
|
865
|
+
callToAction: false,
|
|
866
|
+
data: {
|
|
867
|
+
service: service,
|
|
868
|
+
},
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
eventHelper.notification.publish.creation(notification);
|
|
872
|
+
} catch (error) {
|
|
873
|
+
const notification: Notification = {
|
|
874
|
+
type: "error",
|
|
875
|
+
subtype: "error-instance-update",
|
|
876
|
+
date: Date.now().toString(),
|
|
877
|
+
info_content: {
|
|
878
|
+
code: (error as any).error.code,
|
|
879
|
+
message: (error as any).error.content,
|
|
880
|
+
},
|
|
881
|
+
status: "unread",
|
|
882
|
+
callToAction: false,
|
|
883
|
+
data: {
|
|
884
|
+
service: service,
|
|
885
|
+
},
|
|
886
|
+
};
|
|
887
|
+
eventHelper.notification.publish.creation(notification);
|
|
888
|
+
}
|
|
842
889
|
}
|
package/backend-handler.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
deployService,
|
|
6
6
|
redeployService,
|
|
7
7
|
requestRevisionData,
|
|
8
|
+
restartInstance,
|
|
8
9
|
restartService,
|
|
9
10
|
updateService,
|
|
10
11
|
updateServiceLinks,
|
|
@@ -903,6 +904,13 @@ export class BackendHandler {
|
|
|
903
904
|
this.unsubscribeFunctions.push(() => {
|
|
904
905
|
eventHelper.service.unsubscribe.changeRevision(changeRevisionCb);
|
|
905
906
|
})
|
|
907
|
+
const restartInstanceCb = (payload: { service: Service; roleId: string; instanceId: string; }) => {
|
|
908
|
+
restartInstance(payload.service, payload.roleId, payload.instanceId, token);
|
|
909
|
+
}
|
|
910
|
+
eventHelper.service.subscribe.restartInstance(restartInstanceCb);
|
|
911
|
+
this.unsubscribeFunctions.push(() =>
|
|
912
|
+
eventHelper.service.unsubscribe.restartInstance(restartInstanceCb)
|
|
913
|
+
);
|
|
906
914
|
}
|
|
907
915
|
/**
|
|
908
916
|
* Function to subscribe to the marketplace events
|
package/event-helper.ts
CHANGED
|
@@ -336,7 +336,10 @@ export class EventHelper {
|
|
|
336
336
|
updateServiceLinks : this.createEvent<Link>(EventNames.updateServiceLinks).publish,
|
|
337
337
|
changeRevision: this.createEvent<Service>(EventNames.ChangeRevision).publish,
|
|
338
338
|
revisionChanged: this.createEvent<Service>(EventNames.RevisionChanged).publish,
|
|
339
|
-
revisionChangeError: this.createEvent<Service>(EventNames.RevisionChangeError).publish
|
|
339
|
+
revisionChangeError: this.createEvent<Service>(EventNames.RevisionChangeError).publish,
|
|
340
|
+
restartInstance: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.RestartInstance).publish,
|
|
341
|
+
instanceRestarted: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.InstanceRestarted).publish,
|
|
342
|
+
instanceRestartError: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.InstanceRestartError).publish,
|
|
340
343
|
},
|
|
341
344
|
subscribe: {
|
|
342
345
|
deploy: this.createEvent<Service>(EventNames.DeployService).subscribe,
|
|
@@ -356,7 +359,10 @@ export class EventHelper {
|
|
|
356
359
|
updateServiceLinks : this.createEvent<Link>(EventNames.updateServiceLinks).subscribe,
|
|
357
360
|
changeRevision: this.createEvent<Service>(EventNames.ChangeRevision).subscribe,
|
|
358
361
|
revisionChanged: this.createEvent<Service>(EventNames.RevisionChanged).subscribe,
|
|
359
|
-
revisionChangeError: this.createEvent<Service>(EventNames.RevisionChangeError).subscribe
|
|
362
|
+
revisionChangeError: this.createEvent<Service>(EventNames.RevisionChangeError).subscribe,
|
|
363
|
+
restartInstance: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.RestartInstance).subscribe,
|
|
364
|
+
instanceRestarted: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.InstanceRestarted).subscribe,
|
|
365
|
+
instanceRestartError: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.InstanceRestartError).subscribe,
|
|
360
366
|
},
|
|
361
367
|
unsubscribe: {
|
|
362
368
|
deploy: this.createEvent<Service>(EventNames.DeployService).unsubscribe,
|
|
@@ -376,7 +382,10 @@ export class EventHelper {
|
|
|
376
382
|
updateServiceLinks : this.createEvent<Link>(EventNames.updateServiceLinks).unsubscribe,
|
|
377
383
|
changeRevision: this.createEvent<Service>(EventNames.ChangeRevision).unsubscribe,
|
|
378
384
|
revisionChanged: this.createEvent<Service>(EventNames.RevisionChanged).unsubscribe,
|
|
379
|
-
revisionChangeError: this.createEvent<Service>(EventNames.RevisionChangeError).unsubscribe
|
|
385
|
+
revisionChangeError: this.createEvent<Service>(EventNames.RevisionChangeError).unsubscribe,
|
|
386
|
+
restartInstance: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.RestartInstance).unsubscribe,
|
|
387
|
+
instanceRestarted: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.InstanceRestarted).unsubscribe,
|
|
388
|
+
instanceRestartError: this.createEvent<{ service: Service; roleId: string; instanceId: string }>(EventNames.InstanceRestartError).unsubscribe,
|
|
380
389
|
},
|
|
381
390
|
};
|
|
382
391
|
}
|
package/event-names.ts
CHANGED
|
@@ -102,6 +102,9 @@ export enum EventNames {
|
|
|
102
102
|
ChangeRevision = "changeRevision",
|
|
103
103
|
RevisionChanged = "revisionChanged",
|
|
104
104
|
RevisionChangeError = "revisionChangeError",
|
|
105
|
+
RestartInstance = "restartInstance",
|
|
106
|
+
InstanceRestarted = "instanceRestarted",
|
|
107
|
+
InstanceRestartError = "instanceRestartError",
|
|
105
108
|
// * Marketplace
|
|
106
109
|
DeployMarketplaceItem = "deployMarketplaceItem",
|
|
107
110
|
MarketplaceItemDeployed = "marketplaceItemDeployed",
|
|
@@ -110,7 +110,7 @@ const processRolesAndInstances = (
|
|
|
110
110
|
|
|
111
111
|
const instance: Instance = {
|
|
112
112
|
id: instanceId,
|
|
113
|
-
name: `${
|
|
113
|
+
name: `${instanceId}`,
|
|
114
114
|
status: instanceData.status.status,
|
|
115
115
|
usage: {
|
|
116
116
|
current: {
|
|
@@ -520,31 +520,9 @@ export const extractStructuredSchema = (
|
|
|
520
520
|
| {} => {
|
|
521
521
|
const configSchema = revisionData?.configSchema;
|
|
522
522
|
if (!configSchema) return {};
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
const
|
|
526
|
-
? revisionData?.solution?.deployments?.[deploymentName]
|
|
527
|
-
: Object.values(revisionData?.solution?.deployments ?? {})[0];
|
|
528
|
-
const rolesDefinition: Record<string, any> =
|
|
529
|
-
(deployment as any)?.artifact?.description?.role ?? {};
|
|
530
|
-
|
|
531
|
-
const mergedParameterValues: Record<string, any> = {};
|
|
532
|
-
const mergedResourceValues: Record<string, any> = {};
|
|
533
|
-
|
|
534
|
-
Object.values(rolesDefinition).forEach((roleData: any) => {
|
|
535
|
-
const roleConfig = roleData?.artifact?.description?.config ?? {};
|
|
536
|
-
Object.assign(mergedParameterValues, roleConfig.parameter ?? {});
|
|
537
|
-
Object.assign(mergedResourceValues, roleConfig.resource ?? {});
|
|
538
|
-
});
|
|
539
|
-
const topLevelConfig = (deployment as any)?.config ?? {};
|
|
540
|
-
const parameterValues: Record<string, any> = {
|
|
541
|
-
...topLevelConfig.parameter ?? {},
|
|
542
|
-
...mergedParameterValues,
|
|
543
|
-
};
|
|
544
|
-
const configResourceValues: Record<string, any> = {
|
|
545
|
-
...topLevelConfig.resource ?? {},
|
|
546
|
-
...mergedResourceValues,
|
|
547
|
-
};
|
|
523
|
+
const deployedConfig = revisionData?.config?.config ?? {};
|
|
524
|
+
const parameterValues: Record<string, any> = deployedConfig.parameter ?? {};
|
|
525
|
+
const configResourceValues: Record<string, any> = deployedConfig.resource ?? {};
|
|
548
526
|
|
|
549
527
|
const requiredParams: string[] =
|
|
550
528
|
configSchema?.properties?.config?.required ?? [];
|