diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/boostrap.conf.sample b/JeMPI_Apps/JeMPI_Bootstrapper/boostrap.conf.sample
index feb74c74b..1efeeef99 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/boostrap.conf.sample
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/boostrap.conf.sample
@@ -2,7 +2,10 @@ POSTGRESQL_IP=127.0.0.1
POSTGRESQL_PORT=5432
POSTGRESQL_USER=postgres
POSTGRESQL_PASSWORD=
-POSTGRESQL_PASSWORD=jempi
+POSTGRESQL_USERS_DB=
+POSTGRESQL_NOTIFICATIONS_DB=
+POSTGRESQL_AUDIT_DB=
+POSTGRESQL_KC_TEST_DB=
KAFKA_BOOTSTRAP_SERVERS=127.0.0.1
KAFKA_APPLICATION_ID=aId
DGRAPH_HOSTS=127.0.0.1
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/build.sh b/JeMPI_Apps/JeMPI_Bootstrapper/build.sh
new file mode 100755
index 000000000..c8b32e1a8
--- /dev/null
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/build.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -e
+set -u
+
+source $PROJECT_DEVOPS_DIR/conf/images/conf-app-images.sh
+source ../build-check-jdk.sh
+
+JAR_FILE=${BOOTSTRAPPER_JAR}
+APP_IMAGE=${BOOTSTRAPPER_IMAGE}
+APP=bootstrapper
+
+source ../build-app-image.sh
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/checkstyle/suppression.xml b/JeMPI_Apps/JeMPI_Bootstrapper/checkstyle/suppression.xml
new file mode 100644
index 000000000..062da494b
--- /dev/null
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/checkstyle/suppression.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/docker/.gitignore b/JeMPI_Apps/JeMPI_Bootstrapper/docker/.gitignore
new file mode 100644
index 000000000..c9d5c946a
--- /dev/null
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/docker/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!Dockerfile
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/docker/Dockerfile b/JeMPI_Apps/JeMPI_Bootstrapper/docker/Dockerfile
new file mode 100644
index 000000000..02a528f6c
--- /dev/null
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/docker/Dockerfile
@@ -0,0 +1,14 @@
+ARG JAVA_VERSION
+
+FROM eclipse-temurin:${JAVA_VERSION}-jre
+
+ADD Bootstrapper-1.0-SNAPSHOT-spring-boot.jar /app/Bootstrapper-1.0-SNAPSHOT-spring-boot.jar
+
+RUN printf "#!/bin/bash\n\
+cd /app\n\
+java_args=\"\${@:1}\" \n\
+java --enable-preview -XX:MaxRAMPercentage=80 -XX:+UseZGC -jar /app/Bootstrapper-1.0-SNAPSHOT-spring-boot.jar \$java_args \n" > /bootstrapper.sh
+
+RUN chmod +x /bootstrapper.sh
+
+ENTRYPOINT tail -f /dev/null
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/pom.xml b/JeMPI_Apps/JeMPI_Bootstrapper/pom.xml
index e9726ceb4..b64181841 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/pom.xml
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/pom.xml
@@ -10,7 +10,7 @@
1.0-SNAPSHOT
- JeMPI_Bootstrapper
+ Bootstrapper
jar
@@ -124,7 +124,42 @@
-
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+
+ validate
+ compile
+
+ checkstyle/suppression.xml
+
+
+ check
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${version.org.springframework.boot.spring-boot-maven-plugin}
+
+
+
+ repackage
+
+
+ spring-boot
+ ${start-class}
+
+
+
+
+
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/push.sh b/JeMPI_Apps/JeMPI_Bootstrapper/push.sh
new file mode 100755
index 000000000..b757c151c
--- /dev/null
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/push.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+set -e
+set -u
+
+source $PROJECT_DEVOPS_DIR/conf.env
+source $PROJECT_DEVOPS_DIR/conf/images/conf-app-images.sh
+
+APP_IMAGE=$BOOTSTRAPPER_IMAGE
+
+docker tag ${APP_IMAGE} ${REGISTRY_NODE_IP}/${APP_IMAGE}
+docker push ${REGISTRY_NODE_IP}/${APP_IMAGE}
+docker rmi ${REGISTRY_NODE_IP}/${APP_IMAGE}
+
\ No newline at end of file
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperCLI.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperCLI.java
index c8b78ab41..cbafd68af 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperCLI.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperCLI.java
@@ -4,14 +4,14 @@
import picocli.CommandLine;
import picocli.CommandLine.Command;
-@Command(mixinStandardHelpOptions = true, subcommands = {CLI.class,})
+@Command(mixinStandardHelpOptions = true, subcommands = {CLI.class})
public class BootstrapperCLI implements Runnable {
@CommandLine.Option(names = {"-c", "--config"}, description = "Config file")
private String config;
- public static void main(String... args) {
+ public static void main(final String... args) {
int exitCode = new CommandLine(new BootstrapperCLI()).execute(args);
System.exit(exitCode);
}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperConfig.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperConfig.java
index 7fb45e5a0..421c45897 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperConfig.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/BootstrapperConfig.java
@@ -9,22 +9,32 @@
public class BootstrapperConfig {
- public final String POSTGRESQL_IP;
+ public final String POSTGRESQL_IP;
public final Integer POSTGRESQL_PORT;
public final String POSTGRESQL_USER;
public final String POSTGRESQL_PASSWORD;
public final String POSTGRESQL_DATABASE;
+ public final String POSTGRESQL_USERS_DB;
+ public final String POSTGRESQL_NOTIFICATIONS_DB;
+ public final String POSTGRESQL_AUDIT_DB;
+ public final String POSTGRESQL_KC_TEST_DB;
public final String KAFKA_BOOTSTRAP_SERVERS;
public final String KAFKA_APPLICATION_ID;
public final String[] DGRAPH_ALPHA_HOSTS;
public final int[] DGRAPH_ALPHA_PORTS;
- public BootstrapperConfig(Config parsedConfig) {
+ public BootstrapperConfig(final Config parsedConfig) {
POSTGRESQL_IP = parsedConfig.getString("POSTGRESQL_IP");
POSTGRESQL_PORT = parsedConfig.getInt("POSTGRESQL_PORT");
POSTGRESQL_USER = parsedConfig.getString("POSTGRESQL_USER");
POSTGRESQL_PASSWORD = parsedConfig.getString("POSTGRESQL_PASSWORD");
+
POSTGRESQL_DATABASE = parsedConfig.getString("POSTGRESQL_DATABASE");
+ POSTGRESQL_USERS_DB = parsedConfig.getString("POSTGRESQL_USERS_DB");
+ POSTGRESQL_NOTIFICATIONS_DB = parsedConfig.getString("POSTGRESQL_NOTIFICATIONS_DB");
+ POSTGRESQL_AUDIT_DB = parsedConfig.getString("POSTGRESQL_AUDIT_DB");
+ POSTGRESQL_KC_TEST_DB = parsedConfig.getString("POSTGRESQL_KC_TEST_DB");
+
KAFKA_BOOTSTRAP_SERVERS = parsedConfig.getString("KAFKA_BOOTSTRAP_SERVERS");
KAFKA_APPLICATION_ID = parsedConfig.getString("KAFKA_APPLICATION_ID");
DGRAPH_ALPHA_HOSTS = parsedConfig.getString("DGRAPH_HOSTS").split(",");
@@ -38,9 +48,9 @@ public BootstrapperConfig(Config parsedConfig) {
}
public static BootstrapperConfig create(
- String filepath,
- Logger LOGGER) {
- return new BootstrapperConfig(new Builder(LOGGER).withOptionalFile(filepath)
+ final String filepath,
+ final Logger logger) {
+ return new BootstrapperConfig(new Builder(logger).withOptionalFile(filepath)
.withSystemEnvironment()
.withSystemProperties()
.build());
@@ -53,7 +63,7 @@ private static class Builder {
private final Logger logger;
private Config conf = ConfigFactory.empty();
- public Builder(Logger logger) {
+ Builder(final Logger logger) {
this.logger = logger;
}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/BaseDataBootstrapperCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/BaseDataBootstrapperCommand.java
index d65fb1e7f..ff515da6c 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/BaseDataBootstrapperCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/BaseDataBootstrapperCommand.java
@@ -19,7 +19,7 @@ public BaseDataBootstrapperCommand init() throws Exception {
return this;
}
- protected Integer execute(Callable bootstrapperFunc) {
+ protected Integer execute(final Callable bootstrapperFunc) {
try {
Integer bootstrapperResult = bootstrapperFunc.call();
if (bootstrapperResult != 0) {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/BaseCLICommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/BaseCLICommand.java
index fd631ce3b..b31a30440 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/BaseCLICommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/BaseCLICommand.java
@@ -14,15 +14,15 @@ public BaseCLICommand init() throws Exception {
}
@Override
- protected DataBootstrapper getBootstrapper(String configPath) {
+ protected DataBootstrapper getBootstrapper(final String configPath) {
return null;
}
- protected Integer callMultiple(BaseDataBootstrapperCommand[] bootstrapperCommands) throws Exception {
+ protected Integer callMultiple(final BaseDataBootstrapperCommand[] bootstrapperCommands) throws Exception {
Integer execResult = 0;
for (BaseDataBootstrapperCommand b : bootstrapperCommands) {
execResult += b.setConfigPath(this.config).init().call();
}
return execResult;
}
-}
\ No newline at end of file
+}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CLI.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CLI.java
index 1911f73c6..cff5d187b 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CLI.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CLI.java
@@ -7,8 +7,7 @@
import picocli.CommandLine.Command;
@Command(name = "data", mixinStandardHelpOptions = true, subcommands = {KafkaCLI.class, DgraphCLI.class, PostgresCLI.class,
- ResetAllCommand.class, DeleteAllSchemaDataCommand.class
- , CreateAllSchemaDataCommand.class})
+ ResetAllCommand.class, DeleteAllSchemaDataCommand.class, CreateAllSchemaDataCommand.class})
public class CLI {
@CommandLine.Option(names = {"-c", "--config"}, description = "Config file")
private String config;
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CreateAllSchemaDataCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CreateAllSchemaDataCommand.java
index 8aa7ceedc..7545d39aa 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CreateAllSchemaDataCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/CreateAllSchemaDataCommand.java
@@ -8,8 +8,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required " +
- "schema's and data for JeMPI.")
+@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required "
+ + "schema's and data for JeMPI.")
public class CreateAllSchemaDataCommand extends BaseCLICommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/DeleteAllSchemaDataCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/DeleteAllSchemaDataCommand.java
index e424c754d..d5048730c 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/DeleteAllSchemaDataCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/DeleteAllSchemaDataCommand.java
@@ -8,8 +8,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "deleteAllSchemaData", mixinStandardHelpOptions = true, description = "Delete all the data and " +
- "schema used by JeMPI.")
+@CommandLine.Command(name = "deleteAllSchemaData", mixinStandardHelpOptions = true, description = "Delete all the data and "
+ + "schema used by JeMPI.")
public class DeleteAllSchemaDataCommand extends BaseCLICommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/ResetAllCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/ResetAllCommand.java
index 6cf72b1d2..a4a2005c3 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/ResetAllCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/cli/ResetAllCommand.java
@@ -8,9 +8,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated" +
- " with JeMPI, then recreates schemas, " +
- "and add initial data.")
+@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated"
+ + " with JeMPI, then recreates schemas, and add initial data.")
public class ResetAllCommand extends BaseCLICommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/BaseDgraphCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/BaseDgraphCommand.java
index 7931ef715..b6fd634ca 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/BaseDgraphCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/BaseDgraphCommand.java
@@ -7,7 +7,7 @@
public abstract class BaseDgraphCommand extends BaseDataBootstrapperCommand implements Callable {
@Override
- protected DgraphDataBootstrapper getBootstrapper(String configPath) {
+ protected DgraphDataBootstrapper getBootstrapper(final String configPath) {
return new DgraphDataBootstrapper(configPath);
}
}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphCreateAllSchemaDataCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphCreateAllSchemaDataCommand.java
index 7661ee0b7..f423fcf84 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphCreateAllSchemaDataCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphCreateAllSchemaDataCommand.java
@@ -4,9 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required " +
- "schema's and data for JeMPI " +
- "Dgraph instance.")
+@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required "
+ + "schema's and data for JeMPI Dgraph instance.")
public class DgraphCreateAllSchemaDataCommand extends BaseDgraphCommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphDeleteAllCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphDeleteAllCommand.java
index 2d2775de4..02c7540ed 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphDeleteAllCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphDeleteAllCommand.java
@@ -4,8 +4,7 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "deleteAll", mixinStandardHelpOptions = true, description = "Delete all the data and schema used by" +
- " JeMPI Dgraph instance.")
+@CommandLine.Command(name = "deleteAll", mixinStandardHelpOptions = true, description = "Delete all the data and schema used by JeMPI Dgraph instance.")
public class DgraphDeleteAllCommand extends BaseDgraphCommand implements Callable {
@Override
public Integer call() throws Exception {
@@ -14,4 +13,4 @@ public Integer call() throws Exception {
? 0
: 1);
}
-}
\ No newline at end of file
+}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphResetAllCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphResetAllCommand.java
index 68a633b01..08ac5c4f4 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphResetAllCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/graph/dgraph/cli/DgraphResetAllCommand.java
@@ -4,9 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated" +
- " with JeMPI Dgraph instance, then " +
- "recreates schemas, and add initial data.")
+@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated"
+ + " with JeMPI Dgraph instance, then recreates schemas, and add initial data.")
public class DgraphResetAllCommand extends BaseDgraphCommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDALLib.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDALLib.java
index 7f3134125..12f61421f 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDALLib.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDALLib.java
@@ -1,43 +1,80 @@
package org.jembi.jempi.bootstrapper.data.sql.postgres;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
+import java.sql.*;
import java.util.Locale;
public class PostgresDALLib {
- private final String url;
private final String usr;
private final String psw;
+ private final String ip;
+ private final String defaultDb;
+ private final int port;
public PostgresDALLib(
final String ip,
final int port,
- final String db,
final String usr,
+ final String db,
final String psw) {
- this.url = String.format(Locale.ROOT, "jdbc:postgresql://%s:%d/%s", ip, port, db);
+ this.ip = ip;
+ this.port = port;
+ this.defaultDb = db;
this.usr = usr;
this.psw = psw;
}
- private Connection getConnection() throws SQLException {
- return DriverManager.getConnection(this.url, this.usr, this.psw);
+ private String getDbUrl(final String db) {
+ return String.format(Locale.ROOT, "jdbc:postgresql://%s:%d/%s", ip, port, db);
+ }
+ private Connection getConnection(final String dbName) throws SQLException {
+ return DriverManager.getConnection(getDbUrl(dbName != null ? dbName : defaultDb), this.usr, this.psw);
+ }
+
+ public Boolean createDb(final String dbName) throws SQLException {
+ if (!databaseExists(dbName)) {
+ return runQuery(connection -> {
+ return connection.prepareStatement(getCreateDbSchema(dbName));
+ }, true, null);
+ }
+ return true;
+ }
+
+ protected boolean databaseExists(final String databaseName) throws SQLException {
+ String query = "SELECT 1 FROM pg_database WHERE datname = ?";
+ try (PreparedStatement preparedStatement = getConnection(null).prepareStatement(query)) {
+ preparedStatement.setString(1, databaseName);
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ return resultSet.next();
+ }
+ }
+ }
+ public String getCreateDbSchema(final String dbName) {
+ return String.format("""
+ CREATE DATABASE %s
+ """, dbName);
}
- public Boolean runQuery(final ThrowingFunction getStatement) throws SQLException {
- try (Connection connection = this.getConnection()) {
- connection.setAutoCommit(false);
+ public Boolean runQuery(final ThrowingFunction getStatement, final Boolean autoCommit, final String dbName) throws SQLException {
+ try (Connection connection = this.getConnection(dbName)) {
+ connection.setAutoCommit(autoCommit);
try {
T statement = getStatement.apply(connection);
- statement.executeUpdate();
- connection.commit();
+ if (statement != null) {
+ statement.executeUpdate();
+ if (!autoCommit) {
+ connection.commit();
+ }
+
+ }
+
return true;
} catch (SQLException e) {
- connection.rollback();
+ if (!autoCommit) {
+ connection.rollback();
+ }
+
throw e;
}
} catch (SQLException e) {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDataBootstrapper.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDataBootstrapper.java
index f78597b55..a0ed29ab6 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDataBootstrapper.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/PostgresDataBootstrapper.java
@@ -8,33 +8,58 @@
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
+import java.util.List;
import java.util.stream.Collectors;
public class PostgresDataBootstrapper extends DataBootstrapper {
+
+ private record DBSchemaDetails(String dbName, String schemaFilePath) { }
private final PostgresDALLib postgresDALLib;
public PostgresDataBootstrapper(final String configFilePath) {
super(configFilePath);
postgresDALLib = new PostgresDALLib(this.loadedConfig.POSTGRESQL_IP,
this.loadedConfig.POSTGRESQL_PORT,
- this.loadedConfig.POSTGRESQL_DATABASE,
+ this.loadedConfig.POSTGRESQL_USER,
this.loadedConfig.POSTGRESQL_USER,
this.loadedConfig.POSTGRESQL_PASSWORD);
}
- protected String getCreateSchemaScript() {
- InputStream postgresSchemaScript = this.getClass().getResourceAsStream(DataBootstraperConsts.POSTGRES_INIT_SCHEMA_SQL);
+ protected String getCreateSchemaScript(final String fileName) {
+ InputStream postgresSchemaScript = this.getClass().getResourceAsStream(fileName);
return new BufferedReader(new InputStreamReader(postgresSchemaScript, StandardCharsets.UTF_8)).lines()
.collect(Collectors.joining(
"\n"));
}
+ protected List getAllDbSchemas() {
+ return List.of(
+ new DBSchemaDetails(this.loadedConfig.POSTGRESQL_USERS_DB, DataBootstraperConsts.POSTGRES_INIT_SCHEMA_USERS_DB),
+ new DBSchemaDetails(this.loadedConfig.POSTGRESQL_NOTIFICATIONS_DB, DataBootstraperConsts.POSTGRES_INIT_SCHEMA_NOTIFICATION_DB),
+ new DBSchemaDetails(this.loadedConfig.POSTGRESQL_AUDIT_DB, DataBootstraperConsts.POSTGRES_INIT_SCHEMA_AUDIT_DB),
+ new DBSchemaDetails(this.loadedConfig.POSTGRESQL_KC_TEST_DB, null)
+ );
+ }
@Override
public Boolean createSchema() throws SQLException {
LOGGER.info("Loading Postgres schema data.");
- return postgresDALLib.runQuery(connection -> {
- return connection.prepareStatement(getCreateSchemaScript());
- });
+
+ for (DBSchemaDetails schemaDetails: getAllDbSchemas()) {
+ String dbName = schemaDetails.dbName();
+ String dbSchemaFilePath = schemaDetails.schemaFilePath();
+
+ LOGGER.info(String.format("---> Create schema for database %s", dbName));
+
+ postgresDALLib.createDb(dbName);
+
+ if (dbSchemaFilePath != null) {
+ postgresDALLib.runQuery(connection -> connection.prepareStatement(getCreateSchemaScript(dbSchemaFilePath)),
+ true,
+ dbName);
+ }
+
+ }
+ return true;
}
protected String getAllTablesWrapper(final String innerQuery) {
@@ -47,7 +72,7 @@ protected String getAllTablesWrapper(final String innerQuery) {
FOR table_name IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public')
LOOP
EXECUTE %s
- END LOOP;
+ END LOOP;
END $$;
SET session_replication_role = DEFAULT;
""", innerQuery);
@@ -55,15 +80,35 @@ FOR table_name IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public')
public Boolean deleteTables() throws SQLException {
LOGGER.info("Deleting Postgres tables");
- return postgresDALLib.runQuery(connection -> connection.prepareStatement(this.getAllTablesWrapper(
- "'DROP TABLE ' || table_name || ' CASCADE ;';")));
+ for (DBSchemaDetails schemaDetails: getAllDbSchemas()) {
+ String dbName = schemaDetails.dbName();
+ if (postgresDALLib.databaseExists(dbName)) {
+ LOGGER.info(String.format("---> Deleting tables for database %s", dbName));
+ postgresDALLib.runQuery(connection -> {
+ return connection.prepareStatement(this.getAllTablesWrapper(
+ "'DROP TABLE ' || table_name || ' CASCADE ;';"));
+
+ }, true, dbName);
+ }
+ }
+ return true;
}
@Override
public Boolean deleteData() throws SQLException {
LOGGER.info("Deleting Postgres data");
- return postgresDALLib.runQuery(connection -> connection.prepareStatement(this.getAllTablesWrapper(
- "'DELETE FROM ' || table_name || ';';")));
+ for (DBSchemaDetails schemaDetails: getAllDbSchemas()) {
+ String dbName = schemaDetails.dbName();
+ if (postgresDALLib.databaseExists(dbName)) {
+ LOGGER.info(String.format("---> Deleting data for database %s", dbName));
+ postgresDALLib.runQuery(connection -> {
+ return connection.prepareStatement(this.getAllTablesWrapper(
+ "'DELETE FROM ' || table_name || ';';"));
+
+ }, true, dbName);
+ }
+ }
+ return true;
}
@Override
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/BasePostgresCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/BasePostgresCommand.java
index cb5c6996d..2b6b36f69 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/BasePostgresCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/BasePostgresCommand.java
@@ -7,7 +7,7 @@
public abstract class BasePostgresCommand extends BaseDataBootstrapperCommand implements Callable {
@Override
- protected PostgresDataBootstrapper getBootstrapper(String configPath) {
+ protected PostgresDataBootstrapper getBootstrapper(final String configPath) {
return new PostgresDataBootstrapper(configPath);
}
}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresCreateAllSchemaDataCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresCreateAllSchemaDataCommand.java
index 4c6335a24..e268c5334 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresCreateAllSchemaDataCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresCreateAllSchemaDataCommand.java
@@ -4,9 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required " +
- "schema's and data for JeMPI " +
- "Postgres instance.")
+@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required "
+ + "schema's and data for JeMPI Postgres instance.")
public class PostgresCreateAllSchemaDataCommand extends BasePostgresCommand implements Callable {
@Override
public Integer call() throws Exception {
@@ -15,4 +14,4 @@ public Integer call() throws Exception {
? 0
: 1);
}
-}
\ No newline at end of file
+}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteAllCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteAllCommand.java
index a6daefac9..9e9596e43 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteAllCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteAllCommand.java
@@ -4,8 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "deleteAll", mixinStandardHelpOptions = true, description = "Delete all the data and schema used by" +
- " JeMPI Postgres instance.")
+@CommandLine.Command(name = "deleteAll", mixinStandardHelpOptions = true, description = "Delete all the data and schema used by"
+ + " JeMPI Postgres instance.")
public class PostgresDeleteAllCommand extends BasePostgresCommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteDataOnlyCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteDataOnlyCommand.java
index f19eefad9..d3bb7fac8 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteDataOnlyCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresDeleteDataOnlyCommand.java
@@ -4,8 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "deleteDataOnly", mixinStandardHelpOptions = true, description = "Delete all the data (only) used " +
- "by JeMPI Postgres instance.")
+@CommandLine.Command(name = "deleteDataOnly", mixinStandardHelpOptions = true, description = "Delete all the data (only) used "
+ + "by JeMPI Postgres instance.")
public class PostgresDeleteDataOnlyCommand extends BasePostgresCommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresResetAllCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresResetAllCommand.java
index dc05ed849..b2d82e481 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresResetAllCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/sql/postgres/cli/PostgresResetAllCommand.java
@@ -4,9 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated" +
- " with JeMPI Postgres instance, then " +
- "recreates schemas, and add initial data.")
+@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated"
+ + " with JeMPI Postgres instance, then recreates schemas, and add initial data.")
public class PostgresResetAllCommand extends BasePostgresCommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaBootstrapConfig.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaBootstrapConfig.java
index d5fc07e37..0f6b7d6e2 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaBootstrapConfig.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaBootstrapConfig.java
@@ -1,5 +1,7 @@
package org.jembi.jempi.bootstrapper.data.stream.kafka;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
import java.util.HashMap;
public class KafkaBootstrapConfig {
@@ -14,8 +16,11 @@ public static class BootstrapperTopicConfig {
private String topicName;
private Integer partition;
private short replications;
- private Integer retention_ms;
- private Integer segments_bytes;
+ @JsonProperty("retention_ms")
+ private Integer retentionMs;
+
+ @JsonProperty("segments_bytes")
+ private Integer segmentsBytes;
public Integer getPartition() {
return partition;
@@ -25,12 +30,12 @@ public short getReplications() {
return replications;
}
- public Integer getRetention_ms() {
- return retention_ms;
+ public Integer getRetentionMs() {
+ return retentionMs;
}
- public Integer getSegments_bytes() {
- return segments_bytes;
+ public Integer getSegmentsBytes() {
+ return segmentsBytes;
}
public String getTopicName() {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaDataBootstrapper.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaDataBootstrapper.java
index 54c9ff753..4d61cbf7b 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaDataBootstrapper.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/KafkaDataBootstrapper.java
@@ -57,8 +57,8 @@ private void awaitOperationComplete(final Function, Boo
@Override
public Boolean createSchema() throws InterruptedException {
LOGGER.info("Loading Kafka schema data.");
- for (HashMap.Entry topicDetails :
- this.kafkaBootstrapConfig.topics.entrySet()) {
+ for (HashMap.Entry topicDetails
+ : this.kafkaBootstrapConfig.topics.entrySet()) {
KafkaBootstrapConfig.BootstrapperTopicConfig topic = topicDetails.getValue();
LOGGER.info(String.format("--> Creating topic '%s'", topic.getTopicName()));
@@ -66,8 +66,8 @@ public Boolean createSchema() throws InterruptedException {
kafkaTopicManager.createTopic(topic.getTopicName(),
topic.getPartition(),
topic.getReplications(),
- topic.getRetention_ms(),
- topic.getSegments_bytes());
+ topic.getRetentionMs(),
+ topic.getSegmentsBytes());
} catch (ExecutionException e) {
LOGGER.warn(e.getMessage());
}
@@ -93,8 +93,8 @@ public Boolean describeTopic(final String topicName) throws ExecutionException,
@Override
public Boolean deleteData() throws InterruptedException {
LOGGER.info("Deleting kafka topics.");
- for (HashMap.Entry topicDetails :
- this.kafkaBootstrapConfig.topics.entrySet()) {
+ for (HashMap.Entry topicDetails
+ : this.kafkaBootstrapConfig.topics.entrySet()) {
KafkaBootstrapConfig.BootstrapperTopicConfig topic = topicDetails.getValue();
LOGGER.info(String.format("--> Deleting topic '%s'", topic.getTopicName()));
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaCreateAllSchemaDataCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaCreateAllSchemaDataCommand.java
index 96af59d27..0dfde4c9a 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaCreateAllSchemaDataCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaCreateAllSchemaDataCommand.java
@@ -4,9 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required " +
- "schema's and data for JeMPI " +
- "Kafka instance.")
+@CommandLine.Command(name = "createAllSchemaData", mixinStandardHelpOptions = true, description = "Create all the required "
+ + "schema's and data for JeMPI Kafka instance.")
public class KafkaCreateAllSchemaDataCommand extends BaseKafkaCommand implements Callable {
@Override
public Integer call() throws Exception {
@@ -15,4 +14,4 @@ public Integer call() throws Exception {
? 0
: 1);
}
-}
\ No newline at end of file
+}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDeleteAllCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDeleteAllCommand.java
index 19f3c6acb..7ce3d434e 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDeleteAllCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDeleteAllCommand.java
@@ -4,8 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "deleteAll", mixinStandardHelpOptions = true, description = "Delete all the data and schema used by" +
- " JeMPI kafka instance.")
+@CommandLine.Command(name = "deleteAll", mixinStandardHelpOptions = true, description = "Delete all the data and schema used by"
+ + " JeMPI kafka instance.")
public class KafkaDeleteAllCommand extends BaseKafkaCommand implements Callable {
@Override
public Integer call() throws Exception {
@@ -14,4 +14,4 @@ public Integer call() throws Exception {
? 0
: 1);
}
-}
\ No newline at end of file
+}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDescribeTopicCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDescribeTopicCommand.java
index 5cfa1c8c6..f5e831035 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDescribeTopicCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaDescribeTopicCommand.java
@@ -4,8 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "describeTopic", mixinStandardHelpOptions = true, description = "Describe a topic associated with " +
- "the JeMPI instance.")
+@CommandLine.Command(name = "describeTopic", mixinStandardHelpOptions = true, description = "Describe a topic associated with "
+ + "the JeMPI instance.")
public class KafkaDescribeTopicCommand extends BaseKafkaCommand implements Callable {
@CommandLine.Option(names = {"-t", "--topicName"}, description = "Topic Name", required = true)
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaListTopicsCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaListTopicsCommand.java
index 51aed0862..b6de2bd68 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaListTopicsCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaListTopicsCommand.java
@@ -4,8 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "listTopics", mixinStandardHelpOptions = true, description = "List all the topics associated with " +
- "the JeMPI instance.")
+@CommandLine.Command(name = "listTopics", mixinStandardHelpOptions = true, description = "List all the topics associated with "
+ + "the JeMPI instance.")
public class KafkaListTopicsCommand extends BaseKafkaCommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaResetAllCommand.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaResetAllCommand.java
index d0eb2775e..80d6f058e 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaResetAllCommand.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/stream/kafka/cli/KafkaResetAllCommand.java
@@ -4,9 +4,8 @@
import java.util.concurrent.Callable;
-@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated" +
- " with JeMPI kafka instance, then " +
- "recreates schemas, and add initial data.")
+@CommandLine.Command(name = "resetAll", mixinStandardHelpOptions = true, description = "Deletes all data and schemas associated"
+ + " with JeMPI kafka instance, then recreates schemas, and add initial data.")
public class KafkaResetAllCommand extends BaseKafkaCommand implements Callable {
@Override
public Integer call() throws Exception {
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/utils/DataBootstraperConsts.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/utils/DataBootstraperConsts.java
index 56438b162..9df49d282 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/utils/DataBootstraperConsts.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/data/utils/DataBootstraperConsts.java
@@ -1,6 +1,9 @@
package org.jembi.jempi.bootstrapper.data.utils;
public class DataBootstraperConsts {
+ protected DataBootstraperConsts() { }
public static final String KAFKA_BOOT_STRAP_CONFIG_JSON = "/data/kafka/kafkaBootStrapConfig.json";
- public static final String POSTGRES_INIT_SCHEMA_SQL = "/data/postgres/initialSchema.sql";
+ public static final String POSTGRES_INIT_SCHEMA_AUDIT_DB = "/data/postgres/audit-schema.sql";
+ public static final String POSTGRES_INIT_SCHEMA_NOTIFICATION_DB = "/data/postgres/notifications-schema.sql";
+ public static final String POSTGRES_INIT_SCHEMA_USERS_DB = "/data/postgres/users-schema.sql";
}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/utils/BootstrapperLogger.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/utils/BootstrapperLogger.java
index c524b467a..54dc8d8ab 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/utils/BootstrapperLogger.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/java/org/jembi/jempi/bootstrapper/utils/BootstrapperLogger.java
@@ -4,9 +4,10 @@
import org.apache.logging.log4j.Logger;
public class BootstrapperLogger {
+ protected BootstrapperLogger() { }
public static Logger getChildLogger(
- Logger parentLogger,
- String childLoggerName) {
+ final Logger parentLogger,
+ final String childLoggerName) {
return LogManager.getLogger(String.format("%s > %s", parentLogger.getName(), childLoggerName));
}
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/kafka/kafkaBootStrapConfig.json b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/kafka/kafkaBootStrapConfig.json
index 48831ce78..913ef36d5 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/kafka/kafkaBootStrapConfig.json
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/kafka/kafkaBootStrapConfig.json
@@ -1,7 +1,7 @@
{
"topics": {
- "JeMPI-async-etl": {
- "topicName": "JeMPI-async-etl",
+ "JeMPI-interaction-etl": {
+ "topicName": "JeMPI-interaction-etl",
"partition": 1,
"replications": 1,
"retention_ms": 86400000,
@@ -28,6 +28,13 @@
"retention_ms": 86400000,
"segments_bytes": 4194304
},
+ "JeMPI-mu-controller": {
+ "topicName": "JeMPI-mu-controller",
+ "partition": 1,
+ "replications": 1,
+ "retention_ms": 86400000,
+ "segments_bytes": 4194304
+ },
"JeMPI-mu-linker": {
"topicName": "JeMPI-mu-linker",
"partition": 1,
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/audit-schema.sql b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/audit-schema.sql
new file mode 100644
index 000000000..aa3b4b7c1
--- /dev/null
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/audit-schema.sql
@@ -0,0 +1,11 @@
+CREATE TABLE IF NOT EXISTS audit_trail (
+ id UUID NOT NULL DEFAULT gen_random_uuid(),
+ insertedAt TIMESTAMP NOT NULL DEFAULT now(),
+ createdAt TIMESTAMP NOT NULL,
+ interactionID VARCHAR(64),
+ goldenID VARCHAR(64),
+ event VARCHAR(256),
+ CONSTRAINT PKEY_AUDIT_TRAIL PRIMARY KEY (id)
+);
+CREATE INDEX IF NOT EXISTS idx_gid ON audit_trail(goldenID);
+CREATE INDEX IF NOT EXISTS idx_iid ON audit_trail(interactionID);
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/initialSchema.sql b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/notifications-schema.sql
similarity index 89%
rename from JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/initialSchema.sql
rename to JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/notifications-schema.sql
index 015cbb99f..2da41e5a8 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/initialSchema.sql
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/notifications-schema.sql
@@ -37,10 +37,10 @@ CREATE TABLE IF NOT EXISTS Action
Action_Type_Id UUID,
Date date,
CONSTRAINT FK_Notification
- FOREIGN KEY(Notification_Id)
+ FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id),
CONSTRAINT FK_Action_Type
- FOREIGN KEY(Action_Type_Id)
+ FOREIGN KEY(Action_Type_Id)
REFERENCES Action_Type(Id)
);
@@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS Match
Score Numeric,
Golden_Id VARCHAR(50),
CONSTRAINT FK_Notification
- FOREIGN KEY(Notification_Id)
+ FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id)
);
@@ -60,7 +60,7 @@ CREATE TABLE IF NOT EXISTS candidates
Score Numeric,
Golden_Id VARCHAR(50),
CONSTRAINT FK_Notification
- FOREIGN KEY(Notification_Id)
+ FOREIGN KEY(Notification_Id)
REFERENCES Notification(Id)
);
@@ -77,4 +77,4 @@ INSERT INTO Notification_State(State)
VALUES ('OPEN'), ('CLOSED');
INSERT INTO Notification_Type(Type)
-VALUES ('THRESHOLD'), ('MARGIN'), ('UPDATE');
+VALUES ('THRESHOLD'), ('MARGIN'), ('UPDATE');
\ No newline at end of file
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/users-schema.sql b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/users-schema.sql
new file mode 100644
index 000000000..84ce1ed2a
--- /dev/null
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/users-schema.sql
@@ -0,0 +1,8 @@
+CREATE TABLE IF NOT EXISTS users
+(
+ id UUID DEFAULT gen_random_uuid() PRIMARY KEY UNIQUE,
+ given_name VARCHAR(255),
+ family_name VARCHAR(255),
+ email VARCHAR(255) UNIQUE,
+ username VARCHAR(255) UNIQUE
+);
diff --git a/JeMPI_Apps/JeMPI_Bootstrapper/src/test/java/org/jembi/jempi/bootstrapper/BootstrapperConfigTest.java b/JeMPI_Apps/JeMPI_Bootstrapper/src/test/java/org/jembi/jempi/bootstrapper/BootstrapperConfigTest.java
index f7d8800b9..48bca4012 100644
--- a/JeMPI_Apps/JeMPI_Bootstrapper/src/test/java/org/jembi/jempi/bootstrapper/BootstrapperConfigTest.java
+++ b/JeMPI_Apps/JeMPI_Bootstrapper/src/test/java/org/jembi/jempi/bootstrapper/BootstrapperConfigTest.java
@@ -30,7 +30,7 @@ public void assertPropsCorrect(BootstrapperConfig config){
assertEquals(5432, config.POSTGRESQL_PORT);
assertEquals("postgres", config.POSTGRESQL_USER);
assertEquals("", config.POSTGRESQL_PASSWORD);
- assertEquals("jempi", config.POSTGRESQL_DATABASE);
+ assertEquals("jempi", config.POSTGRESQL_NOTIFICATIONS_DB);
assertEquals("127.0.0.1", config.KAFKA_BOOTSTRAP_SERVERS);
assertEquals("aId", config.KAFKA_APPLICATION_ID);
diff --git a/JeMPI_Apps/build-all-java.sh b/JeMPI_Apps/build-all-java.sh
index 562a7d57c..4c87b1ee3 100755
--- a/JeMPI_Apps/build-all-java.sh
+++ b/JeMPI_Apps/build-all-java.sh
@@ -32,6 +32,9 @@ popd
pushd JeMPI_API_KC
./build.sh || exit 1
popd
+pushd JeMPI_Bootstrapper
+ ./build.sh || exit 1
+popd
pushd JeMPI_AsyncReceiver
./push.sh
popd
@@ -53,4 +56,7 @@ popd
pushd JeMPI_API_KC
./push.sh
popd
+pushd JeMPI_Bootstrapper
+ ./push.sh
+popd
diff --git a/devops/linux/docker/conf/images/conf-app-images.sh b/devops/linux/docker/conf/images/conf-app-images.sh
index 09ce87ba2..39b7bc8aa 100644
--- a/devops/linux/docker/conf/images/conf-app-images.sh
+++ b/devops/linux/docker/conf/images/conf-app-images.sh
@@ -33,3 +33,6 @@ export API_KC_IMAGE=apikc:1.0-SNAPSHOT
export API_KC_JAR=API_KC-1.0-SNAPSHOT-spring-boot.jar
export UI_IMAGE=ui:1.0-SNAPSHOT
+
+export BOOTSTRAPPER_IMAGE=bootstrapper:1.0-SNAPSHOT
+export BOOTSTRAPPER_JAR=Bootstrapper-1.0-SNAPSHOT-spring-boot.jar
diff --git a/devops/linux/docker/conf/stack/docker-stack-high-0.yml b/devops/linux/docker/conf/stack/docker-stack-high-0.yml
index 97be52a60..ee82c4907 100644
--- a/devops/linux/docker/conf/stack/docker-stack-high-0.yml
+++ b/devops/linux/docker/conf/stack/docker-stack-high-0.yml
@@ -684,6 +684,27 @@ services:
constraints:
- node.labels.name == $PLACEMENT_KEYCLOAK_TEST_SERVER
+ bootstrapper:
+ image: ${IMAGE_REGISTRY}$BOOTSTRAPPER_IMAGE
+ networks:
+ - backend
+ environment:
+ POSTGRESQL_IP: postgresql
+ POSTGRESQL_PORT: 5432
+ POSTGRESQL_USER: ${POSTGRESQL_USERNAME}
+ POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
+ POSTGRESQL_DATABASE: ${POSTGRESQL_DATABASE}
+ POSTGRESQL_USERS_DB: ${POSTGRESQL_USERS_DB}
+ POSTGRESQL_NOTIFICATIONS_DB: ${POSTGRESQL_NOTIFICATIONS_DB}
+ POSTGRESQL_AUDIT_DB: ${POSTGRESQL_AUDIT_DB}
+ POSTGRESQL_KC_TEST_DB: ${POSTGRESQL_KC_TEST_DB}
+ KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_SERVERS}
+ KAFKA_APPLICATION_ID: app-id-bootstrapper
+ DGRAPH_HOSTS: ${DGRAPH_HOSTS}
+ DGRAPH_PORTS: ${DGRAPH_PORTS}
+ deploy:
+ mode: global
+
ui:
image: ${IMAGE_REGISTRY}${UI_IMAGE}
environment:
diff --git a/devops/linux/docker/conf/stack/docker-stack-high-1.yml b/devops/linux/docker/conf/stack/docker-stack-high-1.yml
index affdcb8c3..e1d3ff5d2 100644
--- a/devops/linux/docker/conf/stack/docker-stack-high-1.yml
+++ b/devops/linux/docker/conf/stack/docker-stack-high-1.yml
@@ -660,7 +660,7 @@ services:
DB_USER: ${POSTGRESQL_USERNAME}
DB_PASSWORD: ${POSTGRESQL_PASSWORD}
DB_DATABASE: ${POSTGRESQL_KC_TEST_DB}
- healthcheck:
+ healthcheck:
test:
- "CMD"
- "curl"
@@ -684,6 +684,27 @@ services:
constraints:
- node.labels.name == $PLACEMENT_KEYCLOAK_TEST_SERVER
+ bootstrapper:
+ image: ${IMAGE_REGISTRY}$BOOTSTRAPPER_IMAGE
+ networks:
+ - backend
+ environment:
+ POSTGRESQL_IP: postgresql
+ POSTGRESQL_PORT: 5432
+ POSTGRESQL_USER: ${POSTGRESQL_USERNAME}
+ POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
+ POSTGRESQL_DATABASE: ${POSTGRESQL_DATABASE}
+ POSTGRESQL_USERS_DB: ${POSTGRESQL_USERS_DB}
+ POSTGRESQL_NOTIFICATIONS_DB: ${POSTGRESQL_NOTIFICATIONS_DB}
+ POSTGRESQL_AUDIT_DB: ${POSTGRESQL_AUDIT_DB}
+ POSTGRESQL_KC_TEST_DB: ${POSTGRESQL_KC_TEST_DB}
+ KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_SERVERS}
+ KAFKA_APPLICATION_ID: app-id-bootstrapper
+ DGRAPH_HOSTS: ${DGRAPH_HOSTS}
+ DGRAPH_PORTS: ${DGRAPH_PORTS}
+ deploy:
+ mode: global
+
ui:
image: ${IMAGE_REGISTRY}${UI_IMAGE}
environment:
diff --git a/devops/linux/docker/conf/stack/docker-stack-low-0.yml b/devops/linux/docker/conf/stack/docker-stack-low-0.yml
index 78712eea3..34aa7e964 100644
--- a/devops/linux/docker/conf/stack/docker-stack-low-0.yml
+++ b/devops/linux/docker/conf/stack/docker-stack-low-0.yml
@@ -540,6 +540,27 @@ services:
constraints:
- node.labels.name == $PLACEMENT_KEYCLOAK_TEST_SERVER
+ bootstrapper:
+ image: ${IMAGE_REGISTRY}$BOOTSTRAPPER_IMAGE
+ networks:
+ - backend
+ environment:
+ POSTGRESQL_IP: postgresql
+ POSTGRESQL_PORT: 5432
+ POSTGRESQL_USER: ${POSTGRESQL_USERNAME}
+ POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
+ POSTGRESQL_DATABASE: ${POSTGRESQL_DATABASE}
+ POSTGRESQL_USERS_DB: ${POSTGRESQL_USERS_DB}
+ POSTGRESQL_NOTIFICATIONS_DB: ${POSTGRESQL_NOTIFICATIONS_DB}
+ POSTGRESQL_AUDIT_DB: ${POSTGRESQL_AUDIT_DB}
+ POSTGRESQL_KC_TEST_DB: ${POSTGRESQL_KC_TEST_DB}
+ KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_SERVERS}
+ KAFKA_APPLICATION_ID: app-id-bootstrapper
+ DGRAPH_HOSTS: ${DGRAPH_HOSTS}
+ DGRAPH_PORTS: ${DGRAPH_PORTS}
+ deploy:
+ mode: global
+
ui:
image: ${IMAGE_REGISTRY}${UI_IMAGE}
environment:
diff --git a/devops/linux/docker/conf/stack/docker-stack-low-1.yml b/devops/linux/docker/conf/stack/docker-stack-low-1.yml
index 66b3aa697..c0b28ec67 100644
--- a/devops/linux/docker/conf/stack/docker-stack-low-1.yml
+++ b/devops/linux/docker/conf/stack/docker-stack-low-1.yml
@@ -540,6 +540,27 @@ services:
constraints:
- node.labels.name == $PLACEMENT_KEYCLOAK_TEST_SERVER
+ bootstrapper:
+ image: ${IMAGE_REGISTRY}$BOOTSTRAPPER_IMAGE
+ networks:
+ - backend
+ environment:
+ POSTGRESQL_IP: postgresql
+ POSTGRESQL_PORT: 5432
+ POSTGRESQL_USER: ${POSTGRESQL_USERNAME}
+ POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
+ POSTGRESQL_DATABASE: ${POSTGRESQL_DATABASE}
+ POSTGRESQL_USERS_DB: ${POSTGRESQL_USERS_DB}
+ POSTGRESQL_NOTIFICATIONS_DB: ${POSTGRESQL_NOTIFICATIONS_DB}
+ POSTGRESQL_AUDIT_DB: ${POSTGRESQL_AUDIT_DB}
+ POSTGRESQL_KC_TEST_DB: ${POSTGRESQL_KC_TEST_DB}
+ KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_SERVERS}
+ KAFKA_APPLICATION_ID: app-id-bootstrapper
+ DGRAPH_HOSTS: ${DGRAPH_HOSTS}
+ DGRAPH_PORTS: ${DGRAPH_PORTS}
+ deploy:
+ mode: global
+
ui:
image: ${IMAGE_REGISTRY}${UI_IMAGE}
environment:
diff --git a/devops/linux/docker/helper/bootstrapper/bootstrapper-docker.sh b/devops/linux/docker/helper/bootstrapper/bootstrapper-docker.sh
new file mode 100755
index 000000000..5f54a3c99
--- /dev/null
+++ b/devops/linux/docker/helper/bootstrapper/bootstrapper-docker.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+set -e
+set -u
+
+pushd .
+ SCRIPT_DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
+ cd ${SCRIPT_DIR}/../..
+
+ java_args="${@:1}"
+ source ./conf.env
+ docker exec $(docker ps -q -f name=bootstrapper) /bootstrapper.sh $java_args
+
+popd
\ No newline at end of file
diff --git a/devops/linux/bootstrapper.sh b/devops/linux/docker/helper/bootstrapper/bootstrapper.sh
similarity index 100%
rename from devops/linux/bootstrapper.sh
rename to devops/linux/docker/helper/bootstrapper/bootstrapper.sh
diff --git a/devops/linux/docker/helper/scripts/d-stack-up-hub-containers.sh b/devops/linux/docker/helper/scripts/d-stack-up-hub-containers.sh
index 7f1d3c792..e4f72a502 100755
--- a/devops/linux/docker/helper/scripts/d-stack-up-hub-containers.sh
+++ b/devops/linux/docker/helper/scripts/d-stack-up-hub-containers.sh
@@ -21,19 +21,13 @@ pushd .
if [ ! -z ${SCALE_ALPHA_03+x} ] ; then docker service scale ${STACK_NAME}_alpha-03=${SCALE_ALPHA_03}; fi
docker service scale ${STACK_NAME}_ratel=${SCALE_RATEL}
- pushd helper/postgres
- source ./create-schema.sh
- popd
- pushd helper/topics
- source ./topics-create.sh
- source ./topics-list.sh
- popd
- pushd helper/keycloak
- # if [ "$REACT_APP_ENABLE_SSO" = "true" ]; then
- source ./start-keycloak-test-server.sh
- # fi
- popd
+ ./helper/bootstrapper/bootstrapper-docker.sh data resetAll
+ pushd helper/keycloak
+ # if [ "$REACT_APP_ENABLE_SSO" = "true" ]; then
+ source ./start-keycloak-test-server.sh
+ # fi
+ popd
popd