Search in sources :

Example 1 with PureModelContext

use of org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext in project legend-engine by finos.

the class Compile method lambdaReturnType.

@POST
@Path("lambdaReturnType")
@ApiOperation(value = "Loads a given model and lambda. Returns the lambda return type")
@Consumes({ MediaType.APPLICATION_JSON, APPLICATION_ZLIB })
@Prometheus(name = "lambda return type")
public Response lambdaReturnType(LambdaReturnTypeInput lambdaReturnTypeInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager<CommonProfile> pm, @Context UriInfo uriInfo) {
    MutableList<CommonProfile> profiles = ProfileManagerHelper.extractProfiles(pm);
    long start = System.currentTimeMillis();
    try {
        PureModelContext model = lambdaReturnTypeInput.model;
        Lambda lambda = lambdaReturnTypeInput.lambda;
        String typeName = modelManager.getLambdaReturnType(lambda, model, model instanceof PureModelContextPointer ? ((PureModelContextPointer) model).serializer.version : null, profiles);
        Map<String, String> result = new HashMap<>();
        long end = System.currentTimeMillis();
        MetricsHandler.observe("lambda return type", start, end);
        MetricsHandler.observeRequest(uriInfo != null ? uriInfo.getPath() : null, start, end);
        // This is an object in case we want to add more information on the lambda.
        result.put("returnType", typeName);
        return Response.ok(result, MediaType.APPLICATION_JSON_TYPE).build();
    } catch (Exception ex) {
        MetricsHandler.observeError("lambda return type");
        return handleException(uriInfo, profiles, start, ex);
    }
}
Also used : PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) CommonProfile(org.pac4j.core.profile.CommonProfile) HashMap(java.util.HashMap) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus)

Example 2 with PureModelContext

use of org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext in project legend-engine by finos.

the class Compile method compile.

@POST
@Path("compile")
@ApiOperation(value = "Loads the model and then compiles. It performs no action. Mostly used for testing")
@Consumes({ MediaType.APPLICATION_JSON, APPLICATION_ZLIB })
@Prometheus(name = "compile model", doc = "Pure model compilation duration summary")
public Response compile(PureModelContext model, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager<CommonProfile> pm, @Context UriInfo uriInfo) {
    MutableList<CommonProfile> profiles = ProfileManagerHelper.extractProfiles(pm);
    long start = System.currentTimeMillis();
    try (Scope scope = GlobalTracer.get().buildSpan("Service: compile").startActive(true)) {
        CompilerExtensions.logAvailableExtensions();
        Pair<PureModelContextData, PureModel> res = modelManager.loadModelAndData(model, model instanceof PureModelContextPointer ? ((PureModelContextPointer) model).serializer.version : null, profiles, null);
        long end = System.currentTimeMillis();
        MetricsHandler.observe("compile model", start, end);
        MetricsHandler.observeRequest(uriInfo != null ? uriInfo.getPath() : null, start, end);
        // on the another hand, returning 200 Ok with no content is not appropriate. So we have to put this dummy message "OK"
        return Response.ok(new CompileResult("OK", res.getTwo().getWarnings()), MediaType.APPLICATION_JSON_TYPE).build();
    } catch (Exception ex) {
        MetricsHandler.observeError("compile model");
        return handleException(uriInfo, profiles, start, ex);
    }
}
Also used : PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) Scope(io.opentracing.Scope) CommonProfile(org.pac4j.core.profile.CommonProfile) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus)

Example 3 with PureModelContext

use of org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext in project legend-engine by finos.

the class SDLCLoader method cacheKey.

@Override
public PureModelContext cacheKey(PureModelContext context, MutableList<CommonProfile> pm) {
    if (isCacheablePureSDLC(((PureModelContextPointer) context).sdlcInfo)) {
        final Subject executionSubject = getSubject();
        Function0<PureModelContext> pureModelContextFunction = () -> this.pureLoader.getCacheKey(context, pm, executionSubject);
        return executionSubject == null ? pureModelContextFunction.value() : exec(executionSubject, pureModelContextFunction::value);
    } else {
        return this.alloyLoader.getCacheKey(context);
    }
}
Also used : PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) Subject(javax.security.auth.Subject)

Example 4 with PureModelContext

use of org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext in project legend-engine by finos.

the class SDLCLoader method load.

@Override
public PureModelContextData load(MutableList<CommonProfile> pm, PureModelContext ctx, String clientVersion, Span parentSpan) {
    PureModelContextPointer context = (PureModelContextPointer) ctx;
    Assert.assertTrue(clientVersion != null, () -> "Client version should be set when pulling metadata from the metadata repository");
    Function0<PureModelContextData> fetchMetadata;
    final Subject subject = getSubject();
    if (context.sdlcInfo instanceof PureSDLC) {
        fetchMetadata = () -> {
            parentSpan.setTag("sdlc", "pure");
            try (Scope scope = GlobalTracer.get().buildSpan("Request Pure Metadata").startActive(true)) {
                return ListIterate.injectInto(new PureModelContextData.Builder(), context.sdlcInfo.packageableElementPointers, (builder, pointers) -> builder.withPureModelContextData(this.pureLoader.loadPurePackageableElementPointer(pm, pointers, clientVersion, subject == null ? "" : "?auth=kerberos"))).distinct().sorted().build();
            }
        };
    } else if (context.sdlcInfo instanceof AlloySDLC) {
        fetchMetadata = () -> {
            parentSpan.setTag("sdlc", "alloy");
            try (Scope scope = GlobalTracer.get().buildSpan("Request Alloy Metadata").startActive(true)) {
                AlloySDLC sdlc = (AlloySDLC) context.sdlcInfo;
                PureModelContextData loadedProject = this.alloyLoader.loadAlloyProject(pm, sdlc, clientVersion);
                loadedProject.origin.sdlcInfo.packageableElementPointers = sdlc.packageableElementPointers;
                List<String> missingPaths = this.alloyLoader.checkAllPathsExist(loadedProject, sdlc);
                if (missingPaths.isEmpty()) {
                    return loadedProject;
                } else {
                    throw new RuntimeException("The following PackageableElementPointers:" + missingPaths.toString() + " do not exist in the project data loaded from the metadata server");
                }
            }
        };
    } else {
        throw new UnsupportedOperationException("To Code");
    }
    PureModelContextData metaData = subject == null ? fetchMetadata.value() : exec(subject, fetchMetadata::value);
    if (metaData.origin != null) {
        Assert.assertTrue("none".equals(metaData.origin.sdlcInfo.version), () -> "Version can't be set in the pointer");
        metaData.origin.sdlcInfo.version = metaData.origin.sdlcInfo.baseVersion;
        metaData.origin.sdlcInfo.baseVersion = null;
    }
    return metaData;
}
Also used : LoggingEventType(org.finos.legend.engine.shared.core.operational.logs.LoggingEventType) Assert(org.finos.legend.engine.shared.core.operational.Assert) ModelLoader(org.finos.legend.engine.language.pure.modelManager.ModelLoader) CommonProfile(org.pac4j.core.profile.CommonProfile) AlloySDLCLoader(org.finos.legend.engine.language.pure.modelManager.sdlc.alloy.AlloySDLCLoader) HttpRequestHeaderMap(org.finos.legend.engine.shared.core.operational.opentracing.HttpRequestHeaderMap) MutableList(org.eclipse.collections.api.list.MutableList) Supplier(java.util.function.Supplier) EntityUtils(org.apache.http.util.EntityUtils) Function0(org.eclipse.collections.api.block.function.Function0) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) SubjectCache(org.finos.legend.engine.shared.core.kerberos.SubjectCache) PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpEntity(org.apache.http.HttpEntity) HTTP_HEADERS(io.opentracing.propagation.Format.Builtin.HTTP_HEADERS) GlobalTracer(io.opentracing.util.GlobalTracer) ExecSubject.exec(org.finos.legend.engine.shared.core.kerberos.ExecSubject.exec) ListIterate(org.eclipse.collections.impl.utility.ListIterate) AlloySDLC(org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC) MetaDataServerConfiguration(org.finos.legend.engine.language.pure.modelManager.sdlc.configuration.MetaDataServerConfiguration) Subject(javax.security.auth.Subject) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) HttpClientBuilder(org.finos.legend.engine.shared.core.kerberos.HttpClientBuilder) List(java.util.List) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) HttpGet(org.apache.http.client.methods.HttpGet) SDLC(org.finos.legend.engine.protocol.pure.v1.model.context.SDLC) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Span(io.opentracing.Span) PureServerLoader(org.finos.legend.engine.language.pure.modelManager.sdlc.pure.PureServerLoader) Scope(io.opentracing.Scope) PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) Scope(io.opentracing.Scope) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC) HttpClientBuilder(org.finos.legend.engine.shared.core.kerberos.HttpClientBuilder) AlloySDLC(org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Subject(javax.security.auth.Subject)

Example 5 with PureModelContext

use of org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext in project legend-engine by finos.

the class PureServerLoader method getCacheKey.

public PureModelContext getCacheKey(PureModelContext context, MutableList<CommonProfile> profiles, Subject executionSubject) {
    PureModelContextPointer deepCopy = new PureModelContextPointer();
    PureSDLC sdlc = new PureSDLC();
    sdlc.packageableElementPointers = ((PureSDLC) ((PureModelContextPointer) context).sdlcInfo).packageableElementPointers;
    deepCopy.sdlcInfo = sdlc;
    deepCopy.serializer = ((PureModelContextPointer) context).serializer;
    deepCopy.sdlcInfo.baseVersion = this.getBaseServerVersion(profiles, executionSubject);
    return deepCopy;
}
Also used : PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC)

Aggregations

PureModelContext (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext)5 PureModelContextPointer (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer)5 CommonProfile (org.pac4j.core.profile.CommonProfile)5 Scope (io.opentracing.Scope)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 ModelManager (org.finos.legend.engine.language.pure.modelManager.ModelManager)3 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)3 PureSDLC (org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 List (java.util.List)2 Subject (javax.security.auth.Subject)2 MutableList (org.eclipse.collections.api.list.MutableList)2 ObjectMapperFactory (org.finos.legend.engine.shared.core.ObjectMapperFactory)2 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)2 Prometheus (org.finos.legend.engine.shared.core.operational.prometheus.Prometheus)2 Span (io.opentracing.Span)1 HTTP_HEADERS (io.opentracing.propagation.Format.Builtin.HTTP_HEADERS)1