Repository: airavata Updated Branches: refs/heads/master c75d40685 -> 6c1eebe31
http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/pom.xml ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/pom.xml b/modules/registry/registry-tools/registry-tool/pom.xml new file mode 100644 index 0000000..e006551 --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/pom.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!--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. --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-registry-tools</artifactId> + <version>0.16-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>registry-tool</artifactId> + <packaging>jar</packaging> + <name>registry-tool</name> + + <dependencies> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.9.1.0</version> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derbyclient</artifactId> + <version>10.9.1.0</version> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derbynet</artifactId> + <version>10.9.1.0</version> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derbytools</artifactId> + <version>10.9.1.0</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>commons-cli</groupId> + <artifactId>commons-cli</artifactId> + <version>1.1</version> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java b/modules/registry/registry-tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java new file mode 100644 index 0000000..487af1c --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java @@ -0,0 +1,375 @@ +/* + * + * 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.tool; + +import org.apache.commons.cli.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.net.URI; +import java.sql.*; +import java.text.DecimalFormat; +import java.util.*; +import java.util.Date; + +public class DBMigrator { + private static final Logger logger = LoggerFactory.getLogger(DBMigrator.class); + private static final String delimiter = ";"; + private static final String MIGRATE_SQL_DERBY = "migrate_derby.sql"; + private static final String MIGRATE_SQL_MYSQL = "migrate_mysql.sql"; + private static final String REGISTRY_VERSION = "registry.version"; + private static final String AIRAVATA_VERSION = "0.5"; + private static String currentAiravataVersion; + private static String relativePath; + private static String SELECT_QUERY; + private static String INSERT_QUERY; + private static String UPDATE_QUERY; + private static String jdbcURL; + private static String jdbcUser; + private static String jdbcPwd; + + public static void main(String[] args) { + parseArguments(args); + generateConfigTableQueries(); + updateDB(jdbcURL, jdbcUser, jdbcPwd); + } + + public static void generateConfigTableQueries(){ + SELECT_QUERY = "SELECT * FROM CONFIGURATION WHERE config_key='" + REGISTRY_VERSION + "' and category_id='SYSTEM'"; + INSERT_QUERY = "INSERT INTO CONFIGURATION (config_key, config_val, expire_date, category_id) VALUES('" + + REGISTRY_VERSION + "', '" + getIncrementedVersion(currentAiravataVersion) + "', '" + getCurrentDate() + + "','SYSTEM')"; + UPDATE_QUERY = "UPDATE CONFIGURATION SET config_val='" + getIncrementedVersion(currentAiravataVersion) + "', expire_date='" + getCurrentDate() + + "' WHERE config_key='" + REGISTRY_VERSION + "' and category_id='SYSTEM'"; + } + + //we assume given database is up and running + public static void updateDB (String jdbcUrl, String jdbcUser, String jdbcPwd){ + relativePath = "db-scripts/" + getIncrementedVersion(currentAiravataVersion) + "/"; + InputStream sqlStream = null; + Scanner in = new Scanner(System.in); + if (jdbcUrl == null || jdbcUrl.equals("")){ + System.out.println("Enter JDBC URL : "); + jdbcUrl = in.next(); + } + if (jdbcUser == null || jdbcUser.equals("")){ + System.out.println("Enter JDBC Username : "); + jdbcUser = in.next(); + } + if (jdbcPwd == null || jdbcPwd.equals("")){ + System.out.println("Enter JDBC password : "); + jdbcPwd = in.next(); + } + + String dbType = getDBType(jdbcUrl); + String jdbcDriver = null; + + Connection connection; + try { + File file = null; + if (dbType.contains("derby")){ + jdbcDriver = "org.apache.derby.jdbc.ClientDriver"; + sqlStream = DBMigrator.class.getClassLoader().getResourceAsStream(relativePath + MIGRATE_SQL_DERBY); + } else if (dbType.contains("mysql")){ + jdbcDriver = "com.mysql.jdbc.Driver"; + sqlStream = DBMigrator.class.getClassLoader().getResourceAsStream(relativePath + MIGRATE_SQL_MYSQL); + } + Class.forName(jdbcDriver).newInstance(); + connection = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPwd); + if (canUpdated(connection)){ + executeSQLScript(connection, sqlStream); + //update configuration table with airavata version + updateConfigTable(connection); + } + } catch (ClassNotFoundException e) { + logger.error("Unable to find SQL scripts..." , e); + } catch (InstantiationException e) { + logger.error("Error while updating the database..." , e); + } catch (IllegalAccessException e) { + logger.error("Error while updating the database..." , e); + } catch (SQLException e) { + logger.error("Error while updating the database..." , e); + } catch (Exception e) { + logger.error("Error while updating the database..." , e); + } + } + + private static boolean canUpdated (Connection conn){ + if (!currentAiravataVersion.equals(AIRAVATA_VERSION)){ + String config = executeSelectQuery(conn); + if (config != null){ + if (config.equals(getIncrementedVersion(currentAiravataVersion))) { + return false; + } else { + return true; + } + } + } else if (currentAiravataVersion.equals(AIRAVATA_VERSION)){ + return true; + } + return false; + } + + private static void updateConfigTable (Connection connection){ + // if existing need to update, otherwise insert + if (executeSelectQuery(connection) != null){ + executeQuery(connection, UPDATE_QUERY); + } else { + executeQuery(connection, INSERT_QUERY); + } + } + + private static Timestamp getCurrentDate (){ + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + Timestamp d = new Timestamp(date.getTime()); + return d; + } + + private static String getIncrementedVersion (String currentVersion){ + + DecimalFormat decimalFormat = new DecimalFormat("#,##0.0"); + Double currentVer = Double.parseDouble(currentVersion); + double v = currentVer + .1; + String formattedVal = decimalFormat.format(v); + return formattedVal; + } + + private static String executeSelectQuery (Connection conn){ + try { + Statement statement = conn.createStatement(); + ResultSet rs = statement.executeQuery(SELECT_QUERY); + if (rs != null){ + while (rs.next()) { + currentAiravataVersion = rs.getString(2); + return currentAiravataVersion; + } + } + } catch (SQLException e) { + logger.error(e.getMessage() , e); + } + return null; + } + + private static void executeQuery (Connection conn, String query){ + try { + Statement statement = conn.createStatement(); + statement.execute(query) ; + } catch (SQLException e) { + logger.error(e.getMessage() , e); + } + } + + private static void executeSQLScript(Connection conn, InputStream inputStream) throws Exception { + StringBuffer sql = new StringBuffer(); + BufferedReader reader = null; + try{ + 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))) { + String sqlString = sql.substring(0, sql.length() - delimiter.length()); + executeSQL(sqlString, conn); + sql.replace(0, sql.length(), ""); + } + } + System.out.println(sql.toString()); + // 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 String getDBType(String jdbcURL){ + try{ + 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 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 void executeSQL(String sql, Connection conn) throws Exception { + 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")) { + 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); + } + } + } + } + + public static void parseArguments(String[] args){ + try{ + Options options = new Options(); + options.addOption("url", true , "JDBC URL"); + options.addOption("user", true, "JDBC Username"); + options.addOption("pwd", true, "JDBC Password"); + options.addOption("v", true, "Airavata Current Version"); + CommandLineParser parser = new PosixParser(); + CommandLine cmd = parser.parse( options, args); + jdbcURL = cmd.getOptionValue("url"); + if (jdbcURL == null){ + logger.info("You should enter JDBC URL and JDBC Credentials as parameters..."); + } + jdbcUser = cmd.getOptionValue("user"); + if (jdbcUser == null){ + logger.info("You should enter JDBC URL and JDBC Credentials as parameters..."); + } + jdbcPwd = cmd.getOptionValue("pwd"); + currentAiravataVersion = cmd.getOptionValue("v"); + if (currentAiravataVersion == null){ + logger.info("You should enter current Airavata version you are using..."); + } + } catch (ParseException e) { + logger.error("Error while reading command line parameters" , e); + } + } + + protected static InputStream readFile(File file) { + StringBuilder fileContentsBuilder = new StringBuilder(); + BufferedReader bufferedReader = null; + try { + char[] buffer = new char[32767]; + bufferedReader = new BufferedReader(new FileReader(file)); + int read = 0; + + do { + read = bufferedReader.read(buffer); + if (read > 0) { + fileContentsBuilder.append(buffer, 0, read); + } + } while (read > 0); + } catch (Exception e) { + logger.error("Failed to read file " + file.getPath(), e); + } finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException e) { + logger.error("Unable to close BufferedReader for " + file.getPath(), e); + } + } + } + System.out.println(fileContentsBuilder.toString()); + InputStream is = new ByteArrayInputStream(fileContentsBuilder.toString().getBytes()); + + return is; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/resources/db-migrate.sh ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/resources/db-migrate.sh b/modules/registry/registry-tools/registry-tool/src/main/resources/db-migrate.sh new file mode 100755 index 0000000..c390837 --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/resources/db-migrate.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# 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. + +. `dirname $0`/setenv.sh +cd $AIRAVATA_HOME/bin + +# update classpath +REG_MIGRATE_CLASSPATH="$AIRAVATA_HOME/lib" +for f in $AIRAVATA_HOME/lib/*.jar +do + REG_MIGRATE_CLASSPATH=$REG_MIGRATE_CLASSPATH:$f +done + +$JAVA_HOME/bin/java -server -Xms128M -Xmx128M \ + $XDEBUG \ + $TEMP_PROPS \ + -Djava.endorsed.dirs=$AIRAVATA_HOME/lib/endorsed \ + -classpath $REG_MIGRATE_CLASSPATH \ + -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5000,suspend=n \ + org.apache.airavata.registry.tool.DBMigrator $* http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql new file mode 100644 index 0000000..1e6a605 --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql @@ -0,0 +1,35 @@ +/* + * + * 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. + * + */ + +ALTER TABLE Configuration ADD category_id varchar(255) NOT NULL DEFAULT 'SYSTEM'; + +ALTER TABLE Configuration DROP PRIMARY KEY; + +ALTER TABLE Configuration ADD PRIMARY KEY(config_key, config_val, category_id); + +ALTER TABLE Node_Data +ADD execution_index int NOT NULL DEFAULT 0; + +ALTER TABLE Node_Data DROP PRIMARY KEY; + +ALTER TABLE Node_Data ADD PRIMARY KEY(workflow_instanceID, node_id, execution_index); + + http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql new file mode 100644 index 0000000..be3d66e --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql @@ -0,0 +1,32 @@ +/* + * + * 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. + * + */ + +ALTER TABLE Configuration +ADD category_id varchar(255); + +UPDATE Configuration SET category_id="SYSTEM" ; + +ALTER TABLE Configuration DROP PRIMARY KEY, ADD PRIMARY KEY(config_key, config_val, category_id); + +ALTER TABLE Node_Data +ADD execution_index int NOT NULL; + +ALTER TABLE Node_Data DROP PRIMARY KEY, ADD PRIMARY KEY(workflow_instanceID, node_id, execution_index); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql new file mode 100644 index 0000000..0528e10 --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql @@ -0,0 +1,40 @@ +/* + * + * 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 community_user +( + GATEWAY_NAME VARCHAR(256) NOT NULL, + COMMUNITY_USER_NAME VARCHAR(256) NOT NULL, + TOKEN_ID VARCHAR(256) NOT NULL, + COMMUNITY_USER_EMAIL VARCHAR(256) NOT NULL, + PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME, TOKEN_ID) +); + + +CREATE TABLE credentials +( + GATEWAY_ID VARCHAR(256) NOT NULL, + TOKEN_ID VARCHAR(256) NOT NULL, + CREDENTIAL BLOB NOT NULL, + PORTAL_USER_ID VARCHAR(256) NOT NULL, + TIME_PERSISTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (GATEWAY_ID, TOKEN_ID) +); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql new file mode 100644 index 0000000..6b47ed5 --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql @@ -0,0 +1,40 @@ +/* + * + * 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 community_user +( + GATEWAY_NAME VARCHAR(256) NOT NULL, + COMMUNITY_USER_NAME VARCHAR(256) NOT NULL, + TOKEN_ID VARCHAR(256) NOT NULL, + COMMUNITY_USER_EMAIL VARCHAR(256) NOT NULL, + PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME, TOKEN_ID) +); + + +CREATE TABLE credentials +( + GATEWAY_ID VARCHAR(256) NOT NULL, + TOKEN_ID VARCHAR(256) NOT NULL, + CREDENTIAL TEXT NOT NULL, + PORTAL_USER_ID VARCHAR(256) NOT NULL, + TIME_PERSISTED TIMESTAMP DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (GATEWAY_ID, TOKEN_ID) +); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql new file mode 100644 index 0000000..95b2ccf --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql @@ -0,0 +1,72 @@ +/* + * + * 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 Execution_Error +( + error_id INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, + experiment_ID varchar(255), + workflow_instanceID varchar(255), + node_id varchar(255), + gfacJobID varchar(255), + source_type varchar(255), + error_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + error_msg CLOB, + error_des CLOB, + error_code varchar(255), + error_reporter varchar(255), + error_location varchar(255), + action_taken varchar(255), + error_reference INTEGER, + PRIMARY KEY(error_id), + FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) ON DELETE CASCADE, + FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID) ON DELETE CASCADE +); + +create table GFac_Job_Data +( + experiment_ID varchar(255), + workflow_instanceID varchar(255), + node_id varchar(255), + application_descriptor_ID varchar(255), + host_descriptor_ID varchar(255), + service_descriptor_ID varchar(255), + job_data CLOB, + local_Job_ID varchar(255), + submitted_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', + status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', + status varchar(255), + metadata CLOB, + PRIMARY KEY(local_Job_ID), + FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID), + FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) +); + +create table GFac_Job_Status +( + local_Job_ID varchar(255), + status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', + status varchar(255), + FOREIGN KEY (local_Job_ID) REFERENCES GFac_Job_Data(local_Job_ID) +); + +INSERT INTO GFac_Job_Data(experiment_ID, workflow_instanceID, node_id, application_descriptor_ID, host_descriptor_ID, service_descriptor_ID, +job_data, local_Job_ID, submitted_time, statusUpdateTime, status, metadata) SELECT null, workflow_instanceID, node_id, null, invoked_host, +null, null, local_Job_ID, null, null, 'UNKNOWN', null FROM Gram_Data; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql ---------------------------------------------------------------------- diff --git a/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql new file mode 100644 index 0000000..40ca48c --- /dev/null +++ b/modules/registry/registry-tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql @@ -0,0 +1,72 @@ +/* + * + * 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 Execution_Error +( + error_id INT NOT NULL AUTO_INCREMENT, + experiment_ID varchar(255), + workflow_instanceID varchar(255), + node_id varchar(255), + gfacJobID varchar(255), + source_type varchar(255), + error_date TIMESTAMP DEFAULT now() on update now(), + error_msg LONGTEXT, + error_des LONGTEXT, + error_code varchar(255), + error_reporter varchar(255), + error_location varchar(255), + action_taken varchar(255), + error_reference INTEGER, + PRIMARY KEY(error_id), + FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) ON DELETE CASCADE, + FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID) ON DELETE CASCADE +); + +create table GFac_Job_Data +( + experiment_ID varchar(255), + workflow_instanceID varchar(255), + node_id varchar(255), + application_descriptor_ID varchar(255), + host_descriptor_ID varchar(255), + service_descriptor_ID varchar(255), + job_data LONGTEXT, + local_Job_ID varchar(255), + submitted_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', + status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', + status varchar(255), + metadata LONGTEXT, + PRIMARY KEY(local_Job_ID) + FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID), + FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) +); + +create table GFac_Job_Status +( + local_Job_ID varchar(255), + status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', + status varchar(255), + FOREIGN KEY (local_Job_ID) REFERENCES GFac_Job_Data(local_Job_ID) +); + +INSERT INTO GFac_Job_Data(experiment_ID, workflow_instanceID, node_id, application_descriptor_ID, host_descriptor_ID, service_descriptor_ID, +job_data, local_Job_ID, submitted_time, status_update_time, status, metadata) SELECT null, workflow_instanceID, node_id, null, invoked_host, +null, null, local_Job_ID, null, null, 'UNKNOWN', null FROM Gram_Data; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/README ---------------------------------------------------------------------- diff --git a/tools/registry-tool/README b/tools/registry-tool/README deleted file mode 100644 index 40a8e65..0000000 --- a/tools/registry-tool/README +++ /dev/null @@ -1,9 +0,0 @@ -0.7 => 0.8 -============== - -1. Build registry-tools -2. Copy registry-tool-0.8-SNAPSHOT.jar and commons-cli-1.1.jar (you will find this in your maven repository) to <AIRAVATA_HOME>/lib -3. Copy db-migrate.sh file to <AIRAVATA_HOME>/bin -4. Make sure previous version of airavata database is up and running -5. Run db-migrate.sh script file - ./db-migrate.sh -url jdbc:mysql://localhost:3306/experiment_catalog -user airavata -pwd airavata -v 0.7 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/pom.xml ---------------------------------------------------------------------- diff --git a/tools/registry-tool/pom.xml b/tools/registry-tool/pom.xml deleted file mode 100644 index c463167..0000000 --- a/tools/registry-tool/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!--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. --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-tools-parent</artifactId> - <version>0.16-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <modelVersion>4.0.0</modelVersion> - <artifactId>registry-tool</artifactId> - <packaging>jar</packaging> - <name>registry-tool</name> - - <dependencies> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.9.1.0</version> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derbyclient</artifactId> - <version>10.9.1.0</version> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derbynet</artifactId> - <version>10.9.1.0</version> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derbytools</artifactId> - <version>10.9.1.0</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <version>1.6.1</version> - </dependency> - <dependency> - <groupId>commons-cli</groupId> - <artifactId>commons-cli</artifactId> - <version>1.1</version> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java b/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java deleted file mode 100644 index 487af1c..0000000 --- a/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java +++ /dev/null @@ -1,375 +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.tool; - -import org.apache.commons.cli.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.net.URI; -import java.sql.*; -import java.text.DecimalFormat; -import java.util.*; -import java.util.Date; - -public class DBMigrator { - private static final Logger logger = LoggerFactory.getLogger(DBMigrator.class); - private static final String delimiter = ";"; - private static final String MIGRATE_SQL_DERBY = "migrate_derby.sql"; - private static final String MIGRATE_SQL_MYSQL = "migrate_mysql.sql"; - private static final String REGISTRY_VERSION = "registry.version"; - private static final String AIRAVATA_VERSION = "0.5"; - private static String currentAiravataVersion; - private static String relativePath; - private static String SELECT_QUERY; - private static String INSERT_QUERY; - private static String UPDATE_QUERY; - private static String jdbcURL; - private static String jdbcUser; - private static String jdbcPwd; - - public static void main(String[] args) { - parseArguments(args); - generateConfigTableQueries(); - updateDB(jdbcURL, jdbcUser, jdbcPwd); - } - - public static void generateConfigTableQueries(){ - SELECT_QUERY = "SELECT * FROM CONFIGURATION WHERE config_key='" + REGISTRY_VERSION + "' and category_id='SYSTEM'"; - INSERT_QUERY = "INSERT INTO CONFIGURATION (config_key, config_val, expire_date, category_id) VALUES('" + - REGISTRY_VERSION + "', '" + getIncrementedVersion(currentAiravataVersion) + "', '" + getCurrentDate() + - "','SYSTEM')"; - UPDATE_QUERY = "UPDATE CONFIGURATION SET config_val='" + getIncrementedVersion(currentAiravataVersion) + "', expire_date='" + getCurrentDate() + - "' WHERE config_key='" + REGISTRY_VERSION + "' and category_id='SYSTEM'"; - } - - //we assume given database is up and running - public static void updateDB (String jdbcUrl, String jdbcUser, String jdbcPwd){ - relativePath = "db-scripts/" + getIncrementedVersion(currentAiravataVersion) + "/"; - InputStream sqlStream = null; - Scanner in = new Scanner(System.in); - if (jdbcUrl == null || jdbcUrl.equals("")){ - System.out.println("Enter JDBC URL : "); - jdbcUrl = in.next(); - } - if (jdbcUser == null || jdbcUser.equals("")){ - System.out.println("Enter JDBC Username : "); - jdbcUser = in.next(); - } - if (jdbcPwd == null || jdbcPwd.equals("")){ - System.out.println("Enter JDBC password : "); - jdbcPwd = in.next(); - } - - String dbType = getDBType(jdbcUrl); - String jdbcDriver = null; - - Connection connection; - try { - File file = null; - if (dbType.contains("derby")){ - jdbcDriver = "org.apache.derby.jdbc.ClientDriver"; - sqlStream = DBMigrator.class.getClassLoader().getResourceAsStream(relativePath + MIGRATE_SQL_DERBY); - } else if (dbType.contains("mysql")){ - jdbcDriver = "com.mysql.jdbc.Driver"; - sqlStream = DBMigrator.class.getClassLoader().getResourceAsStream(relativePath + MIGRATE_SQL_MYSQL); - } - Class.forName(jdbcDriver).newInstance(); - connection = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPwd); - if (canUpdated(connection)){ - executeSQLScript(connection, sqlStream); - //update configuration table with airavata version - updateConfigTable(connection); - } - } catch (ClassNotFoundException e) { - logger.error("Unable to find SQL scripts..." , e); - } catch (InstantiationException e) { - logger.error("Error while updating the database..." , e); - } catch (IllegalAccessException e) { - logger.error("Error while updating the database..." , e); - } catch (SQLException e) { - logger.error("Error while updating the database..." , e); - } catch (Exception e) { - logger.error("Error while updating the database..." , e); - } - } - - private static boolean canUpdated (Connection conn){ - if (!currentAiravataVersion.equals(AIRAVATA_VERSION)){ - String config = executeSelectQuery(conn); - if (config != null){ - if (config.equals(getIncrementedVersion(currentAiravataVersion))) { - return false; - } else { - return true; - } - } - } else if (currentAiravataVersion.equals(AIRAVATA_VERSION)){ - return true; - } - return false; - } - - private static void updateConfigTable (Connection connection){ - // if existing need to update, otherwise insert - if (executeSelectQuery(connection) != null){ - executeQuery(connection, UPDATE_QUERY); - } else { - executeQuery(connection, INSERT_QUERY); - } - } - - private static Timestamp getCurrentDate (){ - Calendar cal = Calendar.getInstance(); - Date date = cal.getTime(); - Timestamp d = new Timestamp(date.getTime()); - return d; - } - - private static String getIncrementedVersion (String currentVersion){ - - DecimalFormat decimalFormat = new DecimalFormat("#,##0.0"); - Double currentVer = Double.parseDouble(currentVersion); - double v = currentVer + .1; - String formattedVal = decimalFormat.format(v); - return formattedVal; - } - - private static String executeSelectQuery (Connection conn){ - try { - Statement statement = conn.createStatement(); - ResultSet rs = statement.executeQuery(SELECT_QUERY); - if (rs != null){ - while (rs.next()) { - currentAiravataVersion = rs.getString(2); - return currentAiravataVersion; - } - } - } catch (SQLException e) { - logger.error(e.getMessage() , e); - } - return null; - } - - private static void executeQuery (Connection conn, String query){ - try { - Statement statement = conn.createStatement(); - statement.execute(query) ; - } catch (SQLException e) { - logger.error(e.getMessage() , e); - } - } - - private static void executeSQLScript(Connection conn, InputStream inputStream) throws Exception { - StringBuffer sql = new StringBuffer(); - BufferedReader reader = null; - try{ - 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))) { - String sqlString = sql.substring(0, sql.length() - delimiter.length()); - executeSQL(sqlString, conn); - sql.replace(0, sql.length(), ""); - } - } - System.out.println(sql.toString()); - // 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 String getDBType(String jdbcURL){ - try{ - 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 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 void executeSQL(String sql, Connection conn) throws Exception { - 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")) { - 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); - } - } - } - } - - public static void parseArguments(String[] args){ - try{ - Options options = new Options(); - options.addOption("url", true , "JDBC URL"); - options.addOption("user", true, "JDBC Username"); - options.addOption("pwd", true, "JDBC Password"); - options.addOption("v", true, "Airavata Current Version"); - CommandLineParser parser = new PosixParser(); - CommandLine cmd = parser.parse( options, args); - jdbcURL = cmd.getOptionValue("url"); - if (jdbcURL == null){ - logger.info("You should enter JDBC URL and JDBC Credentials as parameters..."); - } - jdbcUser = cmd.getOptionValue("user"); - if (jdbcUser == null){ - logger.info("You should enter JDBC URL and JDBC Credentials as parameters..."); - } - jdbcPwd = cmd.getOptionValue("pwd"); - currentAiravataVersion = cmd.getOptionValue("v"); - if (currentAiravataVersion == null){ - logger.info("You should enter current Airavata version you are using..."); - } - } catch (ParseException e) { - logger.error("Error while reading command line parameters" , e); - } - } - - protected static InputStream readFile(File file) { - StringBuilder fileContentsBuilder = new StringBuilder(); - BufferedReader bufferedReader = null; - try { - char[] buffer = new char[32767]; - bufferedReader = new BufferedReader(new FileReader(file)); - int read = 0; - - do { - read = bufferedReader.read(buffer); - if (read > 0) { - fileContentsBuilder.append(buffer, 0, read); - } - } while (read > 0); - } catch (Exception e) { - logger.error("Failed to read file " + file.getPath(), e); - } finally { - if (bufferedReader != null) { - try { - bufferedReader.close(); - } catch (IOException e) { - logger.error("Unable to close BufferedReader for " + file.getPath(), e); - } - } - } - System.out.println(fileContentsBuilder.toString()); - InputStream is = new ByteArrayInputStream(fileContentsBuilder.toString().getBytes()); - - return is; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/resources/db-migrate.sh ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/resources/db-migrate.sh b/tools/registry-tool/src/main/resources/db-migrate.sh deleted file mode 100755 index c390837..0000000 --- a/tools/registry-tool/src/main/resources/db-migrate.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -# 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. - -. `dirname $0`/setenv.sh -cd $AIRAVATA_HOME/bin - -# update classpath -REG_MIGRATE_CLASSPATH="$AIRAVATA_HOME/lib" -for f in $AIRAVATA_HOME/lib/*.jar -do - REG_MIGRATE_CLASSPATH=$REG_MIGRATE_CLASSPATH:$f -done - -$JAVA_HOME/bin/java -server -Xms128M -Xmx128M \ - $XDEBUG \ - $TEMP_PROPS \ - -Djava.endorsed.dirs=$AIRAVATA_HOME/lib/endorsed \ - -classpath $REG_MIGRATE_CLASSPATH \ - -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5000,suspend=n \ - org.apache.airavata.registry.tool.DBMigrator $* http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql b/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql deleted file mode 100644 index 1e6a605..0000000 --- a/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_derby.sql +++ /dev/null @@ -1,35 +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. - * - */ - -ALTER TABLE Configuration ADD category_id varchar(255) NOT NULL DEFAULT 'SYSTEM'; - -ALTER TABLE Configuration DROP PRIMARY KEY; - -ALTER TABLE Configuration ADD PRIMARY KEY(config_key, config_val, category_id); - -ALTER TABLE Node_Data -ADD execution_index int NOT NULL DEFAULT 0; - -ALTER TABLE Node_Data DROP PRIMARY KEY; - -ALTER TABLE Node_Data ADD PRIMARY KEY(workflow_instanceID, node_id, execution_index); - - http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql b/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql deleted file mode 100644 index be3d66e..0000000 --- a/tools/registry-tool/src/main/resources/db-scripts/0.6/migrate_mysql.sql +++ /dev/null @@ -1,32 +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. - * - */ - -ALTER TABLE Configuration -ADD category_id varchar(255); - -UPDATE Configuration SET category_id="SYSTEM" ; - -ALTER TABLE Configuration DROP PRIMARY KEY, ADD PRIMARY KEY(config_key, config_val, category_id); - -ALTER TABLE Node_Data -ADD execution_index int NOT NULL; - -ALTER TABLE Node_Data DROP PRIMARY KEY, ADD PRIMARY KEY(workflow_instanceID, node_id, execution_index); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql b/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql deleted file mode 100644 index 0528e10..0000000 --- a/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_derby.sql +++ /dev/null @@ -1,40 +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 community_user -( - GATEWAY_NAME VARCHAR(256) NOT NULL, - COMMUNITY_USER_NAME VARCHAR(256) NOT NULL, - TOKEN_ID VARCHAR(256) NOT NULL, - COMMUNITY_USER_EMAIL VARCHAR(256) NOT NULL, - PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME, TOKEN_ID) -); - - -CREATE TABLE credentials -( - GATEWAY_ID VARCHAR(256) NOT NULL, - TOKEN_ID VARCHAR(256) NOT NULL, - CREDENTIAL BLOB NOT NULL, - PORTAL_USER_ID VARCHAR(256) NOT NULL, - TIME_PERSISTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (GATEWAY_ID, TOKEN_ID) -); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql b/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql deleted file mode 100644 index 6b47ed5..0000000 --- a/tools/registry-tool/src/main/resources/db-scripts/0.7/migrate_mysql.sql +++ /dev/null @@ -1,40 +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 community_user -( - GATEWAY_NAME VARCHAR(256) NOT NULL, - COMMUNITY_USER_NAME VARCHAR(256) NOT NULL, - TOKEN_ID VARCHAR(256) NOT NULL, - COMMUNITY_USER_EMAIL VARCHAR(256) NOT NULL, - PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME, TOKEN_ID) -); - - -CREATE TABLE credentials -( - GATEWAY_ID VARCHAR(256) NOT NULL, - TOKEN_ID VARCHAR(256) NOT NULL, - CREDENTIAL TEXT NOT NULL, - PORTAL_USER_ID VARCHAR(256) NOT NULL, - TIME_PERSISTED TIMESTAMP DEFAULT '0000-00-00 00:00:00', - PRIMARY KEY (GATEWAY_ID, TOKEN_ID) -); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql b/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql deleted file mode 100644 index 95b2ccf..0000000 --- a/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_derby.sql +++ /dev/null @@ -1,72 +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 Execution_Error -( - error_id INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, - experiment_ID varchar(255), - workflow_instanceID varchar(255), - node_id varchar(255), - gfacJobID varchar(255), - source_type varchar(255), - error_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - error_msg CLOB, - error_des CLOB, - error_code varchar(255), - error_reporter varchar(255), - error_location varchar(255), - action_taken varchar(255), - error_reference INTEGER, - PRIMARY KEY(error_id), - FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) ON DELETE CASCADE, - FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID) ON DELETE CASCADE -); - -create table GFac_Job_Data -( - experiment_ID varchar(255), - workflow_instanceID varchar(255), - node_id varchar(255), - application_descriptor_ID varchar(255), - host_descriptor_ID varchar(255), - service_descriptor_ID varchar(255), - job_data CLOB, - local_Job_ID varchar(255), - submitted_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', - status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', - status varchar(255), - metadata CLOB, - PRIMARY KEY(local_Job_ID), - FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID), - FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) -); - -create table GFac_Job_Status -( - local_Job_ID varchar(255), - status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', - status varchar(255), - FOREIGN KEY (local_Job_ID) REFERENCES GFac_Job_Data(local_Job_ID) -); - -INSERT INTO GFac_Job_Data(experiment_ID, workflow_instanceID, node_id, application_descriptor_ID, host_descriptor_ID, service_descriptor_ID, -job_data, local_Job_ID, submitted_time, statusUpdateTime, status, metadata) SELECT null, workflow_instanceID, node_id, null, invoked_host, -null, null, local_Job_ID, null, null, 'UNKNOWN', null FROM Gram_Data; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/6c1eebe3/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql ---------------------------------------------------------------------- diff --git a/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql b/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql deleted file mode 100644 index 40ca48c..0000000 --- a/tools/registry-tool/src/main/resources/db-scripts/0.8/migrate_mysql.sql +++ /dev/null @@ -1,72 +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 Execution_Error -( - error_id INT NOT NULL AUTO_INCREMENT, - experiment_ID varchar(255), - workflow_instanceID varchar(255), - node_id varchar(255), - gfacJobID varchar(255), - source_type varchar(255), - error_date TIMESTAMP DEFAULT now() on update now(), - error_msg LONGTEXT, - error_des LONGTEXT, - error_code varchar(255), - error_reporter varchar(255), - error_location varchar(255), - action_taken varchar(255), - error_reference INTEGER, - PRIMARY KEY(error_id), - FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) ON DELETE CASCADE, - FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID) ON DELETE CASCADE -); - -create table GFac_Job_Data -( - experiment_ID varchar(255), - workflow_instanceID varchar(255), - node_id varchar(255), - application_descriptor_ID varchar(255), - host_descriptor_ID varchar(255), - service_descriptor_ID varchar(255), - job_data LONGTEXT, - local_Job_ID varchar(255), - submitted_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', - status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', - status varchar(255), - metadata LONGTEXT, - PRIMARY KEY(local_Job_ID) - FOREIGN KEY (experiment_ID) REFERENCES Experiment_Data(experiment_ID), - FOREIGN KEY (workflow_instanceID) REFERENCES Workflow_Data(workflow_instanceID) -); - -create table GFac_Job_Status -( - local_Job_ID varchar(255), - status_update_time TIMESTAMP DEFAULT '0000-00-00 00:00:00', - status varchar(255), - FOREIGN KEY (local_Job_ID) REFERENCES GFac_Job_Data(local_Job_ID) -); - -INSERT INTO GFac_Job_Data(experiment_ID, workflow_instanceID, node_id, application_descriptor_ID, host_descriptor_ID, service_descriptor_ID, -job_data, local_Job_ID, submitted_time, status_update_time, status, metadata) SELECT null, workflow_instanceID, node_id, null, invoked_host, -null, null, local_Job_ID, null, null, 'UNKNOWN', null FROM Gram_Data; \ No newline at end of file
