Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for post deployment actions #3176

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
<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>
<version>${project.version}</version>
</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.62.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.PostDeploymentLoader;
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.PostDeploymentResult;
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<PostDeploymentResult> deployActions(Identity identity, U artifact)
{
List<PostDeploymentResult> actionResults = Lists.mutable.empty();
PostDeploymentLoader.extensions().forEach((ex) ->
{
actionResults.addAll(ex.processAction(identity, artifact));
});
return actionResults;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.engine.protocol.functionActivator.postDeployment.PostDeploymentContract;
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 PostDeploymentLoader
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to keep the naming consistent: This should be 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;
}
}
Loading