From 8b42d05b77fae998184b6bb5a17ec5ac6624b23a Mon Sep 17 00:00:00 2001 From: Janeen Yamak <88203072+janeenyamak1@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:12:06 -0600 Subject: [PATCH] Update post deployment actions contract (#3263) --- .../FunctionActivatorGenerator.java | 36 ++++++++++++++++ ...stDeploymentActionDeploymentContract.java} | 8 +--- .../PostDeploymentActionLoader.java | 42 ++++++++++++------- .../PostDeploymentGeneration.java | 26 ++++++++++++ .../FunctionActivatorValidator.java | 3 ++ .../api/HostedServiceService.java | 6 ++- .../HostedServiceArtifactGenerator.java | 12 +----- ...tedServiceArtifactGenerationExtension.java | 4 +- 8 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorGenerator.java rename legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/{PostDeploymentContract.java => PostDeploymentActionDeploymentContract.java} (65%) create mode 100644 legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentGeneration.java diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorGenerator.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorGenerator.java new file mode 100644 index 00000000000..4b6d0e46f64 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorGenerator.java @@ -0,0 +1,36 @@ +// 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.generation; + +import org.eclipse.collections.api.factory.Lists; +import org.finos.legend.engine.functionActivator.postDeployment.PostDeploymentActionLoader; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +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; + +public abstract class FunctionActivatorGenerator +{ + public static List generateActions(Root_meta_external_function_activator_FunctionActivator activator, PureModel pureModel) + { + List actionResults = Lists.mutable.empty(); + PostDeploymentActionLoader.generationExtensions().forEach((ex) -> + { + actionResults.addAll(ex.generate(activator, pureModel)); + }); + return actionResults; + } +} 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/PostDeploymentActionDeploymentContract.java similarity index 65% rename from legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentContract.java rename to legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentActionDeploymentContract.java index 4d2fb95d012..080cfd48257 100644 --- 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/PostDeploymentActionDeploymentContract.java @@ -14,19 +14,13 @@ 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 +public interface PostDeploymentActionDeploymentContract { - 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-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 index c697a64fcdf..d3690cbda1c 100644 --- 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 @@ -16,26 +16,23 @@ 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<>(); + private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(PostDeploymentActionLoader.class); + private static final AtomicReference> INSTANCE = new AtomicReference<>(); + private static final AtomicReference> GENERATION_INSTANCE = new AtomicReference<>(); - public static MutableList extensions() + public static MutableList extensions() { return INSTANCE.updateAndGet(existing -> { if (existing == null) { - MutableList extensions = Lists.mutable.empty(); - for (PostDeploymentContract extension : ServiceLoader.load(PostDeploymentContract.class)) + MutableList extensions = Lists.mutable.empty(); + for (PostDeploymentActionDeploymentContract extension : ServiceLoader.load(PostDeploymentActionDeploymentContract.class)) { try { @@ -43,7 +40,7 @@ public static MutableList extensions() } catch (Throwable throwable) { - LOGGER.error("Failed to load execution extension '" + extension.getClass().getSimpleName() + "'"); + LOGGER.error("Failed to load deployment execution extension '" + extension.getClass().getSimpleName() + "'"); } } return extensions; @@ -52,14 +49,27 @@ public static MutableList extensions() }); } - public static List generateActions(Root_meta_external_function_activator_FunctionActivator activator) + public static MutableList generationExtensions() { - List actionsContent = Lists.mutable.empty(); - extensions().forEach(e -> + return GENERATION_INSTANCE.updateAndGet(existing -> { - actionsContent.addAll(e.generate(activator._actions())); + if (existing == null) + { + MutableList generationExtensions = Lists.mutable.empty(); + for (PostDeploymentGeneration extension : ServiceLoader.load(PostDeploymentGeneration.class)) + { + try + { + generationExtensions.add(extension); + } + catch (Throwable throwable) + { + LOGGER.error("Failed to load generation extension '" + extension.getClass().getSimpleName() + "'"); + } + } + return generationExtensions; + } + return existing; }); - - return actionsContent; } } diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentGeneration.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentGeneration.java new file mode 100644 index 00000000000..2b5fdc8d566 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/postDeployment/PostDeploymentGeneration.java @@ -0,0 +1,26 @@ +// 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.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +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; + +public interface PostDeploymentGeneration +{ + List generate(Root_meta_external_function_activator_FunctionActivator activator, PureModel pureModel); +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-http-api/src/main/java/org/finos/legend/engine/functionActivator/validation/FunctionActivatorValidator.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-http-api/src/main/java/org/finos/legend/engine/functionActivator/validation/FunctionActivatorValidator.java index 46f8ae95ef4..952273b4179 100644 --- a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-http-api/src/main/java/org/finos/legend/engine/functionActivator/validation/FunctionActivatorValidator.java +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-http-api/src/main/java/org/finos/legend/engine/functionActivator/validation/FunctionActivatorValidator.java @@ -16,6 +16,7 @@ package org.finos.legend.engine.functionActivator.validation; import org.finos.legend.engine.functionActivator.service.FunctionActivatorError; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; import org.finos.legend.engine.protocol.functionActivator.deployment.FunctionActivatorArtifact; import org.finos.legend.engine.shared.core.identity.Identity; import org.finos.legend.pure.generated.Root_meta_external_function_activator_FunctionActivator; @@ -31,4 +32,6 @@ public interface FunctionActivatorValidator validate(Identity identity, T activator); List validate(Identity identity, V artifact); + + List validate(T activator, PureModel pureModel); } 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 4de4ffd2de5..d59170f9bcc 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 @@ -93,7 +93,11 @@ public MutableList validate(Identity identity, { errors.add(new HostedServiceError("HostedService can't be registered.", e)); } - this.extraValidators.select(v -> v.supports(activator)).forEach(v -> errors.addAll(v.validate(identity, activator))); + this.extraValidators.select(v -> v.supports(activator)).forEach(v -> + { + errors.addAll(v.validate(identity, activator)); + errors.addAll(v.validate(activator, pureModel)); + }); return errors; } 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 41f3df42a9f..348dbda1afa 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,10 +20,9 @@ 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.functionActivator.generation.FunctionActivatorGenerator; 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; @@ -38,7 +37,6 @@ 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; @@ -47,7 +45,6 @@ import org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException; import org.slf4j.Logger; -import java.util.List; import java.util.Map; import java.util.ServiceLoader; @@ -69,7 +66,7 @@ public static HostedServiceArtifact renderServiceArtifact(PureModel pureModel, R { 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); + return new HostedServiceArtifact(activator._pattern(), new GenerationInfoData(plan, lineage), HostedServiceArtifactGenerator.fetchHostedService(activator, (PureModelContextData)inputModel, pureModel), ((Root_meta_external_function_activator_DeploymentOwnership) activator._ownership())._id(), FunctionActivatorGenerator.generateActions(activator, pureModel), ((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) @@ -133,9 +130,4 @@ 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 f191ebb96c9..2072bf4609b 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,7 +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.functionActivator.generation.FunctionActivatorGenerator; 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; @@ -80,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(), PostDeploymentActionLoader.generateActions(activator), (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(), FunctionActivatorGenerator.generateActions(activator, pureModel), (AlloySDLC) data.origin.sdlcInfo)), FILE_NAME, "json")); LOGGER.info("Generated artifacts for " + element.getName()); }