@kumori/aurora-backend-handler 1.0.35 → 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.
@@ -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: 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: eventData.spec || {},
170
+ schema: {},
171
171
  usage: {
172
172
  current: {
173
173
  cpu: usedCpu,
@@ -473,9 +473,9 @@ const collectNamedTypes = (schema: any): string[] => {
473
473
  return names;
474
474
  };
475
475
 
476
- const namedTypeToResourceType = (
476
+ const namedTypeToResourceKind = (
477
477
  namedTypes: string[],
478
- ): { type: Resource["type"]; kind?: Resource["kind"] } | null => {
478
+ ): { type: string; kind?: string } => {
479
479
  for (const name of namedTypes) {
480
480
  switch (name) {
481
481
  case "Secret":
@@ -500,94 +500,158 @@ const namedTypeToResourceType = (
500
500
  return { type: "volume" };
501
501
  }
502
502
  }
503
- return null;
503
+ return { type: "secret" };
504
504
  };
505
505
 
506
- const extractResourcesFromSchema = (
507
- configSchema: any,
508
- resourceValues: Record<string, any> = {},
509
- tenant = "",
510
- ): Resource[] => {
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 ?? {};
511
531
  const schemaResourceProps: Record<string, any> =
512
532
  configSchema?.properties?.resource?.properties ?? {};
513
533
 
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,
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),
541
545
  };
542
- if (kind) resource.kind = kind;
543
- return resource;
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;
544
551
  },
545
552
  );
546
- };
547
553
 
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
+ 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
+ );
554
572
 
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
- });
573
+ return { parameters, resources };
561
574
  };
562
575
 
563
576
  export const processRevisionData = (
564
577
  service: Service,
565
578
  revisionData: any,
579
+ revisionsMap?: Map<string, Revision>,
580
+ serviceId?: string,
566
581
  ): Service => {
567
582
  const { solution } = revisionData;
568
- const configSchema = revisionData?.configSchema;
583
+
584
+ const config = revisionData?.config?.config || {};
585
+ const parameters = extractParametersFromConfig(config.parameter || {});
586
+ const resources = extractResources(config.resource || {});
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
+ }
569
637
 
570
638
  const deploymentName = solution.top || service.name;
571
- const deployment =
572
- solution.deployments[deploymentName] ??
573
- solution.deployments[Object.keys(solution.deployments)[0]];
639
+ const deployment = solution.deployments[deploymentName];
574
640
 
575
641
  if (!deployment) {
576
- return { ...service };
642
+ const firstDeploymentKey = Object.keys(solution.deployments)[0];
643
+ if (firstDeploymentKey) {
644
+ return processDeployment(
645
+ service,
646
+ solution.deployments[firstDeploymentKey],
647
+ revisionData,
648
+ parameters,
649
+ resources,
650
+ );
651
+ }
652
+ return { ...service, parameters, resources };
577
653
  }
578
654
 
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
655
  return processDeployment(
592
656
  service,
593
657
  deployment,
@@ -606,7 +670,6 @@ export const processDeployment = (
606
670
  ): Service => {
607
671
  const artifact = deployment.artifact;
608
672
  const deploymentConfig = deployment.config || {};
609
-
610
673
  const rolesDefinition = artifact.description?.role || {};
611
674
  const hasRoles = Object.keys(rolesDefinition).length > 0;
612
675
  let updatedRoles: Role[] = [];
@@ -620,13 +683,11 @@ export const processDeployment = (
620
683
  hsize = roleData.config.scale.hsize;
621
684
  if (deploymentConfig.scale?.detail?.[roleName]?.hsize !== undefined)
622
685
  hsize = deploymentConfig.scale.detail[roleName].hsize;
623
-
624
686
  const hasDuplex =
625
687
  roleData.artifact?.description?.srv?.duplex?.length > 0;
626
688
  const hasVolumeResource = Object.values(
627
689
  roleData.artifact?.description?.config?.resource || {},
628
690
  ).some((resourceData: any) => resourceData.volume);
629
-
630
691
  const role: Role = {
631
692
  name: roleName,
632
693
  instances: existingRole?.instances || [],
@@ -634,17 +695,15 @@ export const processDeployment = (
634
695
  description:
635
696
  roleData.artifact?.ref?.module || roleData.ref?.module || "",
636
697
  resource: resources,
637
- parameters: parameters,
638
- hsize: hsize,
698
+ parameters,
699
+ hsize,
639
700
  category: hasDuplex || hasVolumeResource ? "stateful" : "",
640
701
  };
641
-
642
702
  if (
643
703
  deployment.meta?.scaling &&
644
704
  Object.keys(deployment.meta.scaling.simple || {}).length > 0
645
705
  )
646
706
  role.scalling = processScalingConfig(deployment.meta);
647
-
648
707
  updatedRoles.push(role);
649
708
  },
650
709
  );
@@ -654,7 +713,6 @@ export const processDeployment = (
654
713
  hsize = deploymentConfig.scale.hsize;
655
714
  if (deploymentConfig.scale?.detail?.[""]?.hsize !== undefined)
656
715
  hsize = deploymentConfig.scale.detail[""].hsize;
657
-
658
716
  updatedRoles = [
659
717
  {
660
718
  name: service.name,
@@ -664,8 +722,8 @@ export const processDeployment = (
664
722
  artifact.ref?.module ||
665
723
  (artifact.description?.builtin ? "Builtin Service" : ""),
666
724
  resource: resources,
667
- parameters: parameters,
668
- hsize: hsize,
725
+ parameters,
726
+ hsize,
669
727
  ...(deployment.meta?.scaling &&
670
728
  Object.keys(deployment.meta.scaling.simple || {}).length > 0 && {
671
729
  scalling: processScalingConfig(deployment.meta),
@@ -688,7 +746,6 @@ export const extractParametersFromConfig = (
688
746
  ([paramName, paramValue]: [string, any]) => {
689
747
  let value: string;
690
748
  let description: string | undefined;
691
-
692
749
  if (typeof paramValue === "object" && paramValue !== null) {
693
750
  if (paramValue.value !== undefined) value = paramValue.value;
694
751
  else if (paramValue.default !== undefined)
@@ -698,7 +755,6 @@ export const extractParametersFromConfig = (
698
755
  } else {
699
756
  value = String(paramValue);
700
757
  }
701
-
702
758
  const parameter: { [key: string]: string } = {
703
759
  name: paramName,
704
760
  value,
@@ -768,7 +824,6 @@ export const extractResourcesFromFilesystem = (
768
824
 
769
825
  export const extractResources = (resourceConfig: any): Resource[] => {
770
826
  const resources: Resource[] = [];
771
-
772
827
  Object.entries(resourceConfig).forEach(
773
828
  ([resourceName, resourceData]: [string, any]) => {
774
829
  let resource: Resource;
@@ -842,36 +897,29 @@ export const extractResources = (resourceConfig: any): Resource[] => {
842
897
  if (resourceData.key) resource.key = resourceData.key;
843
898
  if (resourceData.maxItems) resource.maxItems = resourceData.maxItems;
844
899
  }
845
-
846
900
  resources.push(resource);
847
901
  },
848
902
  );
849
-
850
903
  return resources;
851
904
  };
852
905
 
853
906
  const processScalingConfig = (meta: any): any => {
854
- if (!meta?.scaling?.simple || Object.keys(meta.scaling.simple).length === 0) {
907
+ if (!meta?.scaling?.simple || Object.keys(meta.scaling.simple).length === 0)
855
908
  return {
856
909
  cpu: { up: "80%", down: "20%" },
857
910
  memory: { up: "80%", down: "20%" },
858
911
  instances: { max: 1, min: 1 },
859
912
  histeresys: "5",
860
913
  };
861
- }
862
-
863
914
  const firstRoleName = Object.keys(meta.scaling.simple)[0];
864
915
  const roleScaling = meta.scaling.simple[firstRoleName];
865
-
866
- if (!roleScaling) {
916
+ if (!roleScaling)
867
917
  return {
868
918
  cpu: { up: "80%", down: "20%" },
869
919
  memory: { up: "80%", down: "20%" },
870
920
  instances: { max: 1, min: 1 },
871
921
  histeresys: "5",
872
922
  };
873
- }
874
-
875
923
  return {
876
924
  cpu: {
877
925
  up: `${roleScaling.scale_up?.cpu || 80}%`,
@@ -898,3 +946,4 @@ const extractResourceName = (resourcePath: string): string => {
898
946
  }
899
947
  return resourcePath;
900
948
  };
949
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -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) {