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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations