use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution in project legend-engine by finos.
the class HelperServiceBuilder method processServiceExecution.
public static Root_meta_legend_service_metamodel_Execution processServiceExecution(Execution execution, CompileContext context) {
if (execution instanceof PureSingleExecution) {
PureSingleExecution pureSingleExecution = (PureSingleExecution) execution;
Mapping mapping = context.resolveMapping(pureSingleExecution.mapping, pureSingleExecution.mappingSourceInformation);
inferEmbeddedRuntimeMapping(pureSingleExecution.runtime, pureSingleExecution.mapping);
org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime runtime = HelperRuntimeBuilder.buildPureRuntime(pureSingleExecution.runtime, context);
HelperRuntimeBuilder.checkRuntimeMappingCoverage(runtime, Lists.fixedSize.of(mapping), context, pureSingleExecution.runtime.sourceInformation);
return new Root_meta_legend_service_metamodel_PureSingleExecution_Impl("")._func(HelperValueSpecificationBuilder.buildLambda(pureSingleExecution.func, context))._mapping(mapping)._runtime(runtime);
} else if (execution instanceof PureMultiExecution) {
PureMultiExecution pureMultiExecution = (PureMultiExecution) execution;
if (pureMultiExecution.executionParameters.isEmpty()) {
throw new EngineException("Service multi execution must not be empty", pureMultiExecution.sourceInformation, EngineErrorType.COMPILATION);
}
Set<String> executionKeyValues = new HashSet<>();
return new Root_meta_legend_service_metamodel_PureMultiExecution_Impl("")._executionKey(pureMultiExecution.executionKey)._func(HelperValueSpecificationBuilder.buildLambda(pureMultiExecution.func, context))._executionParameters(ListIterate.collect(pureMultiExecution.executionParameters, executionParameter -> processServiceKeyedExecutionParameter(executionParameter, context, executionKeyValues)));
}
return getServiceCompilerExtensions(context).stream().flatMap(extension -> extension.getExtraServiceExecutionProcessors().stream()).map(processor -> processor.value(execution, context)).filter(Objects::nonNull).findFirst().orElseThrow(() -> new UnsupportedOperationException("Unsupported service execution type '" + execution.getClass().getSimpleName() + "'"));
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution in project legend-sdlc by finos.
the class ServiceExecutionClassGenerator method getExecutionParameters.
private MutableList<ExecutionParameter> getExecutionParameters() {
Execution execution = this.service.execution;
if (!(execution instanceof PureExecution)) {
throw new IllegalArgumentException("Only services with Pure executions are supported: " + service.getPath());
}
Lambda lambda = ((PureExecution) execution).func;
MutableList<ExecutionParameter> parameters = Lists.mutable.ofInitialCapacity(lambda.parameters.size() + 1);
MutableSet<String> javaParameterNames = Sets.mutable.ofInitialCapacity(lambda.parameters.size() + 1);
if (execution instanceof PureMultiExecution) {
String executionKey = ((PureMultiExecution) execution).executionKey;
String javaParameterName = JavaSourceHelper.toValidJavaIdentifier(executionKey);
javaParameterNames.add(javaParameterName);
parameters.add(new ExecutionParameter(new Variable(executionKey, "String", new Multiplicity(1, 1)), javaParameterName));
}
for (Variable legendParameter : lambda.parameters) {
String javaParameterName = JavaSourceHelper.toValidJavaIdentifier(legendParameter.name);
if (!javaParameterNames.add(javaParameterName)) {
String initialJavaParameterName = javaParameterName;
int i = 2;
javaParameterName = initialJavaParameterName + "$" + i;
while (!javaParameterNames.add(javaParameterName)) {
i++;
javaParameterName = initialJavaParameterName + "$" + i;
}
}
parameters.add(new ExecutionParameter(legendParameter, javaParameterName));
}
return parameters;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution in project legend-engine by finos.
the class ServiceTestRunner method executeTests.
public List<RichServiceTestResult> executeTests() throws IOException, JavaCompileException {
Execution serviceExecution = this.service.execution;
if (serviceExecution instanceof PureMultiExecution) {
List<RichServiceTestResult> results = Lists.mutable.empty();
try (Scope scope = GlobalTracer.get().buildSpan("Generate Tests And Run For MultiExecution Service").startActive(true)) {
MutableMap<String, KeyedExecutionParameter> executionsByKey = Iterate.groupByUniqueKey(((PureMultiExecution) serviceExecution).executionParameters, e -> e.key);
for (KeyedSingleExecutionTest es : ((MultiExecutionTest) service.test).tests) {
List<TestContainer> asserts = es.asserts;
KeyedExecutionParameter e = executionsByKey.get(es.key);
PureMultiExecution pureExecution = (PureMultiExecution) service.execution;
PureSingleExecution pureSingleExecution = new PureSingleExecution();
pureSingleExecution.func = pureExecution.func;
pureSingleExecution.mapping = e.mapping;
pureSingleExecution.runtime = e.runtime;
pureSingleExecution.executionOptions = e.executionOptions;
String noAssertMessage = "No test assert found for key - " + es.key + "!!";
RichServiceTestResult richServiceTestResult = executeSingleExecutionTest(pureSingleExecution, es.data, asserts, noAssertMessage, pureModelContextData, pureModel, scope);
richServiceTestResult.setOptionalMultiExecutionKey(es.key);
results.add(richServiceTestResult);
}
return results;
}
} else if (serviceExecution instanceof PureSingleExecution) {
try (Scope scope = GlobalTracer.get().buildSpan("Generate Single Pure Tests And Run").startActive(true)) {
List<TestContainer> asserts = ((SingleExecutionTest) service.test).asserts;
String noAssertMessage = "No test assert found !!";
return Collections.singletonList(executeSingleExecutionTest((PureSingleExecution) service.execution, ((SingleExecutionTest) service.test).data, asserts, noAssertMessage, pureModelContextData, pureModel, scope));
}
} else {
try (Scope scope = GlobalTracer.get().buildSpan("Generate Extra Service Execution Tests and Run").startActive(true)) {
MutableList<ServiceExecutionExtension> serviceExecutionExtensions = Lists.mutable.withAll(ServiceLoader.load(ServiceExecutionExtension.class));
Pair<ExecutionPlan, RichIterable<? extends String>> testExecutor = getExtraServiceExecutionPlan(serviceExecutionExtensions, serviceExecution, ((Root_meta_legend_service_metamodel_SingleExecutionTest) this.pureService._test())._data());
ExecutionPlan executionPlan = testExecutor.getOne();
Assert.assertTrue(executionPlan instanceof SingleExecutionPlan, () -> "Only Single Execution Plan supported");
List<TestContainer> containers = getExtraServiceTestContainers(serviceExecutionExtensions, service.test);
return Collections.singletonList(executeTestAsserts((SingleExecutionPlan) executionPlan, containers, testExecutor.getTwo(), scope));
}
}
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution in project legend-engine by finos.
the class ServiceModeling method testService.
@Prometheus(name = "service test model resolve", doc = "Model resolution duration summary within service test execution")
public List<TestResult> testService(MutableList<CommonProfile> profiles, PureModelContext context, String metricsContext) {
try {
long start = System.currentTimeMillis();
PureModelContextData data = ((PureModelContextData) context).shallowCopy();
Service service = (Service) Iterate.detect(data.getElements(), e -> e instanceof Service);
PureModelContextData dataWithoutService = PureModelContextData.newBuilder().withOrigin(data.getOrigin()).withSerializer(data.getSerializer()).withElements(LazyIterate.select(data.getElements(), e -> e != service)).build();
PureModel pureModel = new PureModel(dataWithoutService, profiles, deploymentMode);
Pair<PureModelContextData, PureModel> pureModelAndData = Tuples.pair(dataWithoutService, pureModel);
long end = System.currentTimeMillis();
MetricsHandler.observe("service test model resolve", start, end);
MetricsHandler.observeServerOperation("model_resolve", metricsContext, start, end);
if (service.execution instanceof PureMultiExecution) {
throw new UnsupportedOperationException("MultiExecutions not yet supported");
}
Root_meta_legend_service_metamodel_Service pureService = compileService(service, pureModel.getContext(service));
TestRun testRun = executeTests(service, pureService, pureModelAndData, PureClientVersions.production, metricsContext);
if (!(testRun instanceof SingleTestRun)) {
throw new UnsupportedOperationException("Expected a single test run result");
}
return ((SingleTestRun) testRun).results.entrySet().stream().map(x -> new TestResult(x.getKey(), x.getValue())).collect(Collectors.toList());
} catch (IOException | JavaCompileException e) {
MetricsHandler.incrementErrorCount("model_resolve", 0);
throw new RuntimeException(e);
}
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution in project legend-engine by finos.
the class ServiceParseTreeWalker method visitExecution.
private Execution visitExecution(ServiceParserGrammar.ServiceExecContext ctx) {
if (ctx.singleExec() != null) {
ServiceParserGrammar.SingleExecContext pureSingleExecContext = ctx.singleExec();
PureSingleExecution pureSingleExecution = new PureSingleExecution();
pureSingleExecution.sourceInformation = walkerSourceInformation.getSourceInformation(pureSingleExecContext);
// function/query
ServiceParserGrammar.ServiceFuncContext funcContext = PureGrammarParserUtility.validateAndExtractRequiredField(pureSingleExecContext.serviceFunc(), "query", pureSingleExecution.sourceInformation);
pureSingleExecution.func = visitLambda(funcContext.combinedExpression());
// mapping
ServiceParserGrammar.ServiceMappingContext mappingContext = PureGrammarParserUtility.validateAndExtractRequiredField(pureSingleExecContext.serviceMapping(), "mapping", pureSingleExecution.sourceInformation);
pureSingleExecution.mapping = PureGrammarParserUtility.fromQualifiedName(mappingContext.qualifiedName().packagePath() == null ? Collections.emptyList() : mappingContext.qualifiedName().packagePath().identifier(), mappingContext.qualifiedName().identifier());
pureSingleExecution.mappingSourceInformation = walkerSourceInformation.getSourceInformation(mappingContext.qualifiedName());
// runtime
ServiceParserGrammar.ServiceRuntimeContext runtimeContext = PureGrammarParserUtility.validateAndExtractRequiredField(pureSingleExecContext.serviceRuntime(), "runtime", pureSingleExecution.sourceInformation);
pureSingleExecution.runtime = this.visitRuntime(runtimeContext);
return pureSingleExecution;
} else if (ctx.multiExec() != null) {
ServiceParserGrammar.MultiExecContext pureMultiExecContext = ctx.multiExec();
PureMultiExecution pureMultiExecution = new PureMultiExecution();
pureMultiExecution.sourceInformation = walkerSourceInformation.getSourceInformation(pureMultiExecContext);
// function/query
ServiceParserGrammar.ServiceFuncContext funcContext = PureGrammarParserUtility.validateAndExtractRequiredField(pureMultiExecContext.serviceFunc(), "query", pureMultiExecution.sourceInformation);
pureMultiExecution.func = visitLambda(funcContext.combinedExpression());
// execution key
ServiceParserGrammar.ExecKeyContext execKeyContext = PureGrammarParserUtility.validateAndExtractRequiredField(pureMultiExecContext.execKey(), "key", pureMultiExecution.sourceInformation);
pureMultiExecution.executionKey = PureGrammarParserUtility.fromGrammarString(execKeyContext.STRING().getText(), true);
// execution parameters (indexed by execution key)
pureMultiExecution.executionParameters = ListIterate.collect(pureMultiExecContext.execParameter(), this::visitKeyedExecutionParameter);
return pureMultiExecution;
}
throw new UnsupportedOperationException();
}
Aggregations