Skip to content

Commit

Permalink
Add sql to generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Święcki committed Jul 15, 2021
1 parent 2dee9be commit b1b246a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
9 changes: 7 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,15 @@ lazy val dist = {
(assembly in Compile) in generic,
(assembly in Compile) in flinkProcessManager,
(assembly in Compile) in engineStandalone,
(assembly in Compile) in openapi
(assembly in Compile) in openapi,
(assembly in Compile) in sql,
).value,
mappings in Universal ++= Seq(
(crossTarget in generic).value / "genericModel.jar" -> "model/genericModel.jar",
(crossTarget in flinkProcessManager).value / "nussknacker-flink-manager.jar" -> "managers/nussknacker-flink-manager.jar",
(crossTarget in engineStandalone).value / "nussknacker-standalone-manager.jar" -> "managers/nussknacker-standalone-manager.jar",
(crossTarget in openapi).value / "openapi.jar" -> "components/openapi.jar"
(crossTarget in openapi).value / "openapi.jar" -> "components/openapi.jar",
(crossTarget in sql).value / "sql.jar" -> "components/sql.jar"
),
/* //FIXME: figure out how to filter out only for .tgz, not for docker
mappings in Universal := {
Expand Down Expand Up @@ -946,6 +948,9 @@ lazy val sql = (project in component("sql")).
configs(IntegrationTest).
settings(commonSettings).
settings(Defaults.itSettings).
settings(commonSettings).
settings(assemblySampleSettings("sql.jar"): _*).
settings(publishAssemblySettings: _*).
settings(
name := "nussknacker-sql",
libraryDependencies ++= Seq(
Expand Down
21 changes: 20 additions & 1 deletion demo/docker/nussknacker/nussknacker.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
#This configuration auguments and overrides configuration in docker image
#Here we configure OpenAPI based enricher, which is implemented by python service in customerservice
{
sqlEnricherDbPool {
driverClassName: "org.hsqldb.jdbc.JDBCDriver"
url: "jdbc:hsqldb:file:/opt/nussknacker/storage/db;sql.syntax_ora=true"
username: "sa"
password: ""
}

processTypes.streaming.modelConfig {
#We add additional jar to model classPath
classPath += "components/openapi.jar"
classPath += "components/openapi.jar" += "components/sql.jar"
components.openAPI {
url: "http://customerservice:5000/swagger"
rootUrl: "http://customerservice:5000"
categories: ["Default"]
}

components.databaseEnricher {
categories: ["Default"]
config: {
databaseQueryEnrichers: [
{ name: "db-query", dbPool: ${sqlEnricherDbPool} }
]
databaseLookupEnrichers: [
{ name: "db-lookup", dbPool: ${sqlEnricherDbPool} }
]
}
}
}
}
69 changes: 69 additions & 0 deletions docs/components/Sql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Overview
========

Nussknacker `Sql` enricher can connect to SQL databases with HikariCP JDBC connection pool.

It supports:

- real time database lookup - a simplified mode where you can select from table filtering for a specified key.
- generic DDM/DDL query enricher
- both `databaseQueryEnricher` as well as `databaseLookupEnricher` can cache queries results
- you can specify cache TTL (Time To Live) duration via `Cache TTL` property
- for `databaseQueryEnricher` you can specify `Result Strategy`
- `Result set` - for retrieving whole query result set
- `Single result` for retrieving single value

Configuration
=============

Sample configuration:

You have to configure database connection pool you will be using in your sql enricher

```
myDatabasePool {
driverClassName: ${dbDriver}
url: ${myDatabaseUrl}
username: ${myDatabaseUser}
password: ${myDatabasePassword}
timeout: ${dbConnectionTimeout}
initialSize: ${dbInitialPoolSize}
maxTotal: ${dbMaxPoolSize}
}
```

| Parameter | Required | Default | Description |
| ---------- | -------- | ------- | ----------- |
| url | true | | URL with your database resource |
| username | true | | Authentication username |
| password | true | | Authentication password |
| driverClassName | true | | Database driver class name |
| timeout | false | 30s | Connection timeout |
| maxTotal | false | 10 | Maximum pool size |
| initialSize | false | 0 | Minimum idle size |

Next you have to configure component itself.

You can have multiple databaseQueryEnrichers and databaseLookupEnrichers for multiple various database connections. You
can also specify only one of them.

```
components {
yourUniqueComponentName: {
type: databaseEnricher #this defines your component type
config: {
databaseQueryEnrichers: [
{ name: "myDatabaseQuery", dbPool: ${myDatabasePool} }
]
databaseLookupEnrichers: [
{ name: "myDatabaseLookup", dbPool: ${myDatabasePool} }
]
}
}
}
```

| Parameter | Required | Default | Description |
| ---------- | -------- | ------- | ----------- |
| databaseQueryEnrichers | true | | List of database query enrichers components |
| databaseLookupEnrichers | true | | List of database lookup components |
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ object HikariDataSourceFactory {
hikariConf.setJdbcUrl(conf.url)
hikariConf.setUsername(conf.username)
hikariConf.setPassword(conf.password)
hikariConf.setMinimumIdle(conf.initialSize)
hikariConf.setMaximumPoolSize(conf.maxTotal)
hikariConf.setConnectionTimeout(conf.timeout.toMillis)
hikariConf.setDriverClassName(conf.driverClassName)
conf.connectionProperties.foreach { case (name, value) =>
hikariConf.addDataSourceProperty(name, value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TODO:
*/
class DatabaseQueryEnricher(val dbPoolConfig: DBPoolConfig) extends EagerService
with Lifecycle with SingleInputGenericNodeTransformation[ServiceInvoker] {

import DatabaseQueryEnricher._

override type State = TransformationState
Expand Down

0 comments on commit b1b246a

Please sign in to comment.