Skip to content

Commit

Permalink
Update post deployment actions contract (#3263)
Browse files Browse the repository at this point in the history
  • Loading branch information
janeenyamak1 authored Nov 22, 2024
1 parent 986c748 commit 8b42d05
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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<ActionContent> generateActions(Root_meta_external_function_activator_FunctionActivator activator, PureModel pureModel)
{
List<ActionContent> actionResults = Lists.mutable.empty();
PostDeploymentActionLoader.generationExtensions().forEach((ex) ->
{
actionResults.addAll(ex.generate(activator, pureModel));
});
return actionResults;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActionContent> generate(RichIterable<? extends Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction> actions);

List<PostDeploymentActionResult> processAction(Identity identity, FunctionActivatorArtifact artifact);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,31 @@

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<MutableList<PostDeploymentContract>> INSTANCE = new AtomicReference<>();
private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(PostDeploymentActionLoader.class);
private static final AtomicReference<MutableList<PostDeploymentActionDeploymentContract>> INSTANCE = new AtomicReference<>();
private static final AtomicReference<MutableList<PostDeploymentGeneration>> GENERATION_INSTANCE = new AtomicReference<>();

public static MutableList<PostDeploymentContract> extensions()
public static MutableList<PostDeploymentActionDeploymentContract> extensions()
{
return INSTANCE.updateAndGet(existing ->
{
if (existing == null)
{
MutableList<PostDeploymentContract> extensions = Lists.mutable.empty();
for (PostDeploymentContract extension : ServiceLoader.load(PostDeploymentContract.class))
MutableList<PostDeploymentActionDeploymentContract> extensions = Lists.mutable.empty();
for (PostDeploymentActionDeploymentContract extension : ServiceLoader.load(PostDeploymentActionDeploymentContract.class))
{
try
{
extensions.add(extension);
}
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;
Expand All @@ -52,14 +49,27 @@ public static MutableList<PostDeploymentContract> extensions()
});
}

public static List<ActionContent> generateActions(Root_meta_external_function_activator_FunctionActivator activator)
public static MutableList<PostDeploymentGeneration> generationExtensions()
{
List<ActionContent> actionsContent = Lists.mutable.empty();
extensions().forEach(e ->
return GENERATION_INSTANCE.updateAndGet(existing ->
{
actionsContent.addAll(e.generate(activator._actions()));
if (existing == null)
{
MutableList<PostDeploymentGeneration> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ActionContent> generate(Root_meta_external_function_activator_FunctionActivator activator, PureModel pureModel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,4 +32,6 @@ public interface FunctionActivatorValidator<T extends Root_meta_external_functio
List<FunctionActivatorError> validate(Identity identity, T activator);

List<FunctionActivatorError> validate(Identity identity, V artifact);

List<FunctionActivatorError> validate(T activator, PureModel pureModel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public MutableList<? extends FunctionActivatorError> 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;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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<PureModel, RichIterable<? extends Root_meta_pure_extension_Extension>> routerExtensions)
Expand Down Expand Up @@ -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<ActionContent> renderActions(Root_meta_external_function_activator_FunctionActivator activator)
{
return PostDeploymentActionLoader.generateActions(activator);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +80,7 @@ public List<Artifact> generate(PackageableElement element, PureModel pureModel,
Function<PureModel, RichIterable<? extends Root_meta_pure_extension_Extension>> 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());

}
Expand Down

0 comments on commit 8b42d05

Please sign in to comment.