Skip to content

Commit

Permalink
support post deployment actions - update (#3193)
Browse files Browse the repository at this point in the history
* support post deployment actions - update

* update hosted service grammar
  • Loading branch information
janeenyamak1 authored Oct 22, 2024
1 parent 88f4288 commit d91790f
Show file tree
Hide file tree
Showing 39 changed files with 864 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-identity-core</artifactId>
</dependency>

<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-grammar</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-executionPlan-generation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -378,6 +379,7 @@ protected Iterable<? extends Class<? extends PureGrammarComposerExtension>> getE
.with(DataSpaceGrammarComposerExtension.class)
.with(SnowflakeAppGrammarComposer.class)
.with(HostedServiceGrammarComposer.class)
.with(PostDeploymentActionGrammarComposer.class)
.with(BigQueryFunctionGrammarComposer.class)
.with(MemSqlFunctionGrammarComposer.class)
.with(DiagramGrammarComposerExtension.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2020 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xts-functionActivator</artifactId>
<version>4.63.1-SNAPSHOT</version>
</parent>

<artifactId>legend-engine-xt-functionActivator-compiler</artifactId>
<packaging>jar</packaging>
<name>Legend Engine - XT - Function Activator - Compiler</name>


<dependencies>
<!--ENGINE-->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-compiler</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-shared-core</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-protocol-pure</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-pure</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-protocol</artifactId>
</dependency>
<!--ENGINE-->

<!--ECLIPSE-->
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-api</artifactId>
</dependency>
<!--ECLIPSE-->
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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<Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction> resolveDeploymentAction(List<PostDeploymentAction> actions, CompileContext context)
{
List<IPostDeploymentCompilerExtension> extensions = IPostDeploymentCompilerExtension.getExtensions();
return ListIterate.collect(actions, action -> IPostDeploymentCompilerExtension.process(
action,
ListIterate.flatCollect(extensions, IPostDeploymentCompilerExtension::getExtraPostDeploymentActionProcessors),
context));
}
}
Original file line number Diff line number Diff line change
@@ -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<IPostDeploymentCompilerExtension> getExtensions()
{
return Lists.mutable.withAll(ServiceLoader.load(IPostDeploymentCompilerExtension.class));
}

static Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction process(PostDeploymentAction postDeploymentAction, List<Function2<PostDeploymentAction, CompileContext, Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction>> processors, CompileContext context)
{
return process(postDeploymentAction, processors, context, "Post Deployment Compiler Extension");
}

static <T, U> U process(T item, List<Function2<T, CompileContext, U>> 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<Function2<PostDeploymentAction, CompileContext, Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction>> getExtraPostDeploymentActionProcessors()
{
return FastList.newList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,23 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-identity-core</artifactId>
</dependency>

<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-protocol</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-generation</artifactId>
</dependency>
<!-- ENGINE -->

<!-- ECLIPSE -->
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-api</artifactId>
</dependency>
<!-- ECLIPSE -->

<!-- TEST -->
<dependency>
<groupId>junit</groupId>
Expand All @@ -48,11 +62,6 @@
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-protocol</artifactId>
</dependency>

<!-- TEST -->
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,4 +34,14 @@ public interface DeploymentManager<U extends FunctionActivatorArtifact, V extend
public V deploy(Identity identity, U artifact, List<W> availableRuntimeConfigurations);

public boolean canDeploy(FunctionActivatorArtifact activatorArtifact);

public default List<PostDeploymentActionResult> deployActions(Identity identity, U artifact)
{
List<PostDeploymentActionResult> actionResults = Lists.mutable.empty();
PostDeploymentActionLoader.extensions().forEach((ex) ->
{
actionResults.addAll(ex.processAction(identity, artifact));
});
return actionResults;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-compiler</artifactId>
</dependency>

<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-pure</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-identity-core</artifactId>
</dependency>

<!-- ENGINE -->

Expand Down
Original file line number Diff line number Diff line change
@@ -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<MutableList<PostDeploymentContract>> INSTANCE = new AtomicReference<>();

public static MutableList<PostDeploymentContract> extensions()
{
return INSTANCE.updateAndGet(existing ->
{
if (existing == null)
{
MutableList<PostDeploymentContract> 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<ActionContent> generateActions(Root_meta_external_function_activator_FunctionActivator activator)
{
List<ActionContent> actionsContent = Lists.mutable.empty();
extensions().forEach(e ->
{
actionsContent.addAll(e.generate(activator._actions()));
});

return actionsContent;
}
}
Original file line number Diff line number Diff line change
@@ -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<ActionContent> generate(RichIterable<? extends Root_meta_external_function_activator_postDeploymentAction_PostDeploymentAction> actions);

List<PostDeploymentActionResult> processAction(Identity identity, FunctionActivatorArtifact artifact);
}
Loading

0 comments on commit d91790f

Please sign in to comment.