@kumori/aurora-backend-handler 1.0.61 → 1.0.63
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 +19 -19
- package/helpers/revision-helper.ts +80 -32
- package/package.json +1 -1
|
@@ -16,13 +16,13 @@ let pendingLinks = new Map<string, Link[]>();
|
|
|
16
16
|
export const deployService = async (data: Service, token: string) => {
|
|
17
17
|
try {
|
|
18
18
|
const url = new URL(
|
|
19
|
-
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}
|
|
19
|
+
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}`,
|
|
20
20
|
);
|
|
21
21
|
url.searchParams.append("dryrun", "false");
|
|
22
22
|
url.searchParams.append("accept", "true");
|
|
23
23
|
url.searchParams.append("wait", "30000");
|
|
24
24
|
url.searchParams.append("validate", "true");
|
|
25
|
-
if(data.dsl){
|
|
25
|
+
if (data.dsl) {
|
|
26
26
|
url.searchParams.append("dsl", "true");
|
|
27
27
|
}
|
|
28
28
|
if (data.serviceData) {
|
|
@@ -33,7 +33,7 @@ export const deployService = async (data: Service, token: string) => {
|
|
|
33
33
|
JSON.stringify({
|
|
34
34
|
targetAccount: data.account,
|
|
35
35
|
targetEnvironment: data.environment,
|
|
36
|
-
})
|
|
36
|
+
}),
|
|
37
37
|
);
|
|
38
38
|
formData.append("labels", JSON.stringify({ project: data.project }));
|
|
39
39
|
formData.append("comment", " ");
|
|
@@ -48,7 +48,7 @@ export const deployService = async (data: Service, token: string) => {
|
|
|
48
48
|
const jsonResponse = await response.json();
|
|
49
49
|
|
|
50
50
|
const isTimeout = jsonResponse?.events?.some(
|
|
51
|
-
(event: any) => event.content === "_timeout_"
|
|
51
|
+
(event: any) => event.content === "_timeout_",
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
if (isTimeout) {
|
|
@@ -81,7 +81,7 @@ export const deployService = async (data: Service, token: string) => {
|
|
|
81
81
|
const jsonResponse = await response.json();
|
|
82
82
|
|
|
83
83
|
const isTimeout = jsonResponse?.events?.some(
|
|
84
|
-
(event: any) => event.content === "_timeout_"
|
|
84
|
+
(event: any) => event.content === "_timeout_",
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
if (isTimeout) {
|
|
@@ -111,7 +111,7 @@ export const redeployService = async (data: Service) => {
|
|
|
111
111
|
try {
|
|
112
112
|
const formData = await deployServiceHelper(data);
|
|
113
113
|
const url = new URL(
|
|
114
|
-
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}/revision/${data.currentRevision}
|
|
114
|
+
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}/revision/${data.currentRevision}`,
|
|
115
115
|
);
|
|
116
116
|
url.searchParams.append("dryrun", "false");
|
|
117
117
|
url.searchParams.append("accept", "true");
|
|
@@ -130,7 +130,7 @@ export const redeployService = async (data: Service) => {
|
|
|
130
130
|
const jsonResponse = await response.json();
|
|
131
131
|
|
|
132
132
|
const isTimeout = jsonResponse?.events?.some(
|
|
133
|
-
(event: any) => event.content === "_timeout_"
|
|
133
|
+
(event: any) => event.content === "_timeout_",
|
|
134
134
|
);
|
|
135
135
|
|
|
136
136
|
if (isTimeout) {
|
|
@@ -163,7 +163,7 @@ export const deleteService = async (data: Service, security: string) => {
|
|
|
163
163
|
deleteBody,
|
|
164
164
|
30000,
|
|
165
165
|
"DELETE",
|
|
166
|
-
data.name
|
|
166
|
+
data.name,
|
|
167
167
|
);
|
|
168
168
|
return response;
|
|
169
169
|
} catch (err) {
|
|
@@ -188,7 +188,7 @@ export const restartService = async (data: Service, security: string) => {
|
|
|
188
188
|
restartBody,
|
|
189
189
|
30000,
|
|
190
190
|
"RESTART",
|
|
191
|
-
data.name
|
|
191
|
+
data.name,
|
|
192
192
|
);
|
|
193
193
|
|
|
194
194
|
const updatedService: Service = {
|
|
@@ -319,7 +319,7 @@ export const linkPendingServices = async (service: Service, token: string) => {
|
|
|
319
319
|
linkBody,
|
|
320
320
|
30000,
|
|
321
321
|
"LINK",
|
|
322
|
-
service.name
|
|
322
|
+
service.name,
|
|
323
323
|
);
|
|
324
324
|
|
|
325
325
|
const notification: Notification = {
|
|
@@ -353,7 +353,7 @@ export const linkPendingServices = async (service: Service, token: string) => {
|
|
|
353
353
|
};
|
|
354
354
|
eventHelper.notification.publish.creation(notification);
|
|
355
355
|
}
|
|
356
|
-
})
|
|
356
|
+
}),
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
359
|
};
|
|
@@ -375,7 +375,7 @@ export const requestRevisionData = async (service: Service, token: string) => {
|
|
|
375
375
|
"GET_REVISION",
|
|
376
376
|
service.name,
|
|
377
377
|
"service",
|
|
378
|
-
service
|
|
378
|
+
service,
|
|
379
379
|
);
|
|
380
380
|
return response;
|
|
381
381
|
} catch (err) {
|
|
@@ -623,7 +623,7 @@ export const updateService = async (
|
|
|
623
623
|
};
|
|
624
624
|
export const unlinkServices = async (service: Service, token: string) => {
|
|
625
625
|
const deleteLinks: Link[] = service.links.filter(
|
|
626
|
-
(link) => link.delete === true
|
|
626
|
+
(link) => link.delete === true,
|
|
627
627
|
);
|
|
628
628
|
if (deleteLinks.length > 0) {
|
|
629
629
|
await Promise.all(
|
|
@@ -638,7 +638,7 @@ export const unlinkServices = async (service: Service, token: string) => {
|
|
|
638
638
|
unlinkBody,
|
|
639
639
|
30000,
|
|
640
640
|
"UNLINK",
|
|
641
|
-
service.name
|
|
641
|
+
service.name,
|
|
642
642
|
);
|
|
643
643
|
|
|
644
644
|
const unlinkNotification: Notification = {
|
|
@@ -674,7 +674,7 @@ export const unlinkServices = async (service: Service, token: string) => {
|
|
|
674
674
|
};
|
|
675
675
|
eventHelper.notification.publish.creation(notification);
|
|
676
676
|
}
|
|
677
|
-
})
|
|
677
|
+
}),
|
|
678
678
|
);
|
|
679
679
|
}
|
|
680
680
|
};
|
|
@@ -699,7 +699,7 @@ export const updateServiceLinks = async (link: Link, token: string) => {
|
|
|
699
699
|
linkBody,
|
|
700
700
|
30000,
|
|
701
701
|
"UNLINK",
|
|
702
|
-
link.origin
|
|
702
|
+
link.origin,
|
|
703
703
|
);
|
|
704
704
|
|
|
705
705
|
// const unlinkNotification: Notification = {
|
|
@@ -745,7 +745,7 @@ export const updateServiceLinks = async (link: Link, token: string) => {
|
|
|
745
745
|
linkBody,
|
|
746
746
|
30000,
|
|
747
747
|
"LINK",
|
|
748
|
-
link.origin
|
|
748
|
+
link.origin,
|
|
749
749
|
);
|
|
750
750
|
|
|
751
751
|
const notification: Notification = {
|
|
@@ -801,7 +801,7 @@ export const changeRevision = async (data: Service, token: string) => {
|
|
|
801
801
|
revisionBody,
|
|
802
802
|
30000,
|
|
803
803
|
"UPDATE_REVISION",
|
|
804
|
-
data.name
|
|
804
|
+
data.name,
|
|
805
805
|
);
|
|
806
806
|
const notification: Notification = {
|
|
807
807
|
type: "success",
|
|
@@ -886,4 +886,4 @@ export async function restartInstance(service: Service, roleId: string, instance
|
|
|
886
886
|
};
|
|
887
887
|
eventHelper.notification.publish.creation(notification);
|
|
888
888
|
}
|
|
889
|
-
}
|
|
889
|
+
}
|
|
@@ -217,12 +217,16 @@ const updateServiceWithRevision = (
|
|
|
217
217
|
const existingRevisionIndex = existingService.revisions.findIndex(
|
|
218
218
|
(rev) => String(rev.id) === String(entityId),
|
|
219
219
|
);
|
|
220
|
-
const existingRevision =
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
220
|
+
const existingRevision =
|
|
221
|
+
existingRevisionIndex !== -1
|
|
222
|
+
? existingService.revisions[existingRevisionIndex]
|
|
223
|
+
: null;
|
|
224
|
+
const hasExistingSchema =
|
|
225
|
+
existingRevision?.schema &&
|
|
226
|
+
("parameters" in existingRevision.schema ||
|
|
227
|
+
"resources" in existingRevision.schema);
|
|
228
|
+
const hasNewSchema =
|
|
229
|
+
newRevision.schema &&
|
|
226
230
|
("parameters" in newRevision.schema || "resources" in newRevision.schema);
|
|
227
231
|
if (hasExistingSchema && !hasNewSchema) {
|
|
228
232
|
newRevision.schema = existingRevision!.schema;
|
|
@@ -238,9 +242,10 @@ const updateServiceWithRevision = (
|
|
|
238
242
|
const updatedService: Service = {
|
|
239
243
|
...existingService,
|
|
240
244
|
revisions: updatedRevisions,
|
|
241
|
-
currentRevision:
|
|
242
|
-
|
|
243
|
-
|
|
245
|
+
currentRevision:
|
|
246
|
+
Number(entityId) >= Number(existingService.currentRevision ?? 0)
|
|
247
|
+
? entityId
|
|
248
|
+
: existingService.currentRevision,
|
|
244
249
|
role: roles.length > 0 ? roles : existingService.role,
|
|
245
250
|
usage: newRevision.usage,
|
|
246
251
|
startedAt: newRevision.createdAt || existingService.startedAt,
|
|
@@ -276,10 +281,14 @@ const updateServiceWithRevision = (
|
|
|
276
281
|
deploymentErrorEvent = updatedService;
|
|
277
282
|
}
|
|
278
283
|
}
|
|
284
|
+
const incomingRevisionId = Number(entityId);
|
|
285
|
+
const currentRevisionId = Number(existingService.currentRevision ?? 0);
|
|
286
|
+
if (incomingRevisionId >= currentRevisionId && !eventData.status.error) {
|
|
287
|
+
updatedService.error = undefined;
|
|
288
|
+
}
|
|
279
289
|
|
|
280
290
|
return { updatedService, deploymentErrorEvent };
|
|
281
291
|
};
|
|
282
|
-
|
|
283
292
|
const updateEnvironmentConsumption = (
|
|
284
293
|
environment: Environment,
|
|
285
294
|
servicesMap: Map<string, Service>,
|
|
@@ -535,7 +544,8 @@ export const extractStructuredSchema = (
|
|
|
535
544
|
if (!configSchema) return {};
|
|
536
545
|
const deployedConfig = revisionData?.config?.config ?? {};
|
|
537
546
|
const parameterValues: Record<string, any> = deployedConfig.parameter ?? {};
|
|
538
|
-
const configResourceValues: Record<string, any> =
|
|
547
|
+
const configResourceValues: Record<string, any> =
|
|
548
|
+
deployedConfig.resource ?? {};
|
|
539
549
|
|
|
540
550
|
const requiredParams: string[] =
|
|
541
551
|
configSchema?.properties?.config?.required ?? [];
|
|
@@ -566,14 +576,22 @@ export const extractStructuredSchema = (
|
|
|
566
576
|
|
|
567
577
|
const resolveResourceValue = (configValue: any): string => {
|
|
568
578
|
if (!configValue || typeof configValue !== "object") return "";
|
|
569
|
-
if (typeof configValue.secret === "string")
|
|
570
|
-
|
|
571
|
-
if (typeof configValue.
|
|
572
|
-
|
|
573
|
-
if (typeof configValue.
|
|
579
|
+
if (typeof configValue.secret === "string")
|
|
580
|
+
return extractResourceName(configValue.secret);
|
|
581
|
+
if (typeof configValue.domain === "string")
|
|
582
|
+
return extractResourceName(configValue.domain);
|
|
583
|
+
if (typeof configValue.port === "string")
|
|
584
|
+
return extractResourceName(configValue.port);
|
|
585
|
+
if (typeof configValue.certificate === "string")
|
|
586
|
+
return extractResourceName(configValue.certificate);
|
|
587
|
+
if (typeof configValue.ca === "string")
|
|
588
|
+
return extractResourceName(configValue.ca);
|
|
574
589
|
if (configValue.volume) {
|
|
575
590
|
const vol = configValue.volume;
|
|
576
|
-
return
|
|
591
|
+
return (
|
|
592
|
+
convertToGigabytes(vol.size, vol.unit)?.toString() ??
|
|
593
|
+
String(vol.size ?? "")
|
|
594
|
+
);
|
|
577
595
|
}
|
|
578
596
|
return "";
|
|
579
597
|
};
|
|
@@ -656,7 +674,9 @@ export const processRevisionData = (
|
|
|
656
674
|
): Service => {
|
|
657
675
|
const { solution } = revisionData;
|
|
658
676
|
const topLevelConfig = revisionData?.config?.config ?? {};
|
|
659
|
-
const topLevelParameters = extractParametersFromConfig(
|
|
677
|
+
const topLevelParameters = extractParametersFromConfig(
|
|
678
|
+
topLevelConfig.parameter || {},
|
|
679
|
+
);
|
|
660
680
|
const topLevelResources = extractResources(topLevelConfig.resource || {});
|
|
661
681
|
|
|
662
682
|
const schemaResult = revisionData.revision
|
|
@@ -736,11 +756,21 @@ export const processRevisionData = (
|
|
|
736
756
|
id: revisionId,
|
|
737
757
|
schema,
|
|
738
758
|
usage: svc.usage || {
|
|
739
|
-
current: {
|
|
759
|
+
current: {
|
|
760
|
+
cpu: 0,
|
|
761
|
+
memory: 0,
|
|
762
|
+
storage: 0,
|
|
763
|
+
volatileStorage: 0,
|
|
764
|
+
nonReplicatedStorage: 0,
|
|
765
|
+
persistentStorage: 0,
|
|
766
|
+
},
|
|
740
767
|
limit: {
|
|
741
|
-
cpu: { max: 0, min: 0 },
|
|
742
|
-
|
|
743
|
-
|
|
768
|
+
cpu: { max: 0, min: 0 },
|
|
769
|
+
memory: { max: 0, min: 0 },
|
|
770
|
+
storage: { max: 0, min: 0 },
|
|
771
|
+
volatileStorage: { max: 0, min: 0 },
|
|
772
|
+
nonReplicatedStorage: { max: 0, min: 0 },
|
|
773
|
+
persistentStorage: { max: 0, min: 0 },
|
|
744
774
|
},
|
|
745
775
|
cost: 0,
|
|
746
776
|
},
|
|
@@ -754,7 +784,10 @@ export const processRevisionData = (
|
|
|
754
784
|
return {
|
|
755
785
|
...svc,
|
|
756
786
|
revisions: updatedRevisions,
|
|
757
|
-
currentRevision:
|
|
787
|
+
currentRevision:
|
|
788
|
+
Number(revisionId) >= Number(currentRevId)
|
|
789
|
+
? revisionId
|
|
790
|
+
: svc.currentRevision,
|
|
758
791
|
};
|
|
759
792
|
};
|
|
760
793
|
|
|
@@ -771,11 +804,21 @@ export const processRevisionData = (
|
|
|
771
804
|
),
|
|
772
805
|
);
|
|
773
806
|
}
|
|
774
|
-
return applySchemaToService({
|
|
807
|
+
return applySchemaToService({
|
|
808
|
+
...service,
|
|
809
|
+
parameters: topLevelParameters,
|
|
810
|
+
resources: topLevelResources,
|
|
811
|
+
});
|
|
775
812
|
}
|
|
776
813
|
|
|
777
814
|
return applySchemaToService(
|
|
778
|
-
processDeployment(
|
|
815
|
+
processDeployment(
|
|
816
|
+
service,
|
|
817
|
+
deployment,
|
|
818
|
+
revisionData,
|
|
819
|
+
topLevelParameters,
|
|
820
|
+
topLevelResources,
|
|
821
|
+
),
|
|
779
822
|
);
|
|
780
823
|
};
|
|
781
824
|
|
|
@@ -796,13 +839,14 @@ export const processDeployment = (
|
|
|
796
839
|
Object.entries(rolesDefinition).forEach(
|
|
797
840
|
([roleName, roleData]: [string, any]) => {
|
|
798
841
|
const existingRole = service.role.find((r) => r.name === roleName);
|
|
799
|
-
const roleArtifactConfig =
|
|
842
|
+
const roleArtifactConfig =
|
|
843
|
+
roleData?.artifact?.description?.config ?? {};
|
|
800
844
|
|
|
801
845
|
const roleParameters = extractParametersFromConfig(
|
|
802
|
-
roleArtifactConfig.parameter ?? {}
|
|
846
|
+
roleArtifactConfig.parameter ?? {},
|
|
803
847
|
);
|
|
804
848
|
const roleResources = extractResources(
|
|
805
|
-
roleArtifactConfig.resource ?? {}
|
|
849
|
+
roleArtifactConfig.resource ?? {},
|
|
806
850
|
);
|
|
807
851
|
const parameters = roleParameters;
|
|
808
852
|
const resources = roleResources;
|
|
@@ -819,8 +863,7 @@ export const processDeployment = (
|
|
|
819
863
|
roleArtifactConfig.resource || {},
|
|
820
864
|
).some((resourceData: any) => resourceData.volume);
|
|
821
865
|
|
|
822
|
-
const artifactName: string =
|
|
823
|
-
roleData.artifact?.ref?.name || "";
|
|
866
|
+
const artifactName: string = roleData.artifact?.ref?.name || "";
|
|
824
867
|
const role: Role = {
|
|
825
868
|
name: roleName,
|
|
826
869
|
artifactName: artifactName || undefined,
|
|
@@ -868,7 +911,12 @@ export const processDeployment = (
|
|
|
868
911
|
},
|
|
869
912
|
];
|
|
870
913
|
}
|
|
871
|
-
return {
|
|
914
|
+
return {
|
|
915
|
+
...service,
|
|
916
|
+
resources: fallbackResources,
|
|
917
|
+
parameters: fallbackParameters,
|
|
918
|
+
role: updatedRoles,
|
|
919
|
+
};
|
|
872
920
|
};
|
|
873
921
|
|
|
874
922
|
export const extractParametersFromConfig = (
|
|
@@ -1081,4 +1129,4 @@ const extractResourceName = (resourcePath: string): string => {
|
|
|
1081
1129
|
return parts[1];
|
|
1082
1130
|
}
|
|
1083
1131
|
return resourcePath;
|
|
1084
|
-
};
|
|
1132
|
+
};
|