@kumori/aurora-backend-handler 1.0.36 → 1.0.37
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/helpers/revision-helper.ts +163 -110
- package/package.json +1 -1
- package/websocket-manager.ts +2 -0
|
@@ -462,9 +462,122 @@ export const handleRevisionEvent = ({
|
|
|
462
462
|
};
|
|
463
463
|
};
|
|
464
464
|
|
|
465
|
+
const collectNamedTypes = (schema: any): string[] => {
|
|
466
|
+
if (!schema || typeof schema !== "object") return [];
|
|
467
|
+
const names: string[] = [];
|
|
468
|
+
if (schema.$kdsl?.const?.NamedType?.Name)
|
|
469
|
+
names.push(schema.$kdsl.const.NamedType.Name as string);
|
|
470
|
+
if (Array.isArray(schema.oneOf)) {
|
|
471
|
+
for (const branch of schema.oneOf) names.push(...collectNamedTypes(branch));
|
|
472
|
+
}
|
|
473
|
+
return names;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const namedTypeToResourceKind = (
|
|
477
|
+
namedTypes: string[],
|
|
478
|
+
): { type: string; kind?: string } => {
|
|
479
|
+
for (const name of namedTypes) {
|
|
480
|
+
switch (name) {
|
|
481
|
+
case "Secret":
|
|
482
|
+
return { type: "secret" };
|
|
483
|
+
case "Domain":
|
|
484
|
+
return { type: "domain" };
|
|
485
|
+
case "Port":
|
|
486
|
+
return { type: "port" };
|
|
487
|
+
case "Certificate":
|
|
488
|
+
return { type: "certificate" };
|
|
489
|
+
case "CA":
|
|
490
|
+
return { type: "ca" };
|
|
491
|
+
case "Volatile":
|
|
492
|
+
case "Ephemeral":
|
|
493
|
+
return { type: "volume", kind: "volatile" };
|
|
494
|
+
case "NonReplicated":
|
|
495
|
+
return { type: "volume", kind: "nonReplicated" };
|
|
496
|
+
case "Persisted":
|
|
497
|
+
case "Persistent":
|
|
498
|
+
return { type: "volume", kind: "persistent" };
|
|
499
|
+
case "Registered":
|
|
500
|
+
return { type: "volume" };
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return { type: "secret" };
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
export const extractStructuredSchema = (
|
|
507
|
+
revisionData: any,
|
|
508
|
+
): {
|
|
509
|
+
parameters: {
|
|
510
|
+
name: string;
|
|
511
|
+
type: string;
|
|
512
|
+
required: boolean;
|
|
513
|
+
defaultValue?: any;
|
|
514
|
+
}[];
|
|
515
|
+
resources: { name: string; type: string; kind?: string; required: boolean }[];
|
|
516
|
+
} => {
|
|
517
|
+
const configSchema = revisionData?.configSchema;
|
|
518
|
+
const deploymentName = revisionData?.solution?.top;
|
|
519
|
+
const deployment = deploymentName
|
|
520
|
+
? revisionData?.solution?.deployments?.[deploymentName]
|
|
521
|
+
: Object.values(revisionData?.solution?.deployments ?? {})[0];
|
|
522
|
+
|
|
523
|
+
const parameterValues: Record<string, any> =
|
|
524
|
+
(deployment as any)?.config?.parameter ?? {};
|
|
525
|
+
const requiredParams: string[] =
|
|
526
|
+
configSchema?.properties?.config?.required ?? [];
|
|
527
|
+
const requiredResources: string[] =
|
|
528
|
+
configSchema?.properties?.resource?.required ?? [];
|
|
529
|
+
const schemaConfigProps: Record<string, any> =
|
|
530
|
+
configSchema?.properties?.config?.properties ?? {};
|
|
531
|
+
const schemaResourceProps: Record<string, any> =
|
|
532
|
+
configSchema?.properties?.resource?.properties ?? {};
|
|
533
|
+
|
|
534
|
+
const parameters = Object.entries(schemaConfigProps).map(
|
|
535
|
+
([name, propSchema]) => {
|
|
536
|
+
const entry: {
|
|
537
|
+
name: string;
|
|
538
|
+
type: string;
|
|
539
|
+
required: boolean;
|
|
540
|
+
defaultValue?: any;
|
|
541
|
+
} = {
|
|
542
|
+
name,
|
|
543
|
+
type: propSchema?.type ?? "string",
|
|
544
|
+
required: requiredParams.includes(name),
|
|
545
|
+
};
|
|
546
|
+
const currentValue = parameterValues[name];
|
|
547
|
+
if (currentValue !== undefined) entry.defaultValue = currentValue;
|
|
548
|
+
else if (propSchema?.default !== undefined)
|
|
549
|
+
entry.defaultValue = propSchema.default;
|
|
550
|
+
return entry;
|
|
551
|
+
},
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
const resources = Object.entries(schemaResourceProps).map(
|
|
555
|
+
([name, propSchema]) => {
|
|
556
|
+
const namedTypes = collectNamedTypes(propSchema);
|
|
557
|
+
const resolved = namedTypeToResourceKind(namedTypes);
|
|
558
|
+
const entry: {
|
|
559
|
+
name: string;
|
|
560
|
+
type: string;
|
|
561
|
+
kind?: string;
|
|
562
|
+
required: boolean;
|
|
563
|
+
} = {
|
|
564
|
+
name,
|
|
565
|
+
type: resolved.type,
|
|
566
|
+
required: requiredResources.includes(name),
|
|
567
|
+
};
|
|
568
|
+
if (resolved.kind) entry.kind = resolved.kind;
|
|
569
|
+
return entry;
|
|
570
|
+
},
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
return { parameters, resources };
|
|
574
|
+
};
|
|
575
|
+
|
|
465
576
|
export const processRevisionData = (
|
|
466
577
|
service: Service,
|
|
467
578
|
revisionData: any,
|
|
579
|
+
revisionsMap?: Map<string, Revision>,
|
|
580
|
+
serviceId?: string,
|
|
468
581
|
): Service => {
|
|
469
582
|
const { solution } = revisionData;
|
|
470
583
|
|
|
@@ -472,6 +585,56 @@ export const processRevisionData = (
|
|
|
472
585
|
const parameters = extractParametersFromConfig(config.parameter || {});
|
|
473
586
|
const resources = extractResources(config.resource || {});
|
|
474
587
|
|
|
588
|
+
if (revisionsMap && serviceId && revisionData.revision) {
|
|
589
|
+
const revisionId: string = revisionData.revision;
|
|
590
|
+
const revisionKey = `${serviceId}-${revisionId}`;
|
|
591
|
+
const schema = extractStructuredSchema(revisionData);
|
|
592
|
+
const existing = revisionsMap.get(revisionKey);
|
|
593
|
+
if (existing) {
|
|
594
|
+
revisionsMap.set(revisionKey, { ...existing, schema });
|
|
595
|
+
} else {
|
|
596
|
+
revisionsMap.set(revisionKey, {
|
|
597
|
+
id: revisionId,
|
|
598
|
+
schema,
|
|
599
|
+
usage: {
|
|
600
|
+
current: {
|
|
601
|
+
cpu: 0,
|
|
602
|
+
memory: 0,
|
|
603
|
+
storage: 0,
|
|
604
|
+
volatileStorage: 0,
|
|
605
|
+
nonReplicatedStorage: 0,
|
|
606
|
+
persistentStorage: 0,
|
|
607
|
+
},
|
|
608
|
+
limit: {
|
|
609
|
+
cpu: { max: revisionData.intensives?.vcpu / 1000 || 0, min: 0 },
|
|
610
|
+
memory: { max: revisionData.intensives?.ram / 1000 || 0, min: 0 },
|
|
611
|
+
storage: {
|
|
612
|
+
max: revisionData.intensives?.shared_disk / 1000 || 0,
|
|
613
|
+
min: 0,
|
|
614
|
+
},
|
|
615
|
+
volatileStorage: {
|
|
616
|
+
max: revisionData.intensives?.volatile_disk / 1000 || 0,
|
|
617
|
+
min: 0,
|
|
618
|
+
},
|
|
619
|
+
nonReplicatedStorage: {
|
|
620
|
+
max: revisionData.intensives?.nrpersistent_disk / 1000 || 0,
|
|
621
|
+
min: 0,
|
|
622
|
+
},
|
|
623
|
+
persistentStorage: {
|
|
624
|
+
max: revisionData.intensives?.persistent_disk / 1000 || 0,
|
|
625
|
+
min: 0,
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
cost: 0,
|
|
629
|
+
},
|
|
630
|
+
status: { code: "", message: "", timestamp: "", args: [] },
|
|
631
|
+
errorCode: "",
|
|
632
|
+
errorMsg: "",
|
|
633
|
+
createdAt: "",
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
475
638
|
const deploymentName = solution.top || service.name;
|
|
476
639
|
const deployment = solution.deployments[deploymentName];
|
|
477
640
|
|
|
@@ -784,113 +947,3 @@ const extractResourceName = (resourcePath: string): string => {
|
|
|
784
947
|
return resourcePath;
|
|
785
948
|
};
|
|
786
949
|
|
|
787
|
-
const collectNamedTypes = (schema: any): string[] => {
|
|
788
|
-
if (!schema || typeof schema !== "object") return [];
|
|
789
|
-
const names: string[] = [];
|
|
790
|
-
if (schema.$kdsl?.const?.NamedType?.Name)
|
|
791
|
-
names.push(schema.$kdsl.const.NamedType.Name as string);
|
|
792
|
-
if (Array.isArray(schema.oneOf)) {
|
|
793
|
-
for (const branch of schema.oneOf) names.push(...collectNamedTypes(branch));
|
|
794
|
-
}
|
|
795
|
-
return names;
|
|
796
|
-
};
|
|
797
|
-
|
|
798
|
-
const namedTypeToResourceKind = (
|
|
799
|
-
namedTypes: string[],
|
|
800
|
-
): { type: string; kind?: string } => {
|
|
801
|
-
for (const name of namedTypes) {
|
|
802
|
-
switch (name) {
|
|
803
|
-
case "Secret":
|
|
804
|
-
return { type: "secret" };
|
|
805
|
-
case "Domain":
|
|
806
|
-
return { type: "domain" };
|
|
807
|
-
case "Port":
|
|
808
|
-
return { type: "port" };
|
|
809
|
-
case "Certificate":
|
|
810
|
-
return { type: "certificate" };
|
|
811
|
-
case "CA":
|
|
812
|
-
return { type: "ca" };
|
|
813
|
-
case "Volatile":
|
|
814
|
-
case "Ephemeral":
|
|
815
|
-
return { type: "volume", kind: "volatile" };
|
|
816
|
-
case "NonReplicated":
|
|
817
|
-
return { type: "volume", kind: "nonReplicated" };
|
|
818
|
-
case "Persisted":
|
|
819
|
-
case "Persistent":
|
|
820
|
-
return { type: "volume", kind: "persistent" };
|
|
821
|
-
case "Registered":
|
|
822
|
-
return { type: "volume" };
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
return { type: "secret" };
|
|
826
|
-
};
|
|
827
|
-
|
|
828
|
-
export const extractStructuredSchema = (
|
|
829
|
-
revisionData: any,
|
|
830
|
-
): {
|
|
831
|
-
parameters: {
|
|
832
|
-
name: string;
|
|
833
|
-
type: string;
|
|
834
|
-
required: boolean;
|
|
835
|
-
defaultValue?: any;
|
|
836
|
-
}[];
|
|
837
|
-
resources: { name: string; type: string; kind?: string; required: boolean }[];
|
|
838
|
-
} => {
|
|
839
|
-
const configSchema = revisionData?.configSchema;
|
|
840
|
-
const deploymentName = revisionData?.solution?.top;
|
|
841
|
-
const deployment = deploymentName
|
|
842
|
-
? revisionData?.solution?.deployments?.[deploymentName]
|
|
843
|
-
: Object.values(revisionData?.solution?.deployments ?? {})[0];
|
|
844
|
-
|
|
845
|
-
const parameterValues: Record<string, any> =
|
|
846
|
-
(deployment as any)?.config?.parameter ?? {};
|
|
847
|
-
const requiredParams: string[] =
|
|
848
|
-
configSchema?.properties?.config?.required ?? [];
|
|
849
|
-
const requiredResources: string[] =
|
|
850
|
-
configSchema?.properties?.resource?.required ?? [];
|
|
851
|
-
const schemaConfigProps: Record<string, any> =
|
|
852
|
-
configSchema?.properties?.config?.properties ?? {};
|
|
853
|
-
const schemaResourceProps: Record<string, any> =
|
|
854
|
-
configSchema?.properties?.resource?.properties ?? {};
|
|
855
|
-
|
|
856
|
-
const parameters = Object.entries(schemaConfigProps).map(
|
|
857
|
-
([name, propSchema]) => {
|
|
858
|
-
const entry: {
|
|
859
|
-
name: string;
|
|
860
|
-
type: string;
|
|
861
|
-
required: boolean;
|
|
862
|
-
defaultValue?: any;
|
|
863
|
-
} = {
|
|
864
|
-
name,
|
|
865
|
-
type: propSchema?.type ?? "string",
|
|
866
|
-
required: requiredParams.includes(name),
|
|
867
|
-
};
|
|
868
|
-
const currentValue = parameterValues[name];
|
|
869
|
-
if (currentValue !== undefined) entry.defaultValue = currentValue;
|
|
870
|
-
else if (propSchema?.default !== undefined)
|
|
871
|
-
entry.defaultValue = propSchema.default;
|
|
872
|
-
return entry;
|
|
873
|
-
},
|
|
874
|
-
);
|
|
875
|
-
|
|
876
|
-
const resources = Object.entries(schemaResourceProps).map(
|
|
877
|
-
([name, propSchema]) => {
|
|
878
|
-
const namedTypes = collectNamedTypes(propSchema);
|
|
879
|
-
const resolved = namedTypeToResourceKind(namedTypes);
|
|
880
|
-
const entry: {
|
|
881
|
-
name: string;
|
|
882
|
-
type: string;
|
|
883
|
-
kind?: string;
|
|
884
|
-
required: boolean;
|
|
885
|
-
} = {
|
|
886
|
-
name,
|
|
887
|
-
type: resolved.type,
|
|
888
|
-
required: requiredResources.includes(name),
|
|
889
|
-
};
|
|
890
|
-
if (resolved.kind) entry.kind = resolved.kind;
|
|
891
|
-
return entry;
|
|
892
|
-
},
|
|
893
|
-
);
|
|
894
|
-
|
|
895
|
-
return { parameters, resources };
|
|
896
|
-
};
|
package/package.json
CHANGED
package/websocket-manager.ts
CHANGED
|
@@ -1218,6 +1218,8 @@ const handleOperationSuccess = (operation: PendingOperation, response: any) => {
|
|
|
1218
1218
|
const updatedService = processRevisionData(
|
|
1219
1219
|
svcSuccessResult.updatedService!,
|
|
1220
1220
|
svcSuccessResult.revisionData,
|
|
1221
|
+
revisionsMap,
|
|
1222
|
+
svcSuccessResult.serviceId,
|
|
1221
1223
|
);
|
|
1222
1224
|
|
|
1223
1225
|
if (svcSuccessResult.revisionData.revision_error) {
|