rename package
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/05c680fd Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/05c680fd Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/05c680fd Branch: refs/heads/master Commit: 05c680fd93621c5eafa712afb98f525a900f6d16 Parents: e55da58 Author: Kevin Xu <[email protected]> Authored: Tue Dec 22 10:24:23 2015 +0800 Committer: Kevin Xu <[email protected]> Committed: Tue Dec 22 10:24:23 2015 +0800 ---------------------------------------------------------------------- core/conn/jdbc_type4/.gitignore | 1 + .../java/org/trafodion/mgmt/JarFileMgmt.java | 434 ------------------- .../java/org/trafodion/spjmgmt/FileMgmt.java | 434 +++++++++++++++++++ .../spj_mgmt/src/main/resources/init_spj.sh | 21 +- 4 files changed, 445 insertions(+), 445 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/05c680fd/core/conn/jdbc_type4/.gitignore ---------------------------------------------------------------------- diff --git a/core/conn/jdbc_type4/.gitignore b/core/conn/jdbc_type4/.gitignore index 99f4389..9a66973 100644 --- a/core/conn/jdbc_type4/.gitignore +++ b/core/conn/jdbc_type4/.gitignore @@ -1,2 +1,3 @@ buildId temp/ +/target/ http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/05c680fd/core/conn/spj_mgmt/src/main/java/org/trafodion/mgmt/JarFileMgmt.java ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/src/main/java/org/trafodion/mgmt/JarFileMgmt.java b/core/conn/spj_mgmt/src/main/java/org/trafodion/mgmt/JarFileMgmt.java deleted file mode 100644 index 3b50a96..0000000 --- a/core/conn/spj_mgmt/src/main/java/org/trafodion/mgmt/JarFileMgmt.java +++ /dev/null @@ -1,434 +0,0 @@ -/** -* @@@ START COPYRIGHT @@@ -* -* 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. -* -* @@@ END COPYRIGHT @@@ - */ -package org.trafodion.mgmt; - -import java.io.File; -import java.io.FileFilter; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.RandomAccessFile; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class JarFileMgmt { - private static final Logger LOG = LoggerFactory.getLogger(JarFileMgmt.class); - private static final String url = "jdbc:default:connection"; - // 100Mb - private static final long MAX_JAR_FILE_SIZE = 104857600; - private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static final int MaxDataSize = 102400; - private static final String CHARTSET = "ISO-8859-1"; - - /** - * Print help info - * - * @param helps: - * INOUT parameter like PUT/LS/... - */ - public static void help(String[] helps) { - String[] help = new String[] { - "PUT - Upload a JAR. SHOWDDL PROCEDURE DEFAULT_SPJ.PUT for more info.", - "LS - List JARs. SHOWDDL PROCEDURE DEFAULT_SPJ.LS for more info.", - "LSALL - List all JARs. SHOWDDL PROCEDURE DEFAULT_SPJ.LSALL for more info.", - "RM - Remove a JAR. SHOWDDL PROCEDURE DEFAULT_SPJ.RM for more info.", - "RMREX - Remove JARs by a perticular pattern. SHOWDDL PROCEDURE DEFAULT_SPJ.RMREX for more info.", - "GETFILE - Download a JAR. SHOWDDL PROCEDURE DEFAULT_SPJ.GETFILE for more info." - }; - List<String> index = new ArrayList<String>(help.length); - index.add("PUT"); - index.add("LS"); - index.add("LSALL"); - index.add("RM"); - index.add("RMREX"); - index.add("GETFILE"); - String tmp = helps[0].trim().toUpperCase(); - helps[0] = "HELP:\r\n"; - switch (index.indexOf(tmp)) { - case 0: - helps[0] = help[0]; - break; - case 1: - helps[0] = help[1]; - break; - case 2: - helps[0] = help[2]; - break; - case 3: - helps[0] = help[3]; - break; - case 4: - helps[0] = help[4]; - break; - case 5: - helps[0] = help[5]; - break; - default: - for (String h : help) { - helps[0] += h + "\r\n"; - } - - } - - } - - public static void syncJar(String userPath, String fileName) throws SQLException, IOException { - checkFileName(fileName); - LOG.info("syncJars " + fileName); - String nodes = System.getenv("MY_NODES"); - if (nodes != null && !"".equals(nodes.trim())) { - execShell("pdcp " + nodes + " " + userPath + fileName.trim() + " " + userPath + " "); - execShell("pdsh " + nodes + " chmod 755 " + userPath + fileName.trim()); - } - } - - private static String execShell(String cmd) throws IOException { - Process p = Runtime.getRuntime().exec(cmd); - if (p != null) { - StringBuilder sb = new StringBuilder(); - InputStream in = null; - try { - in = p.getInputStream(); - int c = -1; - while ((c = in.read()) != -1) { - sb.append((char) c); - } - } finally { - if (in != null) - in.close(); - } - try { - in = p.getErrorStream(); - int c = -1; - boolean flag = true; - while ((c = in.read()) != -1) { - if (flag) { - sb.append("\r\n"); - } else { - flag = false; - } - sb.append((char) c); - } - } finally { - if (in != null) - in.close(); - } - return sb.toString(); - } - return null; - } - - /** - * Download a JAR file - * - * @param fileName - * @param offset - * @param fileData - * @throws SQLException - * @throws IOException - */ - public static void get(String fileName, int offset, String[] fileData, long[] fileLength) - throws SQLException, IOException { - checkFileName(fileName); - Connection conn = getConn(); - LOG.info("Get " + fileName); - String userPath = getCodeFilePath(conn); - close(conn); - File file = new File(userPath + fileName); - if (!file.exists()) { - throw new SQLException("No such file[" + fileName + "]"); - } - RandomAccessFile rAFile = null; - try { - rAFile = new RandomAccessFile(file, "r"); - rAFile.seek(offset); - byte bArray[] = new byte[MaxDataSize]; - int bytesRead = rAFile.read(bArray, 0, MaxDataSize); - if (bytesRead != -1) { - fileData[0] = new String(Arrays.copyOf(bArray, bytesRead), CHARTSET); - fileLength[0] = file.length(); - LOG.info("Download: " + fileName + ", offset:" + offset + ",compressed length:" + fileData[0].length() - + ",file length:" + fileLength[0]); - } - } finally { - if (rAFile != null) { - try { - rAFile.close(); - } catch (Exception e) { - LOG.warn("Something wrong while close file[" + fileName + "] stream: " + e.getMessage()); - } - } - } - - } - - /** - * Remove exact file - * - * @param fileName - * @throws SQLException - */ - public static void rm(String fileName) throws SQLException { - checkFileName(fileName); - Connection conn = getConn(); - LOG.info("Remove " + fileName); - String userPath = getCodeFilePath(conn); - close(conn); - File file = new File(userPath + fileName); - if (file.exists()) { - file.delete(); - LOG.info("Remove " + fileName + " successfully!"); - return; - } else { - throw new SQLException("No such file[" + fileName + "]"); - } - } - - /** - * Remove files via regular formulation - * - * @param pattern: - * to be deleted - * @param names - * : file names to be deleted - * @throws SQLException - */ - public static void rmRex(String pattern, String[] names) throws SQLException { - checkFileName(pattern); - Connection conn = getConn(); - LOG.info("Try to remove files[" + pattern + "]"); - String userPath = getCodeFilePath(conn); - close(conn); - File[] files = getFiles(pattern, new File(userPath)); - StringBuilder sb = new StringBuilder(); - sb.append("<rmRex>"); - sb.append(toXML(files, "rmList")); - sb.append("<message>"); - boolean hasError = false; - for (File f : files) { - try { - f.delete(); - } catch (Exception e) { - hasError = true; - LOG.error(e.getMessage(), e); - sb.append("<error fileName='" + f.getName() + "'>" + e.getMessage() + "</error>"); - } - } - if (!hasError) { - sb.append("Remove the files successfully!"); - } - sb.append("</message>"); - sb.append("</rmRex>"); - names[0] = sb.toString(); - LOG.info("Done for removing files[" + pattern + "]."); - } - - public static void lsAll(String[] names) throws SQLException { - ls("*", names); - } - - /** - * list the Jars matching PATTERN - * - * @param pattern: - * @param names - * @throws SQLException - */ - public static void ls(String pattern, String[] names) throws SQLException { - checkFileName(pattern); - Connection conn = getConn(); - LOG.info("List files[" + pattern + "]"); - String userPath = getCodeFilePath(conn); - close(conn); - File dir = new File(userPath); - if (!dir.exists() || !dir.isDirectory()) { - LOG.error("Directory [" + userPath + "] is not found!"); - throw new SQLException("Directory [" + userPath + "] is not found!"); - } - if (pattern == null) { - LOG.error("File pattern should not be empty!"); - throw new SQLException("Pattern is empty!"); - } - File[] files = getFiles(pattern, dir); - names[0] = toXML(files, "ls"); - } - - /** - * upload a JAR file - * - * @param fileData - * @param fileName - * @param appendFlag - * 0: append; otherwise overwrite - * @throws SQLException - */ - public static void put(String fileData, String fileName, int appendFlag) throws SQLException { - checkFileName(fileName); - try { - byte[] data = fileData.getBytes(CHARTSET); - - Connection conn = getConn(); - LOG.info("Put " + fileName + ", length: " + data.length + ", file string length:" + fileData.length()); - String userPath = getCodeFilePath(conn); - close(conn); - String fname = userPath + fileName; - checkFile(fname, data.length); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(fname, (appendFlag == 0)); - fos.write(Arrays.copyOf(data, data.length)); - fos.flush(); - } finally { - if (fos != null) - fos.close(); - } - - syncJar(userPath, fileName); - - } catch (Throwable t) { - LOG.error(t.getMessage(), t); - throw new SQLException(t.getMessage()); - } - } - - private static void checkFileName(String fileName) throws SQLException { - if (fileName.contains("/") || fileName.contains("\\")) - throw new SQLException("Illegal file name: " + fileName - + ". File name must not contain \"/\"."); - } - - private static void checkFile(String fname, int dataSize) throws SQLException { - File jar = new File(fname); - if (jar.length() + dataSize > MAX_JAR_FILE_SIZE) { - LOG.error("Jar file size is over the threshold[100Mb]"); - throw new SQLException("Jar file size is over the threshold[100Mb]"); - } - } - - private static String getCodeFilePath(Connection conn) throws SQLException { - String user = getCurrentUser(conn); - String root = System.getenv("MY_SQROOT"); - if (root == null || "".equals(root.trim())) { - LOG.error("Cant get your traf installation path!"); - throw new SQLException("Cant get your traf installation path!"); - } - File file = new File(root + "/udr/lib/" + user); - if (!file.exists()) { - file.mkdirs(); - } else if (!file.isDirectory()) { - throw new SQLException("User Directory is not valide or you dont have permission!"); - } - LOG.info("SPJ JARs location: " + file.getAbsolutePath()); - return file.getAbsolutePath() + "/"; - } - - private static Connection getConn() throws SQLException { - Connection conn = null; - try { - conn = DriverManager.getConnection(url); - LOG.info("Create connection successfully. " + conn); - } catch (Throwable t) { - LOG.error("Error encountered while getting connection ", t); - throw new SQLException(t.getMessage()); - } - return conn; - } - - private static String getCurrentUser(Connection conn) throws SQLException { - Statement st = null; - ResultSet rs = null; - String user = null; - try { - st = conn.createStatement(); - rs = st.executeQuery("values(session_user)"); - if (rs.next()) { - user = rs.getString(1); - } - } catch (Exception e) { - LOG.error(e.getMessage(), e); - throw new SQLException(e); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (Exception e) { - LOG.warn(e.getMessage(), e); - } - } - if (st != null) { - try { - st.close(); - } catch (Exception e) { - LOG.warn(e.getMessage(), e); - } - } - } - - return user.replaceAll("[\\\\/]", "_"); - } - - private static File[] getFiles(String pattern, File dir) { - final String p = pattern.replaceAll("\\*", ".*").trim().toUpperCase(); - return dir.listFiles(new FileFilter() { - - @Override - public boolean accept(File name) { - if (name == null || !name.isFile()) { - return false; - } - return name.getName().trim().toUpperCase().matches(p); - } - }); - } - - private static String toXML(File[] files, String root) { - StringBuilder sb = new StringBuilder(); - sb.append("<" + root + ">"); - for (File f : files) { - sb.append("<file name='" + f.getName() + "' lastModifyTime='" + format.format(new Date(f.lastModified())) - + "' size='" + f.length() + "'/>"); - } - sb.append("</" + root + ">"); - return sb.toString(); - } - - private static void close(Connection conn) { - try { - conn.close(); - LOG.info("Closed connection"); - } catch (Exception e) { - LOG.warn(e.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/05c680fd/core/conn/spj_mgmt/src/main/java/org/trafodion/spjmgmt/FileMgmt.java ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/src/main/java/org/trafodion/spjmgmt/FileMgmt.java b/core/conn/spj_mgmt/src/main/java/org/trafodion/spjmgmt/FileMgmt.java new file mode 100644 index 0000000..8b6d5b1 --- /dev/null +++ b/core/conn/spj_mgmt/src/main/java/org/trafodion/spjmgmt/FileMgmt.java @@ -0,0 +1,434 @@ +/** +* @@@ START COPYRIGHT @@@ +* +* 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. +* +* @@@ END COPYRIGHT @@@ + */ +package org.trafodion.spjmgmt; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FileMgmt { + private static final Logger LOG = LoggerFactory.getLogger(FileMgmt.class); + private static final String url = "jdbc:default:connection"; + // 100Mb + private static final long MAX_JAR_FILE_SIZE = 104857600; + private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final int MaxDataSize = 102400; + private static final String CHARTSET = "ISO-8859-1"; + + /** + * Print help info + * + * @param helps: + * INOUT parameter like PUT/LS/... + */ + public static void help(String[] helps) { + String[] help = new String[] { + "PUT - Upload a JAR. SHOWDDL PROCEDURE DEFAULT_SPJ.PUT for more info.", + "LS - List JARs. SHOWDDL PROCEDURE DEFAULT_SPJ.LS for more info.", + "LSALL - List all JARs. SHOWDDL PROCEDURE DEFAULT_SPJ.LSALL for more info.", + "RM - Remove a JAR. SHOWDDL PROCEDURE DEFAULT_SPJ.RM for more info.", + "RMREX - Remove JARs by a perticular pattern. SHOWDDL PROCEDURE DEFAULT_SPJ.RMREX for more info.", + "GETFILE - Download a JAR. SHOWDDL PROCEDURE DEFAULT_SPJ.GETFILE for more info." + }; + List<String> index = new ArrayList<String>(help.length); + index.add("PUT"); + index.add("LS"); + index.add("LSALL"); + index.add("RM"); + index.add("RMREX"); + index.add("GETFILE"); + String tmp = helps[0].trim().toUpperCase(); + helps[0] = "HELP:\r\n"; + switch (index.indexOf(tmp)) { + case 0: + helps[0] = help[0]; + break; + case 1: + helps[0] = help[1]; + break; + case 2: + helps[0] = help[2]; + break; + case 3: + helps[0] = help[3]; + break; + case 4: + helps[0] = help[4]; + break; + case 5: + helps[0] = help[5]; + break; + default: + for (String h : help) { + helps[0] += h + "\r\n"; + } + + } + + } + + public static void syncJar(String userPath, String fileName) throws SQLException, IOException { + checkFileName(fileName); + LOG.info("syncJars " + fileName); + String nodes = System.getenv("MY_NODES"); + if (nodes != null && !"".equals(nodes.trim())) { + execShell("pdcp " + nodes + " " + userPath + fileName.trim() + " " + userPath + " "); + execShell("pdsh " + nodes + " chmod 755 " + userPath + fileName.trim()); + } + } + + private static String execShell(String cmd) throws IOException { + Process p = Runtime.getRuntime().exec(cmd); + if (p != null) { + StringBuilder sb = new StringBuilder(); + InputStream in = null; + try { + in = p.getInputStream(); + int c = -1; + while ((c = in.read()) != -1) { + sb.append((char) c); + } + } finally { + if (in != null) + in.close(); + } + try { + in = p.getErrorStream(); + int c = -1; + boolean flag = true; + while ((c = in.read()) != -1) { + if (flag) { + sb.append("\r\n"); + } else { + flag = false; + } + sb.append((char) c); + } + } finally { + if (in != null) + in.close(); + } + return sb.toString(); + } + return null; + } + + /** + * Download a JAR file + * + * @param fileName + * @param offset + * @param fileData + * @throws SQLException + * @throws IOException + */ + public static void get(String fileName, int offset, String[] fileData, long[] fileLength) + throws SQLException, IOException { + checkFileName(fileName); + Connection conn = getConn(); + LOG.info("Get " + fileName); + String userPath = getCodeFilePath(conn); + close(conn); + File file = new File(userPath + fileName); + if (!file.exists()) { + throw new SQLException("No such file[" + fileName + "]"); + } + RandomAccessFile rAFile = null; + try { + rAFile = new RandomAccessFile(file, "r"); + rAFile.seek(offset); + byte bArray[] = new byte[MaxDataSize]; + int bytesRead = rAFile.read(bArray, 0, MaxDataSize); + if (bytesRead != -1) { + fileData[0] = new String(Arrays.copyOf(bArray, bytesRead), CHARTSET); + fileLength[0] = file.length(); + LOG.info("Download: " + fileName + ", offset:" + offset + ",compressed length:" + fileData[0].length() + + ",file length:" + fileLength[0]); + } + } finally { + if (rAFile != null) { + try { + rAFile.close(); + } catch (Exception e) { + LOG.warn("Something wrong while close file[" + fileName + "] stream: " + e.getMessage()); + } + } + } + + } + + /** + * Remove exact file + * + * @param fileName + * @throws SQLException + */ + public static void rm(String fileName) throws SQLException { + checkFileName(fileName); + Connection conn = getConn(); + LOG.info("Remove " + fileName); + String userPath = getCodeFilePath(conn); + close(conn); + File file = new File(userPath + fileName); + if (file.exists()) { + file.delete(); + LOG.info("Remove " + fileName + " successfully!"); + return; + } else { + throw new SQLException("No such file[" + fileName + "]"); + } + } + + /** + * Remove files via regular formulation + * + * @param pattern: + * to be deleted + * @param names + * : file names to be deleted + * @throws SQLException + */ + public static void rmRex(String pattern, String[] names) throws SQLException { + checkFileName(pattern); + Connection conn = getConn(); + LOG.info("Try to remove files[" + pattern + "]"); + String userPath = getCodeFilePath(conn); + close(conn); + File[] files = getFiles(pattern, new File(userPath)); + StringBuilder sb = new StringBuilder(); + sb.append("<rmRex>"); + sb.append(toXML(files, "rmList")); + sb.append("<message>"); + boolean hasError = false; + for (File f : files) { + try { + f.delete(); + } catch (Exception e) { + hasError = true; + LOG.error(e.getMessage(), e); + sb.append("<error fileName='" + f.getName() + "'>" + e.getMessage() + "</error>"); + } + } + if (!hasError) { + sb.append("Remove the files successfully!"); + } + sb.append("</message>"); + sb.append("</rmRex>"); + names[0] = sb.toString(); + LOG.info("Done for removing files[" + pattern + "]."); + } + + public static void lsAll(String[] names) throws SQLException { + ls("*", names); + } + + /** + * list the Jars matching PATTERN + * + * @param pattern: + * @param names + * @throws SQLException + */ + public static void ls(String pattern, String[] names) throws SQLException { + checkFileName(pattern); + Connection conn = getConn(); + LOG.info("List files[" + pattern + "]"); + String userPath = getCodeFilePath(conn); + close(conn); + File dir = new File(userPath); + if (!dir.exists() || !dir.isDirectory()) { + LOG.error("Directory [" + userPath + "] is not found!"); + throw new SQLException("Directory [" + userPath + "] is not found!"); + } + if (pattern == null) { + LOG.error("File pattern should not be empty!"); + throw new SQLException("Pattern is empty!"); + } + File[] files = getFiles(pattern, dir); + names[0] = toXML(files, "ls"); + } + + /** + * upload a JAR file + * + * @param fileData + * @param fileName + * @param appendFlag + * 0: append; otherwise overwrite + * @throws SQLException + */ + public static void put(String fileData, String fileName, int appendFlag) throws SQLException { + checkFileName(fileName); + try { + byte[] data = fileData.getBytes(CHARTSET); + + Connection conn = getConn(); + LOG.info("Put " + fileName + ", length: " + data.length + ", file string length:" + fileData.length()); + String userPath = getCodeFilePath(conn); + close(conn); + String fname = userPath + fileName; + checkFile(fname, data.length); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(fname, (appendFlag == 0)); + fos.write(Arrays.copyOf(data, data.length)); + fos.flush(); + } finally { + if (fos != null) + fos.close(); + } + + syncJar(userPath, fileName); + + } catch (Throwable t) { + LOG.error(t.getMessage(), t); + throw new SQLException(t.getMessage()); + } + } + + private static void checkFileName(String fileName) throws SQLException { + if (fileName.contains("/") || fileName.contains("\\")) + throw new SQLException("Illegal file name: " + fileName + + ". File name must not contain \"/\"."); + } + + private static void checkFile(String fname, int dataSize) throws SQLException { + File jar = new File(fname); + if (jar.length() + dataSize > MAX_JAR_FILE_SIZE) { + LOG.error("Jar file size is over the threshold[100Mb]"); + throw new SQLException("Jar file size is over the threshold[100Mb]"); + } + } + + private static String getCodeFilePath(Connection conn) throws SQLException { + String user = getCurrentUser(conn); + String root = System.getenv("MY_SQROOT"); + if (root == null || "".equals(root.trim())) { + LOG.error("Cant get your traf installation path!"); + throw new SQLException("Cant get your traf installation path!"); + } + File file = new File(root + "/udr/lib/" + user); + if (!file.exists()) { + file.mkdirs(); + } else if (!file.isDirectory()) { + throw new SQLException("User Directory is not valide or you dont have permission!"); + } + LOG.info("SPJ JARs location: " + file.getAbsolutePath()); + return file.getAbsolutePath() + "/"; + } + + private static Connection getConn() throws SQLException { + Connection conn = null; + try { + conn = DriverManager.getConnection(url); + LOG.info("Create connection successfully. " + conn); + } catch (Throwable t) { + LOG.error("Error encountered while getting connection ", t); + throw new SQLException(t.getMessage()); + } + return conn; + } + + private static String getCurrentUser(Connection conn) throws SQLException { + Statement st = null; + ResultSet rs = null; + String user = null; + try { + st = conn.createStatement(); + rs = st.executeQuery("values(session_user)"); + if (rs.next()) { + user = rs.getString(1); + } + } catch (Exception e) { + LOG.error(e.getMessage(), e); + throw new SQLException(e); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (Exception e) { + LOG.warn(e.getMessage(), e); + } + } + if (st != null) { + try { + st.close(); + } catch (Exception e) { + LOG.warn(e.getMessage(), e); + } + } + } + + return user.replaceAll("[\\\\/]", "_"); + } + + private static File[] getFiles(String pattern, File dir) { + final String p = pattern.replaceAll("\\*", ".*").trim().toUpperCase(); + return dir.listFiles(new FileFilter() { + + @Override + public boolean accept(File name) { + if (name == null || !name.isFile()) { + return false; + } + return name.getName().trim().toUpperCase().matches(p); + } + }); + } + + private static String toXML(File[] files, String root) { + StringBuilder sb = new StringBuilder(); + sb.append("<" + root + ">"); + for (File f : files) { + sb.append("<file name='" + f.getName() + "' lastModifyTime='" + format.format(new Date(f.lastModified())) + + "' size='" + f.length() + "'/>"); + } + sb.append("</" + root + ">"); + return sb.toString(); + } + + private static void close(Connection conn) { + try { + conn.close(); + LOG.info("Closed connection"); + } catch (Exception e) { + LOG.warn(e.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/05c680fd/core/conn/spj_mgmt/src/main/resources/init_spj.sh ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/src/main/resources/init_spj.sh b/core/conn/spj_mgmt/src/main/resources/init_spj.sh index f684a72..796865c 100644 --- a/core/conn/spj_mgmt/src/main/resources/init_spj.sh +++ b/core/conn/spj_mgmt/src/main/resources/init_spj.sh @@ -21,15 +21,14 @@ # @@@ END COPYRIGHT @@@ SERVER_JAR=${MY_SQROOT}/export/lib/spj_mgmt.jar -SQLCI=${MY_SQROOT}/export/bin32/sqlci -CP=/bin/cp +CI=sqlci CATALOG_NAME=TRAFODION CIS_SCHEMA="_SPJ_" function dropAndCreateSchema { echo "Creating Schema for SPJ_MGMT" - sqlci << sqlciEOF + ${CI} << sqlciEOF cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on'; cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on'; @@ -47,7 +46,7 @@ sqlciEOF function createProcedures { echo "Creating Procedures in schema '$CATALOG_NAME.$CIS_SCHEMA' " - sqlci << procEOF + ${CI} << procEOF cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on'; cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on'; @@ -60,7 +59,7 @@ function createProcedures { CREATE PROCEDURE HELP ( INOUT COMMANDNAME VARCHAR(2560) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.help (java.lang.String[])' + EXTERNAL NAME 'org.trafodion.spjmgmt.FileMgmt.help (java.lang.String[])' EXTERNAL SECURITY DEFINER LIBRARY SPJMGMT LANGUAGE JAVA @@ -73,7 +72,7 @@ function createProcedures { IN FILEDATA VARCHAR(102400) CHARACTER SET ISO88591, IN FILENAME VARCHAR(256) CHARACTER SET ISO88591, IN CREATEFLAG INTEGER) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.put(java.lang.String,java.lang.String,int)' + EXTERNAL NAME 'org.trafodion.spjmgmt.FileMgmt.put(java.lang.String,java.lang.String,int)' EXTERNAL SECURITY DEFINER LIBRARY SPJMGMT LANGUAGE JAVA @@ -85,7 +84,7 @@ function createProcedures { CREATE PROCEDURE LS ( IN FILENAME VARCHAR(256) CHARACTER SET ISO88591, OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.ls(java.lang.String,java.lang.String[])' + EXTERNAL NAME 'org.trafodion.spjmgmt.FileMgmt.ls(java.lang.String,java.lang.String[])' EXTERNAL SECURITY DEFINER LIBRARY SPJMGMT LANGUAGE JAVA @@ -96,7 +95,7 @@ function createProcedures { CREATE PROCEDURE LSALL ( OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.lsAll(java.lang.String[])' + EXTERNAL NAME 'org.trafodion.spjmgmt.FileMgmt.lsAll(java.lang.String[])' EXTERNAL SECURITY DEFINER LIBRARY SPJMGMT LANGUAGE JAVA @@ -107,7 +106,7 @@ function createProcedures { CREATE PROCEDURE RM ( IN FILENAME VARCHAR(256) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.rm(java.lang.String)' + EXTERNAL NAME 'org.trafodion.spjmgmt.FileMgmt.rm(java.lang.String)' EXTERNAL SECURITY DEFINER LIBRARY SPJMGMT LANGUAGE JAVA @@ -119,7 +118,7 @@ function createProcedures { CREATE PROCEDURE RMREX ( IN FILENAME VARCHAR(256) CHARACTER SET ISO88591, OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.rmRex(java.lang.String, java.lang.String[])' + EXTERNAL NAME 'org.trafodion.spjmgmt.FileMgmt.rmRex(java.lang.String, java.lang.String[])' EXTERNAL SECURITY DEFINER LIBRARY SPJMGMT LANGUAGE JAVA @@ -133,7 +132,7 @@ function createProcedures { IN OFFSET INTEGER, OUT FILEDATA VARCHAR(51200) CHARACTER SET UTF8, OUT DATALENGTH LARGEINT) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.get (java.lang.String,int,java.lang.String[],long[])' + EXTERNAL NAME 'org.trafodion.spjmgmt.FileMgmt.get (java.lang.String,int,java.lang.String[],long[])' EXTERNAL SECURITY DEFINER LIBRARY SPJMGMT LANGUAGE JAVA
