Skip to content

Commit

Permalink
support unknown post deployment properties
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Nov 21, 2024
1 parent 9f5d3fd commit 138fb26
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changeset/tender-lobsters-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
'@finos/legend-graph': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export class V1_PostDeploymentAction implements Hashable {
automated: boolean | undefined;

get hashCode(): string {
return hashArray([this.automated ?? '']);
return hashArray([this.properties ?? '', this.automated ?? '']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,31 @@
* limitations under the License.
*/

export class V1_PostDeploymentProperties {}
import {
hashArray,
type Hashable,
type PlainObject,
} from '@finos/legend-shared';
import {
CORE_HASH_STRUCTURE,
hashObjectWithoutSourceInformation,
} from '../../../../../../graph/Core_HashUtils.js';

export class V1_PostDeploymentProperties implements Hashable {
get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.FUNCTION_ACTIVATOR_POST_DEPLOYMENT_PROPERTIES,
]);
}
}

export class V1_INTERNAL__UnknownPostDeploymentProperties extends V1_PostDeploymentProperties {
content!: PlainObject;

override get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.FUNCTION_ACTIVATOR_POST_DEPLOYMENT_PROPERTIES,
hashObjectWithoutSourceInformation(this.content),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import type { INTERNAL__UnknownElement } from '../../../../../../../graph/metamo
import { V1_INTERNAL__UnknownElement } from '../../../model/packageableElements/V1_INTERNAL__UnknownElement.js';
import type { HostedService } from '../../../../../../../graph/metamodel/pure/packageableElements/function/HostedService.js';
import { V1_HostedService } from '../../../model/packageableElements/function/V1_HostedService.js';
import { V1_transformFunctionActivatorActions } from '../to/helpers/V1_LegendLambdaTransformerHelper.js';

class V1_PackageableElementTransformer
implements PackageableElementVisitor<V1_PackageableElement>
Expand Down Expand Up @@ -186,6 +187,7 @@ class V1_PackageableElementTransformer
);
protocol.stereotypes = element.stereotypes.map(V1_transformStereotype);
protocol.taggedValues = element.taggedValues.map(V1_transformTaggedValue);
V1_transformFunctionActivatorActions(protocol, element);
return protocol;
}

Expand Down Expand Up @@ -214,6 +216,7 @@ class V1_PackageableElementTransformer
}
protocol.taggedValues = element.taggedValues.map(V1_transformTaggedValue);
protocol.stereotypes = element.stereotypes.map(V1_transformStereotype);
V1_transformFunctionActivatorActions(protocol, element);
return protocol;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import type { V1_INTERNAL__UnknownElement } from '../../../model/packageableElem
import { INTERNAL__UnknownElement } from '../../../../../../../graph/metamodel/pure/packageableElements/INTERNAL__UnknownElement.js';
import type { V1_HostedService } from '../../../model/packageableElements/function/V1_HostedService.js';
import { HostedService } from '../../../../../../../graph/metamodel/pure/packageableElements/function/HostedService.js';
import { V1_buildFunctionActivatorActions } from './helpers/V1_LegendLambdaHelper.js';

export class V1_ElementFirstPassBuilder
implements V1_PackageableElementVisitor<PackageableElement>
Expand Down Expand Up @@ -198,6 +199,7 @@ export class V1_ElementFirstPassBuilder
}

metamodel.description = element.description;
V1_buildFunctionActivatorActions(element, metamodel);
return metamodel;
}

Expand Down Expand Up @@ -227,6 +229,7 @@ export class V1_ElementFirstPassBuilder
metamodel.autoActivateUpdates = element.autoActivateUpdates;
metamodel.storeModel = element.storeModel;
metamodel.generateLineage = element.generateLineage;
V1_buildFunctionActivatorActions(element, metamodel);
return metamodel;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { PostDeploymentAction } from '../../../../../../../../graph/metamodel/pure/functionActivator/PostDeploymentAction.js';
import {
INTERNAL__UnknownPostDeploymentProperties,
type PostDeploymentProperties,
} from '../../../../../../../../graph/metamodel/pure/functionActivator/PostDeploymentProperties.js';
import type { FunctionActivator } from '../../../../../../../../graph/metamodel/pure/packageableElements/function/FunctionActivator.js';
import type { V1_PostDeploymentAction } from '../../../../engine/functionActivator/V1_PostDeploymentAction.js';
import {
V1_INTERNAL__UnknownPostDeploymentProperties,
V1_PostDeploymentProperties,
} from '../../../../engine/functionActivator/V1_PostDeploymentProperties.js';
import type { V1_FunctionActivator } from '../../../../model/packageableElements/function/V1_FunctionActivator.js';

export const V1_buildPostDeploymentProperties = (
protocol: V1_PostDeploymentProperties,
): PostDeploymentProperties => {
if (protocol instanceof V1_INTERNAL__UnknownPostDeploymentProperties) {
const metamodel = new INTERNAL__UnknownPostDeploymentProperties();
metamodel.content = protocol.content;
return metamodel;
}
return new V1_PostDeploymentProperties();
};

export const V1_buildPostDeploymentActions = (
protocol: V1_PostDeploymentAction,
): PostDeploymentAction => {
const val = new PostDeploymentAction();
val.automated = protocol.automated;
if (protocol.properties) {
val.properties = V1_buildPostDeploymentProperties(protocol.properties);
}
return val;
};

export const V1_buildFunctionActivatorActions = (
protocl: V1_FunctionActivator,
metamodel: FunctionActivator,
): void => {
metamodel.actions = protocl.actions.map(V1_buildPostDeploymentActions);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { PostDeploymentAction } from '../../../../../../../../graph/metamodel/pure/functionActivator/PostDeploymentAction.js';
import {
INTERNAL__UnknownPostDeploymentProperties,
type PostDeploymentProperties,
} from '../../../../../../../../graph/metamodel/pure/functionActivator/PostDeploymentProperties.js';
import type { FunctionActivator } from '../../../../../../../../graph/metamodel/pure/packageableElements/function/FunctionActivator.js';
import { V1_PostDeploymentAction } from '../../../../engine/functionActivator/V1_PostDeploymentAction.js';
import {
V1_INTERNAL__UnknownPostDeploymentProperties,
V1_PostDeploymentProperties,
} from '../../../../engine/functionActivator/V1_PostDeploymentProperties.js';
import type { V1_FunctionActivator } from '../../../../model/packageableElements/function/V1_FunctionActivator.js';

export const V1_transformPostDeploymentProperties = (
protocol: PostDeploymentProperties,
): V1_PostDeploymentProperties => {
if (protocol instanceof INTERNAL__UnknownPostDeploymentProperties) {
const metamodel = new V1_INTERNAL__UnknownPostDeploymentProperties();
metamodel.content = protocol.content;
return metamodel;
}
return new V1_PostDeploymentProperties();
};

export const V1_tansformPostDeploymentActions = (
metamodel: PostDeploymentAction,
): V1_PostDeploymentAction => {
const protocol = new V1_PostDeploymentAction();
protocol.automated = metamodel.automated;
if (metamodel.properties) {
protocol.properties = V1_transformPostDeploymentProperties(
metamodel.properties,
);
}
return protocol;
};

export const V1_transformFunctionActivatorActions = (
protocol: V1_FunctionActivator,
metamodel: FunctionActivator,
): void => {
protocol.actions = metamodel.actions.map(V1_tansformPostDeploymentActions);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
usingModelSchema,
type PlainObject,
UnsupportedOperationError,
optionalCustom,
} from '@finos/legend-shared';
import { V1_SnowflakeAppDeploymentConfiguration } from '../../../engine/functionActivator/V1_SnowflakeAppDeploymentConfiguration.js';
import {
Expand All @@ -37,7 +38,10 @@ import {
} from '../../../model/packageableElements/function/V1_Ownership.js';
import { V1_HostedServiceDeploymentConfiguration } from '../../../engine/functionActivator/V1_HostedServiceDeploymentConfiguration.js';
import { V1_PostDeploymentAction } from '../../../engine/functionActivator/V1_PostDeploymentAction.js';
import { V1_PostDeploymentProperties } from '../../../engine/functionActivator/V1_PostDeploymentProperties.js';
import {
V1_INTERNAL__UnknownPostDeploymentProperties,
V1_PostDeploymentProperties,
} from '../../../engine/functionActivator/V1_PostDeploymentProperties.js';

const V1_SNOWFLAKE_APP_DEPLOYMENT_CONFIGURATION_APP_TYPE =
'snowflakeDeploymentConfiguration';
Expand Down Expand Up @@ -115,15 +119,40 @@ export const V1_deserializeOwnership = (
}
};

export const V1_deserializePostDeploymentProperties = (
json: PlainObject<V1_PostDeploymentProperties>,
): V1_PostDeploymentProperties => {
switch (json._type) {
// we can add known post actions here
default:
// Fall back to unknown
const protocol = new V1_INTERNAL__UnknownPostDeploymentProperties();
protocol.content = json;
return protocol;
}
};

export const V1_PostDeploymentPropertiesSchema = createModelSchema(
V1_PostDeploymentProperties,
{},
);

export const V1_serializePostDeploymentProperties = (
protocol: V1_PostDeploymentProperties,
): PlainObject<V1_PostDeploymentProperties> => {
if (protocol instanceof V1_INTERNAL__UnknownPostDeploymentProperties) {
return protocol.content;
}
return serialize(V1_PostDeploymentPropertiesSchema, undefined);
};

export const V1_PostDeploymentActionSchema = createModelSchema(
V1_PostDeploymentAction,
{
automated: optional(primitive()),
properties: usingModelSchema(V1_PostDeploymentPropertiesSchema),
properties: optionalCustom(
(val) => V1_serializePostDeploymentProperties(val),
(val) => V1_deserializePostDeploymentProperties(val),
),
},
);
2 changes: 2 additions & 0 deletions packages/legend-graph/src/graph/Core_HashUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export enum CORE_HASH_STRUCTURE {
FUNCTION_STORE_TEST_DATA = 'FUNCTION_STORE_TEST_DATA',
FUNCTION_PARAMETER_VALUE = 'FUNCTION_PARAMETER_VALUE',

// Function Activator
FUNCTION_ACTIVATOR_POST_DEPLOYMENT_PROPERTIES = 'FUNCTION_ACTIVATOR_POST_DEPLOYMENT_PROPERTIES',
// testable
ASSERT_FAIL = 'ASSERT_FAIL',
ASSERT_PASS = 'ASSERT_PASS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export class PostDeploymentAction implements Hashable {
automated: boolean | undefined;

get hashCode(): string {
return hashArray([this.automated ?? '']);
return hashArray([this.properties ?? '', this.automated ?? '']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,31 @@
* limitations under the License.
*/

export class PostDeploymentProperties {}
import {
hashArray,
type Hashable,
type PlainObject,
} from '@finos/legend-shared';
import {
CORE_HASH_STRUCTURE,
hashObjectWithoutSourceInformation,
} from '../../../Core_HashUtils.js';

export class PostDeploymentProperties implements Hashable {
get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.FUNCTION_ACTIVATOR_POST_DEPLOYMENT_PROPERTIES,
]);
}
}

export class INTERNAL__UnknownPostDeploymentProperties extends PostDeploymentProperties {
content!: PlainObject;

override get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.FUNCTION_ACTIVATOR_POST_DEPLOYMENT_PROPERTIES,
hashObjectWithoutSourceInformation(this.content),
]);
}
}

0 comments on commit 138fb26

Please sign in to comment.