Compare commits

..

110 commits
v2.0.1 ... main

Author SHA1 Message Date
4f16842623
Merge pull request #28 from rasilon/dependabot/maven/org.apache.logging.log4j-log4j-core-2.25.3
Bump org.apache.logging.log4j:log4j-core from 2.17.1 to 2.25.3
2025-12-30 01:16:49 +00:00
dependabot[bot]
d2257f1b81
Bump org.apache.logging.log4j:log4j-core from 2.17.1 to 2.25.3
Bumps org.apache.logging.log4j:log4j-core from 2.17.1 to 2.25.3.

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-core
  dependency-version: 2.25.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-19 22:49:23 +00:00
8ab5b1b79e
Merge pull request #27 from rasilon/dependabot/maven/org.apache.commons-commons-lang3-3.18.0
Bump org.apache.commons:commons-lang3 from 3.9 to 3.18.0
2025-08-12 14:54:56 +01:00
dependabot[bot]
26d47f16c9
Bump org.apache.commons:commons-lang3 from 3.9 to 3.18.0
Bumps org.apache.commons:commons-lang3 from 3.9 to 3.18.0.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-lang3
  dependency-version: 3.18.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-12 02:04:46 +00:00
9f0fe6bb3b Security; update dependencies 2025-06-03 09:23:29 +01:00
bf4ed02af5 Merge branch 'main' of github.com:rasilon/ujetl 2025-06-03 08:39:23 +01:00
5f275b93d8
Merge pull request #26 from rasilon/dependabot/maven/commons-beanutils-commons-beanutils-1.11.0
Bump commons-beanutils:commons-beanutils from 1.9.4 to 1.11.0
2025-06-02 15:00:35 +01:00
dependabot[bot]
d509513084
Bump commons-beanutils:commons-beanutils from 1.9.4 to 1.11.0
Bumps commons-beanutils:commons-beanutils from 1.9.4 to 1.11.0.

---
updated-dependencies:
- dependency-name: commons-beanutils:commons-beanutils
  dependency-version: 1.11.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-28 18:01:36 +00:00
96e28a5abb Merge branch 'dev' 2024-04-17 14:22:30 +01:00
1da5fabb05 Update version for dep updates 2024-04-17 14:22:03 +01:00
8a4d892dfa
Merge pull request #25 from rasilon/dependabot/maven/org.apache.commons-commons-configuration2-2.10.1
Bump org.apache.commons:commons-configuration2 from 2.8.0 to 2.10.1
2024-03-21 19:47:15 +00:00
dependabot[bot]
07f68922b3
Bump org.apache.commons:commons-configuration2 from 2.8.0 to 2.10.1
Bumps org.apache.commons:commons-configuration2 from 2.8.0 to 2.10.1.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-configuration2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-21 19:15:25 +00:00
22af36b555
Merge pull request #24 from rasilon/dependabot/maven/org.postgresql-postgresql-42.7.2
Bump org.postgresql:postgresql from 42.4.3 to 42.7.2
2024-02-21 12:20:28 +00:00
dependabot[bot]
d0a5075191
Bump org.postgresql:postgresql from 42.4.3 to 42.7.2
Bumps [org.postgresql:postgresql](https://github.com/pgjdbc/pgjdbc) from 42.4.3 to 42.7.2.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/pgjdbc/pgjdbc/commits)

---
updated-dependencies:
- dependency-name: org.postgresql:postgresql
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-21 00:12:25 +00:00
1ce7e09751
Merge pull request #23 from rasilon/dev
Fix log file param
2023-07-12 09:49:06 +01:00
f651fd720e Fix log file param 2023-07-12 09:47:21 +01:00
58b78b2021
Merge pull request #22 from rasilon/dev
New Features
2023-07-12 08:58:52 +01:00
a88ac56848 Correct test name; CnP error 2023-07-12 08:48:21 +01:00
9a8716f33e Add the real implementation 2023-07-12 08:45:48 +01:00
1b1ba551c8 Add forced driver loading 2023-07-11 15:04:33 +01:00
866d02fb52 Change how log4j finds its config.
log4j is reacting less well to reconfigurations, so this moves the config file location to earlier in the process, so that no class sees an unconfigured instance.
2023-07-11 14:07:37 +01:00
441b2f4191
Merge pull request #21 from rasilon/dev
Script the docker tagging
2023-07-11 13:51:38 +01:00
b81aedefb1 Script te docker tagging 2023-07-11 13:21:04 +01:00
584f83de0d
Merge pull request #20 from rasilon/dev
H2 security update
2023-07-11 12:50:27 +01:00
4d38679155 bump minor version with H2 update 2023-07-11 12:49:34 +01:00
b378189512 Update default log config location 2023-07-11 12:36:44 +01:00
49487a83af Update unit test syntax to the current version of H2 2023-07-11 12:33:48 +01:00
9f4729bf1d
Merge pull request #19 from rasilon/dependabot/maven/com.h2database-h2-2.2.220
Bump h2 from 2.1.210 to 2.2.220
2023-07-11 11:08:12 +01:00
dependabot[bot]
2126553e5c
Bump h2 from 2.1.210 to 2.2.220
Bumps [h2](https://github.com/h2database/h2database) from 2.1.210 to 2.2.220.
- [Release notes](https://github.com/h2database/h2database/releases)
- [Commits](https://github.com/h2database/h2database/compare/version-2.1.210...version-2.2.220)

---
updated-dependencies:
- dependency-name: com.h2database:h2
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-07 21:54:12 +00:00
64743f430b Update build host and postgres libs
Bumping the postgres libs showed that the upstream build images
were EOL, so we're now running a more modern version of Java
and have migrated the build to ubuntu LTS
2022-12-07 11:00:29 +00:00
28c918dd6a
Merge pull request #18 from rasilon/dependabot/maven/org.postgresql-postgresql-42.4.3
Bump postgresql from 42.4.1 to 42.4.3
2022-12-07 10:29:31 +00:00
dependabot[bot]
17d33ec18b
Bump postgresql from 42.4.1 to 42.4.3
Bumps [postgresql](https://github.com/pgjdbc/pgjdbc) from 42.4.1 to 42.4.3.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/pgjdbc/pgjdbc/compare/REL42.4.1...REL42.4.3)

---
updated-dependencies:
- dependency-name: org.postgresql:postgresql
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-23 22:20:40 +00:00
5a61bb357f
Merge pull request #17 from rasilon/dependabot/maven/org.postgresql-postgresql-42.4.1
Bump postgresql from 42.3.3 to 42.4.1
2022-08-07 08:55:44 +01:00
ffe33276ba
Merge pull request #16 from rasilon/dependabot/maven/org.apache.commons-commons-configuration2-2.8.0
Bump commons-configuration2 from 2.7 to 2.8.0
2022-08-07 08:55:26 +01:00
dependabot[bot]
67f6ec2dab
Bump postgresql from 42.3.3 to 42.4.1
Bumps [postgresql](https://github.com/pgjdbc/pgjdbc) from 42.3.3 to 42.4.1.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/pgjdbc/pgjdbc/compare/REL42.3.3...REL42.4.1)

---
updated-dependencies:
- dependency-name: org.postgresql:postgresql
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-06 05:55:29 +00:00
dependabot[bot]
9554d3df63
Bump commons-configuration2 from 2.7 to 2.8.0
Bumps commons-configuration2 from 2.7 to 2.8.0.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-configuration2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-07 16:58:42 +00:00
f6268344d0
Merge pull request #13 from rasilon/dependabot/maven/com.h2database-h2-2.1.210
Bump h2 from 2.0.206 to 2.1.210
2022-02-16 11:52:01 +00:00
130b120515
Merge pull request #15 from rasilon/dependabot/maven/org.postgresql-postgresql-42.3.3
Bump postgresql from 42.2.5 to 42.3.3
2022-02-16 11:51:47 +00:00
dependabot[bot]
54a8cd6312
Bump postgresql from 42.2.5 to 42.3.3
Bumps [postgresql](https://github.com/pgjdbc/pgjdbc) from 42.2.5 to 42.3.3.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/pgjdbc/pgjdbc/compare/REL42.2.5...REL42.3.3)

---
updated-dependencies:
- dependency-name: org.postgresql:postgresql
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-16 00:56:38 +00:00
dependabot[bot]
d7bde365ed
Bump h2 from 2.0.206 to 2.1.210
Bumps [h2](https://github.com/h2database/h2database) from 2.0.206 to 2.1.210.
- [Release notes](https://github.com/h2database/h2database/releases)
- [Commits](https://github.com/h2database/h2database/compare/version-2.0.206...version-2.1.210)

---
updated-dependencies:
- dependency-name: com.h2database:h2
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-21 23:25:43 +00:00
1c5e54acc9
Merge pull request #11 from rasilon/dependabot/maven/org.apache.logging.log4j-log4j-core-2.17.1
Bump log4j-core from 2.17.0 to 2.17.1
2022-01-07 08:05:08 +00:00
b17ca2479b
Merge pull request #10 from rasilon/dependabot/maven/org.apache.logging.log4j-log4j-api-2.17.1
Bump log4j-api from 2.17.0 to 2.17.1
2022-01-07 08:04:56 +00:00
5de1e80b8c
Merge pull request #12 from rasilon/dependabot/maven/com.h2database-h2-2.0.206
Bump h2 from 2.0.202 to 2.0.206
2022-01-07 08:04:41 +00:00
dependabot[bot]
36acc0ed23
Bump h2 from 2.0.202 to 2.0.206
Bumps [h2](https://github.com/h2database/h2database) from 2.0.202 to 2.0.206.
- [Release notes](https://github.com/h2database/h2database/releases)
- [Commits](https://github.com/h2database/h2database/compare/version-2.0.202...version-2.0.206)

---
updated-dependencies:
- dependency-name: com.h2database:h2
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-07 00:11:15 +00:00
dependabot[bot]
3235db7f6a
Bump log4j-core from 2.17.0 to 2.17.1
Bumps log4j-core from 2.17.0 to 2.17.1.

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-core
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-04 16:34:38 +00:00
dependabot[bot]
79a3dbf499
Bump log4j-api from 2.17.0 to 2.17.1
Bumps log4j-api from 2.17.0 to 2.17.1.

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-api
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-04 16:33:13 +00:00
7a22b6ddae cope with outdated source image 2021-12-18 21:49:35 +00:00
f42fa6550e version bump for security updstes 2021-12-18 21:42:39 +00:00
3c525bf006
Merge pull request #9 from rasilon/dependabot/maven/com.h2database-h2-2.0.202
Bump h2 from 1.4.199 to 2.0.202
2021-12-18 21:34:39 +00:00
e405e372cd
Merge pull request #7 from rasilon/dependabot/maven/org.apache.logging.log4j-log4j-api-2.17.0
Bump log4j-api from 2.16.0 to 2.17.0
2021-12-18 21:31:12 +00:00
dependabot[bot]
bc9849e3ee
Bump h2 from 1.4.199 to 2.0.202
Bumps [h2](https://github.com/h2database/h2database) from 1.4.199 to 2.0.202.
- [Release notes](https://github.com/h2database/h2database/releases)
- [Commits](https://github.com/h2database/h2database/compare/version-1.4.199...version-2.0.202)

---
updated-dependencies:
- dependency-name: com.h2database:h2
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-18 21:30:36 +00:00
0730d1bf9d
Merge pull request #8 from rasilon/dependabot/maven/org.apache.logging.log4j-log4j-core-2.17.0
Bump log4j-core from 2.16.0 to 2.17.0
2021-12-18 21:30:21 +00:00
dependabot[bot]
45c5900481
Bump log4j-core from 2.16.0 to 2.17.0
Bumps log4j-core from 2.16.0 to 2.17.0.

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-core
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-18 18:20:05 +00:00
dependabot[bot]
f4ded0857c
Bump log4j-api from 2.16.0 to 2.17.0
Bumps log4j-api from 2.16.0 to 2.17.0.

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-api
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-18 18:12:08 +00:00
c34f8b54c4 Bump log4j version to 2.16.0, chasing the logging vulnerability. 2021-12-14 08:02:33 +00:00
ce5a48c083 Migrate other log4j to the new versiom 2021-12-10 18:51:02 +00:00
e6ccc6f2af
Merge pull request #5 from rasilon/dependabot/maven/org.apache.logging.log4j-log4j-api-2.15.0
Bump log4j-api from 2.13.3 to 2.15.0
2021-12-10 09:21:51 +00:00
dependabot[bot]
20c1c7695f
Bump log4j-api from 2.13.3 to 2.15.0
Bumps log4j-api from 2.13.3 to 2.15.0.

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-api
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-10 00:53:03 +00:00
5df6384abf Build this branch! 2020-07-02 10:49:49 +01:00
be6fbc73a1 log4j test 2020-07-02 10:32:46 +01:00
b0cc8f8ce7 log4j test 2020-07-02 10:31:47 +01:00
cc03ef6c1d Change to Debian style 2020-07-02 10:23:24 +01:00
f2ef10be64 Change to Debian style 2020-07-02 10:19:56 +01:00
6a1ab875c7 Change to Debian style 2020-07-02 10:06:50 +01:00
b3b02669f7 Remove alpine, since OpenJDK 11 doesn't use it 2020-07-02 09:45:47 +01:00
f963d8bdcf Update to Java 11 2020-07-02 09:23:41 +01:00
f3538a09f9 Migrate to Java 11 2020-07-02 09:00:21 +01:00
af62d6cf96 SYnc versions 2020-07-01 21:09:20 +01:00
ead5a9e173 Bump version 2020-07-01 20:38:46 +01:00
dependabot[bot]
a77be8b696
Bump commons-beanutils from 1.9.3 to 1.9.4
Bumps commons-beanutils from 1.9.3 to 1.9.4.

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-01 19:33:46 +00:00
3493e18630 Bump version 2020-07-01 20:31:01 +01:00
dependabot[bot]
cb3b3e3b63
Bump log4j-core from 2.11.2 to 2.13.2
Bumps log4j-core from 2.11.2 to 2.13.2.

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-01 18:54:25 +00:00
cbb44ce1d9 Bump version number after security fix 2020-05-21 21:48:05 +01:00
8dbe3e9505
Merge pull request #2 from rasilon/dependabot/maven/org.apache.commons-commons-configuration2-2.7
Security fix; doesn't technically affect us since we don't use YAML currently.
Bump commons-configuration2 from 2.4 to 2.7
2020-05-21 21:41:30 +01:00
dependabot[bot]
be9e468354
Bump commons-configuration2 from 2.4 to 2.7
Bumps commons-configuration2 from 2.4 to 2.7.

Signed-off-by: dependabot[bot] <support@github.com>
2020-05-21 19:24:32 +00:00
66dd3bb37d Tidy up inconsistent log formatting 2019-11-06 15:13:18 +00:00
a7d1a6077b Version bump for session ID code 2019-08-27 12:59:06 +01:00
734dc8608f Add session identification 2019-08-27 12:53:37 +01:00
01310bfca4 Fix producer thread name, for logging and monitoring. 2019-08-05 16:38:24 +01:00
06c64d499f Explicitly commit pre and post SQL so that a post command in the last job isn't lost. 2019-08-05 16:00:43 +01:00
892f7b4fa8
Merge pull request #1 from rasilon/pre_setup_post
Add pre and post target SQL
2019-08-05 11:36:14 +01:00
4f0db0a2df Version bump 2019-08-05 11:35:22 +01:00
4f905dd47a Add test config 2019-08-05 11:32:24 +01:00
8fdbc6a78e Add pre and post SQL 2019-08-05 11:10:12 +01:00
ddc67f3a41 Bugfix type quoting and add select generator 2019-07-12 13:51:30 +01:00
633fbe7391 Version bump 2019-07-12 13:04:55 +01:00
f669b1af9d Fix up the docker tests 2019-07-12 13:03:23 +01:00
e71832f57a Refactor variable name 2019-07-12 13:03:08 +01:00
d34a0902d1 Fix logging message order 2019-07-12 10:33:18 +01:00
cde891ee16 Version bump with logging fix 2019-07-11 13:22:06 +01:00
2b5f4f1dbe Add more test data, and fix log ordering 2019-07-11 09:13:15 +01:00
97baf0d11a Improve robustness of insert generator 2019-06-26 16:31:24 +01:00
9d82c9f279 Add insert generator 2019-06-26 12:58:23 +01:00
31a2968f6a Tigten up TimeLimiter test, and add default test logging config 2019-06-18 15:07:29 +01:00
981b59225b Fix integration test assumptions 2019-06-18 15:01:04 +01:00
ff157e6a59 Add TimeLimiter test. 2019-06-18 14:46:21 +01:00
4fe30a196c Add RPM build back 2019-06-18 14:36:54 +01:00
7a858ec64a Add redone unit tests for v2 2019-06-18 14:33:10 +01:00
6737ae6492 Add testing deps 2019-06-18 13:21:51 +01:00
b8883d6f23 Improve the docs a little 2019-06-18 13:17:22 +01:00
61ddbfd817 Bump version after config fix 2019-06-18 09:37:53 +01:00
af46f83799 Fix copy/paste error in poll timeout config 2019-06-18 08:31:46 +01:00
5571bd1b4d Add dockerised tests 2019-06-17 12:53:31 +01:00
3badb97d49 Move to alpine 2019-06-12 16:47:28 +01:00
ea629b3098 Add multistage docker build 2019-06-12 16:21:28 +01:00
3bfc9d6a1b Remove docker instance after use 2019-06-12 15:39:27 +01:00
2e3bdc7004 Add build docker 2019-06-12 14:43:15 +01:00
088f77bc42 Add entrypoint 2019-06-12 14:42:17 +01:00
38b36e90a4 Seperate build docker and run docker 2019-06-12 13:01:42 +01:00
6258e7dcf3 Seperate build docker and run docker 2019-06-12 13:01:25 +01:00
31 changed files with 978 additions and 114 deletions

View file

@ -2,3 +2,9 @@
Originally written in the days of trying to do something, with no budget, I wrote this out of necessity. I subsequently got permission to open-source it so long as there were no references to the company in it. So this is the cleaned up version, with a few additional features added and the things that turned out to be pointless removed. Originally written in the days of trying to do something, with no budget, I wrote this out of necessity. I subsequently got permission to open-source it so long as there were no references to the company in it. So this is the cleaned up version, with a few additional features added and the things that turned out to be pointless removed.
It's probably the smallest functional ETL application with decent performance. Since I only use it on Postgres nowadays, it only officially supports Postgres at the moment. But in the near past it's worked pulling data from "several commercial databases" that don't like being named in benchmarks etc. and if you have the JDBC jars in your classpath then it should just work. It's probably the smallest functional ETL application with decent performance. Since I only use it on Postgres nowadays, it only officially supports Postgres at the moment. But in the near past it's worked pulling data from "several commercial databases" that don't like being named in benchmarks etc. and if you have the JDBC jars in your classpath then it should just work.
For an example config file, please see [TEST_config_live.xml](https://github.com/rasilon/ujetl/blob/master/src/test/resources/TEST_config_live.xml)
To run the dockerised integration tests, use `build_util/run_docker_tests` in this repo.
A runnable docker image is available at [rasilon/ujetl](https://cloud.docker.com/repository/docker/rasilon/ujetl). This expects config files copied into, or mounted into `/var/ujetl/`. RPMs can be built using `build_util/build_rpms_in_docker`. As the name suggests, you need docker for that.

View file

@ -1,6 +0,0 @@
#!/bin/bash
set -e
docker build --rm -t local/c7-buildhost docker
docker run -it -v `pwd`:/root/build local/c7-buildhost /root/build/build_util/build_rpm

View file

@ -1,12 +0,0 @@
#!/bin/bash
set -e
cd /root
cp -Rv build build2
cd build2
SPEC=$(ls *.spec)
VER=$(grep Version $SPEC | awk '{print $2}')
tar cvf $HOME/rpmbuild/SOURCES/uJETL-${VER}.tar.gz --show-transformed --transform="s/^\./uJETL-${VER}/" .
rpmbuild -ba $SPEC
cp /root/rpmbuild/RPMS/x86_64/* /root/build/

3
build_util/create_run_docker Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
docker build --target deploy -t rasilon/ujetl docker/multistage
docker tag rasilon/ujetl:latest rasilon/ujetl:$(xpath -q -e '/project/version/text()' pom.xml)

4
build_util/push_docker_images Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
docker push rasilon/ujetl:latest
docker push rasilon/ujetl:$(xpath -q -e '/project/version/text()' pom.xml)

6
build_util/run_docker_tests Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
docker build --target tester -t rasilon/ujetl_tester docker/multistage
docker-compose -f docker/test_compose/docker-compose.yml run --rm tests
docker-compose -f docker/test_compose/docker-compose.yml down

View file

@ -0,0 +1,76 @@
CREATE OR REPLACE FUNCTION pg_temp.ujetl_insert(sch text, tabname text)
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
s text := '';
header text := '';
col_list text := '';
vals text := '';
sets text := '';
changes text := '';
is_first boolean := true;
colinfo record;
pks text;
begin
SELECT
array_to_string(array_agg(quote_ident(pg_attribute.attname::text) ),', ') into pks
FROM
pg_index,
pg_class,
pg_attribute,
pg_namespace
WHERE
pg_class.relname = tabname
AND indrelid = pg_class.oid
AND nspname = sch
AND pg_class.relnamespace = pg_namespace.oid
AND pg_attribute.attrelid = pg_class.oid
AND pg_attribute.attnum = any(pg_index.indkey)
AND indisprimary ;
header := E'INSERT INTO '||quote_ident(sch)||'.'||quote_ident(tabname)||E' as t (\n ';
for colinfo in
select
*
from
information_schema.columns
where
table_schema = sch
and table_name = tabname
order by ordinal_position
loop
if not is_first then
col_list := col_list || E',\n ';
vals := vals || E',\n ';
sets := sets || E',\n ';
changes := changes || E'\n OR ';
end if;
col_list := col_list || quote_ident(colinfo.column_name);
vals := vals || '?::' || colinfo.data_type;
sets := sets || quote_ident(colinfo.column_name) ||
E' = EXCLUDED.' || quote_ident(colinfo.column_name);
changes := changes || E't.' || quote_ident(colinfo.column_name) ||
E' IS DISTINCT FROM EXCLUDED.' || quote_ident(colinfo.column_name);
is_first = false;
end loop;
s := coalesce(header,'header failed') ||
coalesce(col_list,'col_list failed') ||
E'\n)VALUES(\n ' ||
coalesce(vals,'vals failed') ||
E')\nON CONFLICT(' || coalesce(pks,'No primary keys found') || E') DO UPDATE\nSET\n ' ||
coalesce(sets,'sets failed') ||
E'\nWHERE\n '||
coalesce(changes,'changes failed');
return s;
end;
$function$
;

View file

@ -0,0 +1,65 @@
CREATE OR REPLACE FUNCTION pg_temp.ujetl_select(sch text, tabname text)
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
s text := '';
header text := '';
col_list text := '';
vals text := '';
sets text := '';
changes text := '';
is_first boolean := true;
colinfo record;
pks text;
begin
SELECT
array_to_string(array_agg(quote_ident(pg_attribute.attname::text) ),', ') into pks
FROM
pg_index,
pg_class,
pg_attribute,
pg_namespace
WHERE
pg_class.relname = tabname
AND indrelid = pg_class.oid
AND nspname = sch
AND pg_class.relnamespace = pg_namespace.oid
AND pg_attribute.attrelid = pg_class.oid
AND pg_attribute.attnum = any(pg_index.indkey)
AND indisprimary ;
header := E'SELECT\n ';
for colinfo in
select
*
from
information_schema.columns
where
table_schema = sch
and table_name = tabname
order by ordinal_position
loop
if not is_first then
col_list := col_list || E',\n ';
end if;
col_list := col_list || quote_ident(colinfo.column_name);
is_first = false;
end loop;
s := header ||
coalesce(col_list,'col_list failed') ||
E'\nFROM\n ' ||
quote_ident(sch)||'.'||quote_ident(tabname)||E' as t \n '||
E'WHERE\n insert criteria here >= ?::datatype';
return s;
end;
$function$
;

View file

@ -3,7 +3,7 @@
# VERSION 0.0.1 # VERSION 0.0.1
FROM centos:centos7 FROM centos:centos7
MAINTAINER Derry Hamilton <derryh@postcodelottery.co.uk> MAINTAINER Derry Hamilton <derryh@rasilon.net>
# Install up-to-date epel rpm repository # Install up-to-date epel rpm repository
RUN yum -y install epel-release RUN yum -y install epel-release

View file

@ -0,0 +1,27 @@
FROM ubuntu:22.04 as builder
RUN apt-get update && apt-get -y upgrade
RUN apt-get -y install openjdk-19-jdk-headless maven git
RUN git clone --single-branch --branch main https://github.com/rasilon/ujetl.git
RUN cd ujetl && mvn -e package
FROM openjdk:11 as runner
LABEL maintainer="Derry Hamilton <derryh@rasilon.net>"
RUN apt update && apt upgrade -y && apt install -y bash
RUN mkdir -p /usr/share/ujetl/lib/ /var/ujetl /etc/ujetl
COPY --from=builder /ujetl/target/CopyingApp-2.*-jar-with-dependencies.jar /usr/share/ujetl/lib/CopyingApp.jar
COPY --from=builder /ujetl/install_extra/copying_defaults_log4j.xml /etc/ujetl/
COPY ujetl_entrypoint /
CMD ["/ujetl_entrypoint"]
FROM runner as tester
COPY TEST_config_live.xml /var/ujetl/
COPY wait_for_postgres /
RUN apt-get install -y postgresql-client
FROM runner as deploy
# Convice docker cloud to build the deploy image

View file

@ -0,0 +1,167 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<CopyingApp>
<hardLimitSeconds>360000</hardLimitSeconds>
<nRowsToLog>10000</nRowsToLog>
<blockSize>1000</blockSize>
<pollTimeout>500</pollTimeout>
<drivers>
<driver>org.postgresql.Driver</driver>
<driver>org.relique.jdbc.csv.CsvDriver</driver>
</drivers>
<source>
<dsn>jdbc:postgresql://testdb:5432/test</dsn>
<username>test</username>
<password>test</password>
<networkTimeout>600000</networkTimeout>
</source>
<dest>
<dsn>jdbc:postgresql://testdb:5432/test</dsn>
<username>test</username>
<password>test</password>
</dest>
<jobs>
<job>
<name>test</name>
<identifySourceSQL>select 'PID:'||pg_backend_pid()</identifySourceSQL>
<identifyDestinationSQL>select 'PID:'||pg_backend_pid()</identifyDestinationSQL>
<key>select coalesce(-1,max(id),-1) as key from dest</key>
<select>
select
id,
test_int,
test_text,
test_ts
from
public.source where id > ?::bigint</select>
<insert>
insert into public.dest(
id,
test_int,
test_text,
test_ts
)values(
?::bigint,
?::integer,
?::text,
?::timestamp with time zone
)ON CONFLICT(id) DO UPDATE
set
test_int = EXCLUDED.test_int,
test_text = EXCLUDED.test_text,
test_ts = EXCLUDED.test_ts
WHERE
dest.test_int = EXCLUDED.test_int
OR dest.test_text = EXCLUDED.test_text
OR dest.test_ts = EXCLUDED.test_ts
</insert>
</job>
<job>
<name>test upsert</name>
<identifySourceSQL>select 'PID:'||pg_backend_pid()</identifySourceSQL>
<identifyDestinationSQL>select 'PID:'||pg_backend_pid()</identifyDestinationSQL>
<key>select -1 as key</key>
<select>
select
id,
test_int,
test_text,
test_ts
from
public.source where id > ?::bigint</select>
<insert>
insert into public.dest(
id,
test_int,
test_text,
test_ts
)values(
?::bigint,
?::integer,
?::text,
?::timestamp with time zone
)ON CONFLICT(id) DO UPDATE
set
test_int = EXCLUDED.test_int,
test_text = EXCLUDED.test_text,
test_ts = EXCLUDED.test_ts
WHERE
dest.test_int IS DISTINCT FROM EXCLUDED.test_int
OR dest.test_text IS DISTINCT FROM EXCLUDED.test_text
OR dest.test_ts IS DISTINCT FROM EXCLUDED.test_ts
</insert>
</job>
<job>
<name>denormalise</name>
<identifySourceSQL>select 'PID:'||pg_backend_pid()</identifySourceSQL>
<identifyDestinationSQL>select 'PID:'||pg_backend_pid()</identifyDestinationSQL>
<key>select -1 as key</key>
<select>select person_id,fname,lname from normalised_personalia p join normalised_first_names f using(fid) join normalised_last_names l using(lid) where ?::integer is not null;</select>
<insert>
INSERT INTO denormalised_personalia(person_id,fname,lname)
values(?::integer,?::text,?::text)
ON CONFLICT (person_id) DO UPDATE
SET
fname = EXCLUDED.fname,
lname = EXCLUDED.lname
WHERE
denormalised_personalia.fname is distinct from EXCLUDED.fname
OR denormalised_personalia.lname is distinct from EXCLUDED.lname
</insert>
</job>
<job>
<name>test pre post</name>
<key>select -1 as key</key>
<select>
select
id,
test_int,
test_text,
test_ts
from
public.source where id > ?::bigint
</select>
<preTarget>
drop table if exists tmp_dest;
create temp table tmp_dest(
id bigint,
test_int integer,
test_text text,
test_ts timestamp with time zone
);
</preTarget>
<insert>
insert into tmp_dest(
id,
test_int,
test_text,
test_ts
)values(
?::bigint,
?::integer,
?::text,
?::timestamp with time zone
)
</insert>
<insert>
insert into public.dest(
id,
test_int,
test_text,
test_ts
)
select id,test_int,test_text,test_ts
from tmp_dest
ON CONFLICT(id) DO UPDATE
set
test_int = EXCLUDED.test_int,
test_text = EXCLUDED.test_text,
test_ts = EXCLUDED.test_ts
WHERE
dest.test_int IS DISTINCT FROM EXCLUDED.test_int
OR dest.test_text IS DISTINCT FROM EXCLUDED.test_text
OR dest.test_ts IS DISTINCT FROM EXCLUDED.test_ts
</insert>
</job>
</jobs>
</CopyingApp>

View file

@ -0,0 +1,4 @@
id,dat
1,banana
2,potato
3,nugget
1 id dat
2 1 banana
3 2 potato
4 3 nugget

View file

@ -0,0 +1,22 @@
#!/bin/bash
set -e
LOG_PROPS=/etc/ujetl/copying_defaults_log4j.xml
cd /var/ujetl
echo Currently in `pwd`
echo processing files:
ls
echo Starting run loop
for file in *.xml
do
/usr/local/openjdk-11/bin/java \
-Xms1g \
-Xmx2g \
-cp /usr/share/ujetl/lib/CopyingApp.jar \
-Dlog4j.configurationFile="$LOG_PROPS" \
com.rasilon.ujetl.CopyingApp \
--log4j "$LOG_PROPS" \
--config "$file"
done

View file

@ -0,0 +1,21 @@
#!/bin/bash
set -e
cmd="$@"
until PGPASSWORD=test psql -h "testdb" -U "test" -c 'SELECT 1 FROM public.container_ready' postgres; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - Waiting for the reboot"
sleep 3 # Wait for the Postgres reboot at the end of setup
until PGPASSWORD=test psql -h "testdb" -U "test" -c 'SELECT 1 FROM public.container_ready' postgres; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd

View file

@ -0,0 +1,23 @@
# This is a sample to help put the full application together
version: '3.3'
services:
testdb:
image: rasilon/ujetl_testdb:latest
build:
context: ../test_db
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
tests:
image: rasilon/ujetl_tester:latest
build:
context: ../multistage
links:
- "testdb"
command: ["/wait_for_postgres", "/ujetl_entrypoint"]

View file

@ -0,0 +1,3 @@
FROM postgres:11
COPY setup.sql /docker-entrypoint-initdb.d/
COPY is_ready /

3
docker/test_db/is_ready Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
/usr/lib/postgresql/9.6/bin/psql -U postgres -c "SELECT 1 FROM public.container_ready" postgres

58
docker/test_db/setup.sql Normal file
View file

@ -0,0 +1,58 @@
CREATE DATABASE test;
\c test
CREATE ROLE test login password 'test';
CREATE UNLOGGED TABLE source (
id bigserial primary key,
test_int integer,
test_text text,
test_ts timestamp with time zone
);
CREATE UNLOGGED TABLE dest (
id bigint primary key,
test_int integer,
test_text text,
test_ts timestamp with time zone
);
GRANT SELECT ON source to test;
GRANT SELECT,INSERT,UPDATE,DELETE ON dest TO test;
INSERT INTO source(test_int,test_text,test_ts) SELECT 1,'banana',now() FROM generate_series(1,100000);
CREATE TABLE normalised_first_names(
fid smallserial not null primary key,
fname text not null unique
);
CREATE TABLE normalised_last_names(
lid smallserial not null primary key,
lname text not null unique
);
INSERT INTO normalised_first_names (fname) values ('Abigail'), ('Adam'), ('Beatrice'), ('Bruce'), ('Claire'), ('Clive'), ('Deborah'), ('Dave');
INSERT INTO normalised_last_names (lname) values ('Adams'), ('Bellamy'), ('Clark'), ('Dabrowski');
CREATE TABLE normalised_personalia (
person_id serial not null primary key,
fid smallint not null references normalised_first_names(fid),
lid smallint not null references normalised_last_names(lid)
);
insert into normalised_personalia(fid,lid) values (1,1), (1,2), (1,3), (1,4), (2,1), (2,2), (2,3), (2,4), (3,1), (3,2), (3,3), (3,4), (4,1), (4,2), (4,3), (4,4);
CREATE TABLE denormalised_personalia(
person_id integer not null primary key,
fname text,
lname text
);
CREATE TABLE test_csvjdbc(
id integer not null primary key,
dat text
);
GRANT SELECT ON ALL TABLES IN SCHEMA public TO test;
GRANT SELECT,INSERT,UPDATE ON denormalised_personalia TO test;
\c postgres
CREATE TABLE public.container_ready AS SELECT 1 FROM(VALUES(1)) AS a(a);
GRANT SELECT ON public.container_ready TO TEST;

View file

@ -30,9 +30,9 @@ fi
/usr/bin/java \ /usr/bin/java \
-Xms1g \ -Xms1g \
-Xmx2g \ -Xmx2g \
-Dlog4j.configurationFile="$LOG_PROPS" \
-cp /usr/share/ujetl/lib/CopyingApp.jar \ -cp /usr/share/ujetl/lib/CopyingApp.jar \
com.rasilon.ujetl.CopyingApp \ com.rasilon.ujetl.CopyingApp \
--log4j "$LOG_PROPS" \
--config "/etc/ujetl/${JOBNAME}_config_live.xml" --config "/etc/ujetl/${JOBNAME}_config_live.xml"
#rm -f $LOCKFILE #rm -f $LOCKFILE

60
pom.xml
View file

@ -6,19 +6,42 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<groupId>com.rasilon.ujetl</groupId> <groupId>com.rasilon.ujetl</groupId>
<artifactId>CopyingApp</artifactId> <artifactId>CopyingApp</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>2.0.1</version> <version>2.5.2</version>
<name>uJETL</name> <name>uJETL</name>
<url></url> <url>https://github.com/rasilon/ujetl</url>
<properties>
<project.build.sourceEncoding>
UTF-8</project.build.sourceEncoding>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>4.12</version> <version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.220</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.9</version> <version>3.18.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-logging</groupId> <groupId>commons-logging</groupId>
@ -28,13 +51,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId> <artifactId>commons-configuration2</artifactId>
<version>2.4</version> <version>2.10.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
<dependency> <dependency>
<groupId>commons-beanutils</groupId> <groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId> <artifactId>commons-beanutils</artifactId>
<version>1.9.3</version> <version>1.11.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.beust</groupId> <groupId>com.beust</groupId>
@ -44,27 +66,31 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
<version>2.11.2</version> <version>2.17.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.11.2</version> <version>2.25.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>42.2.5</version> <version>42.7.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.csvjdbc</groupId>
<artifactId>csvjdbc</artifactId>
<version>1.0.40</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version> <version>3.8.0</version>
<configuration> <configuration>
<source>1.8</source> <release>11</release>
<target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -88,6 +114,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View file

@ -34,10 +34,6 @@ public class CopyingApp {
public static void main(String[] args) { public static void main(String[] args) {
CopyingAppCommandParser cli = new CopyingAppCommandParser(args); CopyingAppCommandParser cli = new CopyingAppCommandParser(args);
LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false); LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
String log4jConfigLocation = cli.getLog4jConfigFile();
File file = new File(log4jConfigLocation);
context.setConfigLocation(file.toURI());
System.out.println("Config set from "+file.toURI());
CopyingApp app = new CopyingApp(cli); CopyingApp app = new CopyingApp(cli);
try { try {
@ -79,6 +75,7 @@ public class CopyingApp {
Configuration config = configs.xml(cli.getConfigFile()); Configuration config = configs.xml(cli.getConfigFile());
loadDrivers(config);
String hardLimitSeconds = config.getString("hardLimitSeconds"); String hardLimitSeconds = config.getString("hardLimitSeconds");
if(hardLimitSeconds != null) { if(hardLimitSeconds != null) {
TimeLimiter hardLimit = new TimeLimiter(Integer.decode(hardLimitSeconds).intValue(),true); TimeLimiter hardLimit = new TimeLimiter(Integer.decode(hardLimitSeconds).intValue(),true);
@ -108,14 +105,14 @@ public class CopyingApp {
log.info(String.format("%s - Setting Row count interval to default of 100 rows.",jobName)); log.info(String.format("%s - Setting Row count interval to default of 100 rows.",jobName));
} }
Integer pollTimeout = null; Integer pollTimeout = null;
try { try {
pollTimeout = new Integer(config.getString("nRowsToLog")); pollTimeout = new Integer(config.getString("pollTimeout"));
log.info(String.format("%s - Setting Poll timeout to %s milliseconds", jobName, pollTimeout)); log.info(String.format("%s - Setting Poll timeout to %s milliseconds", jobName, pollTimeout));
} catch(Exception e) { } catch(Exception e) {
pollTimeout = new Integer(1000); // If we don't have a new setting, use the old default pollTimeout = new Integer(1000); // If we don't have a new setting, use the old default
log.info(String.format("%s - Setting poll timeout to default of 1 second.",jobName)); log.info(String.format("%s - Setting poll timeout to default of 1 second.",jobName));
} }
@ -131,7 +128,27 @@ public class CopyingApp {
String tabKey = config.getString("jobs.job("+i+").key"); String tabKey = config.getString("jobs.job("+i+").key");
String tabSelect = config.getString("jobs.job("+i+").select"); String tabSelect = config.getString("jobs.job("+i+").select");
String tabInsert = config.getString("jobs.job("+i+").insert"); String tabInsert = config.getString("jobs.job("+i+").insert");
Job j = new Job(sConn,dConn,tabName,jobName,tabKey,tabSelect,tabInsert,nRowsToLog,blockSize,pollTimeout); String preTarget = config.getString("jobs.job("+i+").preTarget");
String postTarget = config.getString("jobs.job("+i+").postTarget");
String identifySourceSQL = config.getString("jobs.job.identifySourceSQL");
String identifyDestinationSQL = config.getString("jobs.job.identifyDestinationSQL");
Job j = new Job(
sConn,
dConn,
tabName,
jobName,
tabKey,
tabSelect,
tabInsert,
preTarget,
postTarget,
nRowsToLog,
blockSize,
pollTimeout,
identifySourceSQL,
identifyDestinationSQL
);
j.start(); j.start();
j.join(); j.join();
@ -141,7 +158,28 @@ public class CopyingApp {
String tabKey = config.getString("jobs.job.key"); String tabKey = config.getString("jobs.job.key");
String tabSelect = config.getString("jobs.job.select"); String tabSelect = config.getString("jobs.job.select");
String tabInsert = config.getString("jobs.job.insert"); String tabInsert = config.getString("jobs.job.insert");
Job j = new Job(sConn,dConn,tabName,jobName,tabKey,tabSelect,tabInsert,nRowsToLog,blockSize,pollTimeout); String preTarget = config.getString("jobs.job.preTarget");
String postTarget = config.getString("jobs.job.postTarget");
String identifySourceSQL = config.getString("jobs.job.identifySourceSQL");
String identifyDestinationSQL = config.getString("jobs.job.identifyDestinationSQL");
Job j = new Job(
sConn,
dConn,
tabName,
jobName,
tabKey,
tabSelect,
tabInsert,
preTarget,
postTarget,
nRowsToLog,
blockSize,
pollTimeout,
identifySourceSQL,
identifyDestinationSQL
);
j.start(); j.start();
j.join(); j.join();
} else { } else {
@ -203,4 +241,21 @@ public class CopyingApp {
return c; return c;
} }
// Even with JDBC 4, some drivers don't play nicely with whatever
// the classloaders are up to. So this allows us to force it the
// old fashioned way, and works around the
// "But it works fine when it's the /only/ driver!"
// cross-database problem
private void loadDrivers(Configuration config) {
String[] drivers = config.get(String[].class, "drivers.driver");
for(String d:drivers) {
try {
Class.forName(d);
log.info("Preloaded driver "+d);
} catch(ClassNotFoundException e) {
log.error("Could not preload driver "+d,e);
}
}
}
} }

View file

@ -12,7 +12,7 @@ public class CopyingAppCommandParser {
private String configFile; private String configFile;
@Parameter(names = {"-log4j","--log4j"}, description = "Log4J config file for this run") @Parameter(names = {"-log4j","--log4j"}, description = "Log4J config file for this run")
private String log4jConfigFile = "/etc/ppl/default_log4j_config.properties"; private String log4jConfigFile = "/etc/ujetl/default_log4j_config.properties";
public CopyingAppCommandParser(String[] args) { public CopyingAppCommandParser(String[] args) {
super(); super();
@ -23,8 +23,4 @@ public class CopyingAppCommandParser {
return configFile; return configFile;
} }
public String getLog4jConfigFile() {
return log4jConfigFile;
}
} }

View file

@ -22,23 +22,29 @@ import org.apache.logging.log4j.Logger;
public class Job extends Thread { public class Job extends Thread {
static Logger log = org.apache.logging.log4j.LogManager.getLogger(Job.class); static Logger log = org.apache.logging.log4j.LogManager.getLogger(Job.class);
Connection sConn; private Connection sConn;
Connection dConn; private Connection dConn;
String name; private String name;
String jobName; private String jobName;
String key; private String key;
String select; private String select;
String insert; private String insert;
Integer nRowsToLog; private String preTarget;
Integer blockSize; private String postTarget;
Integer pollTimeout; private Integer nRowsToLog;
private Integer blockSize;
private Integer pollTimeout;
private String identifySourceSQL;
private String identifyDestinationSQL;
BlockingQueue<List<String>> resultBuffer; private BlockingQueue<List<String>> resultBuffer;
AtomicBoolean producerLive; private AtomicBoolean producerLive;
AtomicBoolean threadsExit = new AtomicBoolean(false);; private AtomicBoolean threadsExit = new AtomicBoolean(false);;
private String sourceID;
private String destID;
public Job(Connection sConn,Connection dConn,String name,String jobName,String key,String select,String insert,Integer nRowsToLog,Integer blockSize,Integer pollTimeout) { public Job(Connection sConn,Connection dConn,String name,String jobName,String key,String select,String insert,String preTarget,String postTarget,Integer nRowsToLog,Integer blockSize,Integer pollTimeout,String identifySourceSQL, String identifyDestinationSQL) {
this.sConn = sConn; this.sConn = sConn;
this.dConn = dConn; this.dConn = dConn;
this.name = name; this.name = name;
@ -46,9 +52,13 @@ public class Job extends Thread {
this.key = key; this.key = key;
this.select = select; this.select = select;
this.insert = insert; this.insert = insert;
this.preTarget = preTarget;
this.postTarget = postTarget;
this.nRowsToLog = nRowsToLog; this.nRowsToLog = nRowsToLog;
this.blockSize = blockSize; this.blockSize = blockSize;
this.pollTimeout = pollTimeout; this.pollTimeout = pollTimeout;
this.identifySourceSQL = identifySourceSQL;
this.identifyDestinationSQL = identifyDestinationSQL;
resultBuffer = new ArrayBlockingQueue<List<String>>( 3 * blockSize); resultBuffer = new ArrayBlockingQueue<List<String>>( 3 * blockSize);
producerLive = new AtomicBoolean(true); producerLive = new AtomicBoolean(true);
@ -72,12 +82,12 @@ public class Job extends Thread {
public Producer(ResultSet src,BlockingQueue q) { public Producer(ResultSet src,BlockingQueue q) {
this.src = src; this.src = src;
this.q = q; this.q = q;
this.setName(String.format("%s-%s-Consumer",jobName,name)); this.setName(String.format("%s-%s-Producer",jobName,name));
} }
public void run() { public void run() {
try { try {
long rowsInserted = 0; long rowsInserted = 0;
long rowNum = 0; long rowsAttempted = 0;
long stamp = System.nanoTime(); long stamp = System.nanoTime();
long nstamp; long nstamp;
int columnCount = src.getMetaData().getColumnCount(); int columnCount = src.getMetaData().getColumnCount();
@ -95,13 +105,13 @@ public class Job extends Thread {
} }
log.trace("Producer queue full."); log.trace("Producer queue full.");
} }
rowNum++; rowsAttempted++;
if(rowNum % nRowsToLog == 0) { if(rowsAttempted % nRowsToLog == 0) {
log.info(String.format("%s - Queued %s rows for %s so far",jobName,rowNum,name)); log.info(String.format("%s - Queued %s rows for %s so far",jobName,rowsAttempted,name));
} }
} }
producerLive.set(false); producerLive.set(false);
log.info(String.format("%s - Queued a total of %s rows for %s",jobName,rowNum,name)); log.info(String.format("%s - Queued a total of %s rows for %s",jobName,rowsAttempted,name));
} catch(Exception e) { } catch(Exception e) {
producerLive.set(false); // Signal we've exited. producerLive.set(false); // Signal we've exited.
threadsExit.set(true); // Signal we've exited. threadsExit.set(true); // Signal we've exited.
@ -122,7 +132,7 @@ public class Job extends Thread {
} }
public void run() { public void run() {
try { try {
long rowNum = 0; long rowsAttempted = 0;
long rowsInserted = 0; long rowsInserted = 0;
while(true) { while(true) {
@ -133,7 +143,7 @@ public class Job extends Thread {
if(row == null && producerLive.get() == false) { if(row == null && producerLive.get() == false) {
rowsInserted += arraySum(insertStatement.executeBatch()); rowsInserted += arraySum(insertStatement.executeBatch());
dConn.commit(); dConn.commit();
log.info(String.format("%s - Inserted a total of %s of %s notified rows into %s",jobName,rowNum,rowsInserted,name)); log.info(String.format("%s - Inserted a total of %s of %s notified rows into %s",jobName,rowsInserted,rowsAttempted,name));
return; return;
} }
if(threadsExit.get()) { if(threadsExit.get()) {
@ -150,14 +160,14 @@ public class Job extends Thread {
} }
insertStatement.addBatch(); insertStatement.addBatch();
rowNum++; rowsAttempted++;
if(rowNum % nRowsToLog == 0) { if(rowsAttempted % nRowsToLog == 0) {
rowsInserted += arraySum(insertStatement.executeBatch()); rowsInserted += arraySum(insertStatement.executeBatch());
dConn.commit(); dConn.commit();
log.info(String.format("%s - Inserted %s of %s notified rows into %s so far", log.info(String.format("%s - Inserted %s of %s notified rows into %s",
jobName, jobName,
rowNum,
rowsInserted, rowsInserted,
rowsAttempted,
name)); name));
} }
} }
@ -169,11 +179,34 @@ public class Job extends Thread {
} }
} }
// Outer run
public void run() { public void run() {
try { try {
ResultSet rs; ResultSet rs;
log.info(String.format("%s - Processing table: %s",jobName,name)); if(identifySourceSQL != null) sourceID = getSingleString(identifySourceSQL,sConn);
if(identifyDestinationSQL != null) destID = getSingleString(identifyDestinationSQL,dConn);
if(sourceID != null || destID != null){
log.info(String.format(
"%s - Processing table: %s with source: %s, dest: %s",
jobName,
name,
sourceID==null?"":sourceID,
destID==null?"":destID
));
}else{
log.info(String.format("%s - Processing table: %s",jobName,name));
}
if(preTarget != null){
log.info(String.format("%s - Trying to execute preTarget SQL",jobName));
PreparedStatement s = dConn.prepareStatement(preTarget);
s.executeUpdate();
s.close();
dConn.commit();
}else{
log.info(String.format("%s - No preTarget; skipping.",jobName));
}
log.debug("Trying to execute: "+key); log.debug("Trying to execute: "+key);
PreparedStatement keyStatement = dConn.prepareStatement(key); PreparedStatement keyStatement = dConn.prepareStatement(key);
@ -211,10 +244,33 @@ public class Job extends Thread {
p.join(); p.join();
c.join(); c.join();
if(postTarget != null){
log.info(String.format("%s - Trying to execute postTarget SQL",jobName));
PreparedStatement s = dConn.prepareStatement(postTarget);
s.executeUpdate();
s.close();
dConn.commit();
}else{
log.info(String.format("%s - No postTarget; skipping.",jobName));
}
} catch(InterruptedException e) { } catch(InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch(SQLException e) { } catch(SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private String getSingleString(String sql, Connection conn){
try{
PreparedStatement s = conn.prepareStatement(sql);
ResultSet r = s.executeQuery();
r.next();
return r.getString(1);
} catch(SQLException e) {
throw new RuntimeException(e);
}
}
} }

View file

@ -0,0 +1,37 @@
package com.rasilon.ujetl;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.beanutils.PropertyUtils; // Why does config need this?
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author derryh
*
*/
public class TestConfig {
@Test
public void test001VerifyArrayOfDrivers() {
try {
Configurations configs = new Configurations();
Configuration config = configs.xml("TEST_config_live.xml");
String[] drivers = config.get(String[].class, "drivers.driver");
int ndrivers =drivers.length;
if(ndrivers != 3){
fail("Expected 3 drivers, but found "+ndrivers);
}
} catch(Exception e) {
fail(e.toString());
}
}
}

View file

@ -0,0 +1,64 @@
package com.rasilon.ujetl;
import java.sql.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class TestJob {
private static String jdbcURL = "jdbc:h2:mem:dbtest";
@Test
public void test002verifyH2Works() {
try {
Connection conn = DriverManager.getConnection(jdbcURL, "sa", "");
conn.close();
} catch(Exception e) {
fail(e.toString());
}
}
@Test
public void testJob() {
try (
Connection src = DriverManager.getConnection(jdbcURL, "sa", "");
Connection dest = DriverManager.getConnection(jdbcURL, "sa", "");
) {
src.createStatement().executeUpdate("CREATE TABLE src(id bigint not null primary key, dat varchar);");
dest.createStatement().executeUpdate("CREATE TABLE dest(id bigint not null primary key, dat varchar);");
PreparedStatement inserter = src.prepareStatement("INSERT INTO src(id,dat) VALUES(?,'banana')");
for(int i=0; i<10000; i++) {
inserter.setInt(1,i);
inserter.executeUpdate();
}
Job j = new Job(
src,
dest,
"jUnit Test Config",
"jUnit Test Job",
"SELECT -1 AS \"key\"",
"SELECT id,dat FROM src WHERE id > ?",
"INSERT INTO dest VALUES(?,?)",
null,
null,
100,
100,
100,
"select 'PID:'||session_id()",
"select 'PID:'||session_id()"
);
j.start();
j.join();
// do stuff
} catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
}

View file

@ -0,0 +1,27 @@
package com.rasilon.ujetl;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class TestParser {
@Test
public void test001Parset() {
try {
String[] args = {
"--config",
"config_test_banana.xml"
};
CopyingAppCommandParser p = new CopyingAppCommandParser(args);
assertEquals(p.getConfigFile(),"config_test_banana.xml");
} catch(Exception e) {
fail(e.toString());
}
}
}

View file

@ -0,0 +1,64 @@
package com.rasilon.ujetl;
import java.sql.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class TestPrePost {
private static String jdbcURL = "jdbc:h2:mem:dbtest";
@Test
public void test002verifyH2Works() {
try {
Connection conn = DriverManager.getConnection(jdbcURL, "sa", "");
conn.close();
} catch(Exception e) {
fail(e.toString());
}
}
@Test
public void testPrePost() {
try (
Connection src = DriverManager.getConnection(jdbcURL, "sa", "");
Connection dest = DriverManager.getConnection(jdbcURL, "sa", "");
) {
src.createStatement().executeUpdate("CREATE TABLE src(id bigint not null primary key, dat varchar);");
dest.createStatement().executeUpdate("CREATE TABLE dest(id bigint not null primary key, dat varchar);");
PreparedStatement inserter = src.prepareStatement("INSERT INTO src(id,dat) VALUES(?,'banana')");
for(int i=0; i<10000; i++) {
inserter.setInt(1,i);
inserter.executeUpdate();
}
Job j = new Job(
src,
dest,
"jUnit Test Config",
"jUnit Test Job",
"SELECT -1 AS \"key\"",
"SELECT id,dat FROM src WHERE id > ?",
"INSERT INTO tmp_dest VALUES(?,?)",
"CREATE TEMP TABLE tmp_dest(id bigint not null primary key, dat varchar);",
"INSERT INTO dest SELECT * from tmp_dest;",
100,
100,
100,
"select 'PID:'||session_id()",
"select 'PID:'||session_id()"
);
j.start();
j.join();
// do stuff
} catch(Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
}

View file

@ -0,0 +1,28 @@
package com.rasilon.ujetl;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class TestTimeLimiter {
@Test
public void test001Limiter() {
try {
TimeLimiter hardLimit = new TimeLimiter(1,false);
hardLimit.start();
Thread.sleep(10000);
fail("Sleep wasn't interrupted by the limiter!");
} catch(java.lang.InterruptedException e) {
// Pass
} catch(Exception e) {
e.printStackTrace();
fail("Unexpected exception.");
}
}
}

View file

@ -3,6 +3,12 @@
<hardLimitSeconds>360000</hardLimitSeconds> <hardLimitSeconds>360000</hardLimitSeconds>
<nRowsToLog>10000</nRowsToLog> <nRowsToLog>10000</nRowsToLog>
<blockSize>1000</blockSize> <blockSize>1000</blockSize>
<pollTimeout>500</pollTimeout>
<drivers>
<driver>org.postgresql.Driver</driver>
<driver>org.h2.Driver</driver>
<driver>org.relique.jdbc.csv.CsvDriver</driver>
</drivers>
<source> <source>
<dsn>jdbc:postgresql://localhost:5432/test</dsn> <dsn>jdbc:postgresql://localhost:5432/test</dsn>
<username>test</username> <username>test</username>
@ -17,6 +23,8 @@
<jobs> <jobs>
<job> <job>
<name>test</name> <name>test</name>
<identifySourceSQL>select 'PID:'||pg_backend_pid()</identifySourceSQL>
<identifyDestinationSQL>select 'PID:'||pg_backend_pid()</identifyDestinationSQL>
<key>select coalesce(-1,max(id),-1) as key from dest</key> <key>select coalesce(-1,max(id),-1) as key from dest</key>
<select> <select>
select select
@ -48,5 +56,54 @@
OR dest.test_ts = EXCLUDED.test_ts OR dest.test_ts = EXCLUDED.test_ts
</insert> </insert>
</job> </job>
<job>
<name>test upsert</name>
<key>select -1 as key</key>
<select>
select
id,
test_int,
test_text,
test_ts
from
public.source where id > ?::bigint</select>
<insert>
insert into public.dest(
id,
test_int,
test_text,
test_ts
)values(
?::bigint,
?::integer,
?::text,
?::timestamp with time zone
)ON CONFLICT(id) DO UPDATE
set
test_int = EXCLUDED.test_int,
test_text = EXCLUDED.test_text,
test_ts = EXCLUDED.test_ts
WHERE
dest.test_int IS DISTINCT FROM EXCLUDED.test_int
OR dest.test_text IS DISTINCT FROM EXCLUDED.test_text
OR dest.test_ts IS DISTINCT FROM EXCLUDED.test_ts
</insert>
</job>
<job>
<name>denormalise</name>
<key>select -1 as key</key>
<select>select person_id,fname,lname from normalised_personalia p join normalised_first_names f using(fid) join normalised_last_names l using(lid);</select>
<insert>
INSERT INTO denormalised_personalia(person_id,fname,lname)
values(?::integer,?::text,?::text)
ON CONFLICT (person_id) DO UPDATE
SET
fname = EXCLUDED.fname,
lname = EXCLUDED.lname
WHERE
denormalised_personalia.fname is distinct from EXCLUDED.fname
OR denormalised_personalia.lname is distinct from EXCLUDED.lname
</insert>
</job>
</jobs> </jobs>
</CopyingApp> </CopyingApp>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View file

@ -1,33 +0,0 @@
Summary: Java app to facilitate moving data between databases.
Name: uJETL
Version: 2.0.1
Release: 1
Group: Applications/Database
License: All rights reserved.
Source: uJETL-%{version}.tar.gz
URL: https://github.com/rasilon/ujetl.git
Distribution: derryh
Vendor: derryh
Packager: Derry Hamilton <derryh@rasilon.net>
#BuildRoot: .
%description
A very small ETL app
%prep
%setup
%build
#mvn -Dmaven.test.skip=true clean package
true
%install
mkdir -p $RPM_BUILD_ROOT/usr/share/ujetl/lib $RPM_BUILD_ROOT/etc/ujetl $RPM_BUILD_ROOT/usr/bin
cp target/CopyingApp-*-jar-with-dependencies.jar $RPM_BUILD_ROOT/usr/share/ujetl/lib/CopyingApp.jar
cp install_extra/run_copying_job $RPM_BUILD_ROOT/usr/bin
cp install_extra/copying_defaults_log4j.xml $RPM_BUILD_ROOT/etc/ujetl
%files
/usr/share/ujetl/lib/CopyingApp.jar
/usr/bin/run_copying_job
/etc/ujetl/copying_defaults_log4j.xml