@kumori/aurora-backend-handler 1.0.35 → 1.0.36
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 +136 -140
- package/package.json +1 -1
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
Service,
|
|
8
8
|
Usage,
|
|
9
9
|
} from "@kumori/aurora-interfaces";
|
|
10
|
-
import { Revision } from "@kumori/aurora-interfaces/interfaces/revision-interface";
|
|
11
10
|
import { convertToGigabytes, getTimestamp } from "../utils/utils";
|
|
11
|
+
import { Revision } from "@kumori/aurora-interfaces/interfaces/revision-interface";
|
|
12
12
|
|
|
13
13
|
interface Role {
|
|
14
14
|
name: string;
|
|
@@ -138,7 +138,7 @@ const processRolesAndInstances = (
|
|
|
138
138
|
cost: 0,
|
|
139
139
|
},
|
|
140
140
|
logs: [],
|
|
141
|
-
containers
|
|
141
|
+
containers,
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
roleInstances.push(instance);
|
|
@@ -167,7 +167,7 @@ const createRevision = (
|
|
|
167
167
|
): Revision => {
|
|
168
168
|
return {
|
|
169
169
|
id: entityId,
|
|
170
|
-
schema:
|
|
170
|
+
schema: {},
|
|
171
171
|
usage: {
|
|
172
172
|
current: {
|
|
173
173
|
cpu: usedCpu,
|
|
@@ -462,132 +462,33 @@ 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 namedTypeToResourceType = (
|
|
477
|
-
namedTypes: string[],
|
|
478
|
-
): { type: Resource["type"]; kind?: Resource["kind"] } | null => {
|
|
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 null;
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
const extractResourcesFromSchema = (
|
|
507
|
-
configSchema: any,
|
|
508
|
-
resourceValues: Record<string, any> = {},
|
|
509
|
-
tenant = "",
|
|
510
|
-
): Resource[] => {
|
|
511
|
-
const schemaResourceProps: Record<string, any> =
|
|
512
|
-
configSchema?.properties?.resource?.properties ?? {};
|
|
513
|
-
|
|
514
|
-
return Object.entries(schemaResourceProps).map(
|
|
515
|
-
([resourceName, resourceSchema]) => {
|
|
516
|
-
const namedTypes = collectNamedTypes(resourceSchema);
|
|
517
|
-
const resolved = namedTypeToResourceType(namedTypes);
|
|
518
|
-
const type: Resource["type"] = resolved?.type ?? "secret";
|
|
519
|
-
const kind = resolved?.kind;
|
|
520
|
-
|
|
521
|
-
const rawValue = resourceValues[resourceName];
|
|
522
|
-
let value = "";
|
|
523
|
-
if (rawValue) {
|
|
524
|
-
if (rawValue.secret) value = rawValue.secret;
|
|
525
|
-
else if (rawValue.domain) value = rawValue.domain;
|
|
526
|
-
else if (rawValue.port) value = rawValue.port;
|
|
527
|
-
else if (rawValue.certificate?.cert) value = rawValue.certificate.cert;
|
|
528
|
-
else if (rawValue.ca) value = rawValue.ca;
|
|
529
|
-
else if (rawValue.volume) {
|
|
530
|
-
const v = rawValue.volume;
|
|
531
|
-
value = v.size !== undefined ? `${v.size}${v.unit ?? ""}` : "";
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
const resource: Resource = {
|
|
536
|
-
type,
|
|
537
|
-
name: resourceName,
|
|
538
|
-
value,
|
|
539
|
-
status: "available",
|
|
540
|
-
tenant,
|
|
541
|
-
};
|
|
542
|
-
if (kind) resource.kind = kind;
|
|
543
|
-
return resource;
|
|
544
|
-
},
|
|
545
|
-
);
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
const extractParametersFromSchema = (
|
|
549
|
-
configSchema: any,
|
|
550
|
-
parameterValues: Record<string, any> = {},
|
|
551
|
-
): { [key: string]: string }[] => {
|
|
552
|
-
const schemaConfigProps: Record<string, any> =
|
|
553
|
-
configSchema?.properties?.config?.properties ?? {};
|
|
554
|
-
|
|
555
|
-
return Object.entries(schemaConfigProps).map(([paramName, paramSchema]) => {
|
|
556
|
-
const schemaType: string = paramSchema?.type ?? "string";
|
|
557
|
-
const rawValue = parameterValues[paramName];
|
|
558
|
-
const value = rawValue !== undefined ? String(rawValue) : "";
|
|
559
|
-
return { name: paramName, value, type: schemaType, configKey: paramName };
|
|
560
|
-
});
|
|
561
|
-
};
|
|
562
|
-
|
|
563
465
|
export const processRevisionData = (
|
|
564
466
|
service: Service,
|
|
565
467
|
revisionData: any,
|
|
566
468
|
): Service => {
|
|
567
469
|
const { solution } = revisionData;
|
|
568
|
-
|
|
470
|
+
|
|
471
|
+
const config = revisionData?.config?.config || {};
|
|
472
|
+
const parameters = extractParametersFromConfig(config.parameter || {});
|
|
473
|
+
const resources = extractResources(config.resource || {});
|
|
569
474
|
|
|
570
475
|
const deploymentName = solution.top || service.name;
|
|
571
|
-
const deployment =
|
|
572
|
-
solution.deployments[deploymentName] ??
|
|
573
|
-
solution.deployments[Object.keys(solution.deployments)[0]];
|
|
476
|
+
const deployment = solution.deployments[deploymentName];
|
|
574
477
|
|
|
575
478
|
if (!deployment) {
|
|
576
|
-
|
|
479
|
+
const firstDeploymentKey = Object.keys(solution.deployments)[0];
|
|
480
|
+
if (firstDeploymentKey) {
|
|
481
|
+
return processDeployment(
|
|
482
|
+
service,
|
|
483
|
+
solution.deployments[firstDeploymentKey],
|
|
484
|
+
revisionData,
|
|
485
|
+
parameters,
|
|
486
|
+
resources,
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
return { ...service, parameters, resources };
|
|
577
490
|
}
|
|
578
491
|
|
|
579
|
-
const deploymentConfig = deployment.config ?? {};
|
|
580
|
-
const parameterValues = deploymentConfig.parameter ?? {};
|
|
581
|
-
const resourceValues = deploymentConfig.resource ?? {};
|
|
582
|
-
|
|
583
|
-
const parameters = configSchema
|
|
584
|
-
? extractParametersFromSchema(configSchema, parameterValues)
|
|
585
|
-
: extractParametersFromConfig(parameterValues);
|
|
586
|
-
|
|
587
|
-
const resources = configSchema
|
|
588
|
-
? extractResourcesFromSchema(configSchema, resourceValues, service.tenant)
|
|
589
|
-
: extractResources(resourceValues);
|
|
590
|
-
|
|
591
492
|
return processDeployment(
|
|
592
493
|
service,
|
|
593
494
|
deployment,
|
|
@@ -606,7 +507,6 @@ export const processDeployment = (
|
|
|
606
507
|
): Service => {
|
|
607
508
|
const artifact = deployment.artifact;
|
|
608
509
|
const deploymentConfig = deployment.config || {};
|
|
609
|
-
|
|
610
510
|
const rolesDefinition = artifact.description?.role || {};
|
|
611
511
|
const hasRoles = Object.keys(rolesDefinition).length > 0;
|
|
612
512
|
let updatedRoles: Role[] = [];
|
|
@@ -620,13 +520,11 @@ export const processDeployment = (
|
|
|
620
520
|
hsize = roleData.config.scale.hsize;
|
|
621
521
|
if (deploymentConfig.scale?.detail?.[roleName]?.hsize !== undefined)
|
|
622
522
|
hsize = deploymentConfig.scale.detail[roleName].hsize;
|
|
623
|
-
|
|
624
523
|
const hasDuplex =
|
|
625
524
|
roleData.artifact?.description?.srv?.duplex?.length > 0;
|
|
626
525
|
const hasVolumeResource = Object.values(
|
|
627
526
|
roleData.artifact?.description?.config?.resource || {},
|
|
628
527
|
).some((resourceData: any) => resourceData.volume);
|
|
629
|
-
|
|
630
528
|
const role: Role = {
|
|
631
529
|
name: roleName,
|
|
632
530
|
instances: existingRole?.instances || [],
|
|
@@ -634,17 +532,15 @@ export const processDeployment = (
|
|
|
634
532
|
description:
|
|
635
533
|
roleData.artifact?.ref?.module || roleData.ref?.module || "",
|
|
636
534
|
resource: resources,
|
|
637
|
-
parameters
|
|
638
|
-
hsize
|
|
535
|
+
parameters,
|
|
536
|
+
hsize,
|
|
639
537
|
category: hasDuplex || hasVolumeResource ? "stateful" : "",
|
|
640
538
|
};
|
|
641
|
-
|
|
642
539
|
if (
|
|
643
540
|
deployment.meta?.scaling &&
|
|
644
541
|
Object.keys(deployment.meta.scaling.simple || {}).length > 0
|
|
645
542
|
)
|
|
646
543
|
role.scalling = processScalingConfig(deployment.meta);
|
|
647
|
-
|
|
648
544
|
updatedRoles.push(role);
|
|
649
545
|
},
|
|
650
546
|
);
|
|
@@ -654,7 +550,6 @@ export const processDeployment = (
|
|
|
654
550
|
hsize = deploymentConfig.scale.hsize;
|
|
655
551
|
if (deploymentConfig.scale?.detail?.[""]?.hsize !== undefined)
|
|
656
552
|
hsize = deploymentConfig.scale.detail[""].hsize;
|
|
657
|
-
|
|
658
553
|
updatedRoles = [
|
|
659
554
|
{
|
|
660
555
|
name: service.name,
|
|
@@ -664,8 +559,8 @@ export const processDeployment = (
|
|
|
664
559
|
artifact.ref?.module ||
|
|
665
560
|
(artifact.description?.builtin ? "Builtin Service" : ""),
|
|
666
561
|
resource: resources,
|
|
667
|
-
parameters
|
|
668
|
-
hsize
|
|
562
|
+
parameters,
|
|
563
|
+
hsize,
|
|
669
564
|
...(deployment.meta?.scaling &&
|
|
670
565
|
Object.keys(deployment.meta.scaling.simple || {}).length > 0 && {
|
|
671
566
|
scalling: processScalingConfig(deployment.meta),
|
|
@@ -688,7 +583,6 @@ export const extractParametersFromConfig = (
|
|
|
688
583
|
([paramName, paramValue]: [string, any]) => {
|
|
689
584
|
let value: string;
|
|
690
585
|
let description: string | undefined;
|
|
691
|
-
|
|
692
586
|
if (typeof paramValue === "object" && paramValue !== null) {
|
|
693
587
|
if (paramValue.value !== undefined) value = paramValue.value;
|
|
694
588
|
else if (paramValue.default !== undefined)
|
|
@@ -698,7 +592,6 @@ export const extractParametersFromConfig = (
|
|
|
698
592
|
} else {
|
|
699
593
|
value = String(paramValue);
|
|
700
594
|
}
|
|
701
|
-
|
|
702
595
|
const parameter: { [key: string]: string } = {
|
|
703
596
|
name: paramName,
|
|
704
597
|
value,
|
|
@@ -768,7 +661,6 @@ export const extractResourcesFromFilesystem = (
|
|
|
768
661
|
|
|
769
662
|
export const extractResources = (resourceConfig: any): Resource[] => {
|
|
770
663
|
const resources: Resource[] = [];
|
|
771
|
-
|
|
772
664
|
Object.entries(resourceConfig).forEach(
|
|
773
665
|
([resourceName, resourceData]: [string, any]) => {
|
|
774
666
|
let resource: Resource;
|
|
@@ -842,36 +734,29 @@ export const extractResources = (resourceConfig: any): Resource[] => {
|
|
|
842
734
|
if (resourceData.key) resource.key = resourceData.key;
|
|
843
735
|
if (resourceData.maxItems) resource.maxItems = resourceData.maxItems;
|
|
844
736
|
}
|
|
845
|
-
|
|
846
737
|
resources.push(resource);
|
|
847
738
|
},
|
|
848
739
|
);
|
|
849
|
-
|
|
850
740
|
return resources;
|
|
851
741
|
};
|
|
852
742
|
|
|
853
743
|
const processScalingConfig = (meta: any): any => {
|
|
854
|
-
if (!meta?.scaling?.simple || Object.keys(meta.scaling.simple).length === 0)
|
|
744
|
+
if (!meta?.scaling?.simple || Object.keys(meta.scaling.simple).length === 0)
|
|
855
745
|
return {
|
|
856
746
|
cpu: { up: "80%", down: "20%" },
|
|
857
747
|
memory: { up: "80%", down: "20%" },
|
|
858
748
|
instances: { max: 1, min: 1 },
|
|
859
749
|
histeresys: "5",
|
|
860
750
|
};
|
|
861
|
-
}
|
|
862
|
-
|
|
863
751
|
const firstRoleName = Object.keys(meta.scaling.simple)[0];
|
|
864
752
|
const roleScaling = meta.scaling.simple[firstRoleName];
|
|
865
|
-
|
|
866
|
-
if (!roleScaling) {
|
|
753
|
+
if (!roleScaling)
|
|
867
754
|
return {
|
|
868
755
|
cpu: { up: "80%", down: "20%" },
|
|
869
756
|
memory: { up: "80%", down: "20%" },
|
|
870
757
|
instances: { max: 1, min: 1 },
|
|
871
758
|
histeresys: "5",
|
|
872
759
|
};
|
|
873
|
-
}
|
|
874
|
-
|
|
875
760
|
return {
|
|
876
761
|
cpu: {
|
|
877
762
|
up: `${roleScaling.scale_up?.cpu || 80}%`,
|
|
@@ -898,3 +783,114 @@ const extractResourceName = (resourcePath: string): string => {
|
|
|
898
783
|
}
|
|
899
784
|
return resourcePath;
|
|
900
785
|
};
|
|
786
|
+
|
|
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
|
+
};
|