Skip to content

Commit

Permalink
Function activation cleanups (#2350)
Browse files Browse the repository at this point in the history
* Uplift Service Ownership

* Add preEval of SchemaState type

* change deployment interface

* change deployment interfaces

* minor fixes

* Function activator phase II

* cleanup path

* Function Activator uplift

* Update userTestConfig.json
  • Loading branch information
Yasirmod17 authored Oct 10, 2023
1 parent 9e9d3f4 commit 3fbd852
Show file tree
Hide file tree
Showing 40 changed files with 512 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void run(T serverConfiguration, Environment environment)
environment.jersey().register(new ExecutePlanLegacy(planExecutor));

// Function Activator
environment.jersey().register(new FunctionActivatorAPI(modelManager, serverConfiguration.activatorConfiguration, routerExtensions));
environment.jersey().register(new FunctionActivatorAPI(modelManager, Lists.mutable.empty(), routerExtensions));

// GraphQL
environment.jersey().register(new GraphQLGrammar());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,5 @@
},
"errorhandlingconfiguration": {
"enabled": true
},
"activatorConfiguration":[
{"_type":"hostedServiceConfig", "host": "127.0.0.1",
"port":9090,
"path": "/api/service/v1/registerHostedService",
"stage": "SANDBOX"
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import org.eclipse.collections.api.list.MutableList;
import org.finos.legend.engine.functionActivator.api.input.FunctionActivatorInput;
import org.finos.legend.engine.functionActivator.api.output.FunctionActivatorInfo;
import org.finos.legend.engine.functionActivator.deployment.FunctionActivatorDeploymentConfiguration;
import org.finos.legend.engine.functionActivator.service.FunctionActivatorLoader;
import org.finos.legend.engine.functionActivator.service.FunctionActivatorService;
import org.finos.legend.engine.language.pure.compiler.Compiler;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
import org.finos.legend.engine.language.pure.modelManager.ModelManager;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentConfiguration;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentResult;
//import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentConfiguration;
import org.finos.legend.engine.functionActivator.deployment.DeploymentResult;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentStage;
import org.finos.legend.engine.protocol.pure.PureClientVersions;
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class FunctionActivatorAPI
private final ModelManager modelManager;
private final PureModel emptyModel;
private final Function<PureModel, RichIterable<? extends Root_meta_pure_extension_Extension>> routerExtensions;
private List<DeploymentConfiguration> runtimeDeploymentConfig = Lists.mutable.empty();
private List<FunctionActivatorDeploymentConfiguration> runtimeDeploymentConfig = Lists.mutable.empty();

public FunctionActivatorAPI(ModelManager modelManager, Function<PureModel, RichIterable<? extends Root_meta_pure_extension_Extension>> routerExtensions)
{
Expand All @@ -72,7 +73,7 @@ public FunctionActivatorAPI(ModelManager modelManager, Function<PureModel, RichI
this.emptyModel = Compiler.compile(PureModelContextData.newPureModelContextData(), DeploymentMode.PROD, null);
}

public FunctionActivatorAPI(ModelManager modelManager, List<DeploymentConfiguration> activatorConfigurations, Function<PureModel, RichIterable<? extends Root_meta_pure_extension_Extension>> routerExtensions)
public FunctionActivatorAPI(ModelManager modelManager, List<FunctionActivatorDeploymentConfiguration> activatorConfigurations, Function<PureModel, RichIterable<? extends Root_meta_pure_extension_Extension>> routerExtensions)
{
this(modelManager, routerExtensions);
this.runtimeDeploymentConfig = activatorConfigurations;
Expand Down Expand Up @@ -103,7 +104,7 @@ public Response validate(FunctionActivatorInput input, @ApiParam(hidden = true)
String clientVersion = input.clientVersion == null ? PureClientVersions.production : input.clientVersion;
PureModel pureModel = modelManager.loadModel(input.model, clientVersion, profiles, null);
Root_meta_external_function_activator_FunctionActivator activator = (Root_meta_external_function_activator_FunctionActivator) pureModel.getPackageableElement(input.functionActivator);
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, DeploymentConfiguration, DeploymentResult> service = getActivatorService(activator, pureModel);
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, FunctionActivatorDeploymentConfiguration, DeploymentResult> service = getActivatorService(activator, pureModel);
return Response.ok(objectMapper.writeValueAsString(service.validate(profiles, pureModel, activator, input.model, routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build();
}
catch (Exception ex)
Expand All @@ -126,8 +127,8 @@ public Response publishToSandbox(FunctionActivatorInput input, @ApiParam(hidden
String clientVersion = input.clientVersion == null ? PureClientVersions.production : input.clientVersion;
PureModel pureModel = modelManager.loadModel(input.model, clientVersion, profiles, null);
Root_meta_external_function_activator_FunctionActivator activator = (Root_meta_external_function_activator_FunctionActivator) pureModel.getPackageableElement(input.functionActivator);
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, DeploymentConfiguration, DeploymentResult> service = getActivatorService(activator,pureModel);
return Response.ok(objectMapper.writeValueAsString(service.publishToSandbox(profiles, pureModel, activator, input.model, service.selectConfig(this.runtimeDeploymentConfig, DeploymentStage.SANDBOX), routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build();
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, FunctionActivatorDeploymentConfiguration, DeploymentResult> service = getActivatorService(activator,pureModel);
return Response.ok(objectMapper.writeValueAsString(service.publishToSandbox(profiles, pureModel, activator, input.model, service.selectConfig(this.runtimeDeploymentConfig), routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build();
}
catch (Exception ex)
{
Expand All @@ -149,7 +150,7 @@ public Response renderArtifact(FunctionActivatorInput input, @ApiParam(hidden =
String clientVersion = input.clientVersion == null ? PureClientVersions.production : input.clientVersion;
PureModel pureModel = modelManager.loadModel(input.model, clientVersion, profiles, null);
Root_meta_external_function_activator_FunctionActivator activator = (Root_meta_external_function_activator_FunctionActivator) pureModel.getPackageableElement(input.functionActivator);
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, DeploymentConfiguration, DeploymentResult> service = getActivatorService(activator, pureModel);
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, FunctionActivatorDeploymentConfiguration, DeploymentResult> service = getActivatorService(activator, pureModel);
return Response.ok(objectMapper.writeValueAsString(service.renderArtifact(pureModel, activator, input.model, clientVersion,routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build();
}
catch (Exception ex)
Expand All @@ -159,9 +160,9 @@ public Response renderArtifact(FunctionActivatorInput input, @ApiParam(hidden =
}
}

public FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, DeploymentConfiguration, DeploymentResult> getActivatorService(Root_meta_external_function_activator_FunctionActivator activator, PureModel pureModel)
public FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, FunctionActivatorDeploymentConfiguration, DeploymentResult> getActivatorService(Root_meta_external_function_activator_FunctionActivator activator, PureModel pureModel)
{
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, DeploymentConfiguration, DeploymentResult> service = FunctionActivatorLoader.extensions().select(c -> c.supports(activator)).getFirst();
FunctionActivatorService<Root_meta_external_function_activator_FunctionActivator, FunctionActivatorDeploymentConfiguration, DeploymentResult> service = FunctionActivatorLoader.extensions().select(c -> c.supports(activator)).getFirst();
if (service == null)
{
throw new RuntimeException(activator.getClass().getSimpleName() + "is not supported!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@
package org.finos.legend.engine.functionActivator.deployment;

import org.eclipse.collections.api.list.MutableList;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentConfiguration;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentResult;
import org.finos.legend.pure.generated.Root_meta_external_function_activator_FunctionActivator;
import org.pac4j.core.profile.CommonProfile;

import java.util.List;

public interface DeploymentManager<T extends Root_meta_external_function_activator_FunctionActivator, U extends FunctionActivatorArtifact, V extends DeploymentResult, W extends DeploymentConfiguration>
public interface DeploymentManager<U extends FunctionActivatorArtifact, V extends DeploymentResult, W extends FunctionActivatorDeploymentConfiguration>
{

public V deploy(MutableList<CommonProfile> profiles, U artifact, T activator);
public V deploy(MutableList<CommonProfile> profiles, U artifact);

public V deploy(MutableList<CommonProfile> profiles, U artifact, T activator, List<W> availableRuntimeConfigurations);
public V deploy(MutableList<CommonProfile> profiles, U artifact, List<W> availableRuntimeConfigurations);


public boolean canDeploy(T activator);
public boolean canDeploy(FunctionActivatorArtifact activatorArtifact);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.protocol.functionActivator.metamodel;
package org.finos.legend.engine.functionActivator.deployment;

public class DeploymentResult
{
public String activatorIdentifier;
public boolean successful;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

public class FunctionActivatorArtifact
{
public FunctionActivatorDeploymentContent content;
public FunctionActivatorDeploymentConfiguration deploymentConfiguration;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.deployment;

public class FunctionActivatorDeploymentConfiguration
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.deployment;

public class FunctionActivatorDeploymentContent
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
import org.eclipse.collections.api.list.MutableList;
import org.finos.legend.engine.functionActivator.api.output.FunctionActivatorInfo;
import org.finos.legend.engine.functionActivator.deployment.FunctionActivatorArtifact;
import org.finos.legend.engine.functionActivator.deployment.FunctionActivatorDeploymentConfiguration;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentStage;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentConfiguration;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentResult;
import org.finos.legend.engine.functionActivator.deployment.DeploymentResult;
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext;
import org.finos.legend.pure.generated.Root_meta_external_function_activator_FunctionActivator;
import org.finos.legend.pure.generated.Root_meta_pure_extension_Extension;
import org.pac4j.core.profile.CommonProfile;

import java.util.List;

public interface FunctionActivatorService<T extends Root_meta_external_function_activator_FunctionActivator, U extends DeploymentConfiguration, V extends DeploymentResult>
public interface FunctionActivatorService<T extends Root_meta_external_function_activator_FunctionActivator, U extends FunctionActivatorDeploymentConfiguration, V extends DeploymentResult>
{
FunctionActivatorInfo info(PureModel pureModel, String version);

Expand All @@ -42,5 +43,5 @@ public interface FunctionActivatorService<T extends Root_meta_external_function_

FunctionActivatorArtifact renderArtifact(PureModel pureModel, T functionActivator, PureModelContext inputModel, String clientVersion, Function<PureModel, RichIterable<? extends Root_meta_pure_extension_Extension>> routerExtensions);

List<U> selectConfig(List<DeploymentConfiguration> configurations, DeploymentStage state);
List<U> selectConfig(List<FunctionActivatorDeploymentConfiguration> configurations);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type")
public class DeploymentConfiguration extends PackageableElement
{
public DeploymentStage stage;
//public DeploymentStage stage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Class meta::external::function::activator::FunctionActivator extends Packageable

Class meta::external::function::activator::DeploymentConfiguration extends PackageableElement
{
stage: DeploymentStage[1];
}

Class meta::external::function::activator::DeploymentResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-api</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-hostedService-pure</artifactId>
Expand All @@ -94,20 +90,20 @@
<!-- ENGINE -->

<!-- Tracing HTTP implementation + SPNEGO Calls -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.httpcomponents</groupId>-->
<!-- <artifactId>httpclient</artifactId>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>commons-codec</groupId>-->
<!-- <artifactId>commons-codec</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.httpcomponents</groupId>-->
<!-- <artifactId>httpcore</artifactId>-->
<!-- </dependency>-->
<!-- PURE -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.factory.Lists;
import org.finos.legend.engine.functionActivator.api.output.FunctionActivatorInfo;
import org.finos.legend.engine.functionActivator.deployment.FunctionActivatorDeploymentConfiguration;
import org.finos.legend.engine.language.hostedService.deployment.HostedServiceArtifact;
import org.finos.legend.engine.language.hostedService.deployment.HostedServiceDeploymentConfiguration;
import org.finos.legend.engine.language.hostedService.generation.model.GenerationInfoData;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentStage;
import org.finos.legend.engine.functionActivator.service.FunctionActivatorError;
import org.finos.legend.engine.functionActivator.service.FunctionActivatorService;
import org.finos.legend.engine.language.hostedService.deployment.HostedServiceDeploymentManager;
import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentConfiguration;
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.HostedServiceDeploymentResult;
//import org.finos.legend.engine.protocol.hostedService.metamodel.HostedServiceDeploymentConfiguration;
import org.finos.legend.engine.language.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.metamodel.HostedServiceProtocolExtension;
Expand Down Expand Up @@ -95,9 +97,9 @@ public HostedServiceArtifact renderArtifact(PureModel pureModel, Root_meta_exter
}

@Override
public List<HostedServiceDeploymentConfiguration> selectConfig(List<DeploymentConfiguration> configurations, DeploymentStage stage)
public List<HostedServiceDeploymentConfiguration> selectConfig(List<FunctionActivatorDeploymentConfiguration> configurations)
{
return Lists.mutable.withAll(configurations).select(e -> e instanceof HostedServiceDeploymentConfiguration && e.stage.equals(stage)).collect(e -> (HostedServiceDeploymentConfiguration)e);
return Lists.mutable.withAll(configurations).select(e -> e instanceof HostedServiceDeploymentConfiguration).collect(e -> (HostedServiceDeploymentConfiguration)e);
}


Expand All @@ -106,7 +108,7 @@ public HostedServiceDeploymentResult publishToSandbox(MutableList<CommonProfile>
{
GenerationInfoData generation = this.hostedServiceArtifactgenerator.renderArtifact(pureModel, activator, inputModel, "vX_X_X",routerExtensions);
HostedServiceArtifact artifact = new HostedServiceArtifact(generation, fetchHostedService(activator, (PureModelContextData)inputModel, pureModel));
return this.hostedServiceDeploymentManager.deploy(profiles, artifact, activator, runtimeConfigs);
return this.hostedServiceDeploymentManager.deploy(profiles, artifact, runtimeConfigs);
// return new HostedServiceDeploymentResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

public class HostedServiceArtifact extends FunctionActivatorArtifact
{
public GenerationInfo info;
public PureModelContextData serviceData;

public HostedServiceArtifact()
{
Expand All @@ -30,13 +28,12 @@ public HostedServiceArtifact()

public HostedServiceArtifact(GenerationInfo info)
{
this.info = info;
this.content = new HostedServiceContent(info);
}

public HostedServiceArtifact(GenerationInfo info, PureModelContextData serviceData)
{
this(info);
this.serviceData = serviceData;
this.content = new HostedServiceContent(info, serviceData);
}


Expand Down
Loading

0 comments on commit 3fbd852

Please sign in to comment.