use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.
the class ServiceTestGenerationHelper method buildRelationalTestRuntime.
private static Runtime buildRelationalTestRuntime(Runtime runtime, String mappingPath, String testDataCsv, List<String> sql) {
if (runtime instanceof LegacyRuntime) {
LegacyRuntime newRuntime = new LegacyRuntime();
newRuntime.connections = ListIterate.collect(((LegacyRuntime) runtime).connections, c -> newRelationalConnection(c, testDataCsv, sql));
return newRuntime;
}
if (runtime instanceof EngineRuntime) {
EngineRuntime testRuntime = new EngineRuntime();
PackageableElementPointer mappingPointer = new PackageableElementPointer();
mappingPointer.type = PackageableElementType.MAPPING;
mappingPointer.path = mappingPath;
testRuntime.mappings.add(mappingPointer);
testRuntime.connections = ListIterate.collect(((EngineRuntime) runtime).connections, c -> "ModelStore".equals(c.store.path) ? c : newRelationalStoreConnections(c, testDataCsv, sql));
return testRuntime;
}
if (runtime instanceof RuntimePointer) {
return runtime;
}
throw new UnsupportedOperationException("Unsupported runtime type: " + runtime.getClass().getName());
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer 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.runtime.RuntimePointer in project legend-engine by finos.
the class ServiceTestGenerationHelper method resolveRuntime.
private static EngineRuntime resolveRuntime(Runtime runtime, PureModelContextData pureModelContextData) {
if (runtime instanceof EngineRuntime) {
return (EngineRuntime) runtime;
}
if (runtime instanceof LegacyRuntime) {
return ((LegacyRuntime) runtime).toEngineRuntime();
}
if (runtime instanceof RuntimePointer) {
String runtimeFullPath = ((RuntimePointer) runtime).runtime;
PackageableElement found = Iterate.detect(pureModelContextData.getElements(), e -> runtimeFullPath.equals(e.getPath()));
if (!(found instanceof PackageableRuntime)) {
throw new RuntimeException("Can't find runtime '" + runtimeFullPath + "'");
}
return ((PackageableRuntime) found).runtimeValue;
}
throw new UnsupportedOperationException("Unsupported runtime type: " + runtime.getClass().getName());
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.
the class TestExecutionScope method buildTestRuntime.
public static Runtime buildTestRuntime(Runtime runtime, String testData, List<String> setupSqls) {
if (runtime instanceof LegacyRuntime) {
LegacyRuntime newRuntime = new LegacyRuntime();
newRuntime.connections = ListIterate.collect(((LegacyRuntime) runtime).connections, connection -> {
if (connection instanceof ModelChainConnection) {
return connection;
}
return ConnectionManagerSelector.transformToTestConnectionSpecification(connection, testData, setupSqls);
});
return newRuntime;
} else if (runtime instanceof EngineRuntime) {
EngineRuntime newRuntime = new EngineRuntime();
newRuntime.connections = ListIterate.collect(((EngineRuntime) runtime).connections, storeConnections -> {
StoreConnections newStoreConnections = new StoreConnections();
newStoreConnections.store = storeConnections.store;
newStoreConnections.storeConnections = ListIterate.collect(storeConnections.storeConnections, identifiedConnection -> {
if (identifiedConnection.connection instanceof ModelChainConnection) {
return identifiedConnection;
}
IdentifiedConnection newIdentifiedConnection = new IdentifiedConnection();
newIdentifiedConnection.id = identifiedConnection.id;
newIdentifiedConnection.connection = ConnectionManagerSelector.transformToTestConnectionSpecification(identifiedConnection.connection, testData, setupSqls);
return newIdentifiedConnection;
});
return newStoreConnections;
});
return newRuntime;
} else if (runtime instanceof RuntimePointer) {
return runtime;
}
throw new UnsupportedOperationException();
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.
the class HelperRuntimeBuilder method buildPureRuntime.
public static org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime buildPureRuntime(Runtime runtime, CompileContext context) {
if (runtime == null) {
return null;
}
if (runtime instanceof LegacyRuntime) {
LegacyRuntime legacyRuntime = (LegacyRuntime) runtime;
org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime pureRuntime = new Root_meta_pure_runtime_Runtime_Impl("Root::meta::pure::runtime::Runtime");
ListIterate.forEach(legacyRuntime.connections, connection -> pureRuntime._connectionsAdd(connection.accept(new ConnectionFirstPassBuilder(context))));
return pureRuntime;
}
if (runtime instanceof EngineRuntime) {
return buildEngineRuntime(((EngineRuntime) runtime), context);
} else if (runtime instanceof RuntimePointer) {
return context.resolveRuntime(((RuntimePointer) runtime).runtime, ((RuntimePointer) runtime).sourceInformation);
}
throw new UnsupportedOperationException();
}
Aggregations