diff --git a/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml b/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml index 400ea3197b8..95abc465635 100644 --- a/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml +++ b/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml @@ -78,7 +78,10 @@ org.finos.legend.engine legend-engine-identity-core - + + org.finos.legend.engine + legend-engine-xt-functionActivator-grammar + org.finos.legend.engine legend-engine-executionPlan-generation diff --git a/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java b/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java index a95c7297ba0..2522ab7a88f 100644 --- a/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java +++ b/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java @@ -44,6 +44,7 @@ import org.finos.legend.engine.language.hostedService.grammar.to.HostedServiceGrammarComposer; import org.finos.legend.engine.language.memsqlFunction.grammar.from.MemSqlFunctionGrammarParserExtension; import org.finos.legend.engine.language.memsqlFunction.grammar.to.MemSqlFunctionGrammarComposer; +import org.finos.legend.engine.language.functionActivator.grammar.postDeployment.to.PostDeploymentActionGrammarComposer; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.CompilerExtension; import org.finos.legend.engine.language.pure.dsl.authentication.grammar.from.AuthenticationGrammarParserExtension; @@ -378,6 +379,7 @@ protected Iterable> getE .with(DataSpaceGrammarComposerExtension.class) .with(SnowflakeAppGrammarComposer.class) .with(HostedServiceGrammarComposer.class) + .with(PostDeploymentActionGrammarComposer.class) .with(BigQueryFunctionGrammarComposer.class) .with(MemSqlFunctionGrammarComposer.class) .with(DiagramGrammarComposerExtension.class) diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/pom.xml b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/pom.xml new file mode 100644 index 00000000000..b04d8fd5274 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/pom.xml @@ -0,0 +1,68 @@ + + + + + 4.0.0 + + org.finos.legend.engine + legend-engine-xts-functionActivator + 4.63.1-SNAPSHOT + + + legend-engine-xt-functionActivator-compiler + jar + Legend Engine - XT - Function Activator - Compiler + + + + + + org.finos.legend.engine + legend-engine-language-pure-compiler + + + org.finos.legend.engine + legend-engine-shared-core + + + org.finos.legend.engine + legend-engine-protocol-pure + + + org.finos.legend.engine + legend-engine-xt-functionActivator-pure + + + org.finos.legend.engine + legend-engine-xt-functionActivator-protocol + + + + + + org.eclipse.collections + eclipse-collections + + + org.eclipse.collections + eclipse-collections-api + + + + \ No newline at end of file diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/src/main/java/org/finos/legend/engine/language/functionActivator/compiler/toPureGraph/postDeployment/HelperPostDeploymentCompilerBuilder.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/src/main/java/org/finos/legend/engine/language/functionActivator/compiler/toPureGraph/postDeployment/HelperPostDeploymentCompilerBuilder.java new file mode 100644 index 00000000000..e2898f012ea --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/src/main/java/org/finos/legend/engine/language/functionActivator/compiler/toPureGraph/postDeployment/HelperPostDeploymentCompilerBuilder.java @@ -0,0 +1,35 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.language.functionActivator.compiler.toPureGraph.postDeployment; + +import org.eclipse.collections.api.list.MutableList; +import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; +import org.finos.legend.engine.protocol.functionActivator.metamodel.PostDeploymentAction; +import org.finos.legend.pure.generated.Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction; + +import java.util.List; + +public class HelperPostDeploymentCompilerBuilder +{ + public static MutableList resolveDeploymentAction(List actions, CompileContext context) + { + List extensions = IPostDeploymentCompilerExtension.getExtensions(); + return ListIterate.collect(actions, action -> IPostDeploymentCompilerExtension.process( + action, + ListIterate.flatCollect(extensions, IPostDeploymentCompilerExtension::getExtraPostDeploymentActionProcessors), + context)); + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/src/main/java/org/finos/legend/engine/language/functionActivator/compiler/toPureGraph/postDeployment/IPostDeploymentCompilerExtension.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/src/main/java/org/finos/legend/engine/language/functionActivator/compiler/toPureGraph/postDeployment/IPostDeploymentCompilerExtension.java new file mode 100644 index 00000000000..b909f901fcd --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-compiler/src/main/java/org/finos/legend/engine/language/functionActivator/compiler/toPureGraph/postDeployment/IPostDeploymentCompilerExtension.java @@ -0,0 +1,57 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.language.functionActivator.compiler.toPureGraph.postDeployment; + +import org.eclipse.collections.api.block.function.Function2; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.impl.list.mutable.FastList; +import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.CompilerExtension; +import org.finos.legend.engine.protocol.functionActivator.metamodel.PostDeploymentAction; +import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; +import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; +import org.finos.legend.pure.generated.Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction; + +import java.util.List; +import java.util.Objects; +import java.util.ServiceLoader; + +public interface IPostDeploymentCompilerExtension extends CompilerExtension +{ + static List getExtensions() + { + return Lists.mutable.withAll(ServiceLoader.load(IPostDeploymentCompilerExtension.class)); + } + + static Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction process(PostDeploymentAction postDeploymentAction, List> processors, CompileContext context) + { + return process(postDeploymentAction, processors, context, "Post Deployment Compiler Extension"); + } + + static U process(T item, List> processors, CompileContext context, String type) + { + return ListIterate + .collect(processors, processor -> processor.value(item, context)) + .select(Objects::nonNull) + .getFirstOptional() + .orElseThrow(() -> new EngineException("Unsupported " + type + " type '" + item.getClass() + "'", EngineErrorType.COMPILATION)); + } + + default List> getExtraPostDeploymentActionProcessors() + { + return FastList.newList(); + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/pom.xml b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/pom.xml index 619707bc66c..d8c5c5a7eb9 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/pom.xml +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/pom.xml @@ -34,9 +34,23 @@ org.finos.legend.engine legend-engine-identity-core - + + org.finos.legend.engine + legend-engine-xt-functionActivator-protocol + + + org.finos.legend.engine + legend-engine-xt-functionActivator-generation + + + + org.eclipse.collections + eclipse-collections-api + + + junit @@ -48,11 +62,6 @@ log4j test - - org.finos.legend.engine - legend-engine-xt-functionActivator-protocol - - diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/src/main/java/org/finos/legend/engine/functionActivator/deployment/DeploymentManager.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/src/main/java/org/finos/legend/engine/functionActivator/deployment/DeploymentManager.java index cde36ea9980..0a02cc0cac0 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/src/main/java/org/finos/legend/engine/functionActivator/deployment/DeploymentManager.java +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-deployment/src/main/java/org/finos/legend/engine/functionActivator/deployment/DeploymentManager.java @@ -14,9 +14,12 @@ package org.finos.legend.engine.functionActivator.deployment; +import org.eclipse.collections.api.factory.Lists; +import org.finos.legend.engine.functionActivator.postDeployment.PostDeploymentActionLoader; import org.finos.legend.engine.protocol.functionActivator.deployment.DeploymentResult; import org.finos.legend.engine.protocol.functionActivator.deployment.FunctionActivatorArtifact; import org.finos.legend.engine.protocol.functionActivator.deployment.FunctionActivatorDeploymentConfiguration; +import org.finos.legend.engine.protocol.functionActivator.deployment.PostDeploymentActionResult; import org.finos.legend.engine.shared.core.identity.Identity; import java.util.List; @@ -31,4 +34,14 @@ public interface DeploymentManager availableRuntimeConfigurations); public boolean canDeploy(FunctionActivatorArtifact activatorArtifact); + + public default List deployActions(Identity identity, U artifact) + { + List actionResults = Lists.mutable.empty(); + PostDeploymentActionLoader.extensions().forEach((ex) -> + { + actionResults.addAll(ex.processAction(identity, artifact)); + }); + return actionResults; + } } diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/pom.xml b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/pom.xml index e2c18731390..7547532dd00 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/pom.xml +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/pom.xml @@ -52,11 +52,14 @@ org.finos.legend.engine legend-engine-language-pure-compiler - org.finos.legend.engine legend-engine-xt-functionActivator-pure + + org.finos.legend.engine + legend-engine-identity-core + diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentActionLoader.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentActionLoader.java new file mode 100644 index 00000000000..c697a64fcdf --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentActionLoader.java @@ -0,0 +1,65 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.functionActivator.postDeployment; + +import org.eclipse.collections.api.list.MutableList; +import org.eclipse.collections.impl.factory.Lists; +import org.finos.legend.engine.protocol.functionActivator.postDeployment.ActionContent; +import org.finos.legend.pure.generated.Root_meta_external_function_activator_FunctionActivator; + +import java.util.List; +import java.util.ServiceLoader; +import java.util.concurrent.atomic.AtomicReference; + +public class PostDeploymentActionLoader +{ + private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(PostDeploymentContract.class); + private static final AtomicReference> INSTANCE = new AtomicReference<>(); + + public static MutableList extensions() + { + return INSTANCE.updateAndGet(existing -> + { + if (existing == null) + { + MutableList extensions = Lists.mutable.empty(); + for (PostDeploymentContract extension : ServiceLoader.load(PostDeploymentContract.class)) + { + try + { + extensions.add(extension); + } + catch (Throwable throwable) + { + LOGGER.error("Failed to load execution extension '" + extension.getClass().getSimpleName() + "'"); + } + } + return extensions; + } + return existing; + }); + } + + public static List generateActions(Root_meta_external_function_activator_FunctionActivator activator) + { + List actionsContent = Lists.mutable.empty(); + extensions().forEach(e -> + { + actionsContent.addAll(e.generate(activator._actions())); + }); + + return actionsContent; + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentContract.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentContract.java new file mode 100644 index 00000000000..4d2fb95d012 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentContract.java @@ -0,0 +1,32 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.functionActivator.postDeployment; + +import org.eclipse.collections.api.RichIterable; +import org.finos.legend.engine.protocol.functionActivator.deployment.FunctionActivatorArtifact; +import org.finos.legend.engine.protocol.functionActivator.deployment.FunctionActivatorDeploymentConfiguration; +import org.finos.legend.engine.protocol.functionActivator.deployment.PostDeploymentActionResult; +import org.finos.legend.engine.protocol.functionActivator.postDeployment.ActionContent; +import org.finos.legend.engine.shared.core.identity.Identity; +import org.finos.legend.pure.generated.Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction; + +import java.util.List; + +public interface PostDeploymentContract +{ + List generate(RichIterable actions); + + List processAction(Identity identity, FunctionActivatorArtifact artifact); +} \ No newline at end of file diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/pom.xml b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/pom.xml new file mode 100644 index 00000000000..529c69b0057 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/pom.xml @@ -0,0 +1,147 @@ + + + + + org.finos.legend.engine + legend-engine-xts-functionActivator + 4.63.1-SNAPSHOT + + 4.0.0 + + legend-engine-xt-functionActivator-grammar + jar + Legend Engine - XT - Function Activator - Grammar + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-antlr-core-grammar + initialize + + unpack + + + + + org.finos.legend.engine + legend-engine-language-pure-grammar + jar + false + ${project.build.directory} + antlr/*.g4 + + + + + + + + org.antlr + antlr4-maven-plugin + + + + antlr4 + + + true + true + true + target/antlr + target/generated-sources + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + + + + + org.finos.legend.engine + legend-engine-language-pure-grammar + + + org.finos.legend.engine + legend-engine-shared-core + + + org.finos.legend.engine + legend-engine-protocol-pure + + + org.finos.legend.engine + legend-engine-protocol + + + org.finos.legend.engine + legend-engine-xt-relationalStore-grammar + + + org.finos.legend.engine + legend-engine-xt-functionActivator-protocol + + + + + + org.eclipse.collections + eclipse-collections + + + org.eclipse.collections + eclipse-collections-api + + + + + + junit + junit + test + + + org.finos.legend.engine + legend-engine-shared-core + test-jar + test + + + org.finos.legend.engine + legend-engine-language-pure-grammar + test-jar + test + + + + \ No newline at end of file diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/from/IPostDeploymentActionGrammarParserExtension.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/from/IPostDeploymentActionGrammarParserExtension.java new file mode 100644 index 00000000000..4f16859cd71 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/from/IPostDeploymentActionGrammarParserExtension.java @@ -0,0 +1,50 @@ +// Copyright 2021 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. + +package org.finos.legend.engine.language.functionActivator.grammar.postDeployment.from; + +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.language.pure.grammar.from.extension.PureGrammarParserExtension; +import org.finos.legend.engine.protocol.functionActivator.metamodel.PostDeploymentAction; +import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; +import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.ServiceLoader; +import java.util.function.Function; + +public interface IPostDeploymentActionGrammarParserExtension extends PureGrammarParserExtension +{ + static List getExtensions() + { + return Lists.mutable.withAll(ServiceLoader.load(IPostDeploymentActionGrammarParserExtension.class)); + } + + default List> getExtraPostDeploymentActionParsers() + { + return Collections.emptyList(); + } + + static PostDeploymentAction process(PostDeploymentActionSourceCode code, List> processors) + { + return ListIterate + .collect(processors, processor -> processor.apply(code)) + .select(Objects::nonNull) + .getFirstOptional() + .orElseThrow(() -> new EngineException("Unsupported " + " type '" + code.getType() + "'", code.getSourceInformation(), EngineErrorType.PARSER)); + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/from/PostDeploymentActionSourceCode.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/from/PostDeploymentActionSourceCode.java new file mode 100644 index 00000000000..710609c1853 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/from/PostDeploymentActionSourceCode.java @@ -0,0 +1,27 @@ +// Copyright 2021 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. + +package org.finos.legend.engine.language.functionActivator.grammar.postDeployment.from; + +import org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation; +import org.finos.legend.engine.language.pure.grammar.from.SpecificationSourceCode; +import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; + +public class PostDeploymentActionSourceCode extends SpecificationSourceCode +{ + public PostDeploymentActionSourceCode(String code, String type, SourceInformation sourceInformation, ParseTreeWalkerSourceInformation walkerSourceInformation) + { + super(code, type, sourceInformation, walkerSourceInformation); + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/to/IPostDeploymentActionGrammarComposerExtension.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/to/IPostDeploymentActionGrammarComposerExtension.java new file mode 100644 index 00000000000..4dca86bd64f --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/to/IPostDeploymentActionGrammarComposerExtension.java @@ -0,0 +1,55 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.language.functionActivator.grammar.postDeployment.to; + +import org.eclipse.collections.api.block.function.Function; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.impl.list.mutable.FastList; +import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.language.pure.grammar.to.extension.PureGrammarComposerExtension; +import org.finos.legend.engine.protocol.functionActivator.metamodel.PostDeploymentAction; +import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; +import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; + +import java.util.List; +import java.util.Objects; +import java.util.ServiceLoader; + +public interface IPostDeploymentActionGrammarComposerExtension extends PureGrammarComposerExtension +{ + static List getExtensions() + { + return Lists.mutable.withAll(ServiceLoader.load(IPostDeploymentActionGrammarComposerExtension.class)); + } + + static String process(PostDeploymentAction postDeploymentAction, List> processors) + { + return process(postDeploymentAction, processors, "Post Deployment Action"); + } + + static String process(T item, List> processors, String type) + { + return ListIterate + .collect(processors, processor -> processor.valueOf(item)) + .select(Objects::nonNull) + .getFirstOptional() + .orElseThrow(() -> new EngineException("Unsupported " + type + " type '" + item.getClass() + "'", EngineErrorType.PARSER)); + } + + default List> getExtraPostDeploymentActionComposer() + { + return FastList.newList(); + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/to/PostDeploymentActionGrammarComposer.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/to/PostDeploymentActionGrammarComposer.java new file mode 100644 index 00000000000..10c00a917d7 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/java/org/finos/legend/engine/language/functionActivator/grammar/postDeployment/to/PostDeploymentActionGrammarComposer.java @@ -0,0 +1,37 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.language.functionActivator.grammar.postDeployment.to; + +import org.eclipse.collections.impl.list.mutable.FastList; +import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.language.pure.grammar.to.extension.PureGrammarComposerExtension; +import org.finos.legend.engine.protocol.functionActivator.metamodel.PostDeploymentAction; +import java.util.List; +import static org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.getTabString; + +public class PostDeploymentActionGrammarComposer implements PureGrammarComposerExtension +{ + public static String renderActions(List actions) + { + List postDeploymentActionStrings = FastList.newList(); + List extensions = IPostDeploymentActionGrammarComposerExtension.getExtensions(); + + postDeploymentActionStrings.addAll(ListIterate.collect(actions, action -> IPostDeploymentActionGrammarComposerExtension.process( + action, + ListIterate.flatCollect(extensions, IPostDeploymentActionGrammarComposerExtension::getExtraPostDeploymentActionComposer) + ))); + return " actions: [\n" + getTabString() + String.join(",\n", postDeploymentActionStrings) + "\n" + getTabString() + "];"; + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/resources/META-INF/services/org.finos.legend.engine.language.pure.grammar.to.extension.PureGrammarComposerExtension b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/resources/META-INF/services/org.finos.legend.engine.language.pure.grammar.to.extension.PureGrammarComposerExtension new file mode 100644 index 00000000000..9213f861628 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-grammar/src/main/resources/META-INF/services/org.finos.legend.engine.language.pure.grammar.to.extension.PureGrammarComposerExtension @@ -0,0 +1 @@ +org.finos.legend.engine.language.functionActivator.grammar.postDeployment.to.PostDeploymentActionGrammarComposer \ No newline at end of file diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/pom.xml b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/pom.xml index fce89005d6f..b24000088c7 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/pom.xml +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/pom.xml @@ -28,14 +28,27 @@ Legend Engine - XT - Function Activator - Protocol + org.finos.legend.engine legend-engine-protocol-pure + + + + + org.eclipse.collections + eclipse-collections-api + + + + com.fasterxml.jackson.core jackson-annotations + + junit diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/DeploymentResult.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/DeploymentResult.java index 315b0d3bf75..fa391ceb58b 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/DeploymentResult.java +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/DeploymentResult.java @@ -14,11 +14,14 @@ package org.finos.legend.engine.protocol.functionActivator.deployment; +import java.util.List; + public class DeploymentResult { public String activatorIdentifier; public boolean successful; public String deploymentLocation; + public List actionResults; @Override public String toString() diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/FunctionActivatorArtifact.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/FunctionActivatorArtifact.java index 8080dbb41f3..946773adc9a 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/FunctionActivatorArtifact.java +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/FunctionActivatorArtifact.java @@ -16,7 +16,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.eclipse.collections.api.factory.Lists; +import org.finos.legend.engine.protocol.functionActivator.postDeployment.ActionContent; import org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC; +import java.util.List; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type") @JsonIgnoreProperties(ignoreUnknown = true) @@ -24,6 +27,7 @@ public class FunctionActivatorArtifact { public FunctionActivatorDeploymentContent content; public FunctionActivatorDeploymentConfiguration deploymentConfiguration; + public List actions = Lists.mutable.empty(); public String version; diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/PostDeploymentActionResult.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/PostDeploymentActionResult.java new file mode 100644 index 00000000000..84959c0e167 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/deployment/PostDeploymentActionResult.java @@ -0,0 +1,34 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.protocol.functionActivator.deployment; + +public class PostDeploymentActionResult +{ + public String actionType; + public boolean success; + public String detail; + + public PostDeploymentActionResult() + { + + } + + public PostDeploymentActionResult(String actionType, boolean success, String detail) + { + this.actionType = actionType; + this.success = success; + this.detail = detail; + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/FunctionActivator.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/FunctionActivator.java index 9b1e50caef6..4ee7452380a 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/FunctionActivator.java +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/FunctionActivator.java @@ -32,4 +32,5 @@ public abstract class FunctionActivator extends PackageableElement public PackageableElementPointer function; public DeploymentConfiguration activationConfiguration; public Ownership ownership; + public List actions = Collections.emptyList(); } diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/PostDeploymentAction.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/PostDeploymentAction.java new file mode 100644 index 00000000000..ef1464440b2 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/PostDeploymentAction.java @@ -0,0 +1,21 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.protocol.functionActivator.metamodel; + +public class PostDeploymentAction +{ + public PostDeploymentProperties properties; + public boolean automated; +} \ No newline at end of file diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/PostDeploymentProperties.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/PostDeploymentProperties.java new file mode 100644 index 00000000000..b71d4e02388 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/metamodel/PostDeploymentProperties.java @@ -0,0 +1,22 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.protocol.functionActivator.metamodel; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type") +public class PostDeploymentProperties +{ +} \ No newline at end of file diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/postDeployment/ActionContent.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/postDeployment/ActionContent.java new file mode 100644 index 00000000000..5a498eb17da --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-protocol/src/main/java/org/finos/legend/engine/protocol/functionActivator/postDeployment/ActionContent.java @@ -0,0 +1,22 @@ +// Copyright 2023 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. + +package org.finos.legend.engine.protocol.functionActivator.postDeployment; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type") +public class ActionContent +{ +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-pure/src/main/resources/core_function_activator/metamodel.pure b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-pure/src/main/resources/core_function_activator/metamodel.pure index 2d555cc14ee..0fcac18816a 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-pure/src/main/resources/core_function_activator/metamodel.pure +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-pure/src/main/resources/core_function_activator/metamodel.pure @@ -1,10 +1,12 @@ import meta::external::function::activator::*; +import meta::external::function::activator::postDeploymentAction::*; Class meta::external::function::activator::FunctionActivator extends PackageableElement { {doc.doc = 'The function that needs to be activated.'} function : PackageableFunction[1]; {doc.doc = 'The activation configuration.'} activationConfiguration : DeploymentConfiguration[0..1]; {doc.doc = 'The ownership criteria.'} ownership : Ownership[1]; + {doc.doc = 'Optional action that can be executed after deployment'} actions : meta::external::function::activator::postDeploymentAction::PostDeploymentAction[*]; } @@ -33,6 +35,17 @@ Class meta::external::function::activator::DeploymentOwnership extends meta::ext id: String[1]; } +Class meta::external::function::activator::postDeploymentAction::PostDeploymentAction +{ + automated: Boolean[0..1]; + properties: PostDeploymentActionProperties[1]; +} + +Class meta::external::function::activator::postDeploymentAction::PostDeploymentActionProperties +{ + +} + // This section needs to be code generated from the section above Class meta::protocols::pure::vX_X_X::metamodel::function::activator::FunctionActivator extends meta::protocols::pure::vX_X_X::metamodel::PackageableElement, meta::protocols::pure::vX_X_X::metamodel::domain::AnnotatedElement { diff --git a/legend-engine-xts-functionActivator/pom.xml b/legend-engine-xts-functionActivator/pom.xml index 75b9e08ec98..44e0e642f90 100644 --- a/legend-engine-xts-functionActivator/pom.xml +++ b/legend-engine-xts-functionActivator/pom.xml @@ -34,6 +34,8 @@ legend-engine-xt-functionActivator-protocol legend-engine-xt-functionActivator-pure legend-engine-xt-functionActivator-generation + legend-engine-xt-functionActivator-compiler + legend-engine-xt-functionActivator-grammar \ No newline at end of file diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java index f2c8d85e4f0..3b9cb4ac6c7 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java @@ -26,14 +26,12 @@ import org.finos.legend.engine.functionActivator.service.FunctionActivatorError; import org.finos.legend.engine.functionActivator.service.FunctionActivatorService; import org.finos.legend.engine.language.hostedService.generation.deployment.HostedServiceDeploymentManager; -import org.finos.legend.engine.protocol.hostedService.deployment.model.GenerationInfoData; import org.finos.legend.engine.protocol.hostedService.deployment.HostedServiceDeploymentResult; import org.finos.legend.engine.language.hostedService.generation.HostedServiceArtifactGenerator; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +import org.finos.legend.engine.protocol.hostedService.deployment.HostedServiceDestination; import org.finos.legend.engine.protocol.hostedService.metamodel.HostedServiceProtocolExtension; -import org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext; -import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; import org.finos.legend.engine.shared.core.identity.Identity; import org.finos.legend.pure.generated.*; @@ -124,12 +122,15 @@ public HostedServiceDeploymentResult publishToSandbox(Identity identity, PureMod MutableList validationErrors = this.validate(identity, pureModel, activator, inputModel, routerExtensions); if (validationErrors.isEmpty()) { - GenerationInfoData generation = this.hostedServiceArtifactgenerator.renderArtifact(pureModel, activator, inputModel, "vX_X_X", routerExtensions); - HostedServiceArtifact artifact = new HostedServiceArtifact(activator._pattern(), generation, HostedServiceArtifactGenerator.fetchHostedService(activator, (PureModelContextData) inputModel, pureModel), ((Root_meta_external_function_activator_DeploymentOwnership) activator._ownership())._id(), ((PureModelContextData) inputModel).origin != null ? (AlloySDLC) ((PureModelContextData) inputModel).origin.sdlcInfo : null); - return this.hostedServiceDeploymentManager.deploy(identity, artifact, runtimeConfigs); + HostedServiceArtifact artifact = this.hostedServiceArtifactgenerator.renderServiceArtifact(pureModel, activator, inputModel, "vX_X_X", routerExtensions); + HostedServiceDeploymentResult result = this.hostedServiceDeploymentManager.deploy(identity, artifact, runtimeConfigs); + if (result.successful) + { + result.actionResults = this.hostedServiceDeploymentManager.deployActions(identity, artifact); + } + return result; } return new HostedServiceDeploymentResult(validationErrors.collect(v -> v.message)); } - } diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/pom.xml b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/pom.xml index 9ea9aed9534..504c5d89e6f 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/pom.xml +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/pom.xml @@ -81,6 +81,10 @@ org.finos.legend.engine legend-engine-language-pure-compiler + + org.finos.legend.engine + legend-engine-xt-functionActivator-compiler + diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/src/main/java/org/finos/legend/engine/language/hostedService/compiler/toPureGraph/HostedServiceCompilerExtension.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/src/main/java/org/finos/legend/engine/language/hostedService/compiler/toPureGraph/HostedServiceCompilerExtension.java index e20aaca0651..9cfd888d8b2 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/src/main/java/org/finos/legend/engine/language/hostedService/compiler/toPureGraph/HostedServiceCompilerExtension.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-compiler/src/main/java/org/finos/legend/engine/language/hostedService/compiler/toPureGraph/HostedServiceCompilerExtension.java @@ -18,6 +18,7 @@ import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.utility.ListIterate; import org.finos.legend.engine.code.core.CoreFunctionActivatorCodeRepositoryProvider; +import org.finos.legend.engine.language.functionActivator.compiler.toPureGraph.postDeployment.HelperPostDeploymentCompilerBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.CompilerExtension; import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.Processor; @@ -97,6 +98,7 @@ public Root_meta_external_function_activator_hostedService_HostedService buildHo ._generateLineage(app.generateLineage) ._storeModel(app.storeModel) ._ownership(buildHostedServiceOwner(app.ownership, context)) + ._actions(HelperPostDeploymentCompilerBuilder.resolveDeploymentAction(app.actions, context)) ._activationConfiguration(app.activationConfiguration != null ? buildDeploymentConfig((HostedServiceDeploymentConfiguration) app.activationConfiguration, context) : null); } catch (Exception e) @@ -105,7 +107,6 @@ public Root_meta_external_function_activator_hostedService_HostedService buildHo } } - public Root_meta_external_function_activator_Ownership buildHostedServiceOwner(Ownership owner, CompileContext context) { if (owner instanceof UserList) diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml index 0e5c0d50ac4..1e3bdcb7e16 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml @@ -85,6 +85,10 @@ org.finos.legend.engine legend-engine-xt-functionActivator-pure + + org.finos.legend.engine + legend-engine-xt-functionActivator-generation + diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java index f049796b010..8fb9839e8a4 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java @@ -20,24 +20,31 @@ import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.list.ListIterable; import org.eclipse.collections.api.list.MutableList; +import org.finos.legend.engine.functionActivator.postDeployment.PostDeploymentActionLoader; import org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension; import org.finos.legend.engine.plan.generation.transformers.PlanTransformer; +import org.finos.legend.engine.protocol.functionActivator.postDeployment.ActionContent; +import org.finos.legend.engine.protocol.hostedService.deployment.HostedServiceArtifact; import org.finos.legend.engine.protocol.hostedService.deployment.model.GenerationInfoData; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; import org.finos.legend.engine.plan.generation.PlanGenerator; import org.finos.legend.engine.plan.platform.PlanPlatform; import org.finos.legend.engine.protocol.hostedService.deployment.model.lineage.Lineage; import org.finos.legend.engine.protocol.hostedService.metamodel.HostedService; +import org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.CompositeExecutionPlan; import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan; import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan; +import org.finos.legend.pure.generated.Root_meta_external_function_activator_DeploymentOwnership; +import org.finos.legend.pure.generated.Root_meta_external_function_activator_FunctionActivator; import org.finos.legend.pure.generated.Root_meta_external_function_activator_hostedService_HostedService; import org.finos.legend.pure.generated.Root_meta_pure_extension_Extension; import org.finos.legend.pure.generated.core_hostedservice_generation_generation; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition; +import java.util.List; import java.util.Map; import java.util.ServiceLoader; @@ -54,6 +61,13 @@ public static GenerationInfoData renderArtifact(PureModel pureModel, Root_meta_e return new GenerationInfoData(plan, lineage); } + public static HostedServiceArtifact renderServiceArtifact(PureModel pureModel, Root_meta_external_function_activator_hostedService_HostedService activator, PureModelContext inputModel, String clientVersion, Function> routerExtensions) + { + ExecutionPlan plan = generatePlan(pureModel, activator, inputModel, clientVersion, routerExtensions); + Lineage lineage = new Lineage(); + return new HostedServiceArtifact(activator._pattern(), new GenerationInfoData(plan, lineage), HostedServiceArtifactGenerator.fetchHostedService(activator, (PureModelContextData)inputModel, pureModel), ((Root_meta_external_function_activator_DeploymentOwnership) activator._ownership())._id(), renderActions(activator), ((PureModelContextData)inputModel).origin != null ? (AlloySDLC) ((PureModelContextData)inputModel).origin.sdlcInfo : null); + } + public static ExecutionPlan generatePlan(PureModel pureModel, Root_meta_external_function_activator_hostedService_HostedService activator, PureModelContext inputModel, String clientVersion,Function> routerExtensions) { ListIterable transformers = generatorExtensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers); @@ -101,4 +115,9 @@ public static String fullName(org.finos.legend.engine.protocol.pure.v1.model.pac return e._package + "::" + e.name; } + public static List renderActions(Root_meta_external_function_activator_FunctionActivator activator) + { + return PostDeploymentActionLoader.generateActions(activator); + } + } diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/deployment/HostedServiceArtifactGenerationExtension.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/deployment/HostedServiceArtifactGenerationExtension.java index bd67a2ea2d2..fd746d549e1 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/deployment/HostedServiceArtifactGenerationExtension.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/deployment/HostedServiceArtifactGenerationExtension.java @@ -20,6 +20,7 @@ import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.MutableList; +import org.finos.legend.engine.functionActivator.postDeployment.PostDeploymentActionLoader; import org.finos.legend.engine.language.hostedService.generation.HostedServiceArtifactGenerator; import org.finos.legend.engine.protocol.hostedService.deployment.HostedServiceArtifact; import org.finos.legend.engine.protocol.hostedService.deployment.model.GenerationInfoData; @@ -79,7 +80,7 @@ public List generate(PackageableElement element, PureModel pureModel, Function> routerExtensions = (PureModel p) -> PureCoreExtensionLoader.extensions().flatCollect(e -> e.extraPureCoreExtensions(p.getExecutionSupport())); GenerationInfoData info = HostedServiceArtifactGenerator.renderArtifact(pureModel, activator, data, clientVersion, routerExtensions); PureModelContextData serviceData = HostedServiceArtifactGenerator.fetchHostedService(activator, data, pureModel); - result.add(new Artifact(mapper.writeValueAsString(new HostedServiceArtifact(activator._pattern(), info, generatePointerForActivator(serviceData, data), ((Root_meta_external_function_activator_DeploymentOwnership)activator._ownership())._id(), (AlloySDLC) data.origin.sdlcInfo)), FILE_NAME, "json")); + result.add(new Artifact(mapper.writeValueAsString(new HostedServiceArtifact(activator._pattern(), info, generatePointerForActivator(serviceData, data), ((Root_meta_external_function_activator_DeploymentOwnership)activator._ownership())._id(), PostDeploymentActionLoader.generateActions(activator), (AlloySDLC) data.origin.sdlcInfo)), FILE_NAME, "json")); if (!(element._stereotypes().anySatisfy(stereotype -> stereotype._profile()._name().equals("devStatus") && stereotype._profile()._p_stereotypes().anySatisfy(s -> s._value().equals("inProgress"))))) { diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/pom.xml b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/pom.xml index 2db9ddbdb36..169a36568f4 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/pom.xml +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/pom.xml @@ -100,6 +100,11 @@ + + org.finos.legend.engine + legend-engine-xt-functionActivator-grammar + ${project.version} + org.finos.legend.engine legend-engine-language-pure-grammar diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceLexerGrammar.g4 b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceLexerGrammar.g4 index 5e0c8ecd8ae..524701a1df8 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceLexerGrammar.g4 +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceLexerGrammar.g4 @@ -41,6 +41,8 @@ SERVICE_POST_VALIDATION_DESCRIPTION: 'description'; SERVICE_POST_VALIDATION_PARAMETERS: 'params'; SERVICE_POST_VALIDATION_ASSERTIONS: 'assertions'; +// -------------------------------------- POST_DEPLOYMENT_ACTIONS------------------------- +POST_DEPLOYMENT_ACTIONS: 'actions'; // -------------------------------------- EXECUTION_ENVIRONMENT------------------------- diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceParserGrammar.g4 b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceParserGrammar.g4 index 6b8d78d545f..076045a241b 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceParserGrammar.g4 +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/HostedServiceParserGrammar.g4 @@ -21,7 +21,7 @@ identifier: VALID_STRING | STRING | SERVICE_TEST_SERIALIZATION_FORMAT | PARAM_GROUP | ASSERT_FOR_KEYS | SERVICE_POST_VALIDATION | SERVICE_POST_VALIDATION_DESCRIPTION | SERVICE_POST_VALIDATION_PARAMETERS | SERVICE_POST_VALIDATION_ASSERTIONS | EXEC_ENV| SERVICE_EXECUTION_EXECUTIONS | SERVICE_OWNERSHIP_USERLIST |SERVICE_OWNERSHIP_USERLIST_USERS - | SERVICE_OWNERSHIP_DEPLOYMENT | SERVICE_OWNERSHIP_DEPLOYMENT_IDENTIFIER + | SERVICE_OWNERSHIP_DEPLOYMENT | SERVICE_OWNERSHIP_DEPLOYMENT_IDENTIFIER | POST_DEPLOYMENT_ACTIONS ; @@ -50,9 +50,24 @@ service: SERVICE stereotypes? taggedValues? quali | serviceActivationConfiguration | serviceLineage | serviceModel + | postDeploymentActions )* BRACE_CLOSE ; +postDeploymentActions: POST_DEPLOYMENT_ACTIONS COLON + BRACKET_OPEN + (postDeploymentAction (COMMA postDeploymentAction)*)? + BRACKET_CLOSE + SEMI_COLON +; +postDeploymentAction: actionType (actionBody)? +; +actionBody: ISLAND_OPEN actionValue +; +actionValue: (ISLAND_START | ISLAND_BRACE_OPEN | ISLAND_CONTENT | ISLAND_BRACE_CLOSE | ISLAND_END)* +; +actionType: VALID_STRING +; stereotypes: LESS_THAN LESS_THAN stereotype (COMMA stereotype)* GREATER_THAN GREATER_THAN ; stereotype: qualifiedName DOT identifier diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/from/HostedServiceTreeWalker.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/from/HostedServiceTreeWalker.java index d628f08e450..ecfdd2b9e09 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/from/HostedServiceTreeWalker.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/from/HostedServiceTreeWalker.java @@ -17,19 +17,24 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import java.util.function.Function; import org.antlr.v4.runtime.CharStream; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.language.functionActivator.grammar.postDeployment.from.IPostDeploymentActionGrammarParserExtension; +import org.finos.legend.engine.language.functionActivator.grammar.postDeployment.from.PostDeploymentActionSourceCode; import org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation; import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext; import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserUtility; import org.finos.legend.engine.language.pure.grammar.from.antlr4.HostedServiceParserGrammar; import org.finos.legend.engine.language.pure.grammar.from.runtime.RuntimeParser; +import org.finos.legend.engine.protocol.functionActivator.metamodel.PostDeploymentAction; import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentOwner; import org.finos.legend.engine.protocol.hostedService.metamodel.HostedService; import org.finos.legend.engine.protocol.hostedService.metamodel.HostedServiceDeploymentConfiguration; import org.finos.legend.engine.protocol.hostedService.metamodel.control.UserList; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; +import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer; import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement; @@ -114,9 +119,38 @@ private HostedService visitHostedService(HostedServiceParserGrammar.ServiceConte HostedServiceParserGrammar.ServiceAutoActivateUpdatesContext autoActivateUpdatesContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.serviceAutoActivateUpdates(), "autoActivateUpdates", hostedService.sourceInformation); hostedService.autoActivateUpdates = autoActivateUpdatesContext != null && Boolean.parseBoolean(autoActivateUpdatesContext.BOOLEAN().getText()); + HostedServiceParserGrammar.PostDeploymentActionsContext postDeploymentActionsContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.postDeploymentActions(), "actions", hostedService.sourceInformation); + hostedService.actions = postDeploymentActionsContext == null ? Lists.mutable.empty() : this.visitPostDeploymentActions(postDeploymentActionsContext); return hostedService; } + private List visitPostDeploymentActions(HostedServiceParserGrammar.PostDeploymentActionsContext ctx) + { + List specifications = ctx.postDeploymentAction(); + List extensions = IPostDeploymentActionGrammarParserExtension.getExtensions(); + List> parsers = ListIterate.flatCollect(extensions, IPostDeploymentActionGrammarParserExtension::getExtraPostDeploymentActionParsers); + return ListIterate.collect(specifications, spec -> visitPostDeploymentAction(spec, parsers)); + } + + public PostDeploymentAction visitPostDeploymentAction(HostedServiceParserGrammar.PostDeploymentActionContext spec, List> parsers) + { + SourceInformation sourceInformation = walkerSourceInformation.getSourceInformation(spec); + PostDeploymentActionSourceCode code = new PostDeploymentActionSourceCode( + spec.actionBody().actionValue().getText(), + spec.actionType().getText(), + sourceInformation, + ParseTreeWalkerSourceInformation.offset(walkerSourceInformation, spec.getStart()) + ); + + PostDeploymentAction processor = IPostDeploymentActionGrammarParserExtension.process(code, parsers); + + if (processor == null) + { + throw new EngineException("Unsupported syntax", this.walkerSourceInformation.getSourceInformation(spec), EngineErrorType.PARSER); + } + return processor; + } + private List visitTaggedValues(HostedServiceParserGrammar.TaggedValuesContext ctx) { return ListIterate.collect(ctx.taggedValue(), taggedValueContext -> diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/to/HostedServiceGrammarComposer.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/to/HostedServiceGrammarComposer.java index aaf674c2003..4e8c52a9fb5 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/to/HostedServiceGrammarComposer.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-grammar/src/main/java/org/finos/legend/engine/language/hostedService/grammar/to/HostedServiceGrammarComposer.java @@ -38,6 +38,7 @@ import static org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer.buildSectionComposer; import static org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.convertString; import static org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.getTabString; +import static org.finos.legend.engine.language.functionActivator.grammar.postDeployment.to.PostDeploymentActionGrammarComposer.renderActions; public class HostedServiceGrammarComposer implements PureGrammarComposerExtension { @@ -88,6 +89,7 @@ private static String renderHostedService(HostedService app) " function : " + app.function.path + ";\n" + (app.documentation == null ? "" : " documentation : '" + app.documentation + "';\n") + " autoActivateUpdates : " + app.autoActivateUpdates + ";\n" + + (app.actions.isEmpty() ? "" : renderActions(app.actions) + "\n") + "}"; } diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-protocol/src/main/java/org/finos/legend/engine/protocol/hostedService/deployment/HostedServiceArtifact.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-protocol/src/main/java/org/finos/legend/engine/protocol/hostedService/deployment/HostedServiceArtifact.java index 3fdfa326d69..cb718c50e85 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-protocol/src/main/java/org/finos/legend/engine/protocol/hostedService/deployment/HostedServiceArtifact.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-protocol/src/main/java/org/finos/legend/engine/protocol/hostedService/deployment/HostedServiceArtifact.java @@ -15,9 +15,11 @@ package org.finos.legend.engine.protocol.hostedService.deployment; import org.finos.legend.engine.protocol.functionActivator.deployment.FunctionActivatorArtifact; +import org.finos.legend.engine.protocol.functionActivator.postDeployment.ActionContent; import org.finos.legend.engine.protocol.hostedService.deployment.model.GenerationInfo; import org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext; +import java.util.List; public class HostedServiceArtifact extends FunctionActivatorArtifact { @@ -33,11 +35,17 @@ public HostedServiceArtifact(String pattern, GenerationInfo info, String ownersh this.version = sdlc != null ? getVersionInfo(sdlc) : null; } - public HostedServiceArtifact(String pattern, GenerationInfo info, PureModelContext serviceData, String ownership,AlloySDLC sdlc) + public HostedServiceArtifact(String pattern, GenerationInfo info, PureModelContext serviceData, String ownership, AlloySDLC sdlc) { this.content = new HostedServiceContent(pattern, info, serviceData, ownership); this.version = sdlc != null ? getVersionInfo(sdlc) : null; } + public HostedServiceArtifact(String pattern, GenerationInfo info, PureModelContext serviceData, String ownership, List actions, AlloySDLC sdlc) + { + this.content = new HostedServiceContent(pattern, info, serviceData, ownership); + this.version = sdlc != null ? getVersionInfo(sdlc) : null; + this.actions = actions; + } } diff --git a/pom.xml b/pom.xml index 967cd781b8d..776a793ebf7 100644 --- a/pom.xml +++ b/pom.xml @@ -736,7 +736,16 @@ legend-engine-xt-functionActivator-generation ${project.version} - + + org.finos.legend.engine + legend-engine-xt-functionActivator-compiler + ${project.version} + + + org.finos.legend.engine + legend-engine-xt-functionActivator-grammar + ${project.version} + org.finos.legend.engine