Skip to content
Permalink
Browse files
Migrate provisioner from MariaDB to PostgreSQL
  • Loading branch information
Izakey committed Mar 18, 2019
1 parent 9014297 commit 47b14343c558928c12de8296618a837b74a00116
Showing 12 changed files with 48 additions and 42 deletions.
@@ -1,5 +1,5 @@
Apache Fineract CN Provisioner
Copyright [2017-2018] The Apache Software Foundation
Copyright [2017-2019] The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
@@ -50,7 +50,8 @@ dependencies {
[group: 'org.apache.fineract.cn', name: 'lang', version: versions.frameworklang],
[group: 'org.springframework.boot', name: 'spring-boot-starter-test'],
[group: 'org.springframework.restdocs', name: 'spring-restdocs-mockmvc'],
[group: 'junit', name: 'junit', version: '4.12']
[group: 'junit', name: 'junit', version: '4.12'],
[group: 'com.opentable.components', name: 'otj-pg-embedded', version: '0.7.1']
)
}

@@ -61,13 +61,13 @@ public Logger logger() {


private static TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
private static ProvisionerMariaDBInitializer mariaDBInitializer = new ProvisionerMariaDBInitializer();
private static ProvisionerPostgreSQLInitializer postgreSQLInitializer = new ProvisionerPostgreSQLInitializer();
private static ProvisionerCassandraInitializer cassandraInitializer = new ProvisionerCassandraInitializer();

@ClassRule
public static TestRule orderClassRules = RuleChain
.outerRule(testEnvironment)
.around(mariaDBInitializer)
.around(postgreSQLInitializer)
.around(cassandraInitializer);

@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@@ -88,4 +88,4 @@ public static void setup() throws Exception {
protected String getClientId() {
return CLIENT_ID;
}
}
}
@@ -18,27 +18,32 @@
*/
package org.apache.fineract.cn.provisioner;

import ch.vorburger.exec.ManagedProcessException;
import ch.vorburger.mariadb4j.DB;
import com.opentable.db.postgres.embedded.EmbeddedPostgres;
import org.junit.rules.ExternalResource;

import java.io.IOException;

/**
* @author Myrle Krantz
*/
public class ProvisionerMariaDBInitializer extends ExternalResource {
private static DB EMBEDDED_MARIA_DB;
public class ProvisionerPostgreSQLInitializer extends ExternalResource {
private static EmbeddedPostgres EMBEDDED_POSTGRESQL_DB;
@Override
protected void before() throws ManagedProcessException {
EMBEDDED_MARIA_DB = DB.newEmbeddedDB(3306);
EMBEDDED_MARIA_DB.start();
protected void before() throws IOException {
try {
EMBEDDED_POSTGRESQL_DB = EmbeddedPostgres.builder().setPort(5432).start();
}
catch (IOException ioex) {
System.out.println(ioex);
}
}

@Override
protected void after() {
try {
EMBEDDED_MARIA_DB.stop();
} catch (ManagedProcessException e) {
throw new RuntimeException(e);
EMBEDDED_POSTGRESQL_DB.close();
} catch (IOException io) {
System.out.println(io);
}
}
}
@@ -25,7 +25,7 @@

import com.google.gson.Gson;
import org.apache.fineract.cn.provisioner.ProvisionerCassandraInitializer;
import org.apache.fineract.cn.provisioner.ProvisionerMariaDBInitializer;
import org.apache.fineract.cn.provisioner.ProvisionerPostgreSQLInitializer;
import org.apache.fineract.cn.provisioner.api.v1.client.Provisioner;
import org.apache.fineract.cn.provisioner.api.v1.domain.Application;
import org.apache.fineract.cn.provisioner.api.v1.domain.AssignedApplication;
@@ -124,15 +124,15 @@ public TokenProvider tokenProviderSpy(final @Qualifier("tokenProvider") TokenPro


private static TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
private static ProvisionerMariaDBInitializer mariaDBInitializer = new ProvisionerMariaDBInitializer();
private static ProvisionerPostgreSQLInitializer postgreSQLInitializer = new ProvisionerPostgreSQLInitializer();
private static ProvisionerCassandraInitializer cassandraInitializer = new ProvisionerCassandraInitializer();
private static SystemSecurityEnvironment systemSecurityEnvironment
= new SystemSecurityEnvironment(testEnvironment.getSystemKeyTimestamp(), testEnvironment.getSystemPublicKey(), testEnvironment.getSystemPrivateKey());

@ClassRule
public static TestRule orderClassRules = RuleChain
.outerRule(testEnvironment)
.around(mariaDBInitializer)
.around(postgreSQLInitializer)
.around(cassandraInitializer);

@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@@ -62,7 +62,6 @@ dependencies {
[group: 'org.apache.fineract.cn', name: 'lang', version: versions.frameworklang],
[group: 'org.apache.fineract.cn', name: 'async', version: versions.frameworkasync],
[group: 'org.apache.fineract.cn', name: 'cassandra', version: versions.frameworkcassandra],
[group: 'org.apache.fineract.cn', name: 'mariadb', version: versions.frameworkmariadb],
[group: 'org.hibernate', name: 'hibernate-validator', version: versions.validator],
[group: 'org.apache.fineract.cn', name: 'crypto', version: versions.frameworkcrypto],
)
@@ -29,7 +29,7 @@
import org.apache.fineract.cn.crypto.config.EnableCrypto;
import org.apache.fineract.cn.lang.config.EnableApplicationName;
import org.apache.fineract.cn.lang.config.EnableServiceException;
import org.apache.fineract.cn.mariadb.config.EnableMariaDB;
import org.apache.fineract.cn.postgresql.config.EnablePostgreSQL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -55,7 +55,7 @@
@EnableCrypto
@EnableAsync
@EnableAnubis(provideSignatureRestController = false)
@EnableMariaDB
@EnablePostgreSQL
@EnableCassandra
@EnableServiceException
@EnableApplicationName
@@ -37,7 +37,7 @@
import org.apache.fineract.cn.cassandra.util.CassandraConnectorConstants;
import org.apache.fineract.cn.crypto.HashGenerator;
import org.apache.fineract.cn.crypto.SaltGenerator;
import org.apache.fineract.cn.mariadb.util.MariaDBConstants;
import org.apache.fineract.cn.postgresql.util.PostgreSQLConstants;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -58,7 +58,7 @@ public class ProvisionerInitializer {
private final HashGenerator hashGenerator;
private final String initialClientId;
private String metaKeySpaceName;
private String mariaDBName;
private String postgreSQLName;

@Autowired
public ProvisionerInitializer(final Environment environment, @Qualifier(ProvisionerConstants.LOGGER_NAME) final Logger logger,
@@ -80,9 +80,9 @@ public void initialize() {
metaKeySpaceName = this.environment.getProperty(
CassandraConnectorConstants.KEYSPACE_PROP,
CassandraConnectorConstants.KEYSPACE_PROP_DEFAULT);
mariaDBName = this.environment.getProperty(
MariaDBConstants.MARIADB_DATABASE_NAME_PROP,
MariaDBConstants.MARIADB_DATABASE_NAME_DEFAULT);
postgreSQLName = this.environment.getProperty(
PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_PROP,
PostgreSQLConstants.POSTGRESQL_DATABASE_NAME_DEFAULT);

this.initializeCassandra();
this.initializeDatabase();
@@ -202,8 +202,8 @@ private void initializeDatabase() throws Exception {
final Connection connection = DataSourceUtils.createProvisionerConnection(this.environment);
try (final Statement statement = connection.createStatement()) {
// create meta data database
statement.execute("CREATE DATABASE IF NOT EXISTS " + mariaDBName);
statement.execute("USE " + mariaDBName);
statement.execute("CREATE DATABASE IF NOT EXISTS " + postgreSQLName);
statement.execute("USE " + postgreSQLName);
// create tenants table
statement.execute("CREATE TABLE IF NOT EXISTS tenants (" +
" identifier VARCHAR(32) NOT NULL," +
@@ -39,7 +39,7 @@ public static Connection create(final DatabaseConnectionInfo databaseConnectionI
throw new IllegalArgumentException(cnfex.getMessage(), cnfex);
}
final String jdbcUrl = JdbcUrlBuilder
.create(JdbcUrlBuilder.DatabaseType.MARIADB)
.create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
.host(databaseConnectionInfo.getHost())
.port(databaseConnectionInfo.getPort())
.build();
@@ -54,11 +54,11 @@ public static Connection create(final DatabaseConnectionInfo databaseConnectionI

public static Connection createProvisionerConnection(final Environment environment) {
final DatabaseConnectionInfo databaseConnectionInfo = new DatabaseConnectionInfo();
databaseConnectionInfo.setDriverClass(environment.getProperty("mariadb.driverClass"));
databaseConnectionInfo.setHost(environment.getProperty("mariadb.host"));
databaseConnectionInfo.setPort(environment.getProperty("mariadb.port"));
databaseConnectionInfo.setUser(environment.getProperty("mariadb.user"));
databaseConnectionInfo.setPassword(environment.getProperty("mariadb.password"));
databaseConnectionInfo.setDriverClass(environment.getProperty("postgresql.driverClass"));
databaseConnectionInfo.setHost(environment.getProperty("postgresql.host"));
databaseConnectionInfo.setPort(environment.getProperty("postgresql.port"));
databaseConnectionInfo.setUser(environment.getProperty("postgresql.user"));
databaseConnectionInfo.setPassword(environment.getProperty("postgresql.password"));
final Connection connection = DataSourceUtils.create(databaseConnectionInfo);
try {
connection.setAutoCommit(false);
@@ -21,7 +21,7 @@
final class JdbcUrlBuilder {

enum DatabaseType {
MARIADB("jdbc:mariadb://");
POSTGRESQL("jdbc:postgresql:");

private final String prefix;

@@ -65,7 +65,7 @@ JdbcUrlBuilder instanceName(final String instanceName) {

String build() {
switch (this.type) {
case MARIADB:
case POSTGRESQL:
return this.type.prefix()
+ this.host + ":"
+ this.port
@@ -37,10 +37,10 @@ cassandra:
type: Network
replicas: datacenter1:3

mariadb:
driverClass: org.mariadb.jdbc.Driver
postgresql:
driverClass: org.postgresql.Driver
database: seshat
host: localhost
port: 3306
user: root
password: mysql
port: 5432
user: postgres
password: postgres
@@ -65,7 +65,8 @@ ext['spring-data-releasetrain.version'] = 'Gosling-SR2A'

dependencies {
compile(
[group: 'com.google.code.findbugs', name: 'jsr305']
[group: 'com.google.code.findbugs', name: 'jsr305'],
[group: 'org.apache.fineract.cn', name: 'postgresql', version: '0.1.0-BUILD-SNAPSHOT']
)

testCompile(

0 comments on commit 47b1434

Please sign in to comment.