Skip to content

Commit

Permalink
add ownership to function activator (#2939)
Browse files Browse the repository at this point in the history
  • Loading branch information
janeenyamak1 authored Feb 12, 2024
1 parent 3f701b3 commit 2a54433
Show file tree
Hide file tree
Showing 20 changed files with 254 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/metal-walls-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@finos/legend-application-studio': patch
'@finos/legend-graph': patch
---

Add ownership to snowflake app
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
extractElementNameFromPath,
extractPackagePathFromPath,
SnowflakeAppDeploymentConfiguration,
DeploymentOwner,
} from '@finos/legend-graph';
import { type GeneratorFn } from '@finos/legend-shared';
import { FUNCTION_ACTIVATE_TYPE } from '../../../../components/editor/editor-group/function-activator/FunctionEditor.js';
Expand Down Expand Up @@ -92,7 +93,7 @@ export class FunctionActivatorState {
const snowflakeApp = new SnowflakeApp(activatorName);
snowflakeApp.applicationName = '';
snowflakeApp.description = '';
snowflakeApp.owner = undefined;
snowflakeApp.ownership = new DeploymentOwner('', snowflakeApp);
snowflakeApp.function =
PackageableElementExplicitReference.create(functionElement);
snowflakeApp.activationConfiguration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
PackageableElementExplicitReference,
observe_SnowflakeAppDeploymentConfiguration,
observe_SnowflakeApp,
DeploymentOwner,
observe_DeploymentOwnership,
} from '@finos/legend-graph';
import {
type GeneratorFn,
Expand All @@ -43,7 +45,7 @@ export class SnowflakeAppFunctionActivatorEdtiorState extends ElementEditorState
makeObservable(this, {
activator: computed,
reprocess: action,
updateOwner: action,
updateOwnership: action,
updateAppDescription: action,
updateApplicationName: action,
updateConnection: action,
Expand All @@ -70,8 +72,9 @@ export class SnowflakeAppFunctionActivatorEdtiorState extends ElementEditorState
);
}

updateOwner(val: string): void {
this.activator.owner = val;
updateOwnership(val: string): void {
this.activator.ownership = new DeploymentOwner(val, this.activator);
observe_DeploymentOwnership(this.activator.ownership);
}

updateApplicationName(val: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* limitations under the License.
*/

import { makeObservable, observable } from 'mobx';
import { computed, makeObservable, observable } from 'mobx';
import type { SnowflakeAppDeploymentConfiguration } from '../../../graph/metamodel/pure/functionActivator/SnowflakeAppDeploymentConfiguration.js';
import { skipObserved } from './CoreObserverHelper.js';
import { observe_ConnectionPointer } from './DSL_Mapping_ObserverHelper.js';
import type { DeploymentOwner } from '../../../graph/metamodel/pure/packageableElements/function/Ownership.js';

export const observe_SnowflakeAppDeploymentConfiguration = skipObserved(
(
Expand All @@ -34,3 +35,13 @@ export const observe_SnowflakeAppDeploymentConfiguration = skipObserved(
return metamodel;
},
);

export const observe_DeploymentOwnership = skipObserved(
(metamodel: DeploymentOwner): DeploymentOwner => {
makeObservable(metamodel, {
id: observable,
hashCode: computed,
});
return metamodel;
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export const observe_SnowflakeApp = skipObserved(
makeObservable<SnowflakeApp, '_elementHashCode'>(metamodel, {
applicationName: observable,
description: observable,
owner: observable,
ownership: observable,
activationConfiguration: observable,
_elementHashCode: override,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import {
import type { V1_TaggedValue } from '../domain/V1_TaggedValue.js';
import type { V1_StereotypePtr } from '../domain/V1_StereotypePtr.js';
import type { V1_DeploymentConfiguration } from '../../../engine/functionActivator/V1_DeploymentConfiguration.js';
import type { V1_Ownership } from './V1_Ownership.js';

export abstract class V1_FunctionActivator
extends V1_PackageableElement
implements Hashable
{
function!: V1_PackageableElementPointer;
activationConfiguration: V1_DeploymentConfiguration | undefined;
ownership?: V1_Ownership;
stereotypes: V1_StereotypePtr[] = [];
taggedValues: V1_TaggedValue[] = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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 { hashArray, type Hashable } from '@finos/legend-shared';
import { CORE_HASH_STRUCTURE } from '../../../../../../../graph/Core_HashUtils.js';

export abstract class V1_Ownership implements Hashable {
abstract get hashCode(): string;
}

export class V1_DeploymentOwner extends V1_Ownership implements Hashable {
id!: string;

get hashCode(): string {
return hashArray([CORE_HASH_STRUCTURE.SERVICE_OWNER, this.id]);
}
}

export class V1_UserList extends V1_Ownership implements Hashable {
users: string[] = [];

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.SERVICE_OWNER,
hashArray(this.users),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import { V1_FunctionActivator } from './V1_FunctionActivator.js';
import type { V1_PackageableElementVisitor } from '../V1_PackageableElement.js';
import { CORE_HASH_STRUCTURE } from '../../../../../../../graph/Core_HashUtils.js';
import type { V1_SnowflakeAppDeploymentConfiguration } from '../../../engine/functionActivator/V1_SnowflakeAppDeploymentConfiguration.js';
import type { V1_DeploymentOwner } from './V1_Ownership.js';

export class V1_SnowflakeApp extends V1_FunctionActivator {
applicationName!: string;
description: string | undefined;
owner: string | undefined;
declare ownership: V1_DeploymentOwner;
declare activationConfiguration: V1_SnowflakeAppDeploymentConfiguration;

accept_PackageableElementVisitor<T>(
Expand All @@ -37,7 +38,7 @@ export class V1_SnowflakeApp extends V1_FunctionActivator {
CORE_HASH_STRUCTURE.SNOWFLAKE_APP,
this.applicationName,
this.description ?? '',
this.owner ?? '',
this.ownership,
this.activationConfiguration,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
* limitations under the License.
*/

import { UnsupportedOperationError } from '@finos/legend-shared';
import type { SnowflakeAppDeploymentConfiguration } from '../../../../../../../graph/metamodel/pure/functionActivator/SnowflakeAppDeploymentConfiguration.js';
import {
DeploymentOwner,
type Ownership,
} from '../../../../../../../graph/metamodel/pure/packageableElements/function/Ownership.js';
import { V1_SnowflakeAppDeploymentConfiguration } from '../../../engine/functionActivator/V1_SnowflakeAppDeploymentConfiguration.js';
import { V1_DeploymentOwner } from '../../../model/packageableElements/function/V1_Ownership.js';
import { V1_transformConnectionPointer } from './V1_ConnectionTransformer.js';

export const V1_transformSnowflakeAppDeploymentConfiguration = (
Expand All @@ -31,3 +37,21 @@ export const V1_transformSnowflakeAppDeploymentConfiguration = (

return protocol;
};

const transformDeployment = (element: DeploymentOwner): V1_DeploymentOwner => {
const ownership = new V1_DeploymentOwner();
ownership.id = element.id;
return ownership;
};

export const V1_transformDeployment = (
metamodel: Ownership,
): V1_DeploymentOwner => {
if (metamodel instanceof DeploymentOwner) {
return transformDeployment(metamodel);
}
throw new UnsupportedOperationError(
"Can't transform function activator ownership",
metamodel,
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ import { V1_INTERNAL__UnknownStore } from '../../../model/packageableElements/st
import { generateFunctionPrettyName } from '../../../../../../../graph/helpers/PureLanguageHelper.js';
import { V1_SnowflakeApp } from '../../../model/packageableElements/function/V1_SnowflakeApp.js';
import type { SnowflakeApp } from '../../../../../../../graph/metamodel/pure/packageableElements/function/SnowflakeApp.js';
import { V1_transformSnowflakeAppDeploymentConfiguration } from './V1_FunctionActivatorTransformer.js';
import {
V1_transformDeployment,
V1_transformSnowflakeAppDeploymentConfiguration,
} from './V1_FunctionActivatorTransformer.js';
import { PackageableElementPointerType } from '../../../../../../../graph/MetaModelConst.js';

class V1_PackageableElementTransformer
Expand Down Expand Up @@ -152,7 +155,7 @@ class V1_PackageableElementTransformer
);
protocol.applicationName = element.applicationName;
protocol.description = element.description;
protocol.owner = element.owner;
protocol.ownership = V1_transformDeployment(element.ownership);
protocol.activationConfiguration =
V1_transformSnowflakeAppDeploymentConfiguration(
element.activationConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export class V1_ElementFirstPassBuilder
);
metamodel.applicationName = element.applicationName;
metamodel.description = element.description;
metamodel.owner = element.owner;
return metamodel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ import {
import { V1_INTERNAL__UnknownMappingInclude } from '../../../model/packageableElements/mapping/V1_INTERNAL__UnknownMappingInclude.js';
import type { V1_INTERNAL__UnknownStore } from '../../../model/packageableElements/store/V1_INTERNAL__UnknownStore.js';
import type { V1_SnowflakeApp } from '../../../model/packageableElements/function/V1_SnowflakeApp.js';
import { V1_buildSnowflakeAppDeploymentConfiguration } from './helpers/V1_FunctionActivatorBuilderHelper.js';
import {
V1_buildDeploymentOwnership,
V1_buildSnowflakeAppDeploymentConfiguration,
} from './helpers/V1_FunctionActivatorBuilderHelper.js';

export class V1_ElementSecondPassBuilder
implements V1_PackageableElementVisitor<void>
Expand Down Expand Up @@ -162,6 +165,10 @@ export class V1_ElementSecondPassBuilder
),
),
);
metamodel.ownership = V1_buildDeploymentOwnership(
element.ownership,
metamodel,
);
metamodel.activationConfiguration =
V1_buildSnowflakeAppDeploymentConfiguration(
element.activationConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ import { SnowflakeAppDeploymentConfiguration } from '../../../../../../../../gra
import type { V1_SnowflakeAppDeploymentConfiguration } from '../../../../engine/functionActivator/V1_SnowflakeAppDeploymentConfiguration.js';
import type { V1_GraphBuilderContext } from '../V1_GraphBuilderContext.js';
import { V1_buildConnection } from './V1_ConnectionBuilderHelper.js';
import { guaranteeType } from '@finos/legend-shared';
import { UnsupportedOperationError, guaranteeType } from '@finos/legend-shared';
import {
DeploymentOwner,
type Ownership,
} from '../../../../../../../../graph/metamodel/pure/packageableElements/function/Ownership.js';
import {
V1_DeploymentOwner,
type V1_Ownership,
} from '../../../../model/packageableElements/function/V1_Ownership.js';
import type { FunctionActivator } from '../../../../../../../../graph/metamodel/pure/packageableElements/function/FunctionActivator.js';

export const V1_buildSnowflakeAppDeploymentConfiguration = (
element: V1_SnowflakeAppDeploymentConfiguration,
Expand All @@ -37,3 +46,13 @@ export const V1_buildSnowflakeAppDeploymentConfiguration = (
}
return metamodel;
};

export const V1_buildDeploymentOwnership = (
ownership: V1_Ownership,
functionActivator: FunctionActivator,
): Ownership => {
if (ownership instanceof V1_DeploymentOwner) {
return new DeploymentOwner(ownership.id, functionActivator);
}
throw new UnsupportedOperationError();
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
customEquivalentList,
customList,
customListWithSchema,
optionalCustom,
optionalCustomList,
usingConstantValueSchema,
usingModelSchema,
Expand Down Expand Up @@ -59,7 +60,11 @@ import {
} from './V1_RawValueSpecificationSerializationHelper.js';
import { V1_INTERNAL__UnknownFunctionActivator } from '../../../model/packageableElements/function/V1_INTERNAL__UnknownFunctionActivator.js';
import { V1_SnowflakeApp } from '../../../model/packageableElements/function/V1_SnowflakeApp.js';
import { V1_SnowflakeAppDeploymentConfigurationAppModelSchema } from './V1_FunctionActivatorSerializationHelper.js';
import {
V1_SnowflakeAppDeploymentConfigurationAppModelSchema,
V1_deserializeDeploymentOwnership,
V1_serializeDeploymentOwership,
} from './V1_FunctionActivatorSerializationHelper.js';
import {
V1_deserializeTestSuite,
V1_serializeTestSuite,
Expand Down Expand Up @@ -155,7 +160,6 @@ export const V1_measureModelSchema = createModelSchema(V1_Measure, {
export const V1_snowflakeAppModelSchema = createModelSchema(V1_SnowflakeApp, {
_type: usingConstantValueSchema(V1_SNOWFLAKE_APP_TYPE),
description: optional(primitive()),
owner: optional(primitive()),
applicationName: primitive(),
function: usingModelSchema(V1_packageableElementPointerModelSchema),
name: primitive(),
Expand All @@ -169,6 +173,10 @@ export const V1_snowflakeAppModelSchema = createModelSchema(V1_SnowflakeApp, {
activationConfiguration: usingModelSchema(
V1_SnowflakeAppDeploymentConfigurationAppModelSchema,
),
ownership: optionalCustom(
(val) => V1_serializeDeploymentOwership(val),
(val) => V1_deserializeDeploymentOwnership(val),
),
});

// ------------------------------------- Class -------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@
import {
usingConstantValueSchema,
usingModelSchema,
type PlainObject,
UnsupportedOperationError,
} from '@finos/legend-shared';
import { V1_SnowflakeAppDeploymentConfiguration } from '../../../engine/functionActivator/V1_SnowflakeAppDeploymentConfiguration.js';
import { createModelSchema } from 'serializr';
import {
createModelSchema,
deserialize,
primitive,
serialize,
} from 'serializr';
import { V1_connectionPointerModelSchema } from './V1_ConnectionSerializationHelper.js';
import {
V1_DeploymentOwner,
type V1_Ownership,
} from '../../../model/packageableElements/function/V1_Ownership.js';

const V1_SNOWFLAKE_APP_DEPLOYMENT_CONFIGURATION_APP_TYPE =
'snowflakeDeploymentConfiguration';
Expand All @@ -32,3 +43,38 @@ export const V1_SnowflakeAppDeploymentConfigurationAppModelSchema =
),
activationConnection: usingModelSchema(V1_connectionPointerModelSchema),
});

enum V1_OwnershipType {
DEPLOYMENT_OWNERSHIP = 'DeploymentOwner',
USERLIST_OWNERSHIP = 'userList',
}

const deploymentOwnershipSchema = createModelSchema(V1_DeploymentOwner, {
_type: usingConstantValueSchema(V1_OwnershipType.DEPLOYMENT_OWNERSHIP),
id: primitive(),
});

export const V1_deserializeDeploymentOwnership = (
json: PlainObject<V1_Ownership>,
): V1_DeploymentOwner => {
switch (json._type) {
case V1_OwnershipType.DEPLOYMENT_OWNERSHIP:
return deserialize(deploymentOwnershipSchema, json);
default:
throw new UnsupportedOperationError(
`Can't deserialize function activator ownership of type '${json._type}'`,
);
}
};

export const V1_serializeDeploymentOwership = (
protocol: V1_DeploymentOwner,
): PlainObject<V1_Ownership> => {
if (protocol instanceof V1_DeploymentOwner) {
return serialize(deploymentOwnershipSchema, protocol);
}
throw new UnsupportedOperationError(
`Can't serialize function activator ownership`,
protocol,
);
};
Loading

0 comments on commit 2a54433

Please sign in to comment.