Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Runtime Components to Execution Environment #3821

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/khaki-jars-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
'@finos/legend-graph': patch
---
5 changes: 5 additions & 0 deletions .changeset/twenty-avocados-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-extension-store-service-store': patch
---

Add Runtime Components to Execution Environment
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const observe_ComplexTypeReference = skipObserved(
});

observe_PackageableElementReference(metamodel.type);
//hre
observe_PackageableElementReference(metamodel.binding);

return metamodel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { type Hashable, hashArray } from '@finos/legend-shared';
import { CORE_HASH_STRUCTURE } from '../../../../../../../graph/Core_HashUtils.js';
import type { V1_Runtime } from '../runtime/V1_Runtime.js';
import {
V1_PackageableElement,
type V1_PackageableElementPointer,
type V1_PackageableElementVisitor,
V1_PackageableElement,
} from '../V1_PackageableElement.js';

export class V1_ExecutionEnvironmentInstance
Expand Down Expand Up @@ -47,20 +48,37 @@ export abstract class V1_ExecutionParameters implements Hashable {
abstract get hashCode(): string;
}

export class V1_RuntimeComponents implements Hashable {
runtime!: V1_Runtime;
binding!: V1_PackageableElementPointer;
clazz!: V1_PackageableElementPointer;

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.RUNTIME_COMPONENTS,
this.binding.path,
this.clazz.path,
this.runtime,
]);
}
}

export class V1_SingleExecutionParameters
extends V1_ExecutionParameters
implements Hashable
{
key!: string;
mapping!: string;
runtime!: V1_Runtime;
runtime?: V1_Runtime;
runtimeComponents?: V1_RuntimeComponents;

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.SINGLE_EXECUTION_PARAMETER,
this.key,
this.mapping,
this.runtime,
this.runtime ?? '',
this.runtimeComponents ?? '',
]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ import {
type V1_ExecutionParameters,
V1_ExecutionEnvironmentInstance,
V1_MultiExecutionParameters,
V1_RuntimeComponents,
V1_SingleExecutionParameters,
} from '../../../model/packageableElements/service/V1_ExecutionEnvironmentInstance.js';
import { V1_transformRuntime } from './V1_RuntimeTransformer.js';
import { UnsupportedOperationError } from '@finos/legend-shared';
import { PackageableElementPointerType } from '../../../../../../../graph/MetaModelConst.js';
import { V1_PackageableElementPointer } from '../../../model/packageableElements/V1_PackageableElement.js';

const V1_transformSingleExecutionParameters = (
element: SingleExecutionParameters,
Expand All @@ -38,7 +41,25 @@ const V1_transformSingleExecutionParameters = (
const _val = new V1_SingleExecutionParameters();
_val.key = element.key;
_val.mapping = element.mapping.valueForSerialization ?? '';
_val.runtime = V1_transformRuntime(element.runtime, context);
if (element.runtime) {
_val.runtime = V1_transformRuntime(element.runtime, context);
}
if (element.runtimeComponents) {
_val.runtimeComponents = new V1_RuntimeComponents();
_val.runtimeComponents.binding = new V1_PackageableElementPointer(
PackageableElementPointerType.BINDING,
element.runtimeComponents.binding.valueForSerialization ?? '',
);
_val.runtimeComponents.clazz = new V1_PackageableElementPointer(
PackageableElementPointerType.CLASS,
element.runtimeComponents.clazz.valueForSerialization ?? '',
);
_val.runtimeComponents.runtime = V1_transformRuntime(
element.runtimeComponents.runtime,
context,
);
}

return _val;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {
assertNonNullable,
guaranteeNonEmptyString,
UnsupportedOperationError,
} from '@finos/legend-shared';
import {
Expand All @@ -25,6 +26,7 @@ import {
import {
type ExecutionParameters,
MultiExecutionParameters,
RuntimeComponents,
SingleExecutionParameters,
} from '../../../../../../../graph/metamodel/pure/packageableElements/service/ExecutionEnvironmentInstance.js';
import {
Expand All @@ -39,6 +41,7 @@ import {
} from '../../../model/packageableElements/service/V1_ExecutionEnvironmentInstance.js';
import { V1_buildEngineRuntime } from './helpers/V1_RuntimeBuilderHelper.js';
import type { V1_GraphBuilderContext } from './V1_GraphBuilderContext.js';
import { V1_resolveBinding } from './V1_DSL_ExternalFormat_GraphBuilderHelper.js';

const buildExecutionRuntime = (
runtime: V1_Runtime,
Expand All @@ -63,7 +66,27 @@ export const V1_buildSingleExecutionParameters = (
const element = new SingleExecutionParameters();
element.key = protocol.key;
element.mapping = context.resolveMapping(protocol.mapping);
element.runtime = buildExecutionRuntime(protocol.runtime, context);
if (protocol.runtime) {
element.runtime = buildExecutionRuntime(protocol.runtime, context);
}
if (protocol.runtimeComponents) {
const runtimeComponents = new RuntimeComponents();
runtimeComponents.binding = V1_resolveBinding(
guaranteeNonEmptyString(
protocol.runtimeComponents.binding.path,
`Service runtime components 'binding' field is missing or empty`,
),
context,
);
runtimeComponents.clazz = context.resolveClass(
protocol.runtimeComponents.clazz.path,
);
runtimeComponents.runtime = buildExecutionRuntime(
protocol.runtimeComponents.runtime,
context,
);
element.runtimeComponents = runtimeComponents;
}

return element;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
usingConstantValueSchema,
usingModelSchema,
UnsupportedOperationError,
optionalCustom,
optionalCustomUsingModelSchema,
} from '@finos/legend-shared';
import {
createModelSchema,
Expand All @@ -31,13 +33,15 @@ import {
import {
V1_ExecutionEnvironmentInstance,
V1_MultiExecutionParameters,
V1_RuntimeComponents,
V1_SingleExecutionParameters,
type V1_ExecutionParameters,
} from '../../../model/packageableElements/service/V1_ExecutionEnvironmentInstance.js';
import {
V1_deserializeRuntime,
V1_serializeRuntime,
} from './V1_RuntimeSerializationHelper.js';
import { V1_packageableElementPointerModelSchema } from './V1_CoreSerializationHelper.js';

export const V1_EXECUTION_ENVIRONMENT_ELEMENT_PROTOCOL_TYPE =
'executionEnvironmentInstance';
Expand All @@ -47,6 +51,24 @@ enum V1_ExecEnvirParameterType {
PURE_MULTI_EXECUTION = 'multiExecutionParameters',
}

const V1_runtimeComponentsModelSchema = createModelSchema(
V1_RuntimeComponents,
{
clazz: custom(
(val) => serialize(V1_packageableElementPointerModelSchema, val),
(val) => deserialize(V1_packageableElementPointerModelSchema, val),
),
binding: custom(
(val) => serialize(V1_packageableElementPointerModelSchema, val),
(val) => deserialize(V1_packageableElementPointerModelSchema, val),
),
runtime: custom(
(val) => V1_serializeRuntime(val),
(val) => V1_deserializeRuntime(val),
),
},
);

const V1_singleExecutionParametersModelSchema = createModelSchema(
V1_SingleExecutionParameters,
{
Expand All @@ -55,10 +77,13 @@ const V1_singleExecutionParametersModelSchema = createModelSchema(
),
key: primitive(),
mapping: primitive(),
runtime: custom(
runtime: optionalCustom(
(val) => V1_serializeRuntime(val),
(val) => V1_deserializeRuntime(val),
),
runtimeComponents: optionalCustomUsingModelSchema(
V1_runtimeComponentsModelSchema,
),
},
);

Expand Down
1 change: 1 addition & 0 deletions packages/legend-graph/src/graph/Core_HashUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export enum CORE_HASH_STRUCTURE {
EXECUTION_ENVIRONMENT_INSTANCE = 'EXECUTION_ENVIRONMENT_INSTANCE',
SINGLE_EXECUTION_PARAMETER = 'SINGLE_EXECUTION_PARAMETER',
MULTI_EXECUTION_PARAMETER = 'MULTI_EXECUTION_PARAMETER',
RUNTIME_COMPONENTS = 'RUNTIME_COMPONENTS',

// ---------------------------------- STO Relational --------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
PackageableElement,
} from '../PackageableElement.js';
import type { PackageableElementReference } from '../PackageableElementReference.js';
import type { Class } from '../domain/Class.js';
import type { Binding } from '../externalFormat/store/DSL_ExternalFormat_Binding.js';

export class ExecutionEnvironmentInstance
extends PackageableElement
Expand All @@ -49,17 +51,34 @@ export abstract class ExecutionParameters implements Hashable {
abstract get hashCode(): string;
}

export class RuntimeComponents implements Hashable {
runtime!: Runtime;
binding!: PackageableElementReference<Binding>;
clazz!: PackageableElementReference<Class>;

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.RUNTIME_COMPONENTS,
this.binding.valueForSerialization ?? '',
this.clazz.valueForSerialization ?? '',
this.runtime,
]);
}
}

export class SingleExecutionParameters implements Hashable {
key!: string;
mapping!: PackageableElementReference<Mapping>;
runtime!: Runtime;
runtime?: Runtime;
runtimeComponents?: RuntimeComponents;

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.SINGLE_EXECUTION_PARAMETER,
this.key,
this.mapping.valueForSerialization ?? '',
this.runtime,
this.runtime ?? '',
this.runtimeComponents ?? '',
]);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
###Service
ExecutionEnvironment test::executionEnvironment
{
executions:
[
UAT:
{
mapping: test::mapping;
runtimeComponents:
{
class: test::class;
binding: test::bind;
runtime: test::runtime;
}
},
PROD:
{
mapping: test::mapping;
runtimeComponents:
{
class: test::class;
binding: test::bind;
runtime: test::runtime;
}
}
];
}


###ExternalFormat
Binding test::bind
{
contentType: 'application/json';
modelIncludes: [
test::class
];
}


###Pure
Class test::class
{
prop1: Integer[0..1];
}


###Mapping
Mapping test::mapping
(
)


###Connection
JsonModelConnection test::connection
{
class: test::class;
url: 'asd';
}


###Runtime
Runtime test::runtime
{
mappings:
[
test::mapping
];
}
Loading