Merge pull request #22 from rasilon/dev

New Features
This commit is contained in:
Derry Hamilton 2023-07-12 08:58:52 +01:00 committed by GitHub
commit 58b78b2021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 91 additions and 24 deletions

View file

@ -4,6 +4,11 @@
<nRowsToLog>10000</nRowsToLog> <nRowsToLog>10000</nRowsToLog>
<blockSize>1000</blockSize> <blockSize>1000</blockSize>
<pollTimeout>500</pollTimeout> <pollTimeout>500</pollTimeout>
<drivers>
<driver>org.postgresql.Driver</driver>
<driver>org.relique.jdbc.csv.CsvDriver</driver>
</drivers>
<source> <source>
<dsn>jdbc:postgresql://testdb:5432/test</dsn> <dsn>jdbc:postgresql://testdb:5432/test</dsn>
<username>test</username> <username>test</username>

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

@ -44,10 +44,14 @@ CREATE TABLE denormalised_personalia(
lname 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 ON ALL TABLES IN SCHEMA public TO test;
GRANT SELECT,INSERT,UPDATE ON denormalised_personalia TO test; GRANT SELECT,INSERT,UPDATE ON denormalised_personalia TO test;
\c postgres \c postgres
CREATE TABLE public.container_ready AS SELECT 1 FROM(VALUES(1)) AS a(a); CREATE TABLE public.container_ready AS SELECT 1 FROM(VALUES(1)) AS a(a);
GRANT SELECT ON public.container_ready TO TEST; 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.configuration=file:"$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

View file

@ -6,7 +6,7 @@ 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.4.4</version> <version>2.5.0</version>
<name>uJETL</name> <name>uJETL</name>
<url>https://github.com/rasilon/ujetl</url> <url>https://github.com/rasilon/ujetl</url>
<properties> <properties>
@ -78,6 +78,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>42.4.3</version> <version>42.4.3</version>
</dependency> </dependency>
<dependency>
<groupId>net.sourceforge.csvjdbc</groupId>
<artifactId>csvjdbc</artifactId>
<version>1.0.40</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

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);
@ -244,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

@ -23,8 +23,4 @@ public class CopyingAppCommandParser {
return configFile; return configFile;
} }
public String getLog4jConfigFile() {
return log4jConfigFile;
}
} }

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

@ -13,15 +13,12 @@ public class TestParser {
public void test001Parset() { public void test001Parset() {
try { try {
String[] args = { String[] args = {
"--log4j",
"log4j_test_banana.xml",
"--config", "--config",
"config_test_banana.xml" "config_test_banana.xml"
}; };
CopyingAppCommandParser p = new CopyingAppCommandParser(args); CopyingAppCommandParser p = new CopyingAppCommandParser(args);
assertEquals(p.getConfigFile(),"config_test_banana.xml"); assertEquals(p.getConfigFile(),"config_test_banana.xml");
assertEquals(p.getLog4jConfigFile(),"log4j_test_banana.xml");
} catch(Exception e) { } catch(Exception e) {
fail(e.toString()); fail(e.toString());

View file

@ -4,6 +4,11 @@
<nRowsToLog>10000</nRowsToLog> <nRowsToLog>10000</nRowsToLog>
<blockSize>1000</blockSize> <blockSize>1000</blockSize>
<pollTimeout>500</pollTimeout> <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>