Skip to content

Commit

Permalink
remove import from generation extension (#2677)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Mar 8, 2024
1 parent 6a43b15 commit 851200d
Show file tree
Hide file tree
Showing 37 changed files with 1,290 additions and 644 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,6 @@
</dependency>
<!-- Avro -->

<!-- Roestta -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-rosetta</artifactId>
</dependency>
<!-- Roestta -->

<!-- GraphQL -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ protected Iterable<? extends Class<? extends GenerationExtension>> getExpectedGe
.with(org.finos.legend.engine.external.format.protobuf.deprecated.generation.ProtobufGenerationExtension.class)
.with(org.finos.legend.engine.external.format.avro.extension.AvroGenerationExtension.class)
.with(org.finos.legend.engine.external.format.jsonSchema.extension.JSONSchemaGenerationExtension.class)
.with(org.finos.legend.engine.external.format.rosetta.extension.RosettaGenerationExtension.class)
.with(org.finos.legend.engine.external.language.morphir.extension.MorphirGenerationExtension.class)
.with(org.finos.legend.engine.query.graphQL.api.format.generation.GraphQLGenerationExtension.class)
.with(org.finos.legend.engine.external.format.daml.generation.DAMLGenerationExtension.class);
Expand Down Expand Up @@ -492,7 +491,6 @@ protected Iterable<String> getExpectedCodeRepositories()
.with("core_diagram")
.with("core_diagram_metamodel")
.with("core_external_format_avro")
.with("core_external_format_rosetta")
.with("core_external_language_morphir")
.with("core_external_format_flatdata")
.with("core_external_format_json")
Expand Down
21 changes: 20 additions & 1 deletion legend-engine-config/legend-engine-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-graphQL-query</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-graphQL-api</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-graphQL-relational-extension</artifactId>
Expand Down Expand Up @@ -507,6 +511,10 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-external-shared-format-model</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-protobuf-api</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-protobuf</artifactId>
Expand All @@ -517,6 +525,10 @@
<artifactId>legend-engine-xt-avro</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-avro-api</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-external-format-jsonSchema</artifactId>
Expand Down Expand Up @@ -552,7 +564,10 @@
<artifactId>legend-engine-xt-arrow-pure</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-json-api</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-json-model</artifactId>
Expand All @@ -578,6 +593,10 @@
<artifactId>legend-engine-xt-morphir</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-daml-api</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-daml-model</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
import org.finos.legend.engine.external.shared.format.extension.GenerationMode;
import org.finos.legend.engine.external.shared.format.generations.loaders.CodeGenerators;
import org.finos.legend.engine.external.shared.format.generations.loaders.SchemaGenerators;
import org.finos.legend.engine.external.shared.format.imports.loaders.CodeImports;
import org.finos.legend.engine.external.shared.format.imports.loaders.SchemaImports;
import org.finos.legend.engine.external.shared.format.model.api.ExternalFormats;
import org.finos.legend.engine.functionActivator.api.FunctionActivatorAPI;
import org.finos.legend.engine.generation.artifact.api.ArtifactGenerationExtensionApi;
Expand Down Expand Up @@ -108,6 +106,11 @@
import org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory;
import org.finos.legend.engine.protocol.pure.v1.model.PureProtocol;
import org.finos.legend.engine.protocol.snowflakeApp.deployment.SnowflakeAppDeploymentConfiguration;
import org.finos.legend.engine.query.graphQL.api.format.generation.api.GraphQLGenerationService;
import org.finos.legend.engine.external.format.jsonSchema.schema.generations.api.JSONSchemaGenerationService;
import org.finos.legend.engine.external.format.daml.generation.api.DAMLGenerationService;
import org.finos.legend.engine.external.format.protobuf.deprecated.generation.api.ProtobufGenerationService;
import org.finos.legend.engine.external.format.avro.schema.generations.api.AvroGenerationService;
import org.finos.legend.engine.pure.code.core.PureCoreExtensionLoader;
import org.finos.legend.engine.query.graphQL.api.debug.GraphQLDebug;
import org.finos.legend.engine.query.graphQL.api.execute.GraphQLExecute;
Expand Down Expand Up @@ -350,10 +353,14 @@ public void run(T serverConfiguration, Environment environment)
// Generation and Import
MutableList<GenerationExtension> genExtensions = Iterate.addAllTo(ServiceLoader.load(GenerationExtension.class), Lists.mutable.empty());
environment.jersey().register(new CodeGenerators(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Code).collect(GenerationExtension::getGenerationDescription).select(Objects::nonNull)));
environment.jersey().register(new CodeImports(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Code).collect(GenerationExtension::getImportDescription).select(Objects::nonNull)));
environment.jersey().register(new SchemaGenerators(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Schema).collect(GenerationExtension::getGenerationDescription).select(Objects::nonNull)));
environment.jersey().register(new SchemaImports(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Schema).collect(GenerationExtension::getImportDescription).select(Objects::nonNull)));
genExtensions.forEach(p -> environment.jersey().register(p.getService(modelManager)));
// generator apis
environment.jersey().register(new GraphQLGenerationService(modelManager));
environment.jersey().register(new DAMLGenerationService(modelManager));
environment.jersey().register(new ProtobufGenerationService(modelManager));
environment.jersey().register(new GraphQLGenerationService(modelManager));
environment.jersey().register(new JSONSchemaGenerationService(modelManager));
environment.jersey().register(new AvroGenerationService(modelManager));

// Execution
MutableList<PlanGeneratorExtension> generatorExtensions = Lists.mutable.withAll(ServiceLoader.load(PlanGeneratorExtension.class));
Expand Down
100 changes: 100 additions & 0 deletions legend-engine-xts-avro/legend-engine-xt-avro-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<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-avro</artifactId>
<version>4.40.1-SNAPSHOT</version>
</parent>

<artifactId>legend-engine-xt-avro-api</artifactId>
<name>Legend Engine - XT - AVRO -API</name>

<dependencies>
<!-- ENGINE -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-avro</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-external-shared</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-dsl-generation-pure</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-avro-pure</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-language-pure-modelManager</artifactId>
</dependency>
<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>
<!-- ENGINE -->

<!-- ANNOTATIONS -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<!-- ANNOTATIONS -->

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

<!-- OPEN TRACING -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
</dependency>
<!-- OPEN TRACING -->

<!-- LOG -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- LOG -->

<!-- PAC4J -->
<dependency>
<groupId>org.pac4j.jax-rs</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-core</artifactId>
</dependency>
<!-- PAC4J -->
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2024 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.external.format.avro.schema.generations.api;

import io.opentracing.Scope;
import io.opentracing.util.GlobalTracer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.list.MutableList;
import org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationConfig;
import org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationInput;
import org.finos.legend.engine.external.shared.format.generations.GenerationOutput;
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.pure.v1.model.context.PureModelContextData;
import org.finos.legend.engine.shared.core.api.result.ManageConstantResult;
import org.finos.legend.engine.shared.core.identity.Identity;
import org.finos.legend.engine.shared.core.identity.factory.IdentityFactoryProvider;
import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper;
import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool;
import org.finos.legend.engine.shared.core.operational.logs.LogInfo;
import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType;
import org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationOutput;
import org.finos.legend.pure.generated.core_external_format_avro_transformation_transformation_avroSchemaGenerator;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.slf4j.Logger;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import static org.finos.legend.engine.shared.core.operational.http.InflateInterceptor.APPLICATION_ZLIB;

@Deprecated
@Api(tags = "Z - Deprecated - Generation - Schema")
@Path("pure/v1/schemaGeneration")
@Produces(MediaType.APPLICATION_JSON)
public class AvroGenerationService
{
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(AvroGenerationService.class);
private final ModelManager modelManager;

public AvroGenerationService(ModelManager modelManager)
{
this.modelManager = modelManager;
}

@Deprecated
@POST
@Path("avro")
@ApiOperation(value = "Generates Avro schema for a given class and transitive dependencies")
@Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB})
public Response generateAvro(AvroGenerationInput generateAvroInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager<CommonProfile> pm)
{
MutableList<CommonProfile> profiles = ProfileManagerHelper.extractProfiles(pm);
Identity identity = IdentityFactoryProvider.getInstance().makeIdentity(profiles);
boolean interactive = generateAvroInput.model instanceof PureModelContextData;
try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate Avro").startActive(true))
{
return exec(generateAvroInput.config != null ? generateAvroInput.config : new AvroGenerationConfig(),
() -> this.modelManager.loadModelAndData(generateAvroInput.model, generateAvroInput.clientVersion, identity, null).getTwo(),
interactive,
identity);
}
catch (Exception ex)
{
return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_AVRO_CODE_ERROR, identity.getName());
}
}

private Response exec(AvroGenerationConfig avroConfig, Function0<PureModel> pureModelFunc, boolean interactive, Identity identity)
{
try
{
long start = System.currentTimeMillis();
LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_START : LoggingEventType.GENERATE_AVRO_CODE_START).toString());
PureModel pureModel = pureModelFunc.value();
RichIterable<? extends Root_meta_pure_generation_metamodel_GenerationOutput> output = core_external_format_avro_transformation_transformation_avroSchemaGenerator.Root_meta_external_format_avro_generation_generateAvroFromPureWithScope_AvroConfig_1__AvroOutput_MANY_(avroConfig.process(pureModel), pureModel.getExecutionSupport());
LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_STOP : LoggingEventType.GENERATE_AVRO_CODE_STOP, (double) System.currentTimeMillis() - start).toString());
return ManageConstantResult.manageResult(identity.getName(), output.collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList());
}
catch (Exception ex)
{
return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_AVRO_CODE_ERROR, identity.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.list.MutableList;
import org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationConfig;
import org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationService;
import org.finos.legend.engine.external.shared.format.extension.GenerationExtension;
import org.finos.legend.engine.external.shared.format.extension.GenerationMode;
import org.finos.legend.engine.external.shared.format.generations.description.FileGenerationDescription;
import org.finos.legend.engine.external.shared.format.generations.description.GenerationConfigurationDescription;
import org.finos.legend.engine.external.shared.format.generations.description.GenerationProperty;
import org.finos.legend.engine.external.shared.format.imports.description.ImportConfigurationDescription;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext;
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.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.fileGeneration.FileGenerationSpecification;
import org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationConfiguration;
Expand Down Expand Up @@ -88,18 +85,6 @@ public List<GenerationProperty> getProperties(PureModel pureModel)
};
}

@Override
public ImportConfigurationDescription getImportDescription()
{
return null;
}

@Override
public Object getService(ModelManager modelManager)
{
return new AvroGenerationService(modelManager);
}

@Override
public List<Root_meta_pure_generation_metamodel_GenerationOutput> generateFromElement(PackageableElement element, CompileContext compileContext)
{
Expand Down
1 change: 1 addition & 0 deletions legend-engine-xts-avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<modules>
<module>legend-engine-xt-avro</module>
<module>legend-engine-xt-avro-pure</module>
<module>legend-engine-xt-avro-api</module>
</modules>
</project>
Loading

0 comments on commit 851200d

Please sign in to comment.