use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution in project legend-engine by finos.
the class ServiceTestRunner method executeSingleExecutionTest.
private RichServiceTestResult executeSingleExecutionTest(PureSingleExecution execution, String testData, List<TestContainer> asserts, String noAssertMessage, PureModelContextData pureModelContextData, PureModel pureModel, Scope scope) throws IOException, JavaCompileException {
if (asserts == null || asserts.isEmpty()) {
scope.span().log(noAssertMessage);
return new RichServiceTestResult(service.getPath(), Collections.emptyMap(), Collections.emptyMap(), null, null, null);
} else {
Runtime testRuntime = ServiceTestGenerationHelper.buildTestRuntime(execution.runtime, execution.mapping, testData, pureModelContextData, pureModel);
RichIterable<? extends String> sqlStatements = extractSetUpSQLFromTestRuntime(testRuntime);
PureSingleExecution testPureSingleExecution = shallowCopySingleExecution(execution);
testPureSingleExecution.runtime = testRuntime;
ExecutionPlan executionPlan = generatePlan(testPureSingleExecution);
SingleExecutionPlan singleExecutionPlan = (SingleExecutionPlan) executionPlan;
compilePlan(singleExecutionPlan);
return executeTestAsserts(singleExecutionPlan, asserts, sqlStatements, scope);
}
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution in project legend-engine by finos.
the class TestRuntimeGenerationForServiceTests method testRuntimeGenerationForModelChainConnection.
@Test
public void testRuntimeGenerationForModelChainConnection() {
String pureGrammarWithModelChainConnection = "###Relational\n" + "Database demo::modelChainConnection::relationalDB\n" + "(\n" + " Table Person\n" + " (\n" + " fullname VARCHAR(1000) PRIMARY KEY,\n" + " firm VARCHAR(200)\n" + " )\n" + ")\n" + "\n" + "\n" + "###Service\n" + "Service demo::modelChainConnection::testModelChainConnectionService\n" + "{\n" + " pattern: '/maheha/testModelChainConnection/fromStudio/';\n" + " owners:\n" + " [\n" + " 'maheha'\n" + " ];\n" + " documentation: '';\n" + " autoActivateUpdates: false;\n" + " execution: Single\n" + " {\n" + " query: |demo::modelChainConnection::dest::Person.all()->project([f|$f.firstName, f|$f.lastName], ['firstName', 'lastName']);\n" + " mapping: demo::modelChainConnection::simpleModelMappingWithAssociation;\n" + " runtime:\n" + " #{\n" + " mappings:\n" + " [\n" + " demo::modelChainConnection::simpleModelMappingWithAssociation\n" + " ];\n" + " connections:\n" + " [\n" + " ModelStore:\n" + " [\n" + " connection_1: demo::modelChainConnection::modelChainConnection\n" + " ],\n" + " demo::modelChainConnection::relationalDB:\n" + " [\n" + " connection_2: demo::modelChainConnection::mySimpleConnection\n" + " ]\n" + " ];\n" + " }#;\n" + " }\n" + " test: Single\n" + " {\n" + " data: 'default\\nPerson\\nfullname,firm\\nPierre DeBelen,A\\nA. Only One,A\\n\\n\\n\\n';\n" + " asserts:\n" + " [\n" + " ];\n" + " }\n" + "}\n" + "\n" + "\n" + "###Pure\n" + "Class demo::modelChainConnection::dest::Address\n" + "{\n" + " street: String[0..1];\n" + " extension: demo::modelChainConnection::dest::AddressExtension[0..1];\n" + "}\n" + "\n" + "Class demo::modelChainConnection::dest::AddressExtension\n" + "{\n" + " stuff: String[1];\n" + "}\n" + "\n" + "Class demo::modelChainConnection::dest::Firm\n" + "{\n" + " legalName: String[1];\n" + " employees: demo::modelChainConnection::dest::Person[*];\n" + " addresses: demo::modelChainConnection::dest::Address[*];\n" + " count: Integer[1];\n" + "}\n" + "\n" + "Class demo::modelChainConnection::dest::Person\n" + "{\n" + " firstName: String[1];\n" + " lastName: String[1];\n" + " addresses: demo::modelChainConnection::dest::Address[*];\n" + " firm: demo::modelChainConnection::dest::Firm[0..1];\n" + " description: String[0..1];\n" + " type: String[0..1];\n" + "}\n" + "\n" + "Class demo::modelChainConnection::src::_Person\n" + "{\n" + " fullName: String[1];\n" + " addresses: demo::modelChainConnection::dest::Address[*];\n" + "}\n" + "\n" + "\n" + "###Mapping\n" + "Mapping demo::modelChainConnection::relationalMapping\n" + "(\n" + " demo::modelChainConnection::src::_Person: Relational\n" + " {\n" + " ~primaryKey\n" + " (\n" + " [demo::modelChainConnection::relationalDB]Person.fullname\n" + " )\n" + " ~mainTable [demo::modelChainConnection::relationalDB]Person\n" + " fullName: [demo::modelChainConnection::relationalDB]Person.fullname\n" + " }\n" + ")\n" + "\n" + "Mapping demo::modelChainConnection::simpleModelMappingWithAssociation\n" + "(\n" + " demo::modelChainConnection::dest::Person: Pure\n" + " {\n" + " ~src demo::modelChainConnection::src::_Person\n" + " firstName: $src.fullName->substring(0, $src.fullName->indexOf(' ')),\n" + " lastName: $src.fullName->substring($src.fullName->indexOf(' ') + 1, $src.fullName->length())\n" + " }\n" + ")\n" + "\n" + "\n" + "###Connection\n" + "ModelChainConnection demo::modelChainConnection::modelChainConnection\n" + "{\n" + " mappings: [\n" + " demo::modelChainConnection::relationalMapping\n" + " ];\n" + "}\n" + "\n" + "RelationalDatabaseConnection demo::modelChainConnection::mySimpleConnection\n" + "{\n" + " store: demo::modelChainConnection::relationalDB;\n" + " type: H2;\n" + " specification: LocalH2\n" + " {\n" + " testDataSetupCSV: '';\n" + " };\n" + " auth: DefaultH2;\n" + "}\n" + "\n" + "\n" + "###Runtime\n" + "Runtime demo::modelChainConnection\n" + "{\n" + " mappings:\n" + " [\n" + " demo::modelChainConnection::simpleModelMappingWithAssociation\n" + " ];\n" + " connections:\n" + " [\n" + " ModelStore:\n" + " [\n" + " connection_1: demo::modelChainConnection::modelChainConnection\n" + " ],\n" + " demo::modelChainConnection::relationalDB:\n" + " [\n" + " connection_2: demo::modelChainConnection::mySimpleConnection\n" + " ]\n" + " ];\n" + "}\n";
PureModelContextData contextData = PureGrammarParser.newInstance().parseModel(pureGrammarWithModelChainConnection);
PureModel pureModel = new PureModel(contextData, null, DeploymentMode.TEST);
Service service = contextData.getElementsOfType(Service.class).get(0);
EngineRuntime testRuntime = (EngineRuntime) ServiceTestGenerationHelper.buildSingleExecutionTestRuntime((PureSingleExecution) service.execution, (SingleExecutionTest) service.test, contextData, pureModel);
Assert.assertEquals(testRuntime.connections.size(), 2);
Assert.assertNotNull(testRuntime.getStoreConnections("ModelStore"));
Assert.assertEquals(testRuntime.getStoreConnections("ModelStore").storeConnections.size(), 1);
Assert.assertFalse((testRuntime.getStoreConnections("ModelStore").storeConnections.get(0).connection instanceof RelationalDatabaseConnection));
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution in project legend-engine by finos.
the class TestRuntimeGenerationForServiceTests method testRuntimeGenerationForServiceWithRuntimePointer.
@Test
public void testRuntimeGenerationForServiceWithRuntimePointer() {
String pureGrammarWithModelChainConnection = "###Relational\n" + "Database test::relationalDB\n" + "(\n" + " Table Person\n" + " (\n" + " fullname VARCHAR(1000) PRIMARY KEY\n" + " )\n" + ")\n" + "\n" + "\n" + "###Service\n" + "Service test::serviceWithRuntimePointer\n" + "{\n" + " pattern: '/garprat/test/fromStudio/';\n" + " owners:\n" + " [\n" + " 'garprat'\n" + " ];\n" + " documentation: '';\n" + " autoActivateUpdates: false;\n" + " execution: Single\n" + " {\n" + " query: |test::Person.all()->project([f|$f.fullName], ['fullName']);\n" + " mapping: test::relationalMapping;\n" + " runtime: test::runtimePointer;\n" + " }\n" + " test: Single\n" + " {\n" + " data: 'default\\nPerson\\nfullname\\nPierre DeBelen\\n';\n" + " asserts:\n" + " [\n" + " ];\n" + " }\n" + "}\n" + "\n" + "\n" + "###Pure\n" + "Class test::Person\n" + "{\n" + " fullName: String[1];\n" + "}\n" + "\n" + "\n" + "###Mapping\n" + "Mapping test::relationalMapping\n" + "(\n" + " test::Person: Relational\n" + " {\n" + " ~primaryKey\n" + " (\n" + " [test::relationalDB]Person.fullname\n" + " )\n" + " ~mainTable [test::relationalDB]Person\n" + " fullName: [test::relationalDB]Person.fullname\n" + " }\n" + ")\n" + "\n" + "###Connection\n" + "RelationalDatabaseConnection test::mySimpleConnection\n" + "{\n" + " store: test::relationalDB;\n" + " type: MemSQL;\n" + " specification: Static\n" + " {\n" + " name: 'memsql_person_data';\n" + " host: 'myserver_url';\n" + " port: 80;\n" + " };\n" + " auth: DefaultH2;\n" + "}\n" + "\n" + "\n" + "###Runtime\n" + "Runtime test::runtimePointer\n" + "{\n" + " mappings:\n" + " [\n" + " test::relationalMapping\n" + " ];\n" + " connections:\n" + " [\n" + " test::relationalDB:\n" + " [\n" + " connection_1: test::mySimpleConnection\n" + " ]\n" + " ];\n" + "}\n";
PureModelContextData contextData = PureGrammarParser.newInstance().parseModel(pureGrammarWithModelChainConnection);
PureModel pureModel = new PureModel(contextData, null, DeploymentMode.TEST);
Service service = contextData.getElementsOfType(Service.class).get(0);
EngineRuntime testRuntime = (EngineRuntime) ServiceTestGenerationHelper.buildSingleExecutionTestRuntime((PureSingleExecution) service.execution, (SingleExecutionTest) service.test, contextData, pureModel);
Assert.assertEquals(testRuntime.connections.size(), 1);
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution in project legend-engine by finos.
the class TestServicePlanGenerator method testSingleExecutionServiceGenerationJSON.
@Test
public void testSingleExecutionServiceGenerationJSON() {
PureModelContextData data = loadModelDataFromResource("simpleJsonService.json");
PureModel pureModel = new PureModel(data, null, DeploymentMode.TEST);
Service service = data.getElementsOfType(Service.class).get(0);
Assert.assertTrue(service.execution instanceof PureSingleExecution);
ExecutionPlan plan = ServicePlanGenerator.generateServiceExecutionPlan(service, null, pureModel, "vX_X_X", PlanPlatform.JAVA, Lists.mutable.empty(), LegendPlanTransformers.transformers);
Assert.assertTrue(plan instanceof SingleExecutionPlan);
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution 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() + "'"));
}
Aggregations