You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/01/29 15:59:14 UTC
[airavata] branch
airavata-2938-change-db-initialization-in-registry-server-to-use-registry-refactoring-code
updated: AIRAVATA-2938 Converting registry DB tests to use DBInitializer,
DerbyUtil
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch airavata-2938-change-db-initialization-in-registry-server-to-use-registry-refactoring-code
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/airavata-2938-change-db-initialization-in-registry-server-to-use-registry-refactoring-code by this push:
new 54c3b03 AIRAVATA-2938 Converting registry DB tests to use DBInitializer, DerbyUtil
54c3b03 is described below
commit 54c3b035a189e2741728c04d2c32095879e75311
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Jan 29 10:58:36 2019 -0500
AIRAVATA-2938 Converting registry DB tests to use DBInitializer, DerbyUtil
---
.../core/utils/UserProfileCatalogJDBCConfig.java | 5 +
modules/commons/pom.xml | 3 +-
.../airavata/common/utils/DBInitializer.java | 39 ---
.../org/apache/airavata/common/utils/DBUtil.java | 17 +-
.../airavata/common/utils/DerbyTestUtil.java} | 253 ++++++++++++-----
.../apache/airavata/common/utils/DerbyUtil.java | 2 +-
.../apache/airavata/common/utils/JDBCConfig.java | 1 +
.../store/impl/util/CredentialStoreJDBCConfig.java | 9 +
.../appcatalog/AppCatAbstractRepository.java | 12 +-
.../expcatalog/ExpCatAbstractRepository.java | 7 +-
.../replicacatalog/RepCatAbstractRepository.java | 7 +-
.../WorkflowCatAbstractRepository.java | 7 +-
.../core/utils/AppCatalogDBInitConfig.java | 9 +-
.../registry/core/utils/AppCatalogJDBCConfig.java | 7 +
.../core/utils/ExpCatalogDBInitConfig.java | 9 +-
.../registry/core/utils/ExpCatalogJDBCConfig.java | 7 +
.../core/utils/JPAUtil/AppCatalogJPAUtils.java | 31 +-
.../core/utils/JPAUtil/ExpCatalogJPAUtils.java | 34 +--
.../core/utils/JPAUtil/RepCatalogJPAUtils.java | 31 +-
.../utils/JPAUtil/WorkflowCatalogJPAUtils.java | 34 +--
.../core/utils/ReplicaCatalogDBInitConfig.java | 13 +-
.../core/utils/ReplicaCatalogJDBCConfig.java | 14 +-
...onfig.java => WorkflowCatalogDBInitConfig.java} | 16 +-
...CConfig.java => WorkflowCatalogJDBCConfig.java} | 25 +-
.../src/main/resources/replicacatalog-derby.sql | 3 +
.../src/main/resources/replicacatalog-mysql.sql | 3 +
.../appcatalog/GatewayProfileRepositoryTest.java | 13 +-
.../core/repositories/common/DerbyDBManager.java | 240 ----------------
.../core/repositories/common/TestBase.java | 53 ++--
.../expcatalog/GatewayRepositoryTest.java | 17 +-
.../repositories/expcatalog/util/Initialize.java | 293 -------------------
.../replicacatalog/DataProductRepositoryTest.java | 32 +--
.../DataReplicaLocationRepositoryTest.java | 34 +--
.../replicacatalog/util/Initialize.java | 313 ---------------------
.../workflowcatalog/WorkflowRepositoryTest.java | 30 +-
.../src/test/resources/airavata-server.properties | 70 +++++
.../resources/airavataworkflowcatalog-derby.sql | 172 -----------
.../registry/db/repositories/EntityRepository.java | 33 +--
.../sharing/registry/db/utils/JPAUtils.java | 33 +--
.../db/utils/SharingRegistryJDBCConfig.java | 14 +-
40 files changed, 504 insertions(+), 1441 deletions(-)
diff --git a/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogJDBCConfig.java b/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogJDBCConfig.java
index 0d09dae..94c0ddc 100644
--- a/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogJDBCConfig.java
+++ b/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogJDBCConfig.java
@@ -44,4 +44,9 @@ public class UserProfileCatalogJDBCConfig implements JDBCConfig {
public String getPassword() {
return Utils.getJDBCPassword();
}
+
+ @Override
+ public String getValidationQuery() {
+ return Utils.getValidationQuery();
+ }
}
diff --git a/modules/commons/pom.xml b/modules/commons/pom.xml
index e0ad64e..7130f8a 100644
--- a/modules/commons/pom.xml
+++ b/modules/commons/pom.xml
@@ -97,12 +97,11 @@
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
- <!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <scope>test</scope>
</dependency>
+ <!-- Testing -->
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>airavata-server-configuration</artifactId>
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBInitializer.java b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBInitializer.java
index ed9ddef..7cc993a 100644
--- a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBInitializer.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBInitializer.java
@@ -20,18 +20,14 @@
package org.apache.airavata.common.utils;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.net.URI;
import java.sql.Connection;
public class DBInitializer {
private static final Logger logger = LoggerFactory.getLogger(DBInitializer.class);
- private static final String START_DERBY_ENABLE = "start.derby.server.mode";
-
private JDBCConfig jdbcConfig;
private String initScriptPrefix;
private String checkTableName;
@@ -55,9 +51,6 @@ public class DBInitializer {
Connection conn = null;
try {
DBUtil dbUtil = new DBUtil(jdbcConfig);
- if (DatabaseCreator.getDatabaseType(jdbcConfig.getURL()) == DatabaseCreator.DatabaseType.derby && isDerbyStartEnabled()) {
- startDerbyInServerMode();
- }
conn = dbUtil.getConnection();
if (!DatabaseCreator.isDatabaseStructureCreated(checkTableName, conn)) {
DatabaseCreator.createRegistryDatabase(initScriptPrefix, conn);
@@ -75,36 +68,4 @@ public class DBInitializer {
}
}
-
- private boolean isDerbyStartEnabled(){
- try {
- String s = ServerSettings.getSetting(START_DERBY_ENABLE);
- if("true".equals(s)){
- return true;
- }
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read airavata server properties", e.getMessage(), e);
- return false;
- }
- return false;
- }
-
- private void startDerbyInServerMode() {
- try {
- DerbyUtil.startDerbyInServerMode("0.0.0.0", getPort(jdbcConfig.getURL()), jdbcConfig.getUser(), jdbcConfig.getPassword());
- } catch (Exception e) {
- throw new RuntimeException("Unable to start Derby in server mode", e);
- }
- }
-
- private int getPort(String jdbcURL){
- try{
- String cleanURI = jdbcURL.substring(5);
- URI uri = URI.create(cleanURI);
- return uri.getPort();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- return -1;
- }
- }
}
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBUtil.java b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBUtil.java
index 1734fe8..8775732 100644
--- a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBUtil.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBUtil.java
@@ -230,13 +230,7 @@ public class DBUtil {
log.error("Error closing prepared statement.", e);
}
}
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- log.error("Error closing database connection.", e);
- }
- }
+ cleanup(connection);
}
/**
@@ -280,10 +274,15 @@ public class DBUtil {
public static void cleanup(Connection connection) {
if (connection != null) {
try {
+ if (connection.isClosed()) {
+ return;
+ }
+ if (!connection.getAutoCommit()) {
+ connection.rollback();
+ }
connection.close();
} catch (SQLException e) {
- log.debug("Error closing connection.", e);
- log.warn("Error closing connection.");
+ throw new RuntimeException("Error closing connection", e);
}
}
}
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/JdbcUtil.java b/modules/commons/src/main/java/org/apache/airavata/common/utils/DerbyTestUtil.java
similarity index 60%
rename from modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/JdbcUtil.java
rename to modules/commons/src/main/java/org/apache/airavata/common/utils/DerbyTestUtil.java
index d253bfa..8aa85bc 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/JdbcUtil.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/DerbyTestUtil.java
@@ -17,14 +17,23 @@
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
-package org.apache.airavata.registry.core.repositories.common;
-
-import java.sql.*;
+package org.apache.airavata.common.utils;
+
+import java.sql.BatchUpdateException;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import java.util.ListIterator;
-import junit.framework.Assert;
+import org.junit.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* JdbcUtil utility methods for the JUnit tests.
@@ -34,34 +43,161 @@ import junit.framework.Assert;
*
* Borrowed from http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?view=markup
*/
-public class JdbcUtil {
+public class DerbyTestUtil {
+
+ private static final Logger logger = LoggerFactory.getLogger(DerbyUtil.class);
/**
- * Constant to pass to DatabaseMetaData.getTables() to fetch
- * just synonyms.
+ * Constant to pass to DatabaseMetaData.getTables() to fetch just synonyms.
*/
- public static final String[] GET_TABLES_SYNONYM =
- new String[]{"SYNONYM"};
+ public static final String[] GET_TABLES_SYNONYM = new String[] { "SYNONYM" };
/**
- * Constant to pass to DatabaseMetaData.getTables() to fetch
- * just views.
+ * Constant to pass to DatabaseMetaData.getTables() to fetch just views.
*/
- public static final String[] GET_TABLES_VIEW = new String[]{"VIEW"};
+ public static final String[] GET_TABLES_VIEW = new String[] { "VIEW" };
/**
- * Constant to pass to DatabaseMetaData.getTables() to fetch
- * just tables.
+ * Constant to pass to DatabaseMetaData.getTables() to fetch just tables.
*/
- public static final String[] GET_TABLES_TABLE = new String[]{"TABLE"};
+ public static final String[] GET_TABLES_TABLE = new String[] { "TABLE" };
+
+ private static final String[] CLEAR_DB_PROPERTIES = {"derby.database.classpath",};
+
+ public static void destroyDatabase(JDBCConfig jdbcConfig) {
+
+ Connection conn = null;
+ try {
+ DBUtil dbUtil = new DBUtil(jdbcConfig);
+ conn = dbUtil.getConnection();
+ clearProperties(conn);
+ removeObjects(conn);
+ removeRoles(conn);
+ removeUsers(conn);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new RuntimeException("Database failure", e);
+ } finally {
+ DBUtil.cleanup(conn);
+ }
+ }
+
+
+ private static void clearProperties(Connection conn) throws SQLException {
+ PreparedStatement ps = conn.prepareCall(
+ "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, NULL)");
+
+ for (String CLEAR_DB_PROPERTY : CLEAR_DB_PROPERTIES) {
+ ps.setString(1, CLEAR_DB_PROPERTY);
+ ps.executeUpdate();
+ }
+ ps.close();
+ conn.commit();
+ }
+
+ private static void removeObjects(Connection conn) throws SQLException {
+
+ DatabaseMetaData dmd = conn.getMetaData();
+
+ SQLException sqle = null;
+ // Loop a number of arbitary times to catch cases
+ // where objects are dependent on objects in
+ // different schemas.
+ for (int count = 0; count < 5; count++) {
+ // Fetch all the user schemas into a list
+ List<String> schemas = new ArrayList<>();
+ ResultSet rs = dmd.getSchemas();
+ while (rs.next()) {
+
+ String schema = rs.getString("TABLE_SCHEM");
+ if (schema.startsWith("SYS"))
+ continue;
+ if (schema.equals("SQLJ"))
+ continue;
+ if (schema.equals("NULLID"))
+ continue;
+ schemas.add(schema);
+ }
+ rs.close();
+
+ // DROP all the user schemas.
+ sqle = null;
+ for (String schema : schemas) {
+ try {
+ dropSchema(dmd, schema);
+ } catch (SQLException e) {
+ sqle = e;
+ }
+ }
+ // No errors means all the schemas we wanted to
+ // drop were dropped, so nothing more to do.
+ if (sqle == null)
+ return;
+ }
+ throw sqle;
+ }
+
+ private static void removeRoles(Connection conn) throws SQLException {
+ // No metadata for roles, so do a query against SYSROLES
+ Statement stm = conn.createStatement();
+ Statement dropStm = conn.createStatement();
+
+ // cast to overcome territory differences in some cases:
+ ResultSet rs = stm.executeQuery(
+ "select roleid from sys.sysroles where " +
+ "cast(isdef as char(1)) = 'Y'");
+
+ while (rs.next()) {
+ dropStm.executeUpdate("DROP ROLE " + escape(rs.getString(1)));
+ }
+
+ stm.close();
+ dropStm.close();
+ conn.commit();
+ }
+
+ private static void removeUsers(Connection conn) throws SQLException {
+ // Get the users
+ Statement stm = conn.createStatement();
+ ResultSet rs = stm.executeQuery("select username from sys.sysusers");
+ ArrayList<String> users = new ArrayList<String>();
+
+ while (rs.next()) {
+ users.add(rs.getString(1));
+ }
+ rs.close();
+ stm.close();
+
+ // Now delete them
+ PreparedStatement ps = conn.prepareStatement("call syscs_util.syscs_drop_user( ? )");
+
+ for (int i = 0; i < users.size(); i++) {
+ ps.setString(1, (String) users.get(i));
+
+ // you can't drop the DBO's credentials. sorry.
+ try {
+ ps.executeUpdate();
+ } catch (SQLException se) {
+ if ("4251F".equals(se.getSQLState())) {
+ continue;
+ } else {
+ throw se;
+ }
+ }
+ }
+
+ ps.close();
+ conn.commit();
+ }
public static String escape(String name) {
StringBuffer buffer = new StringBuffer(name.length() + 2);
buffer.append('"');
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
// escape double quote characters with an extra double quote
- if (c == '"') buffer.append('"');
+ if (c == '"')
+ buffer.append('"');
buffer.append(c);
}
buffer.append('"');
@@ -69,20 +205,19 @@ public class JdbcUtil {
}
/**
- * Escape a schama-qualified name so that it is suitable
- * for use in a SQL query executed by JdbcUtil.
+ * Escape a schama-qualified name so that it is suitable for use in a SQL query
+ * executed by JdbcUtil.
*/
public static String escape(String schema, String name) {
return escape(schema) + "." + escape(name);
}
/**
- * Drop a database schema by dropping all objects in it
- * and then executing DROP SCHEMA. If the schema is
- * APP it is cleaned but DROP SCHEMA is not executed.
+ * Drop a database schema by dropping all objects in it and then executing DROP
+ * SCHEMA. If the schema is APP it is cleaned but DROP SCHEMA is not executed.
* <p>
- * TODO: Handle dependencies by looping in some intelligent
- * way until everything can be dropped.
+ * TODO: Handle dependencies by looping in some intelligent way until everything
+ * can be dropped.
*
* @param dmd DatabaseMetaData object for database
* @param schema Name of the schema
@@ -94,14 +229,13 @@ public class JdbcUtil {
Statement s = dmd.getConnection().createStatement();
// Triggers
- PreparedStatement pstr = conn.prepareStatement(
- "SELECT TRIGGERNAME FROM SYS.SYSSCHEMAS S, SYS.SYSTRIGGERS T "
- + "WHERE S.SCHEMAID = T.SCHEMAID AND SCHEMANAME = ?");
+ PreparedStatement pstr = conn.prepareStatement("SELECT TRIGGERNAME FROM SYS.SYSSCHEMAS S, SYS.SYSTRIGGERS T "
+ + "WHERE S.SCHEMAID = T.SCHEMAID AND SCHEMANAME = ?");
pstr.setString(1, schema);
ResultSet trrs = pstr.executeQuery();
while (trrs.next()) {
String trigger = trrs.getString(1);
- s.execute("DROP TRIGGER " + JdbcUtil.escape(schema, trigger));
+ s.execute("DROP TRIGGER " + DerbyTestUtil.escape(schema, trigger));
}
trrs.close();
pstr.close();
@@ -109,31 +243,25 @@ public class JdbcUtil {
// Functions - not supported by JdbcUtil meta data until JdbcUtil 4
// Need to use the CHAR() function on A.ALIASTYPE
// so that the compare will work in any schema.
- PreparedStatement psf = conn.prepareStatement(
- "SELECT ALIAS FROM SYS.SYSALIASES A, SYS.SYSSCHEMAS S" +
- " WHERE A.SCHEMAID = S.SCHEMAID " +
- " AND CHAR(A.ALIASTYPE) = ? " +
- " AND S.SCHEMANAME = ?");
+ PreparedStatement psf = conn.prepareStatement("SELECT ALIAS FROM SYS.SYSALIASES A, SYS.SYSSCHEMAS S"
+ + " WHERE A.SCHEMAID = S.SCHEMAID " + " AND CHAR(A.ALIASTYPE) = ? " + " AND S.SCHEMANAME = ?");
psf.setString(1, "F");
psf.setString(2, schema);
ResultSet rs = psf.executeQuery();
dropUsingDMD(s, rs, schema, "ALIAS", "FUNCTION");
// Procedures
- rs = dmd.getProcedures((String) null,
- schema, (String) null);
+ rs = dmd.getProcedures((String) null, schema, (String) null);
dropUsingDMD(s, rs, schema, "PROCEDURE_NAME", "PROCEDURE");
// Views
- rs = dmd.getTables((String) null, schema, (String) null,
- GET_TABLES_VIEW);
+ rs = dmd.getTables((String) null, schema, (String) null, GET_TABLES_VIEW);
dropUsingDMD(s, rs, schema, "TABLE_NAME", "VIEW");
// Tables
- rs = dmd.getTables((String) null, schema, (String) null,
- GET_TABLES_TABLE);
+ rs = dmd.getTables((String) null, schema, (String) null, GET_TABLES_TABLE);
dropUsingDMD(s, rs, schema, "TABLE_NAME", "TABLE");
@@ -141,8 +269,7 @@ public class JdbcUtil {
// foreign key constraints leading to a dependency loop.
// Drop any constraints that remain and then drop the tables.
// If there are no tables then this should be a quick no-op.
- ResultSet table_rs = dmd.getTables((String) null, schema, (String) null,
- GET_TABLES_TABLE);
+ ResultSet table_rs = dmd.getTables((String) null, schema, (String) null, GET_TABLES_TABLE);
while (table_rs.next()) {
String tablename = table_rs.getString("TABLE_NAME");
@@ -158,10 +285,8 @@ public class JdbcUtil {
String fkSchema = rs.getString("FKTABLE_SCHEM");
String fkTable = rs.getString("FKTABLE_NAME");
- String ddl = "ALTER TABLE " +
- JdbcUtil.escape(fkSchema, fkTable) +
- " DROP FOREIGN KEY " +
- JdbcUtil.escape(fkName);
+ String ddl = "ALTER TABLE " + DerbyTestUtil.escape(fkSchema, fkTable) + " DROP FOREIGN KEY "
+ + DerbyTestUtil.escape(fkName);
s.executeUpdate(ddl);
}
rs.close();
@@ -170,8 +295,7 @@ public class JdbcUtil {
conn.commit();
// Tables (again)
- rs = dmd.getTables((String) null, schema, (String) null,
- GET_TABLES_TABLE);
+ rs = dmd.getTables((String) null, schema, (String) null, GET_TABLES_TABLE);
dropUsingDMD(s, rs, schema, "TABLE_NAME", "TABLE");
// drop UDTs
@@ -189,18 +313,14 @@ public class JdbcUtil {
// Synonyms - need work around for DERBY-1790 where
// passing a table type of SYNONYM fails.
- rs = dmd.getTables((String) null, schema, (String) null,
- GET_TABLES_SYNONYM);
+ rs = dmd.getTables((String) null, schema, (String) null, GET_TABLES_SYNONYM);
dropUsingDMD(s, rs, schema, "TABLE_NAME", "SYNONYM");
// sequences
if (sysSequencesExists(conn)) {
- psf = conn.prepareStatement
- (
- "SELECT SEQUENCENAME FROM SYS.SYSSEQUENCES A, SYS.SYSSCHEMAS S" +
- " WHERE A.SCHEMAID = S.SCHEMAID " +
- " AND S.SCHEMANAME = ?");
+ psf = conn.prepareStatement("SELECT SEQUENCENAME FROM SYS.SYSSEQUENCES A, SYS.SYSSCHEMAS S"
+ + " WHERE A.SCHEMAID = S.SCHEMAID " + " AND S.SCHEMANAME = ?");
psf.setString(1, schema);
rs = psf.executeQuery();
dropUsingDMD(s, rs, schema, "SEQUENCENAME", "SEQUENCE");
@@ -209,39 +329,34 @@ public class JdbcUtil {
// Finally drop the schema if it is not APP
if (!schema.equals("APP")) {
- s.executeUpdate("DROP SCHEMA " + JdbcUtil.escape(schema) + " RESTRICT");
+ s.executeUpdate("DROP SCHEMA " + DerbyTestUtil.escape(schema) + " RESTRICT");
}
conn.commit();
s.close();
}
-
/**
- * DROP a set of objects based upon a ResultSet from a
- * DatabaseMetaData call.
+ * DROP a set of objects based upon a ResultSet from a DatabaseMetaData call.
* <p>
- * TODO: Handle errors to ensure all objects are dropped,
- * probably requires interaction with its caller.
+ * TODO: Handle errors to ensure all objects are dropped, probably requires
+ * interaction with its caller.
*
* @param s Statement object used to execute the DROP commands.
* @param rs DatabaseMetaData ResultSet
* @param schema Schema the objects are contained in
- * @param mdColumn The column name used to extract the object's
- * name from rs
+ * @param mdColumn The column name used to extract the object's name from rs
* @param dropType The keyword to use after DROP in the SQL statement
* @throws SQLException database errors.
*/
- private static void dropUsingDMD(
- Statement s, ResultSet rs, String schema,
- String mdColumn,
- String dropType) throws SQLException {
+ private static void dropUsingDMD(Statement s, ResultSet rs, String schema, String mdColumn, String dropType)
+ throws SQLException {
String dropLeadIn = "DROP " + dropType + " ";
// First collect the set of DROP SQL statements.
ArrayList<String> ddl = new ArrayList<String>();
while (rs.next()) {
String objectName = rs.getString(mdColumn);
- String raw = dropLeadIn + JdbcUtil.escape(schema, objectName);
+ String raw = dropLeadIn + DerbyTestUtil.escape(schema, objectName);
if (
"TYPE".equals(dropType) ||
"SEQUENCE".equals(dropType) ||
@@ -258,10 +373,10 @@ public class JdbcUtil {
// Execute them as a complete batch, hoping they will all succeed.
s.clearBatch();
int batchCount = 0;
- for (Iterator i = ddl.iterator(); i.hasNext(); ) {
- Object sql = i.next();
+ for (Iterator<String> i = ddl.iterator(); i.hasNext(); ) {
+ String sql = i.next();
if (sql != null) {
- s.addBatch(sql.toString());
+ s.addBatch(sql);
batchCount++;
}
}
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java b/modules/commons/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java
index 8af345b..fba9db1 100644
--- a/modules/commons/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java
@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException;
/**
- * This class includes methods to start stop Derby database. Mainly user for tests.
+ * This class includes methods to start stop Derby database. Mainly used for tests.
*/
public class DerbyUtil {
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/utils/JDBCConfig.java b/modules/commons/src/main/java/org/apache/airavata/common/utils/JDBCConfig.java
index 017d54a..3e6c85e 100644
--- a/modules/commons/src/main/java/org/apache/airavata/common/utils/JDBCConfig.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/JDBCConfig.java
@@ -25,4 +25,5 @@ public interface JDBCConfig {
String getDriver();
String getUser();
String getPassword();
+ String getValidationQuery();
}
diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java
index 605163b..198baf4 100644
--- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java
+++ b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/util/CredentialStoreJDBCConfig.java
@@ -61,4 +61,13 @@ public class CredentialStoreJDBCConfig implements JDBCConfig {
throw new RuntimeException(e);
}
}
+
+ @Override
+ public String getValidationQuery() {
+ try {
+ return ServerSettings.getSetting("credential.store.jdbc.validationQuery");
+ } catch (ApplicationSettingsException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/AppCatAbstractRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/AppCatAbstractRepository.java
index 1468dd8..d800a3a 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/AppCatAbstractRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/AppCatAbstractRepository.java
@@ -20,16 +20,12 @@
*/
package org.apache.airavata.registry.core.repositories.appcatalog;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.registry.core.repositories.AbstractRepository;
import org.apache.airavata.registry.core.utils.JPAUtil.AppCatalogJPAUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
public class AppCatAbstractRepository<T, E, Id> extends AbstractRepository<T, E, Id> {
- private final static Logger logger = LoggerFactory.getLogger(AppCatAbstractRepository.class);
public AppCatAbstractRepository(Class<T> thriftGenericClass, Class<E> dbEntityGenericClass) {
super(thriftGenericClass, dbEntityGenericClass);
@@ -37,10 +33,6 @@ public class AppCatAbstractRepository<T, E, Id> extends AbstractRepository<T, E,
@Override
protected EntityManager getEntityManager() {
- try {
- return AppCatalogJPAUtils.getEntityManager();
- } catch (ApplicationSettingsException e) {
- throw new RuntimeException("Failed to get App Catalog EntityManager", e);
- }
+ return AppCatalogJPAUtils.getEntityManager();
}
-}
\ No newline at end of file
+}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExpCatAbstractRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExpCatAbstractRepository.java
index e85491a..30216c0 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExpCatAbstractRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExpCatAbstractRepository.java
@@ -1,6 +1,5 @@
package org.apache.airavata.registry.core.repositories.expcatalog;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.registry.core.repositories.AbstractRepository;
import org.apache.airavata.registry.core.utils.JPAUtil.ExpCatalogJPAUtils;
@@ -14,10 +13,6 @@ public class ExpCatAbstractRepository<T, E, Id> extends AbstractRepository<T, E,
@Override
protected EntityManager getEntityManager() {
- try {
- return ExpCatalogJPAUtils.getEntityManager();
- } catch (ApplicationSettingsException e) {
- throw new RuntimeException("Failed to get Experiment Catalog EntityManager", e);
- }
+ return ExpCatalogJPAUtils.getEntityManager();
}
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
index 31e6e5f..1f94cf1 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
@@ -20,7 +20,6 @@
*/
package org.apache.airavata.registry.core.repositories.replicacatalog;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.registry.core.repositories.AbstractRepository;
import org.apache.airavata.registry.core.utils.JPAUtil.RepCatalogJPAUtils;
@@ -34,10 +33,6 @@ public class RepCatAbstractRepository<T, E, Id> extends AbstractRepository<T, E,
@Override
protected EntityManager getEntityManager() {
- try {
- return RepCatalogJPAUtils.getEntityManager();
- } catch (ApplicationSettingsException e) {
- throw new RuntimeException("Failed to get Replica Catalog EntityManager", e);
- }
+ return RepCatalogJPAUtils.getEntityManager();
}
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowCatAbstractRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowCatAbstractRepository.java
index 93adbc5..fc2c260 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowCatAbstractRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowCatAbstractRepository.java
@@ -20,7 +20,6 @@
*/
package org.apache.airavata.registry.core.repositories.workflowcatalog;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.registry.core.repositories.AbstractRepository;
import org.apache.airavata.registry.core.utils.JPAUtil.WorkflowCatalogJPAUtils;
@@ -34,10 +33,6 @@ public class WorkflowCatAbstractRepository<T, E, Id> extends AbstractRepository<
@Override
protected EntityManager getEntityManager() {
- try {
- return WorkflowCatalogJPAUtils.getEntityManager();
- } catch (ApplicationSettingsException e) {
- throw new RuntimeException("Failed to get Workflow Catalog EntityManager", e);
- }
+ return WorkflowCatalogJPAUtils.getEntityManager();
}
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogDBInitConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogDBInitConfig.java
index 0d05869..35704fc 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogDBInitConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogDBInitConfig.java
@@ -27,6 +27,8 @@ import org.apache.airavata.registry.core.repositories.appcatalog.GwyResourceProf
public class AppCatalogDBInitConfig implements DBInitConfig {
+ private String dbInitScriptPrefix = "database_scripts/appcatalog";
+
@Override
public JDBCConfig getJDBCConfig() {
return new AppCatalogJDBCConfig();
@@ -34,7 +36,12 @@ public class AppCatalogDBInitConfig implements DBInitConfig {
@Override
public String getDBInitScriptPrefix() {
- return "database_scripts/appcatalog";
+ return dbInitScriptPrefix;
+ }
+
+ public AppCatalogDBInitConfig setDbInitScriptPrefix(String dbInitScriptPrefix) {
+ this.dbInitScriptPrefix = dbInitScriptPrefix;
+ return this;
}
@Override
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java
index dacf711..f418886 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java
@@ -29,6 +29,7 @@ public class AppCatalogJDBCConfig implements JDBCConfig {
private static final String APPCATALOG_JDBC_URL = "appcatalog.jdbc.url";
private static final String APPCATALOG_JDBC_USER = "appcatalog.jdbc.user";
private static final String APPCATALOG_JDBC_PWD = "appcatalog.jdbc.password";
+ private static final String APPCATALOG_JDBC_VALIDATION_QUERY = "appcatalog.validationQuery";
@Override
public String getURL() {
@@ -50,6 +51,11 @@ public class AppCatalogJDBCConfig implements JDBCConfig {
return readServerProperties(APPCATALOG_JDBC_PWD);
}
+ @Override
+ public String getValidationQuery() {
+ return readServerProperties(APPCATALOG_JDBC_VALIDATION_QUERY);
+ }
+
private String readServerProperties(String propertyName) {
try {
return ServerSettings.getSetting(propertyName);
@@ -57,4 +63,5 @@ public class AppCatalogJDBCConfig implements JDBCConfig {
throw new RuntimeException("Unable to read airavata-server.properties...", e);
}
}
+
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogDBInitConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogDBInitConfig.java
index c8d76f3..0e7e721 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogDBInitConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogDBInitConfig.java
@@ -30,6 +30,8 @@ import org.apache.airavata.registry.core.repositories.expcatalog.UserRepository;
public class ExpCatalogDBInitConfig implements DBInitConfig {
+ private String dbInitScriptPrefix = "database_scripts/expcatalog";
+
@Override
public JDBCConfig getJDBCConfig() {
return new ExpCatalogJDBCConfig();
@@ -37,7 +39,12 @@ public class ExpCatalogDBInitConfig implements DBInitConfig {
@Override
public String getDBInitScriptPrefix() {
- return "database_scripts/expcatalog";
+ return this.dbInitScriptPrefix;
+ }
+
+ public ExpCatalogDBInitConfig setDbInitScriptPrefix(String dbInitScriptPrefix) {
+ this.dbInitScriptPrefix = dbInitScriptPrefix;
+ return this;
}
@Override
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java
index 62d17dc..f2f1ab8 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ExpCatalogJDBCConfig.java
@@ -28,6 +28,7 @@ public class ExpCatalogJDBCConfig implements JDBCConfig {
private static final String EXPCATALOG_JDBC_URL = "registry.jdbc.url";
private static final String EXPCATALOG_JDBC_USER = "registry.jdbc.user";
private static final String EXPCATALOG_JDBC_PWD = "registry.jdbc.password";
+ private static final String EXPCATALOG_VALIDATION_QUERY = "validationQuery";
@Override
public String getURL() {
@@ -49,6 +50,11 @@ public class ExpCatalogJDBCConfig implements JDBCConfig {
return readServerProperties(EXPCATALOG_JDBC_PWD);
}
+ @Override
+ public String getValidationQuery() {
+ return readServerProperties(EXPCATALOG_VALIDATION_QUERY);
+ }
+
private String readServerProperties(String propertyName) {
try {
return ServerSettings.getSetting(propertyName);
@@ -56,4 +62,5 @@ public class ExpCatalogJDBCConfig implements JDBCConfig {
throw new RuntimeException("Unable to read airavata-server.properties...", e);
}
}
+
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java
index 097effd..f79c0cd 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java
@@ -19,8 +19,8 @@
*/
package org.apache.airavata.registry.core.utils.JPAUtil;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.common.utils.JDBCConfig;
+import org.apache.airavata.registry.core.utils.AppCatalogJDBCConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,23 +37,19 @@ public class AppCatalogJPAUtils {
private final static Logger logger = LoggerFactory.getLogger(AppCatalogJPAUtils.class);
// TODO: we can rename this back to appcatalog_data once we completely replace the other appcatalog_data persistence context in airavata-registry-core
private static final String PERSISTENCE_UNIT_NAME = "appcatalog_data_new";
- private static final String APPCATALOG_JDBC_DRIVER = "appcatalog.jdbc.driver";
- private static final String APPCATALOG_JDBC_URL = "appcatalog.jdbc.url";
- private static final String APPCATALOG_JDBC_USER = "appcatalog.jdbc.user";
- private static final String APPCATALOG_JDBC_PWD = "appcatalog.jdbc.password";
- private static final String APPCATALOG_VALIDATION_QUERY = "appcatalog.validationQuery";
+ private static final JDBCConfig JDBC_CONFIG = new AppCatalogJDBCConfig();
@PersistenceUnit(unitName = PERSISTENCE_UNIT_NAME)
protected static EntityManagerFactory factory;
@PersistenceContext(unitName = PERSISTENCE_UNIT_NAME)
private static EntityManager appCatEntityManager;
- public static EntityManager getEntityManager() throws ApplicationSettingsException {
+ public static EntityManager getEntityManager() {
if (factory == null) {
- String connectionProperties = "DriverClassName=" + readServerProperties(APPCATALOG_JDBC_DRIVER) + "," +
- "Url=" + readServerProperties(APPCATALOG_JDBC_URL) + "?autoReconnect=true," +
- "Username=" + readServerProperties(APPCATALOG_JDBC_USER) + "," +
- "Password=" + readServerProperties(APPCATALOG_JDBC_PWD) +
- ",validationQuery=" + readServerProperties(APPCATALOG_VALIDATION_QUERY);
+ String connectionProperties = "DriverClassName=" + JDBC_CONFIG.getDriver() + "," +
+ "Url=" + JDBC_CONFIG.getURL() + "?autoReconnect=true," +
+ "Username=" + JDBC_CONFIG.getUser() + "," +
+ "Password=" + JDBC_CONFIG.getPassword() +
+ ",validationQuery=" + JDBC_CONFIG.getValidationQuery();
System.out.println(connectionProperties);
Map<String, String> properties = new HashMap<String, String>();
properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
@@ -79,13 +75,4 @@ public class AppCatalogJPAUtils {
}
return appCatEntityManager;
}
-
- private static String readServerProperties(String propertyName) throws ApplicationSettingsException {
- try {
- return ServerSettings.getSetting(propertyName);
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read airavata-server.properties...", e);
- throw new ApplicationSettingsException("Unable to read airavata-server.properties...");
- }
- }
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java
index 9c9d4ff..9cbc752 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java
@@ -19,8 +19,8 @@
*/
package org.apache.airavata.registry.core.utils.JPAUtil;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.common.utils.JDBCConfig;
+import org.apache.airavata.registry.core.utils.ExpCatalogJDBCConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,26 +32,20 @@ public class ExpCatalogJPAUtils {
private final static Logger logger = LoggerFactory.getLogger(ExpCatalogJPAUtils.class);
private static final String PERSISTENCE_UNIT_NAME = "experiment_data_new";
- private static final String EXPCATALOG_JDBC_DRIVER = "registry.jdbc.driver";
- private static final String EXPCATALOG_JDBC_URL = "registry.jdbc.url";
- private static final String EXPCATALOG_JDBC_USER = "registry.jdbc.user";
- private static final String EXPCATALOG_JDBC_PASSWORD = "registry.jdbc.password";
- private static final String EXPCATALOG_VALIDATION_QUERY = "validationQuery";
- private static final String JPA_CACHE_SIZE = "jpa.cache.size";
- private static final String JPA_CACHE_ENABLED = "cache.enable";
+ private static final JDBCConfig JDBC_CONFIG = new ExpCatalogJDBCConfig();
@PersistenceUnit(unitName=PERSISTENCE_UNIT_NAME)
protected static EntityManagerFactory factory;
@PersistenceContext(unitName=PERSISTENCE_UNIT_NAME)
private static EntityManager expCatEntityManager;
- public static EntityManager getEntityManager() throws ApplicationSettingsException {
+ public static EntityManager getEntityManager() {
if (factory == null) {
- String connectionProperties = "DriverClassName=" + readServerProperties(EXPCATALOG_JDBC_DRIVER) + "," +
- "Url=" + readServerProperties(EXPCATALOG_JDBC_URL) + "?autoReconnect=true," +
- "Username=" + readServerProperties(EXPCATALOG_JDBC_USER) + "," +
- "Password=" + readServerProperties(EXPCATALOG_JDBC_PASSWORD) +
- ",validationQuery=" + readServerProperties(EXPCATALOG_VALIDATION_QUERY);
+ String connectionProperties = "DriverClassName=" + JDBC_CONFIG.getDriver() + "," +
+ "Url=" + JDBC_CONFIG.getURL() + "?autoReconnect=true," +
+ "Username=" + JDBC_CONFIG.getUser() + "," +
+ "Password=" + JDBC_CONFIG.getPassword() +
+ ",validationQuery=" + JDBC_CONFIG.getValidationQuery();
System.out.println(connectionProperties);
Map<String, String> properties = new HashMap<>();
properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
@@ -72,14 +66,4 @@ public class ExpCatalogJPAUtils {
expCatEntityManager = factory.createEntityManager();
return expCatEntityManager;
}
-
- private static String readServerProperties(String propertyName) throws ApplicationSettingsException {
- try {
- return ServerSettings.getSetting(propertyName);
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read airavata-server.properties...", e);
- throw new ApplicationSettingsException("Unable to read airavata-server.properties...");
- }
- }
-
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
index 2cc6f03..0052599 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
@@ -19,8 +19,8 @@
*/
package org.apache.airavata.registry.core.utils.JPAUtil;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.common.utils.JDBCConfig;
+import org.apache.airavata.registry.core.utils.ReplicaCatalogJDBCConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,23 +33,19 @@ public class RepCatalogJPAUtils {
// TODO: we can rename this back to replicacatalog_data once we completely replace the other replicacatalog_data persistence context in airavata-registry-core
private static final String PERSISTENCE_UNIT_NAME = "replicacatalog_data_new";
- private static final String REPLICACATALOG_JDBC_DRIVER = "replicacatalog.jdbc.driver";
- private static final String REPLICACATALOG_JDBC_URL = "replicacatalog.jdbc.url";
- private static final String REPLICACATALOG_JDBC_USER = "replicacatalog.jdbc.user";
- private static final String REPLICACATALOG_JDBC_PWD = "replicacatalog.jdbc.password";
- private static final String REPLICACATALOG_VALIDATION_QUERY = "replicacatalog.validationQuery";
+ private static final JDBCConfig JDBC_CONFIG = new ReplicaCatalogJDBCConfig();
@PersistenceUnit(unitName=PERSISTENCE_UNIT_NAME)
protected static EntityManagerFactory factory;
@PersistenceContext(unitName=PERSISTENCE_UNIT_NAME)
private static EntityManager dataCatEntityManager;
- public static EntityManager getEntityManager() throws ApplicationSettingsException {
+ public static EntityManager getEntityManager() {
if (factory == null) {
- String connectionProperties = "DriverClassName=" + readServerProperties(REPLICACATALOG_JDBC_DRIVER) + "," +
- "Url=" + readServerProperties(REPLICACATALOG_JDBC_URL) + "?autoReconnect=true," +
- "Username=" + readServerProperties(REPLICACATALOG_JDBC_USER) + "," +
- "Password=" + readServerProperties(REPLICACATALOG_JDBC_PWD) +
- ",validationQuery=" + readServerProperties(REPLICACATALOG_VALIDATION_QUERY);
+ String connectionProperties = "DriverClassName=" + JDBC_CONFIG.getDriver() + "," +
+ "Url=" + JDBC_CONFIG.getURL() + "?autoReconnect=true," +
+ "Username=" + JDBC_CONFIG.getUser() + "," +
+ "Password=" + JDBC_CONFIG.getPassword() +
+ ",validationQuery=" + JDBC_CONFIG.getValidationQuery();
System.out.println(connectionProperties);
Map<String, String> properties = new HashMap<>();
properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
@@ -69,13 +65,4 @@ public class RepCatalogJPAUtils {
return dataCatEntityManager;
}
- private static String readServerProperties (String propertyName) throws ApplicationSettingsException {
- try {
- return ServerSettings.getSetting(propertyName);
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read airavata-server.properties...", e);
- throw new ApplicationSettingsException("Unable to read airavata-server.properties...");
- }
- }
-
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java
index 852007e..39aa869 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java
@@ -19,8 +19,8 @@
*/
package org.apache.airavata.registry.core.utils.JPAUtil;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.common.utils.JDBCConfig;
+import org.apache.airavata.registry.core.utils.WorkflowCatalogJDBCConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,25 +32,19 @@ public class WorkflowCatalogJPAUtils {
private final static Logger logger = LoggerFactory.getLogger(WorkflowCatalogJPAUtils.class);
private static final String PERSISTENCE_UNIT_NAME = "workflowcatalog_data_new";
- private static final String WFCATALOG_JDBC_DRIVER = "workflowcatalog.jdbc.driver";
- private static final String WFCATALOG_JDBC_URL = "workflowcatalog.jdbc.url";
- private static final String WFCATALOG_JDBC_USER = "workflowcatalog.jdbc.user";
- private static final String WFCATALOG_JDBC_PASSWORD = "workflowcatalog.jdbc.password";
- private static final String WFCATALOG_VALIDATION_QUERY = "workflowcatalog.validationQuery";
- private static final String JPA_CACHE_SIZE = "jpa.cache.size";
- private static final String JPA_CACHE_ENABLED = "cache.enable";
+ private static final JDBCConfig JDBC_CONFIG = new WorkflowCatalogJDBCConfig();
@PersistenceUnit(unitName=PERSISTENCE_UNIT_NAME)
protected static EntityManagerFactory factory;
@PersistenceContext(unitName=PERSISTENCE_UNIT_NAME)
private static EntityManager wfCatEntityManager;
- public static EntityManager getEntityManager() throws ApplicationSettingsException {
+ public static EntityManager getEntityManager() {
if (factory == null) {
- String connectionProperties = "DriverClassName=" + readServerProperties(WFCATALOG_JDBC_DRIVER) + "," +
- "Url=" + readServerProperties(WFCATALOG_JDBC_URL) + "?autoReconnect=true," +
- "Username=" + readServerProperties(WFCATALOG_JDBC_USER) + "," +
- "Password=" + readServerProperties(WFCATALOG_JDBC_PASSWORD) +
- ",validationQuery=" + readServerProperties(WFCATALOG_VALIDATION_QUERY);
+ String connectionProperties = "DriverClassName=" + JDBC_CONFIG.getDriver() + "," +
+ "Url=" + JDBC_CONFIG.getURL() + "?autoReconnect=true," +
+ "Username=" + JDBC_CONFIG.getUser() + "," +
+ "Password=" + JDBC_CONFIG.getPassword() +
+ ",validationQuery=" + JDBC_CONFIG.getValidationQuery();
System.out.println(connectionProperties);
Map<String, String> properties = new HashMap<>();
properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
@@ -68,14 +62,4 @@ public class WorkflowCatalogJPAUtils {
wfCatEntityManager = factory.createEntityManager();
return wfCatEntityManager;
}
-
- private static String readServerProperties (String propertyName) throws ApplicationSettingsException {
- try {
- return ServerSettings.getSetting(propertyName);
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read airavata-server.properties...", e);
- throw new ApplicationSettingsException("Unable to read airavata-server.properties...");
- }
- }
-
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogDBInitConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogDBInitConfig.java
index c446b39..6b38fc6 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogDBInitConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogDBInitConfig.java
@@ -24,7 +24,9 @@ import org.apache.airavata.common.utils.JDBCConfig;
public class ReplicaCatalogDBInitConfig implements DBInitConfig {
- public static final String REPLICA_CATALOG = "DATA_PRODUCT";
+ public static final String CHECK_TABLE = "DATA_PRODUCT";
+ private String dbInitScriptPrefix = "database_scripts/replicacatalog";
+
@Override
public JDBCConfig getJDBCConfig() {
return new ReplicaCatalogJDBCConfig();
@@ -32,11 +34,16 @@ public class ReplicaCatalogDBInitConfig implements DBInitConfig {
@Override
public String getDBInitScriptPrefix() {
- return "database_scripts/replicacatalog";
+ return dbInitScriptPrefix;
+ }
+
+ public ReplicaCatalogDBInitConfig setDbInitScriptPrefix(String dbInitScriptPrefix) {
+ this.dbInitScriptPrefix = dbInitScriptPrefix;
+ return this;
}
@Override
public String getCheckTableName() {
- return REPLICA_CATALOG;
+ return CHECK_TABLE;
}
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java
index a250da3..528432a 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogJDBCConfig.java
@@ -24,10 +24,11 @@ import org.apache.airavata.common.utils.JDBCConfig;
import org.apache.airavata.common.utils.ServerSettings;
public class ReplicaCatalogJDBCConfig implements JDBCConfig {
- public static final String REPLICA_CATALOG_JDBC_DRIVER = "replicacatalog.jdbc.driver";
- public static final String REPLICA_CATALOG_JDBC_URL = "replicacatalog.jdbc.url";
- public static final String REPLICA_CATALOG_JDBC_USER = "replicacatalog.jdbc.user";
- public static final String REPLICA_CATALOG_JDBC_PASSWORD = "replicacatalog.jdbc.password";
+ private static final String REPLICA_CATALOG_JDBC_DRIVER = "replicacatalog.jdbc.driver";
+ private static final String REPLICA_CATALOG_JDBC_URL = "replicacatalog.jdbc.url";
+ private static final String REPLICA_CATALOG_JDBC_USER = "replicacatalog.jdbc.user";
+ private static final String REPLICA_CATALOG_JDBC_PASSWORD = "replicacatalog.jdbc.password";
+ private static final String REPLICA_CATALOG_VALIDATION_QUERY = "replicacatalog.validationQuery";
@Override
public String getURL() {
@@ -49,6 +50,11 @@ public class ReplicaCatalogJDBCConfig implements JDBCConfig {
return readServerProperties(REPLICA_CATALOG_JDBC_PASSWORD);
}
+ @Override
+ public String getValidationQuery() {
+ return readServerProperties(REPLICA_CATALOG_VALIDATION_QUERY);
+ }
+
private String readServerProperties(String propertyName) {
try {
return ServerSettings.getSetting(propertyName);
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogDBInitConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogDBInitConfig.java
similarity index 72%
copy from modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogDBInitConfig.java
copy to modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogDBInitConfig.java
index c446b39..42cdaba 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ReplicaCatalogDBInitConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogDBInitConfig.java
@@ -22,21 +22,27 @@ package org.apache.airavata.registry.core.utils;
import org.apache.airavata.common.utils.DBInitConfig;
import org.apache.airavata.common.utils.JDBCConfig;
-public class ReplicaCatalogDBInitConfig implements DBInitConfig {
+public class WorkflowCatalogDBInitConfig implements DBInitConfig {
+
+ private String dbInitScriptPrefix = "database_scripts/airavataworkflowcatalog";
- public static final String REPLICA_CATALOG = "DATA_PRODUCT";
@Override
public JDBCConfig getJDBCConfig() {
- return new ReplicaCatalogJDBCConfig();
+ return new WorkflowCatalogJDBCConfig();
}
@Override
public String getDBInitScriptPrefix() {
- return "database_scripts/replicacatalog";
+ return dbInitScriptPrefix;
+ }
+
+ public WorkflowCatalogDBInitConfig setDbInitScriptPrefix(String dbInitScriptPrefix) {
+ this.dbInitScriptPrefix = dbInitScriptPrefix;
+ return this;
}
@Override
public String getCheckTableName() {
- return REPLICA_CATALOG;
+ return "CONFIGURATION";
}
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogJDBCConfig.java
similarity index 62%
copy from modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java
copy to modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogJDBCConfig.java
index dacf711..7a74402 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/AppCatalogJDBCConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/WorkflowCatalogJDBCConfig.java
@@ -17,37 +17,42 @@
* under the License.
*
*/
-
package org.apache.airavata.registry.core.utils;
import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.common.utils.JDBCConfig;
import org.apache.airavata.common.utils.ServerSettings;
-public class AppCatalogJDBCConfig implements JDBCConfig {
- private static final String APPCATALOG_JDBC_DRIVER = "appcatalog.jdbc.driver";
- private static final String APPCATALOG_JDBC_URL = "appcatalog.jdbc.url";
- private static final String APPCATALOG_JDBC_USER = "appcatalog.jdbc.user";
- private static final String APPCATALOG_JDBC_PWD = "appcatalog.jdbc.password";
+public class WorkflowCatalogJDBCConfig implements JDBCConfig {
+ private static final String WORKFLOW_CATALOG_JDBC_DRIVER = "workflowcatalog.jdbc.driver";
+ private static final String WORKFLOW_CATALOG_JDBC_URL = "workflowcatalog.jdbc.url";
+ private static final String WORKFLOW_CATALOG_JDBC_USER = "workflowcatalog.jdbc.user";
+ private static final String WORKFLOW_CATALOG_JDBC_PASSWORD = "workflowcatalog.jdbc.password";
+ private static final String WORKFLOW_CATALOG_VALIDATION_QUERY = "workflowcatalog.validationQuery";
@Override
public String getURL() {
- return readServerProperties(APPCATALOG_JDBC_URL);
+ return readServerProperties(WORKFLOW_CATALOG_JDBC_URL);
}
@Override
public String getDriver() {
- return readServerProperties(APPCATALOG_JDBC_DRIVER);
+ return readServerProperties(WORKFLOW_CATALOG_JDBC_DRIVER);
}
@Override
public String getUser() {
- return readServerProperties(APPCATALOG_JDBC_USER);
+ return readServerProperties(WORKFLOW_CATALOG_JDBC_USER);
}
@Override
public String getPassword() {
- return readServerProperties(APPCATALOG_JDBC_PWD);
+ return readServerProperties(WORKFLOW_CATALOG_JDBC_PASSWORD);
+ }
+
+ @Override
+ public String getValidationQuery() {
+ return readServerProperties(WORKFLOW_CATALOG_VALIDATION_QUERY);
}
private String readServerProperties(String propertyName) {
diff --git a/modules/registry-refactoring/src/main/resources/replicacatalog-derby.sql b/modules/registry-refactoring/src/main/resources/replicacatalog-derby.sql
index a39a10d..e0f4950 100644
--- a/modules/registry-refactoring/src/main/resources/replicacatalog-derby.sql
+++ b/modules/registry-refactoring/src/main/resources/replicacatalog-derby.sql
@@ -31,6 +31,7 @@ CREATE TABLE DATA_PRODUCT
PRODUCT_SIZE INTEGER ,
CREATION_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
LAST_MODIFIED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
+ PRODUCT_TYPE VARCHAR(10),
PRIMARY KEY (PRODUCT_URI)
);
@@ -45,6 +46,8 @@ CREATE TABLE DATA_REPLICA_LOCATION
CREATION_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
LAST_MODIFIED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
VALID_UNTIL_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
+ REPLICA_LOCATION_CATEGORY VARCHAR(26),
+ REPLICA_PERSISTENT_TYPE VARCHAR(10),
PRIMARY KEY (REPLICA_ID),
FOREIGN KEY (PRODUCT_URI) REFERENCES DATA_PRODUCT(PRODUCT_URI) ON DELETE CASCADE
);
diff --git a/modules/registry-refactoring/src/main/resources/replicacatalog-mysql.sql b/modules/registry-refactoring/src/main/resources/replicacatalog-mysql.sql
index 2cce9ac..ec9a720 100644
--- a/modules/registry-refactoring/src/main/resources/replicacatalog-mysql.sql
+++ b/modules/registry-refactoring/src/main/resources/replicacatalog-mysql.sql
@@ -31,6 +31,7 @@ CREATE TABLE DATA_PRODUCT
PRODUCT_SIZE INT,
CREATION_TIME TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
LAST_MODIFIED_TIME TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ PRODUCT_TYPE VARCHAR(10),
PRIMARY KEY (PRODUCT_URI)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
@@ -45,6 +46,8 @@ CREATE TABLE DATA_REPLICA_LOCATION
CREATION_TIME TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
LAST_MODIFIED_TIME TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
VALID_UNTIL_TIME TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
+ REPLICA_LOCATION_CATEGORY VARCHAR(26),
+ REPLICA_PERSISTENT_TYPE VARCHAR(10),
PRIMARY KEY (REPLICA_ID),
FOREIGN KEY (PRODUCT_URI) REFERENCES DATA_PRODUCT(PRODUCT_URI) ON DELETE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GatewayProfileRepositoryTest.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GatewayProfileRepositoryTest.java
index 99e90fe..bbf70e0 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GatewayProfileRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GatewayProfileRepositoryTest.java
@@ -19,6 +19,8 @@
*/
package org.apache.airavata.registry.core.repositories.appcatalog;
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription;
import org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol;
import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
@@ -35,6 +37,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class GatewayProfileRepositoryTest extends TestBase {
@@ -49,7 +52,13 @@ public class GatewayProfileRepositoryTest extends TestBase {
}
@Test
- public void gatewayProfileRepositorytest() throws AppCatalogException {
+ public void gatewayProfileRepositorytest() throws AppCatalogException, ApplicationSettingsException {
+
+ // Verify that the default Gateway Resource Profile exists already
+ List<GatewayResourceProfile> defaultGatewayResourceProfileList = this.gwyResourceProfileRepository.getAllGatewayProfiles();
+ assertEquals(1, defaultGatewayResourceProfileList.size());
+ assertEquals(ServerSettings.getDefaultUserGateway(), defaultGatewayResourceProfileList.get(0).getGatewayID());
+
GatewayResourceProfile gf = new GatewayResourceProfile();
ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository();
ComputeResourceDescription cm1 = new ComputeResourceDescription();
@@ -113,7 +122,7 @@ public class GatewayProfileRepositoryTest extends TestBase {
gwyResourceProfileRepository.addGatewayResourceProfile(gf1);
List<GatewayResourceProfile> getGatewayResourceList = gwyResourceProfileRepository.getAllGatewayProfiles();
- assertTrue(getGatewayResourceList.size() == 2);
+ assertEquals("should be 3 gateway profiles (1 default and 2 just added)", 3, getGatewayResourceList.size());
List<ComputeResourcePreference> preferences = gwyResourceProfileRepository.getAllComputeResourcePreferences(gwId);
System.out.println("compute preferences size : " + preferences.size());
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/DerbyDBManager.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/DerbyDBManager.java
deleted file mode 100644
index 201b241..0000000
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/DerbyDBManager.java
+++ /dev/null
@@ -1,240 +0,0 @@
-package org.apache.airavata.registry.core.repositories.common;
-
-import com.ibatis.common.jdbc.ScriptRunner;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.derby.drda.NetworkServerControl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.net.InetAddress;
-import java.sql.*;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Most of the code in this class was influenced by
- * http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java?view=markup
- */
-public class DerbyDBManager {
-
- private static final Logger logger = LoggerFactory.getLogger(DerbyDBManager.class);
-
- private static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer";
-
- private static final String[] CLEAR_DB_PROPERTIES = {"derby.database.classpath",};
-
- private NetworkServerControl server;
- private String jdbcDriver = null;
- private String jdbcUser = null;
- private String jdbcPassword = null;
-
-
- public DerbyDBManager() {
-
- try {
- jdbcDriver = ServerSettings.getSetting("appcatalog.jdbc.driver");
- jdbcUser = ServerSettings.getSetting("appcatalog.jdbc.user");
- jdbcPassword = ServerSettings.getSetting("appcatalog.jdbc.password");
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read properties", e);
- }
- }
-
- public void startDatabaseServer() {
- try {
- System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
- server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"),
- 20000,
- jdbcUser, jdbcPassword);
- java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true);
- server.start(consoleWriter);
- } catch (IOException e) {
- logger.error("Unable to start Apache derby in the server mode! Check whether " +
- "specified port is available");
- } catch (Exception e) {
- logger.error("Unable to start Apache derby in the server mode! Check whether " +
- "specified port is available");
- }
- }
-
- public void stopDatabaseServer() {
- try {
- server.shutdown();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
-
- public void initializeDatabase(String databaseName, String initFile) {
-
- String jdbcUrl = "jdbc:derby:" + databaseName + ";create=true;user=" + jdbcUser + ";password=" + jdbcPassword;
-
- Connection conn = null;
- try {
- Class.forName(jdbcDriver).newInstance();
- conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
- ScriptRunner scriptRunner = new ScriptRunner(conn, false, false);
- Reader reader = new BufferedReader(new FileReader(initFile));
- scriptRunner.runScript(reader);
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new RuntimeException("Database failure", e);
- } finally {
- try {
- if (conn != null) {
- if (!conn.getAutoCommit()) {
- conn.commit();
- }
- conn.close();
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- }
- }
- }
-
- // TODO: move this into DerbyUtil
- public void destroyDatabase(String databaseName) {
-
- String jdbcUrl = "jdbc:derby:" + databaseName + ";create=true;user=" + jdbcUser + ";password=" + jdbcPassword;
-
- Connection conn = null;
- try {
- Class.forName(jdbcDriver).newInstance();
- conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
- conn.setAutoCommit(false);
- clearProperties(conn);
- removeObjects(conn);
- removeRoles(conn);
- removeUsers(conn);
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new RuntimeException("Database failure", e);
- } finally {
- try {
- if (conn != null) {
- if (!conn.getAutoCommit()) {
- conn.commit();
- }
- conn.close();
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- }
- }
- }
-
-
- private static void clearProperties(Connection conn) throws SQLException {
- PreparedStatement ps = conn.prepareCall(
- "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, NULL)");
-
- for (String CLEAR_DB_PROPERTY : CLEAR_DB_PROPERTIES) {
- ps.setString(1, CLEAR_DB_PROPERTY);
- ps.executeUpdate();
- }
- ps.close();
- conn.commit();
- }
-
- private static void removeObjects(Connection conn) throws SQLException {
-
- DatabaseMetaData dmd = conn.getMetaData();
-
- SQLException sqle = null;
- // Loop a number of arbitary times to catch cases
- // where objects are dependent on objects in
- // different schemas.
- for (int count = 0; count < 5; count++) {
- // Fetch all the user schemas into a list
- List<String> schemas = new ArrayList<>();
- ResultSet rs = dmd.getSchemas();
- while (rs.next()) {
-
- String schema = rs.getString("TABLE_SCHEM");
- if (schema.startsWith("SYS"))
- continue;
- if (schema.equals("SQLJ"))
- continue;
- if (schema.equals("NULLID"))
- continue;
-
- schemas.add(schema);
- }
- rs.close();
-
- // DROP all the user schemas.
- sqle = null;
- for (String schema : schemas) {
- try {
- JdbcUtil.dropSchema(dmd, schema);
- } catch (SQLException e) {
- sqle = e;
- }
- }
- // No errors means all the schemas we wanted to
- // drop were dropped, so nothing more to do.
- if (sqle == null)
- return;
- }
- throw sqle;
- }
-
- private static void removeRoles(Connection conn) throws SQLException {
- // No metadata for roles, so do a query against SYSROLES
- Statement stm = conn.createStatement();
- Statement dropStm = conn.createStatement();
-
- // cast to overcome territory differences in some cases:
- ResultSet rs = stm.executeQuery(
- "select roleid from sys.sysroles where " +
- "cast(isdef as char(1)) = 'Y'");
-
- while (rs.next()) {
- dropStm.executeUpdate("DROP ROLE " + JdbcUtil.escape(rs.getString(1)));
- }
-
- stm.close();
- dropStm.close();
- conn.commit();
- }
-
- private static void removeUsers(Connection conn) throws SQLException {
- // Get the users
- Statement stm = conn.createStatement();
- ResultSet rs = stm.executeQuery("select username from sys.sysusers");
- ArrayList<String> users = new ArrayList<String>();
-
- while (rs.next()) {
- users.add(rs.getString(1));
- }
- rs.close();
- stm.close();
-
- // Now delete them
- PreparedStatement ps = conn.prepareStatement("call syscs_util.syscs_drop_user( ? )");
-
- for (int i = 0; i < users.size(); i++) {
- ps.setString(1, (String) users.get(i));
-
- // you can't drop the DBO's credentials. sorry.
- try {
- ps.executeUpdate();
- } catch (SQLException se) {
- if ("4251F".equals(se.getSQLState())) {
- continue;
- } else {
- throw se;
- }
- }
- }
-
- ps.close();
- conn.commit();
- }
-}
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/TestBase.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/TestBase.java
index 80b2b9b..578eb82 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/TestBase.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/common/TestBase.java
@@ -1,20 +1,26 @@
package org.apache.airavata.registry.core.repositories.common;
+import org.apache.airavata.common.utils.DBInitConfig;
+import org.apache.airavata.common.utils.DBInitializer;
+import org.apache.airavata.common.utils.DerbyTestUtil;
+import org.apache.airavata.common.utils.DerbyUtil;
+import org.apache.airavata.common.utils.JDBCConfig;
import org.apache.airavata.registry.core.repositories.appcatalog.ApplicationDeploymentRepositoryTest;
+import org.apache.airavata.registry.core.utils.AppCatalogDBInitConfig;
+import org.apache.airavata.registry.core.utils.ExpCatalogDBInitConfig;
+import org.apache.airavata.registry.core.utils.ReplicaCatalogDBInitConfig;
+import org.apache.airavata.registry.core.utils.WorkflowCatalogDBInitConfig;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Objects;
-
public class TestBase {
private static final Logger logger = LoggerFactory.getLogger(ApplicationDeploymentRepositoryTest.class);
- public enum Database {APP_CATALOG, EXP_CATALOG, REPLICA_CATALOG}
+ public enum Database {APP_CATALOG, EXP_CATALOG, REPLICA_CATALOG, WORKFLOW_CATALOG}
- private DerbyDBManager dbManager = new DerbyDBManager();
private Database[] databases;
public TestBase(Database... databases) {
@@ -25,14 +31,14 @@ public class TestBase {
}
@Before
- public void setUp() {
+ public void setUp() throws Exception {
try {
- dbManager.startDatabaseServer();
+ DerbyUtil.startDerbyInServerMode("0.0.0.0", 20000, "airavata", "airavata");
for (Database database: databases) {
logger.info("Creating database " + database.name());
- dbManager.destroyDatabase(getDatabaseName(database));
- dbManager.initializeDatabase(getDatabaseName(database), getDatabasePath(database));
+ DerbyTestUtil.destroyDatabase(getDatabaseJDBCConfig(database));
+ DBInitializer.initializeDB(getDBInitConfig(database));
}
} catch (Exception e) {
logger.error("Failed to create the databases" , e);
@@ -44,32 +50,29 @@ public class TestBase {
public void tearDown() throws Exception {
for (Database database: databases) {
System.out.println("Tearing down database " + database.name());
- dbManager.destroyDatabase(getDatabaseName(database));
+ DerbyTestUtil.destroyDatabase(getDatabaseJDBCConfig(database));
}
- dbManager.stopDatabaseServer();
+ DerbyUtil.stopDerbyServer();
}
- private String getDatabasePath(Database database) {
- switch (database) {
- case APP_CATALOG:
- return Objects.requireNonNull(getClass().getClassLoader().getResource("appcatalog-derby.sql")).getPath();
- case EXP_CATALOG:
- return Objects.requireNonNull(getClass().getClassLoader().getResource("expcatalog-derby.sql")).getPath();
- case REPLICA_CATALOG:
- return Objects.requireNonNull(getClass().getClassLoader().getResource("replicacatalog-derby.sql")).getPath();
- default:
- return null;
- }
+ private JDBCConfig getDatabaseJDBCConfig(Database database) {
+ return getDBInitConfig(database).getJDBCConfig();
}
- private String getDatabaseName(Database database) {
+ private DBInitConfig getDBInitConfig(Database database) {
switch (database) {
case APP_CATALOG:
- return "app_catalog";
+ return new AppCatalogDBInitConfig()
+ .setDbInitScriptPrefix("appcatalog");
case EXP_CATALOG:
- return "experiment_catalog";
+ return new ExpCatalogDBInitConfig()
+ .setDbInitScriptPrefix("expcatalog");
case REPLICA_CATALOG:
- return "replica_catalog";
+ return new ReplicaCatalogDBInitConfig()
+ .setDbInitScriptPrefix("replicacatalog");
+ case WORKFLOW_CATALOG:
+ return new WorkflowCatalogDBInitConfig()
+ .setDbInitScriptPrefix("airavataworkflowcatalog");
default:
return null;
}
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/GatewayRepositoryTest.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/GatewayRepositoryTest.java
index d79a26e..5763c76 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/GatewayRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/GatewayRepositoryTest.java
@@ -21,22 +21,18 @@
package org.apache.airavata.registry.core.repositories.expcatalog;
import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.model.workspace.Gateway;
import org.apache.airavata.model.workspace.GatewayApprovalStatus;
import org.apache.airavata.registry.core.repositories.common.TestBase;
import org.apache.airavata.registry.cpi.RegistryException;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import java.util.List;
public class GatewayRepositoryTest extends TestBase {
- private static final Logger logger = LoggerFactory.getLogger(GatewayRepositoryTest.class);
-
private String testGatewayId = "testGateway";
GatewayRepository gatewayRepository;
@@ -46,7 +42,12 @@ public class GatewayRepositoryTest extends TestBase {
}
@Test
- public void GatewayRepositoryTest() throws ApplicationSettingsException, RegistryException {
+ public void gatewayRepositoryTest() throws ApplicationSettingsException, RegistryException {
+ // Verify that default Gateway is already created
+ List<Gateway> defaultGatewayList = gatewayRepository.getAllGateways();
+ assertEquals(1, defaultGatewayList.size());
+ assertEquals(ServerSettings.getDefaultUserGateway(), defaultGatewayList.get(0).getGatewayId());
+
Gateway gateway = new Gateway();
gateway.setGatewayId(testGatewayId);
gateway.setDomain("SEAGRID");
@@ -67,7 +68,7 @@ public class GatewayRepositoryTest extends TestBase {
assertEquals(gateway.getOauthClientId(), retrievedGateway.getOauthClientId());
assertEquals(gateway.getOauthClientSecret(), retrievedGateway.getOauthClientSecret());
- assertTrue(gatewayRepository.getAllGateways().size() == 1);
+ assertEquals("should be 2 gateways (1 default plus 1 just added)", 2, gatewayRepository.getAllGateways().size());
gatewayRepository.removeGateway(gatewayId);
assertFalse(gatewayRepository.isGatewayExist(gatewayId));
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/util/Initialize.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/util/Initialize.java
deleted file mode 100644
index c21928a..0000000
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/util/Initialize.java
+++ /dev/null
@@ -1,293 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.airavata.registry.core.repositories.expcatalog.util;
-
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.airavata.registry.core.utils.DBConstants;
-import org.apache.derby.drda.NetworkServerControl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.sql.*;
-import java.util.StringTokenizer;
-
-public class Initialize {
- private static final Logger logger = LoggerFactory.getLogger(Initialize.class);
- public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer";
- public String scriptName = "expcatalog-derby.sql";
- private NetworkServerControl server;
- private static final String delimiter = ";";
- private String jdbcUrl = null;
- private String jdbcDriver = null;
- private String jdbcUser = null;
- private String jdbcPassword = null;
-
- public Initialize(String scriptName) {
- this.scriptName = scriptName;
- }
-
- public static boolean checkStringBufferEndsWith(StringBuffer buffer, String suffix) {
- if (suffix.length() > buffer.length()) {
- return false;
- }
- // this loop is done on purpose to avoid memory allocation performance
- // problems on various JDKs
- // StringBuffer.lastIndexOf() was introduced in jdk 1.4 and
- // implementation is ok though does allocation/copying
- // StringBuffer.toString().endsWith() does massive memory
- // allocation/copying on JDK 1.5
- // See http://issues.apache.org/bugzilla/show_bug.cgi?id=37169
- int endIndex = suffix.length() - 1;
- int bufferIndex = buffer.length() - 1;
- while (endIndex >= 0) {
- if (buffer.charAt(bufferIndex) != suffix.charAt(endIndex)) {
- return false;
- }
- bufferIndex--;
- endIndex--;
- }
- return true;
- }
-
- private static boolean isServerStarted(NetworkServerControl server, int ntries)
- {
- for (int i = 1; i <= ntries; i ++)
- {
- try {
- Thread.sleep(500);
- server.ping();
- return true;
- }
- catch (Exception e) {
- if (i == ntries)
- return false;
- }
- }
- return false;
- }
-
- public void initializeDB() throws SQLException{
- try{
- jdbcDriver = ServerSettings.getSetting("registry.jdbc.driver");
- jdbcUrl = ServerSettings.getSetting("registry.jdbc.url");
- jdbcUser = ServerSettings.getSetting("registry.jdbc.user");
- jdbcPassword = ServerSettings.getSetting("registry.jdbc.password");
- jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read properties", e);
- }
- startDerbyInServerMode();
- if(!isServerStarted(server, 20)){
- throw new RuntimeException("Derby server cound not started within five seconds...");
- }
-
- Connection conn = null;
- try {
- Class.forName(jdbcDriver).newInstance();
- conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
- if (!isDatabaseStructureCreated(DBConstants.CONFIGURATION, conn)) {
- executeSQLScript(conn);
- logger.info("New Database created for Registry");
- } else {
- logger.debug("Database already created for Registry!");
- }
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new RuntimeException("Database failure", e);
- } finally {
- try {
- if (conn != null){
- if (!conn.getAutoCommit()) {
- conn.commit();
- }
- conn.close();
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- }
- }
- }
-
- public static boolean isDatabaseStructureCreated(String tableName, Connection conn) {
- try {
- System.out.println("Running a query to test the database tables existence.");
- // check whether the tables are already created with a query
- Statement statement = null;
- try {
- statement = conn.createStatement();
- ResultSet rs = statement.executeQuery("select * from " + tableName);
- if (rs != null) {
- rs.close();
- }
- } finally {
- try {
- if (statement != null) {
- statement.close();
- }
- } catch (SQLException e) {
- return false;
- }
- }
- } catch (SQLException e) {
- return false;
- }
-
- return true;
- }
-
- private void executeSQLScript(Connection conn) throws Exception {
- StringBuffer sql = new StringBuffer();
- BufferedReader reader = null;
- try{
-
- InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(scriptName);
- reader = new BufferedReader(new InputStreamReader(inputStream));
- String line;
- while ((line = reader.readLine()) != null) {
- line = line.trim();
- if (line.startsWith("//")) {
- continue;
- }
- if (line.startsWith("--")) {
- continue;
- }
- StringTokenizer st = new StringTokenizer(line);
- if (st.hasMoreTokens()) {
- String token = st.nextToken();
- if ("REM".equalsIgnoreCase(token)) {
- continue;
- }
- }
- sql.append(" ").append(line);
-
- // SQL defines "--" as a comment to EOL
- // and in Oracle it may contain a hint
- // so we cannot just remove it, instead we must end it
- if (line.indexOf("--") >= 0) {
- sql.append("\n");
- }
- if ((checkStringBufferEndsWith(sql, delimiter))) {
- executeSQL(sql.substring(0, sql.length() - delimiter.length()), conn);
- sql.replace(0, sql.length(), "");
- }
- }
- // Catch any statements not followed by ;
- if (sql.length() > 0) {
- executeSQL(sql.toString(), conn);
- }
- }catch (IOException e){
- logger.error("Error occurred while executing SQL script for creating Airavata database", e);
- throw new Exception("Error occurred while executing SQL script for creating Airavata database", e);
- }finally {
- if (reader != null) {
- reader.close();
- }
-
- }
-
- }
-
- private static void executeSQL(String sql, Connection conn) throws Exception {
- // Check and ignore empty statements
- if ("".equals(sql.trim())) {
- return;
- }
-
- Statement statement = null;
- try {
- logger.debug("SQL : " + sql);
-
- boolean ret;
- int updateCount = 0, updateCountTotal = 0;
- statement = conn.createStatement();
- ret = statement.execute(sql);
- updateCount = statement.getUpdateCount();
- do {
- if (!ret) {
- if (updateCount != -1) {
- updateCountTotal += updateCount;
- }
- }
- ret = statement.getMoreResults();
- if (ret) {
- updateCount = statement.getUpdateCount();
- }
- } while (ret);
-
- logger.debug(sql + " : " + updateCountTotal + " rows affected");
-
- SQLWarning warning = conn.getWarnings();
- while (warning != null) {
- logger.warn(warning + " sql warning");
- warning = warning.getNextWarning();
- }
- conn.clearWarnings();
- } catch (SQLException e) {
- if (e.getSQLState().equals("X0Y32")) {
- // eliminating the table already exception for the derby
- // database
- logger.info("Table Already Exists", e);
- } else {
- throw new Exception("Error occurred while executing : " + sql, e);
- }
- } finally {
- if (statement != null) {
- try {
- statement.close();
- } catch (SQLException e) {
- logger.error("Error occurred while closing result set.", e);
- }
- }
- }
- }
-
- private void startDerbyInServerMode() {
- try {
- System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
- server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"),
- 20000,
- jdbcUser, jdbcPassword);
- java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true);
- server.start(consoleWriter);
- } catch (IOException e) {
- logger.error("Unable to start Apache derby in the server mode! Check whether " +
- "specified port is available");
- } catch (Exception e) {
- logger.error("Unable to start Apache derby in the server mode! Check whether " +
- "specified port is available");
- }
-
- }
-
- public void stopDerbyServer() throws SQLException{
- try {
- server.shutdown();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new SQLException("Error while stopping derby server", e);
- }
- }
-}
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
index 64da753..75b182d 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
@@ -25,13 +25,9 @@ import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
import org.apache.airavata.model.data.replica.ReplicaLocationCategory;
import org.apache.airavata.model.data.replica.ReplicaPersistentType;
import org.apache.airavata.registry.core.entities.replicacatalog.DataProductMetadataEntity;
-import org.apache.airavata.registry.core.repositories.replicacatalog.util.Initialize;
+import org.apache.airavata.registry.core.repositories.common.TestBase;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.List;
@@ -41,34 +37,24 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-public class DataProductRepositoryTest {
+public class DataProductRepositoryTest extends TestBase {
- private static Initialize initialize;
private DataProductRepository dataProductRepository;
private String gatewayId = "testGateway";
private String userId = "testUser";
private String productName = "testProduct";
- private static final Logger logger = LoggerFactory.getLogger(DataProductRepositoryTest.class);
-
- @Before
- public void setUp() {
- try {
- initialize = new Initialize("replicacatalog-derby.sql");
- initialize.initializeDB();
- dataProductRepository = new DataProductRepository();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
+
+ public DataProductRepositoryTest() {
+ super(Database.REPLICA_CATALOG);
}
- @After
- public void tearDown() throws Exception {
- System.out.println("********** TEAR DOWN ************");
- initialize.stopDerbyServer();
+ public void setUp() throws Exception {
+ super.setUp();
+ dataProductRepository = new DataProductRepository();
}
@Test
- public void DataProductRepositoryTest() throws ReplicaCatalogException {
+ public void dataProductRepositoryTest() throws ReplicaCatalogException {
DataProductModel testDataProductModel1 = new DataProductModel();
testDataProductModel1.setGatewayId(gatewayId);
testDataProductModel1.setOwnerName(userId);
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
index 16e5b0f..2784733 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
@@ -24,13 +24,9 @@ import org.apache.airavata.model.data.replica.DataProductType;
import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
import org.apache.airavata.model.data.replica.ReplicaPersistentType;
import org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaMetadataEntity;
-import org.apache.airavata.registry.core.repositories.replicacatalog.util.Initialize;
+import org.apache.airavata.registry.core.repositories.common.TestBase;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.HashMap;
@@ -41,34 +37,20 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-public class DataReplicaLocationRepositoryTest {
+public class DataReplicaLocationRepositoryTest extends TestBase {
- private static Initialize initialize;
private DataProductRepository dataProductRepository;
private DataReplicaLocationRepository dataReplicaLocationRepository;
private String gatewayId = "testGateway";
- private static final Logger logger = LoggerFactory.getLogger(DataReplicaLocationRepositoryTest.class);
-
- @Before
- public void setUp() {
- try {
- initialize = new Initialize("replicacatalog-derby.sql");
- initialize.initializeDB();
- dataProductRepository = new DataProductRepository();
- dataReplicaLocationRepository = new DataReplicaLocationRepository();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
-
- @After
- public void tearDown() throws Exception {
- System.out.println("********** TEAR DOWN ************");
- initialize.stopDerbyServer();
+
+ public DataReplicaLocationRepositoryTest() {
+ super(Database.REPLICA_CATALOG);
+ dataProductRepository = new DataProductRepository();
+ dataReplicaLocationRepository = new DataReplicaLocationRepository();
}
@Test
- public void DataReplicaLocationRepositoryTest() throws ReplicaCatalogException {
+ public void dataReplicaLocationRepositoryTest() throws ReplicaCatalogException {
DataProductModel testDataProductModel = new DataProductModel();
testDataProductModel.setGatewayId(gatewayId);
testDataProductModel.setOwnerName("testUser");
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/util/Initialize.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/util/Initialize.java
deleted file mode 100644
index 667d56e..0000000
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/util/Initialize.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.airavata.registry.core.repositories.replicacatalog.util;
-
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.airavata.registry.core.utils.DBConstants;
-import org.apache.derby.drda.NetworkServerControl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.URI;
-import java.sql.*;
-import java.util.StringTokenizer;
-
-public class Initialize {
- private static final Logger logger = LoggerFactory.getLogger(Initialize.class);
- public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer";
- public String scriptName = "replicacatalog-derby.sql";
- private NetworkServerControl server;
- private static final String delimiter = ";";
- private String jdbcUrl = null;
- private String jdbcDriver = null;
- private String jdbcUser = null;
- private String jdbcPassword = null;
-
- public Initialize(String scriptName) {
- this.scriptName = scriptName;
- }
-
- public static boolean checkStringBufferEndsWith(StringBuffer buffer, String suffix) {
- if (suffix.length() > buffer.length()) {
- return false;
- }
- // this loop is done on purpose to avoid memory allocation performance
- // problems on various JDKs
- // StringBuffer.lastIndexOf() was introduced in jdk 1.4 and
- // implementation is ok though does allocation/copying
- // StringBuffer.toString().endsWith() does massive memory
- // allocation/copying on JDK 1.5
- // See http://issues.apache.org/bugzilla/show_bug.cgi?id=37169
- int endIndex = suffix.length() - 1;
- int bufferIndex = buffer.length() - 1;
- while (endIndex >= 0) {
- if (buffer.charAt(bufferIndex) != suffix.charAt(endIndex)) {
- return false;
- }
- bufferIndex--;
- endIndex--;
- }
- return true;
- }
-
- private static boolean isServerStarted(NetworkServerControl server, int ntries)
- {
- for (int i = 1; i <= ntries; i ++)
- {
- try {
- Thread.sleep(500);
- server.ping();
- return true;
- }
- catch (Exception e) {
- if (i == ntries)
- return false;
- }
- }
- return false;
- }
-
- public void initializeDB() {
- try{
- jdbcDriver = ServerSettings.getSetting("replicacatalog.jdbc.driver");
- jdbcUrl = ServerSettings.getSetting("replicacatalog.jdbc.url");
- jdbcUser = ServerSettings.getSetting("replicacatalog.jdbc.user");
- jdbcPassword = ServerSettings.getSetting("replicacatalog.jdbc.password");
- jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read properties", e);
- }
-
- startDerbyInServerMode();
- if(!isServerStarted(server, 20)){
- throw new RuntimeException("Derby server could not started within five seconds...");
- }
- Connection conn = null;
- try {
- Class.forName(jdbcDriver).newInstance();
- conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
- if (!isDatabaseStructureCreated(DBConstants.CONFIGURATION, conn)) {
- executeSQLScript(conn);
- logger.info("New Database created for Replica Catalog !!!");
- } else {
- logger.debug("Database already created for Replica Catalog!");
- }
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- throw new RuntimeException("Database failure", e);
- } finally {
- try {
- if (conn != null){
- if (!conn.getAutoCommit()) {
- conn.commit();
- }
- conn.close();
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- }
- }
- }
-
- public static boolean isDatabaseStructureCreated(String tableName, Connection conn) {
- try {
- System.out.println("Running a query to test the database tables existence.");
- // check whether the tables are already created with a query
- Statement statement = null;
- try {
- statement = conn.createStatement();
- ResultSet rs = statement.executeQuery("select * from " + tableName);
- if (rs != null) {
- rs.close();
- }
- } finally {
- try {
- if (statement != null) {
- statement.close();
- }
- } catch (SQLException e) {
- return false;
- }
- }
- } catch (SQLException e) {
- return false;
- }
-
- return true;
- }
-
- private void executeSQLScript(Connection conn) throws Exception {
- StringBuffer sql = new StringBuffer();
- BufferedReader reader = null;
- try{
-
- InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(scriptName);
- reader = new BufferedReader(new InputStreamReader(inputStream));
- String line;
- while ((line = reader.readLine()) != null) {
- line = line.trim();
- if (line.startsWith("//")) {
- continue;
- }
- if (line.startsWith("--")) {
- continue;
- }
- StringTokenizer st = new StringTokenizer(line);
- if (st.hasMoreTokens()) {
- String token = st.nextToken();
- if ("REM".equalsIgnoreCase(token)) {
- continue;
- }
- }
- sql.append(" ").append(line);
-
- // SQL defines "--" as a comment to EOL
- // and in Oracle it may contain a hint
- // so we cannot just remove it, instead we must end it
- if (line.indexOf("--") >= 0) {
- sql.append("\n");
- }
- if ((checkStringBufferEndsWith(sql, delimiter))) {
- executeSQL(sql.substring(0, sql.length() - delimiter.length()), conn);
- sql.replace(0, sql.length(), "");
- }
- }
- // Catch any statements not followed by ;
- if (sql.length() > 0) {
- executeSQL(sql.toString(), conn);
- }
- }catch (IOException e){
- logger.error("Error occurred while executing SQL script for creating Airavata Replica Catalog database", e);
- throw new Exception("Error occurred while executing SQL script for creating Airavata Replica Catalog database", e);
- }finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
-
- private static void executeSQL(String sql, Connection conn) throws Exception {
- // Check and ignore empty statements
- if ("".equals(sql.trim())) {
- return;
- }
-
- Statement statement = null;
- try {
- logger.debug("SQL : " + sql);
-
- boolean ret;
- int updateCount = 0, updateCountTotal = 0;
- statement = conn.createStatement();
- ret = statement.execute(sql);
- updateCount = statement.getUpdateCount();
- do {
- if (!ret) {
- if (updateCount != -1) {
- updateCountTotal += updateCount;
- }
- }
- ret = statement.getMoreResults();
- if (ret) {
- updateCount = statement.getUpdateCount();
- }
- } while (ret);
-
- logger.debug(sql + " : " + updateCountTotal + " rows affected");
-
- SQLWarning warning = conn.getWarnings();
- while (warning != null) {
- logger.warn(warning + " sql warning");
- warning = warning.getNextWarning();
- }
- conn.clearWarnings();
- } catch (SQLException e) {
- if (e.getSQLState().equals("X0Y32")) {
- // eliminating the table already exception for the derby
- // database
- logger.info("Table Already Exists", e);
- } else {
- throw new Exception("Error occurred while executing : " + sql, e);
- }
- } finally {
- if (statement != null) {
- try {
- statement.close();
- } catch (SQLException e) {
- logger.error("Error occurred while closing result set.", e);
- }
- }
- }
- }
-
- private void startDerbyInServerMode() {
- try {
- System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
- server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"),
- 20000,
- jdbcUser, jdbcPassword);
- java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true);
- server.start(consoleWriter);
- } catch (IOException e) {
- logger.error("Unable to start Apache derby in the server mode! Check whether " +
- "specified port is available");
- } catch (Exception e) {
- logger.error("Unable to start Apache derby in the server mode! Check whether " +
- "specified port is available");
- }
-
- }
-
- public static int getPort(String jdbcURL){
- try{
- String cleanURI = jdbcURL.substring(5);
- URI uri = URI.create(cleanURI);
- return uri.getPort();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- return -1;
- }
- }
-
- private void startDerbyInEmbeddedMode(){
- try {
- Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
- DriverManager.getConnection("jdbc:derby:memory:unit-testing-jpa;create=true").close();
- } catch (ClassNotFoundException e) {
- logger.error(e.getMessage(), e);
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- }
- }
-
- public void stopDerbyServer() {
- try {
- server.shutdown();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
-}
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowRepositoryTest.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowRepositoryTest.java
index 3767b90..4f4d129 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/workflowcatalog/WorkflowRepositoryTest.java
@@ -20,21 +20,15 @@
package org.apache.airavata.registry.core.repositories.workflowcatalog;
import org.apache.airavata.model.workflow.*;
-import org.apache.airavata.registry.core.repositories.workflowcatalog.util.Initialize;
+import org.apache.airavata.registry.core.repositories.common.TestBase;
import org.apache.airavata.registry.cpi.WorkflowCatalogException;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
-public class WorkflowRepositoryTest {
+public class WorkflowRepositoryTest extends TestBase {
- private static final Logger logger = LoggerFactory.getLogger(WorkflowRepositoryTest.class);
-
- private static Initialize initialize;
private WorkflowRepository workflowRepository;
// Workflow related constants
@@ -60,21 +54,15 @@ public class WorkflowRepositoryTest {
private String SAMPLE_HANDLER_INPUT_NAME = "handler_input";
private String SAMPLE_HANDLER_OUTPUT_NAME = "handler_output";
- @Before
- public void setUp() {
- try {
- initialize = new Initialize("airavataworkflowcatalog-derby.sql");
- initialize.initializeDB();
- workflowRepository = new WorkflowRepository();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
+ public WorkflowRepositoryTest() {
+ super(Database.WORKFLOW_CATALOG);
}
- @After
- public void tearDown() throws Exception {
- System.out.println("********** TEAR DOWN ************");
- initialize.stopDerbyServer();
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ workflowRepository = new WorkflowRepository();
}
@Test
diff --git a/modules/registry-refactoring/src/test/resources/airavata-server.properties b/modules/registry-refactoring/src/test/resources/airavata-server.properties
new file mode 100644
index 0000000..8eedb7a
--- /dev/null
+++ b/modules/registry-refactoring/src/test/resources/airavata-server.properties
@@ -0,0 +1,70 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+###########################################################################
+#
+# Properties file for running tests
+#
+###########################################################################
+
+###########################################################################
+# API Server Registry Configuration
+###########################################################################
+
+#for derby [AiravataJPARegistry]
+registry.jdbc.driver=org.apache.derby.jdbc.ClientDriver
+registry.jdbc.url=jdbc:derby:experiment_catalog;create=true;user=airavata;password=airavata
+registry.jdbc.user=airavata
+registry.jdbc.password=airavata
+validationQuery=SELECT 1 from CONFIGURATION
+
+# Properties for default user mode
+default.registry.user=admin
+default.registry.gateway=php_reference_gateway
+
+###########################################################################
+# Application Catalog DB Configuration
+###########################################################################
+#for derby [AiravataJPARegistry]
+appcatalog.jdbc.driver=org.apache.derby.jdbc.ClientDriver
+appcatalog.jdbc.url=jdbc:derby:app_catalog;create=true;user=airavata;password=airavata
+appcatalog.jdbc.user=airavata
+appcatalog.jdbc.password=airavata
+appcatalog.validationQuery=SELECT 1 from CONFIGURATION
+
+##########################################################################
+# Replica Catalog DB Configuration
+###########################################################################
+#for derby [AiravataJPARegistry]
+replicacatalog.jdbc.driver=org.apache.derby.jdbc.ClientDriver
+replicacatalog.jdbc.url=jdbc:derby:replica_catalog;create=true;user=airavata;password=airavata
+replicacatalog.jdbc.user=airavata
+replicacatalog.jdbc.password=airavata
+replicacatalog.validationQuery=SELECT 1 from CONFIGURATION
+
+###########################################################################
+# Workflow Catalog DB Configuration
+###########################################################################
+#for derby [AiravataJPARegistry]
+workflowcatalog.jdbc.driver=org.apache.derby.jdbc.ClientDriver
+workflowcatalog.jdbc.url=jdbc:derby:workflow_catalog;create=true;user=airavata;password=airavata
+workflowcatalog.jdbc.user=airavata
+workflowcatalog.jdbc.password=airavata
+workflowcatalog.validationQuery=SELECT 1 from CONFIGURATION
diff --git a/modules/registry-refactoring/src/test/resources/airavataworkflowcatalog-derby.sql b/modules/registry-refactoring/src/test/resources/airavataworkflowcatalog-derby.sql
deleted file mode 100644
index 6668ebb..0000000
--- a/modules/registry-refactoring/src/test/resources/airavataworkflowcatalog-derby.sql
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-CREATE TABLE AIRAVATA_WORKFLOW
-(
- ID VARCHAR (255) NOT NULL,
- EXPERIMENT_ID varchar(255),
- DESCRIPTION VARCHAR (255),
- CREATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- UPDATED_AT timestamp,
- PRIMARY KEY (ID)
-);
-
-CREATE TABLE AIRAVATA_WORKFLOW_ERROR
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- CREATION_TIME timestamp DEFAULT CURRENT_TIMESTAMP,
- ACTUAL_ERROR_MESSAGE CLOB,
- USER_FRIENDLY_MESSAGE CLOB,
- TRANSIENT_OR_PERSISTENT SMALLINT,
- ROOT_CAUSE_ERROR_ID_LIST CLOB,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE AIRAVATA_WORKFLOW_STATUS
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- STATE VARCHAR (255) NOT NULL,
- DESCRIPTION VARCHAR (255),
- UPDATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE WORKFLOW_APPLICATION
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- EXPERIMENT_ID varchar(255),
- APPLICATION_INTERFACE_ID VARCHAR (255),
- COMPUTE_RESOURCE_ID VARCHAR (255),
- QUEUE_NAME VARCHAR (255),
- NODE_COUNT INTEGER,
- CORE_COUNT INTEGER,
- WALL_TIME_LIMIT INTEGER,
- PHYSICAL_MEMORY INTEGER,
- CREATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- UPDATED_AT timestamp,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE APPLICATION_ERROR
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- CREATION_TIME timestamp DEFAULT CURRENT_TIMESTAMP,
- ACTUAL_ERROR_MESSAGE CLOB,
- USER_FRIENDLY_MESSAGE CLOB,
- TRANSIENT_OR_PERSISTENT SMALLINT,
- ROOT_CAUSE_ERROR_ID_LIST CLOB,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE APPLICATION_STATUS
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- STATE VARCHAR (255) NOT NULL,
- DESCRIPTION VARCHAR (255),
- UPDATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE WORKFLOW_HANDLER
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- TYPE VARCHAR (255),
- CREATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- UPDATED_AT timestamp,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE HANDLER_ERROR
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- CREATION_TIME timestamp DEFAULT CURRENT_TIMESTAMP,
- ACTUAL_ERROR_MESSAGE CLOB,
- USER_FRIENDLY_MESSAGE CLOB,
- TRANSIENT_OR_PERSISTENT SMALLINT,
- ROOT_CAUSE_ERROR_ID_LIST CLOB,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE HANDLER_STATUS
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- STATE VARCHAR (255) NOT NULL,
- DESCRIPTION VARCHAR (255),
- UPDATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE WORKFLOW_DATA_BLOCK
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- VALUE VARCHAR (255),
- DATA_TYPE VARCHAR (255),
- CREATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- UPDATED_AT timestamp,
- PRIMARY KEY (ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE WORKFLOW_CONNECTION
-(
- ID VARCHAR (255) NOT NULL,
- WORKFLOW_ID VARCHAR (255) NOT NULL,
- DATA_BLOCK_ID VARCHAR (255),
- FROM_TYPE VARCHAR (255),
- FROM_ID VARCHAR (255),
- FROM_OUTPUT_NAME VARCHAR (255),
- TO_TYPE VARCHAR (255),
- TO_ID VARCHAR (255),
- TO_INPUT_NAME VARCHAR (255),
- CREATED_AT timestamp DEFAULT CURRENT_TIMESTAMP,
- UPDATED_AT timestamp,
- PRIMARY KEY (ID, WORKFLOW_ID),
- FOREIGN KEY (WORKFLOW_ID) REFERENCES AIRAVATA_WORKFLOW(ID) ON DELETE CASCADE,
- FOREIGN KEY (DATA_BLOCK_ID) REFERENCES WORKFLOW_DATA_BLOCK(ID) ON DELETE CASCADE
-);
-
-CREATE TABLE CONFIGURATION
-(
- CONFIG_KEY VARCHAR(255),
- CONFIG_VAL VARCHAR(255),
- EXPIRE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- CATEGORY_ID VARCHAR (255),
- PRIMARY KEY(CONFIG_KEY, CONFIG_VAL, CATEGORY_ID)
-);
-
-INSERT INTO CONFIGURATION (CONFIG_KEY, CONFIG_VAL, EXPIRE_DATE, CATEGORY_ID) VALUES('airavata.workflow.version', '0.17', CURRENT_TIMESTAMP ,'SYSTEM');
\ No newline at end of file
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
index 9b1bdbe..4aa85ff 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
@@ -19,20 +19,15 @@
*/
package org.apache.airavata.sharing.registry.db.repositories;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.sharing.registry.db.entities.EntityEntity;
import org.apache.airavata.sharing.registry.db.entities.EntityPK;
import org.apache.airavata.sharing.registry.db.utils.DBConstants;
-import org.apache.airavata.sharing.registry.db.utils.JPAUtils;
+import org.apache.airavata.sharing.registry.db.utils.SharingRegistryJDBCConfig;
import org.apache.airavata.sharing.registry.models.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.*;
public class EntityRepository extends AbstractRepository<Entity, EntityEntity, EntityPK> {
- private final static Logger logger = LoggerFactory.getLogger(EntityRepository.class);
public EntityRepository() {
super(Entity.class, EntityEntity.class);
@@ -73,22 +68,16 @@ public class EntityRepository extends AbstractRepository<Entity, EntityEntity, E
+ (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId) + "') AND ";
}
}else if(searchCriteria.getSearchField().equals(EntitySearchField.FULL_TEXT)){
- try {
- if(ServerSettings.getSetting(JPAUtils.SHARING_REG_JDBC_DRIVER).contains("derby")){
- query += "E.FULL_TEXT LIKE '%" + searchCriteria.getValue() + "%' AND ";
- }else{
- //FULL TEXT Search with Query Expansion
- String queryTerms = "";
- for(String word : searchCriteria.getValue().trim().replaceAll(" +", " ").split(" ")){
- queryTerms += queryTerms + " +" + word;
- }
- queryTerms = queryTerms.trim();
- query += "MATCH(E.FULL_TEXT) AGAINST ('" + queryTerms
- + "' IN BOOLEAN MODE) AND ";
+ if (new SharingRegistryJDBCConfig().getDriver().contains("derby")) {
+ query += "E.FULL_TEXT LIKE '%" + searchCriteria.getValue() + "%' AND ";
+ } else {
+ // FULL TEXT Search with Query Expansion
+ String queryTerms = "";
+ for (String word : searchCriteria.getValue().trim().replaceAll(" +", " ").split(" ")) {
+ queryTerms += queryTerms + " +" + word;
}
- } catch (ApplicationSettingsException e) {
- logger.error(e.getMessage(), e);
- throw new SharingRegistryException(e.getMessage());
+ queryTerms = queryTerms.trim();
+ query += "MATCH(E.FULL_TEXT) AGAINST ('" + queryTerms + "' IN BOOLEAN MODE) AND ";
}
}else if(searchCriteria.getSearchField().equals(EntitySearchField.PARRENT_ENTITY_ID)){
if (searchCriteria.getSearchCondition() != null && searchCriteria.getSearchCondition().equals(SearchCondition.NOT)) {
@@ -181,4 +170,4 @@ public class EntityRepository extends AbstractRepository<Entity, EntityEntity, E
return query;
}
-}
\ No newline at end of file
+}
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
index 7052eac..858d51c 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
@@ -19,27 +19,17 @@
*/
package org.apache.airavata.sharing.registry.db.utils;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.common.utils.JDBCConfig;
import org.apache.airavata.sharing.registry.models.SharingRegistryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import javax.persistence.*;
import java.util.HashMap;
import java.util.Map;
public class JPAUtils {
- private final static Logger logger = LoggerFactory.getLogger(JPAUtils.class);
public static final String PERSISTENCE_UNIT_NAME = "airavata-sharing-registry";
- public static final String SHARING_REG_JDBC_DRIVER = "sharingcatalog.jdbc.driver";
- public static final String SHARING_REG_JDBC_URL = "sharingcatalog.jdbc.url";
- public static final String SHARING_REG_JDBC_USER = "sharingcatalog.jdbc.user";
- public static final String SHARING_REG_JDBC_PWD = "sharingcatalog.jdbc.password";
- public static final String SHARING_REG_VALIDATION_QUERY = "sharingcatalog.validationQuery";
- public static final String JPA_CACHE_SIZE = "jpa.cache.size";
- public static final String JPA_CACHE_ENABLED = "cache.enable";
+ private static final JDBCConfig JDBC_CONFIG = new SharingRegistryJDBCConfig();
@PersistenceUnit(unitName = PERSISTENCE_UNIT_NAME)
protected static EntityManagerFactory factory;
@@ -48,11 +38,11 @@ public class JPAUtils {
public synchronized static EntityManager getEntityManager() throws SharingRegistryException {
if (factory == null) {
- String connectionProperties = "DriverClassName=" + readServerProperties(SHARING_REG_JDBC_DRIVER) + "," +
- "Url=" + readServerProperties(SHARING_REG_JDBC_URL) + "?autoReconnect=true," +
- "Username=" + readServerProperties(SHARING_REG_JDBC_USER) + "," +
- "Password=" + readServerProperties(SHARING_REG_JDBC_PWD) +
- ",validationQuery=" + readServerProperties(SHARING_REG_VALIDATION_QUERY);
+ String connectionProperties = "DriverClassName=" + JDBC_CONFIG.getDriver() + "," +
+ "Url=" + JDBC_CONFIG.getURL() + "?autoReconnect=true," +
+ "Username=" + JDBC_CONFIG.getUser() + "," +
+ "Password=" + JDBC_CONFIG.getPassword() +
+ ",validationQuery=" + JDBC_CONFIG.getValidationQuery();
// String connectionProperties = "DriverClassName=com.mysql.jdbc.Driver," +
// "Url=jdbc:mysql://localhost:3306/airavata_sharing_catalog?autoReconnect=true," +
@@ -85,13 +75,4 @@ public class JPAUtils {
entityManager = factory.createEntityManager();
return entityManager;
}
-
- public static String readServerProperties(String propertyName) throws SharingRegistryException {
- try {
- return ServerSettings.getSetting(propertyName);
- } catch (ApplicationSettingsException e) {
- logger.error("Unable to read airavata-server.properties...", e);
- throw new SharingRegistryException("Unable to read airavata-server.properties...");
- }
- }
}
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java
index 78ce7e4..41c5c18 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/SharingRegistryJDBCConfig.java
@@ -26,10 +26,11 @@ import org.apache.airavata.common.utils.ServerSettings;
public class SharingRegistryJDBCConfig implements JDBCConfig {
- public static final String SHARING_REG_JDBC_DRIVER = "sharingcatalog.jdbc.driver";
- public static final String SHARING_REG_JDBC_URL = "sharingcatalog.jdbc.url";
- public static final String SHARING_REG_JDBC_USER = "sharingcatalog.jdbc.user";
- public static final String SHARING_REG_JDBC_PWD = "sharingcatalog.jdbc.password";
+ private static final String SHARING_REG_JDBC_DRIVER = "sharingcatalog.jdbc.driver";
+ private static final String SHARING_REG_JDBC_URL = "sharingcatalog.jdbc.url";
+ private static final String SHARING_REG_JDBC_USER = "sharingcatalog.jdbc.user";
+ private static final String SHARING_REG_JDBC_PWD = "sharingcatalog.jdbc.password";
+ private static final String SHARING_REG_VALIDATION_QUERY = "sharingcatalog.validationQuery";
@Override
public String getURL() {
@@ -51,6 +52,11 @@ public class SharingRegistryJDBCConfig implements JDBCConfig {
return readServerProperties(SHARING_REG_JDBC_PWD);
}
+ @Override
+ public String getValidationQuery() {
+ return readServerProperties(SHARING_REG_VALIDATION_QUERY);
+ }
+
private String readServerProperties(String propertyName) {
try {
return ServerSettings.getSetting(propertyName);