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 3be8dd9 AIRAVATA-2938 Update ProfileServiceServer to run db init script
3be8dd9 is described below
commit 3be8dd97f73781da1edd9d01a9e2b3ce0e4d4878
Author: Marcus Christie <machristie@apache.org>
AuthorDate: Fri Jan 25 11:00:13 2019 -0500
AIRAVATA-2938 Update ProfileServiceServer to run db init script
---
.../service/profile/commons/utils/Utils.java | 27 +------------
.../profile/server/ProfileServiceServer.java | 15 +++++++
.../core/utils/UserProfileCatalogDBInitConfig.java | 42 +++++++++++++++++++
.../core/utils/UserProfileCatalogJDBCConfig.java | 47 ++++++++++++++++++++++
..._catalog.sql => user-profile-catalog-derby.sql} | 45 +++++++++++++++------
..._catalog.sql => user-profile-catalog-mysql.sql} | 23 ++++++++++-
.../src/main/assembly/bin-assembly.xml | 9 +++++
7 files changed, 169 insertions(+), 39 deletions(-)
diff --git a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/Utils.java
b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/Utils.java
index 71d0029..79e3ba2 100644
--- a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/Utils.java
+++ b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/Utils.java
@@ -83,31 +83,6 @@ public class Utils {
}
}
- public static String getDBType(){
- try{
- String jdbcURL = getJDBCURL();
- String cleanURI = jdbcURL.substring(5);
- URI uri = URI.create(cleanURI);
- return uri.getScheme();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- return null;
- }
- }
-
- public static boolean isDerbyStartEnabled(){
- try {
- String s = ServerSettings.getSetting(JPAConstants.KEY_DERBY_START_ENABLE);
- if("true".equals(s)){
- return true;
- }
- } catch (ApplicationSettingsException e) {
- logger.error(e.getMessage(), e);
- return false;
- }
- return false;
- }
-
public static String getJDBCUser(){
try {
return ServerSettings.getSetting(JPAConstants.KEY_JDBC_USER);
@@ -144,4 +119,4 @@ public class Utils {
return null;
}
}
-}
\ No newline at end of file
+}
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
index c371173..079e943 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
@@ -21,6 +21,8 @@
package org.apache.airavata.service.profile.server;
+import org.apache.airavata.common.utils.DBInitConfig;
+import org.apache.airavata.common.utils.DBInitializer;
import org.apache.airavata.common.utils.IServer;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService;
@@ -33,6 +35,7 @@ import org.apache.airavata.service.profile.tenant.cpi.profile_tenant_cpiConstant
import org.apache.airavata.service.profile.handlers.TenantProfileServiceHandler;
import org.apache.airavata.service.profile.handlers.UserProfileServiceHandler;
import org.apache.airavata.service.profile.tenant.cpi.TenantProfileService;
+import org.apache.airavata.service.profile.user.core.utils.UserProfileCatalogDBInitConfig;
import org.apache.airavata.service.profile.user.cpi.UserProfileService;
import org.apache.airavata.service.profile.user.cpi.profile_user_cpiConstants;
import org.apache.thrift.TMultiplexedProcessor;
@@ -45,7 +48,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Date;
+import java.util.List;
/**
* Created by goshenoy on 03/08/2017.
@@ -59,6 +64,9 @@ public class ProfileServiceServer implements IServer {
private ServerStatus status;
private TServer server;
+ private List<DBInitConfig> dbInitConfigs = Arrays.asList(
+ new UserProfileCatalogDBInitConfig()
+ );
public ProfileServiceServer() {
setStatus(ServerStatus.STOPPED);
@@ -84,6 +92,13 @@ public class ProfileServiceServer implements IServer {
try {
setStatus(ServerStatus.STARTING);
+
+ logger.info("Initialing profile service databases...");
+ for (DBInitConfig dbInitConfig : dbInitConfigs) {
+ DBInitializer.initializeDB(dbInitConfig);
+ }
+ logger.info("Profile service databases initialized successfully");
+
final int serverPort = Integer.parseInt(ServerSettings.getProfileServiceServerPort());
final String serverHost = ServerSettings.getProfileServiceServerHost();
diff --git a/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogDBInitConfig.java
b/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogDBInitConfig.java
new file mode 100644
index 0000000..565dea6
--- /dev/null
+++ b/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogDBInitConfig.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * 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.service.profile.user.core.utils;
+
+import org.apache.airavata.common.utils.DBInitConfig;
+import org.apache.airavata.common.utils.JDBCConfig;
+
+public class UserProfileCatalogDBInitConfig implements DBInitConfig {
+
+ @Override
+ public JDBCConfig getJDBCConfig() {
+ return new UserProfileCatalogJDBCConfig();
+ }
+
+ @Override
+ public String getDBInitScriptPrefix() {
+ return "database_scripts/user-profile-catalog";
+ }
+
+ @Override
+ public String getCheckTableName() {
+ return "CONFIGURATION";
+ }
+}
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
new file mode 100644
index 0000000..0d09dae
--- /dev/null
+++ b/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/utils/UserProfileCatalogJDBCConfig.java
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.service.profile.user.core.utils;
+
+import org.apache.airavata.common.utils.JDBCConfig;
+import org.apache.airavata.service.profile.commons.utils.Utils;
+
+public class UserProfileCatalogJDBCConfig implements JDBCConfig {
+
+ @Override
+ public String getURL() {
+ return Utils.getJDBCURL();
+ }
+
+ @Override
+ public String getDriver() {
+ return Utils.getJDBCDriver();
+ }
+
+ @Override
+ public String getUser() {
+ return Utils.getJDBCUser();
+ }
+
+ @Override
+ public String getPassword() {
+ return Utils.getJDBCPassword();
+ }
+}
diff --git a/airavata-services/profile-service/profile-user-core/src/main/resources/user_profile_catalog.sql
b/airavata-services/profile-service/profile-user-core/src/main/resources/user-profile-catalog-derby.sql
similarity index 75%
copy from airavata-services/profile-service/profile-user-core/src/main/resources/user_profile_catalog.sql
copy to airavata-services/profile-service/profile-user-core/src/main/resources/user-profile-catalog-derby.sql
index 120146f..c93c1bc 100644
--- a/airavata-services/profile-service/profile-user-core/src/main/resources/user_profile_catalog.sql
+++ b/airavata-services/profile-service/profile-user-core/src/main/resources/user-profile-catalog-derby.sql
@@ -1,4 +1,25 @@
-CREATE TABLE IF NOT EXISTS USER_PROFILE (
+/*
+ *
+ * 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 USER_PROFILE (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
USER_ID VARCHAR (255),
GATEWAY_ID VARCHAR (255),
@@ -12,69 +33,69 @@ CREATE TABLE IF NOT EXISTS USER_PROFILE (
LAST_ACCESS_TIME BIGINT,
VALID_UNTIL BIGINT,
STATE VARCHAR (255),
- COMMENTS TEXT,
+ COMMENTS CLOB,
GPG_KEY VARCHAR (8192),
TIME_ZONE VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID)
);
-CREATE TABLE IF NOT EXISTS USER_PROFILE_EMAIL (
+CREATE TABLE USER_PROFILE_EMAIL (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
EMAIL VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID, EMAIL),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES USER_PROFILE(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS USER_PROFILE_PHONE (
+CREATE TABLE USER_PROFILE_PHONE (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
PHONE VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID, PHONE ),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES USER_PROFILE(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS USER_PROFILE_NATIONALITY (
+CREATE TABLE USER_PROFILE_NATIONALITY (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
NATIONALITY VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID, NATIONALITY ),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES USER_PROFILE(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS USER_PROFILE_LABELED_URI (
+CREATE TABLE USER_PROFILE_LABELED_URI (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
LABELED_URI VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID, LABELED_URI ),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES USER_PROFILE(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS NSF_DEMOGRAPHIC (
+CREATE TABLE NSF_DEMOGRAPHIC (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
GENDER VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES USER_PROFILE(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS NSF_DEMOGRAPHIC_ETHNICITY (
+CREATE TABLE NSF_DEMOGRAPHIC_ETHNICITY (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
ETHNICITY VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID, ETHNICITY ),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES NSF_DEMOGRAPHIC(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS NSF_DEMOGRAPHIC_RACE (
+CREATE TABLE NSF_DEMOGRAPHIC_RACE (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
RACE VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID, RACE ),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES NSF_DEMOGRAPHIC(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS NSF_DEMOGRAPHIC_DISABILITY (
+CREATE TABLE NSF_DEMOGRAPHIC_DISABILITY (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
DISABILITY VARCHAR (255),
PRIMARY KEY (AIRAVATA_INTERNAL_USER_ID, DISABILITY ),
FOREIGN KEY (AIRAVATA_INTERNAL_USER_ID) REFERENCES NSF_DEMOGRAPHIC(AIRAVATA_INTERNAL_USER_ID)
ON DELETE CASCADE
);
-CREATE TABLE IF NOT EXISTS CUSTOMIZED_DASHBOARD (
+CREATE TABLE CUSTOMIZED_DASHBOARD (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
ENABLED_EXPERIMENT_ID VARCHAR (255),
ENABLED_NAME VARCHAR (255),
@@ -111,4 +132,4 @@ CREATE TABLE CONFIGURATION
PRIMARY KEY(CONFIG_KEY, CONFIG_VAL)
);
-INSERT INTO CONFIGURATION (CONFIG_KEY, CONFIG_VAL) VALUES('user_profile_catalog_version',
'0.17');
\ No newline at end of file
+INSERT INTO CONFIGURATION (CONFIG_KEY, CONFIG_VAL) VALUES('user_profile_catalog_version',
'0.17');
diff --git a/airavata-services/profile-service/profile-user-core/src/main/resources/user_profile_catalog.sql
b/airavata-services/profile-service/profile-user-core/src/main/resources/user-profile-catalog-mysql.sql
similarity index 83%
rename from airavata-services/profile-service/profile-user-core/src/main/resources/user_profile_catalog.sql
rename to airavata-services/profile-service/profile-user-core/src/main/resources/user-profile-catalog-mysql.sql
index 120146f..db5f100 100644
--- a/airavata-services/profile-service/profile-user-core/src/main/resources/user_profile_catalog.sql
+++ b/airavata-services/profile-service/profile-user-core/src/main/resources/user-profile-catalog-mysql.sql
@@ -1,3 +1,24 @@
+/*
+ *
+ * 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 IF NOT EXISTS USER_PROFILE (
AIRAVATA_INTERNAL_USER_ID VARCHAR (255),
USER_ID VARCHAR (255),
@@ -111,4 +132,4 @@ CREATE TABLE CONFIGURATION
PRIMARY KEY(CONFIG_KEY, CONFIG_VAL)
);
-INSERT INTO CONFIGURATION (CONFIG_KEY, CONFIG_VAL) VALUES('user_profile_catalog_version',
'0.17');
\ No newline at end of file
+INSERT INTO CONFIGURATION (CONFIG_KEY, CONFIG_VAL) VALUES('user_profile_catalog_version',
'0.17');
diff --git a/modules/distribution/src/main/assembly/bin-assembly.xml b/modules/distribution/src/main/assembly/bin-assembly.xml
index 57343cd..a97d326 100644
--- a/modules/distribution/src/main/assembly/bin-assembly.xml
+++ b/modules/distribution/src/main/assembly/bin-assembly.xml
@@ -95,6 +95,15 @@
</includes>
</fileSet>
<fileSet>
+ <directory>../../airavata-services/profile-service/profile-user-core/src/main/resources/
+ </directory>
+ <outputDirectory>bin/database_scripts
+ </outputDirectory>
+ <includes>
+ <include>*sql*</include>
+ </includes>
+ </fileSet>
+ <fileSet>
<directory>src/main/resources/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>777</fileMode>
|