rename project
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/417bb819 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/417bb819 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/417bb819 Branch: refs/heads/master Commit: 417bb81972b5273a0be20b251b920c932a9b3e19 Parents: 84f4ccd Author: Kevin Xu <[email protected]> Authored: Fri Dec 11 13:36:37 2015 +0800 Committer: Kevin Xu <[email protected]> Committed: Fri Dec 11 13:36:37 2015 +0800 ---------------------------------------------------------------------- core/conn/spj_init/Makefile | 37 -- core/conn/spj_init/README.md | 24 - core/conn/spj_init/pom.xml | 68 --- .../main/java/com/traf/mgmt/JarFileMgmt.java | 435 ------------------- .../spj_init/src/main/resources/init_spj.sql | 156 ------- .../com/trafodion/mgmt/JarFileMgmtTest.java | 27 -- core/conn/spj_mgmt/.gitignore | 4 + core/conn/spj_mgmt/Makefile | 37 ++ core/conn/spj_mgmt/README.md | 24 + core/conn/spj_mgmt/pom.xml | 68 +++ .../java/org/trafodion/mgmt/JarFileMgmt.java | 433 ++++++++++++++++++ .../spj_mgmt/src/main/resources/init_spj.sh | 155 +++++++ .../com/trafodion/mgmt/JarFileMgmtTest.java | 27 ++ 13 files changed, 748 insertions(+), 747 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_init/Makefile ---------------------------------------------------------------------- diff --git a/core/conn/spj_init/Makefile b/core/conn/spj_init/Makefile deleted file mode 100644 index 698fbf2..0000000 --- a/core/conn/spj_init/Makefile +++ /dev/null @@ -1,37 +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 @@@ - -LIBDIR := lib -JAVAC := $(JAVA_HOME)/bin/javac -INSTALL_LIBDIR := ${MY_SQROOT}/export/lib -INSTALL_SCRIPTSDIR := ${MY_SQROOT}/sql/scripts -CP :=/bin/cp -f -INSTALL_INCLUDEDIR := ${MY_SQROOT}/export/include -all: - @$(MAVEN) package - ${CP} target/spj_init-*.jar ${INSTALL_LIBDIR}/spj_init.jar - ${CP} src/main/resources/init_spj.sql ${INSTALL_SCRIPTSDIR}/ - @chmod +x ${INSTALL_SCRIPTSDIR}/init_spj.sql -clean: - @rm ${INSTALL_LIBDIR}/spj_init.jar - @rm -f ${INSTALL_SCRIPTSDIR}/init_spj.sql - @$(MAVEN) clean -cleanall: clean http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_init/README.md ---------------------------------------------------------------------- diff --git a/core/conn/spj_init/README.md b/core/conn/spj_init/README.md deleted file mode 100644 index 7228a65..0000000 --- a/core/conn/spj_init/README.md +++ /dev/null @@ -1,24 +0,0 @@ -##How to build and initialize default SPJs -###Build -``` -cd $MY_SQROOT/../conn/spj_init -make clean && make all -``` -###Initialization -``` -cds -./init_spj.sql -``` -###SPJ Example -``` -DEFAULT_SPJ.HELP(INOUT COMMANDNAME VARCHAR) -E.g. -trafci>set param ?p1 help; -trafci>call DEFAULT_SPJ.HELP(?p1) -PUT - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.PUT for more info. -LS - List JARs. SHOWDDL PRODURE DEFAULT_SPJ.LS for more info. -LSALL - List all JARs. SHOWDDL PRODURE DEFAULT_SPJ.LSALL for more info. -RM - Remove a JAR. SHOWDDL PRODURE DEFAULT_SPJ.RM for more info. -RMREX - Remove JARs by a perticular pattern. SHOWDDL PRODURE DEFAULT_SPJ.RMREX for more info. -GETFILE - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.GETFILE for more info. -``` http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_init/pom.xml ---------------------------------------------------------------------- diff --git a/core/conn/spj_init/pom.xml b/core/conn/spj_init/pom.xml deleted file mode 100644 index 0d898ec..0000000 --- a/core/conn/spj_init/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ -<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/xsd/maven-4.0.0.xsd"> - <!-- - * @@@ 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 @@@ - --> - <modelVersion>4.0.0</modelVersion> - <groupId>org.trafodion</groupId> - <artifactId>spj_init</artifactId> - <version>${env.TRAFODION_VER}</version> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <version>1.7.12</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.xerial.snappy</groupId> - <artifactId>snappy-java</artifactId> - <version>1.1.2</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-assembly-plugin</artifactId> - <version>2.3</version> - <configuration> - <appendAssemblyId>false</appendAssemblyId> - <descriptorRefs> - <descriptorRef>jar-with-dependencies</descriptorRef> - </descriptorRefs> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>assembly</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_init/src/main/java/com/traf/mgmt/JarFileMgmt.java ---------------------------------------------------------------------- diff --git a/core/conn/spj_init/src/main/java/com/traf/mgmt/JarFileMgmt.java b/core/conn/spj_init/src/main/java/com/traf/mgmt/JarFileMgmt.java deleted file mode 100644 index 90caa8c..0000000 --- a/core/conn/spj_init/src/main/java/com/traf/mgmt/JarFileMgmt.java +++ /dev/null @@ -1,435 +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 com.traf.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; -import org.xerial.snappy.Snappy; - -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 + " "); - } - } - - 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(Snappy.compress(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(Snappy.uncompress(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 + "/spj/" + 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(current_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; - } - - 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/417bb819/core/conn/spj_init/src/main/resources/init_spj.sql ---------------------------------------------------------------------- diff --git a/core/conn/spj_init/src/main/resources/init_spj.sql b/core/conn/spj_init/src/main/resources/init_spj.sql deleted file mode 100644 index c70bc87..0000000 --- a/core/conn/spj_init/src/main/resources/init_spj.sql +++ /dev/null @@ -1,156 +0,0 @@ -#!/bin/bash -# @@@ 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 @@@ - -SERVER_JAR=${MY_SQROOT}/export/lib/spj_init.jar -CI_SERVER_LOG=${MY_SQROOT}/ciserver/cislog -SQLCI=${MY_SQROOT}/export/bin32/sqlci -CP=/bin/cp -MANAGEABILITY_CATALOG=TRAFODION -CIS_SCHEMA=DEFAULT_SPJ - - -function dropAndCreateSchema { - echo "Creating Schema for CI Server Component" - sqlci << sqlciEOF - - cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on'; - cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on'; - - DROP SCHEMA $MANAGEABILITY_CATALOG.$CIS_SCHEMA CASCADE; - CREATE SCHEMA $MANAGEABILITY_CATALOG.$CIS_SCHEMA; - - cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off'; - cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off'; - - exit; -sqlciEOF -} - -function createProcedures { - - echo "Creating Procedures in schema '$MANAGEABILITY_CATALOG.$CIS_SCHEMA' " - sqlci << procEOF - - cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on'; - cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on'; - - -- Creating Procedures - set schema $MANAGEABILITY_CATALOG.$CIS_SCHEMA; - - DROP LIBRARY SPJMGMT CASCADE; - CREATE LIBRARY SPJMGMT FILE '${SERVER_JAR}'; - - CREATE PROCEDURE HELP ( - INOUT COMMANDNAME VARCHAR(2560) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.help (java.lang.String[])' - EXTERNAL SECURITY DEFINER - LIBRARY SPJMGMT - LANGUAGE JAVA - PARAMETER STYLE JAVA - READS SQL DATA - ; - GRANT EXECUTE ON PROCEDURE HELP TO PUBLIC; - - CREATE PROCEDURE PUT ( - 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 SECURITY DEFINER - LIBRARY SPJMGMT - LANGUAGE JAVA - PARAMETER STYLE JAVA - READS SQL DATA - ; - GRANT EXECUTE ON PROCEDURE PUT TO PUBLIC; - - 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 SECURITY DEFINER - LIBRARY SPJMGMT - LANGUAGE JAVA - PARAMETER STYLE JAVA - READS SQL DATA - ; - GRANT EXECUTE ON PROCEDURE LS TO PUBLIC; - - CREATE PROCEDURE LSALL ( - OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.lsAll(java.lang.String[])' - EXTERNAL SECURITY DEFINER - LIBRARY SPJMGMT - LANGUAGE JAVA - PARAMETER STYLE JAVA - READS SQL DATA - ; - GRANT EXECUTE ON PROCEDURE LSALL TO PUBLIC; - - CREATE PROCEDURE RM ( - IN FILENAME VARCHAR(256) CHARACTER SET ISO88591) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.rm(java.lang.String)' - EXTERNAL SECURITY DEFINER - LIBRARY SPJMGMT - LANGUAGE JAVA - PARAMETER STYLE JAVA - READS SQL DATA - ; - GRANT EXECUTE ON PROCEDURE RM TO PUBLIC; - - 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 SECURITY DEFINER - LIBRARY SPJMGMT - LANGUAGE JAVA - PARAMETER STYLE JAVA - READS SQL DATA - ; - GRANT EXECUTE ON PROCEDURE RMREX TO PUBLIC; - - CREATE PROCEDURE GETFILE ( - IN FILENAME VARCHAR(256) CHARACTER SET ISO88591, - IN OFFSET INTEGER, - OUT FILEDATA VARCHAR(102400) CHARACTER SET ISO88591, - OUT DATALENGTH LARGEINT) - EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.get (java.lang.String,int,java.lang.String[],long[])' - EXTERNAL SECURITY DEFINER - LIBRARY SPJMGMT - LANGUAGE JAVA - PARAMETER STYLE JAVA - READS SQL DATA - ; - GRANT EXECUTE ON PROCEDURE GETFILE TO PUBLIC; - - cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off'; - cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off'; - - exit; -procEOF - -} - -dropAndCreateSchema -createProcedures -echo "Successfully completed installation of SPJs." http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_init/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java ---------------------------------------------------------------------- diff --git a/core/conn/spj_init/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java b/core/conn/spj_init/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java deleted file mode 100644 index d424f0f..0000000 --- a/core/conn/spj_init/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java +++ /dev/null @@ -1,27 +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 com.trafodion.mgmt; - -public class JarFileMgmtTest { - -} http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_mgmt/.gitignore ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/.gitignore b/core/conn/spj_mgmt/.gitignore new file mode 100644 index 0000000..c541155 --- /dev/null +++ b/core/conn/spj_mgmt/.gitignore @@ -0,0 +1,4 @@ +/target/ +/bin/ +/.classpath +/.project http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_mgmt/Makefile ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/Makefile b/core/conn/spj_mgmt/Makefile new file mode 100644 index 0000000..2961add --- /dev/null +++ b/core/conn/spj_mgmt/Makefile @@ -0,0 +1,37 @@ +# @@@ 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 @@@ + +LIBDIR := lib +JAVAC := $(JAVA_HOME)/bin/javac +INSTALL_LIBDIR := ${MY_SQROOT}/export/lib +INSTALL_SCRIPTSDIR := ${MY_SQROOT}/sql/scripts +CP :=/bin/cp -f +INSTALL_INCLUDEDIR := ${MY_SQROOT}/export/include +all: + @$(MAVEN) package + ${CP} target/spj_mgmt-*.jar ${INSTALL_LIBDIR}/spj_mgmt.jar + ${CP} src/main/resources/init_spj.sh ${INSTALL_SCRIPTSDIR}/ + @chmod +x ${INSTALL_SCRIPTSDIR}/init_spj.sh +clean: + @rm ${INSTALL_LIBDIR}/spj_mgmt.jar + @rm -f ${INSTALL_SCRIPTSDIR}/init_spj.sh + @$(MAVEN) clean +cleanall: clean http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_mgmt/README.md ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/README.md b/core/conn/spj_mgmt/README.md new file mode 100644 index 0000000..7228a65 --- /dev/null +++ b/core/conn/spj_mgmt/README.md @@ -0,0 +1,24 @@ +##How to build and initialize default SPJs +###Build +``` +cd $MY_SQROOT/../conn/spj_init +make clean && make all +``` +###Initialization +``` +cds +./init_spj.sql +``` +###SPJ Example +``` +DEFAULT_SPJ.HELP(INOUT COMMANDNAME VARCHAR) +E.g. +trafci>set param ?p1 help; +trafci>call DEFAULT_SPJ.HELP(?p1) +PUT - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.PUT for more info. +LS - List JARs. SHOWDDL PRODURE DEFAULT_SPJ.LS for more info. +LSALL - List all JARs. SHOWDDL PRODURE DEFAULT_SPJ.LSALL for more info. +RM - Remove a JAR. SHOWDDL PRODURE DEFAULT_SPJ.RM for more info. +RMREX - Remove JARs by a perticular pattern. SHOWDDL PRODURE DEFAULT_SPJ.RMREX for more info. +GETFILE - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.GETFILE for more info. +``` http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_mgmt/pom.xml ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/pom.xml b/core/conn/spj_mgmt/pom.xml new file mode 100644 index 0000000..37414c1 --- /dev/null +++ b/core/conn/spj_mgmt/pom.xml @@ -0,0 +1,68 @@ +<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/xsd/maven-4.0.0.xsd"> + <!-- + * @@@ 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 @@@ + --> + <modelVersion>4.0.0</modelVersion> + <groupId>org.trafodion</groupId> + <artifactId>spj_mgmt</artifactId> + <version>${env.TRAFODION_VER}</version> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.7.12</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.xerial.snappy</groupId> + <artifactId>snappy-java</artifactId> + <version>1.1.2</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.3</version> + <configuration> + <appendAssemblyId>false</appendAssemblyId> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>assembly</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/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 new file mode 100644 index 0000000..0753428 --- /dev/null +++ b/core/conn/spj_mgmt/src/main/java/org/trafodion/mgmt/JarFileMgmt.java @@ -0,0 +1,433 @@ +/** +* @@@ 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 + " "); + } + } + + 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/417bb819/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 new file mode 100644 index 0000000..ae1042e --- /dev/null +++ b/core/conn/spj_mgmt/src/main/resources/init_spj.sh @@ -0,0 +1,155 @@ +#!/bin/bash +# @@@ 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 @@@ + +SERVER_JAR=${MY_SQROOT}/export/lib/spj_mgmt.jar +SQLCI=${MY_SQROOT}/export/bin32/sqlci +CP=/bin/cp +MANAGEABILITY_CATALOG=TRAFODION +CIS_SCHEMA="_SPJ_" + + +function dropAndCreateSchema { + echo "Creating Schema for CI Server Component" + sqlci << sqlciEOF + + cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on'; + cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on'; + + DROP SCHEMA $MANAGEABILITY_CATALOG.$CIS_SCHEMA CASCADE; + CREATE SCHEMA $MANAGEABILITY_CATALOG.$CIS_SCHEMA; + + cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off'; + cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off'; + + exit; +sqlciEOF +} + +function createProcedures { + + echo "Creating Procedures in schema '$MANAGEABILITY_CATALOG.$CIS_SCHEMA' " + sqlci << procEOF + + cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on'; + cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on'; + + -- Creating Procedures + set schema $MANAGEABILITY_CATALOG.$CIS_SCHEMA; + + DROP LIBRARY SPJMGMT CASCADE; + CREATE LIBRARY SPJMGMT FILE '${SERVER_JAR}'; + + CREATE PROCEDURE HELP ( + INOUT COMMANDNAME VARCHAR(2560) CHARACTER SET ISO88591) + EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.help (java.lang.String[])' + EXTERNAL SECURITY DEFINER + LIBRARY SPJMGMT + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + ; + GRANT EXECUTE ON PROCEDURE HELP TO PUBLIC; + + CREATE PROCEDURE PUT ( + 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 SECURITY DEFINER + LIBRARY SPJMGMT + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + ; + GRANT EXECUTE ON PROCEDURE PUT TO PUBLIC; + + 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 SECURITY DEFINER + LIBRARY SPJMGMT + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + ; + GRANT EXECUTE ON PROCEDURE LS TO PUBLIC; + + CREATE PROCEDURE LSALL ( + OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591) + EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.lsAll(java.lang.String[])' + EXTERNAL SECURITY DEFINER + LIBRARY SPJMGMT + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + ; + GRANT EXECUTE ON PROCEDURE LSALL TO PUBLIC; + + CREATE PROCEDURE RM ( + IN FILENAME VARCHAR(256) CHARACTER SET ISO88591) + EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.rm(java.lang.String)' + EXTERNAL SECURITY DEFINER + LIBRARY SPJMGMT + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + ; + GRANT EXECUTE ON PROCEDURE RM TO PUBLIC; + + 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 SECURITY DEFINER + LIBRARY SPJMGMT + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + ; + GRANT EXECUTE ON PROCEDURE RMREX TO PUBLIC; + + CREATE PROCEDURE GETFILE ( + IN FILENAME VARCHAR(256) CHARACTER SET ISO88591, + IN OFFSET INTEGER, + OUT FILEDATA VARCHAR(102400) CHARACTER SET ISO88591, + OUT DATALENGTH LARGEINT) + EXTERNAL NAME 'com.traf.mgmt.JarFileMgmt.get (java.lang.String,int,java.lang.String[],long[])' + EXTERNAL SECURITY DEFINER + LIBRARY SPJMGMT + LANGUAGE JAVA + PARAMETER STYLE JAVA + READS SQL DATA + ; + GRANT EXECUTE ON PROCEDURE GETFILE TO PUBLIC; + + cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off'; + cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off'; + + exit; +procEOF + +} + +dropAndCreateSchema +createProcedures +echo "Successfully completed installation of SPJs." http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/417bb819/core/conn/spj_mgmt/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java ---------------------------------------------------------------------- diff --git a/core/conn/spj_mgmt/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java b/core/conn/spj_mgmt/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java new file mode 100644 index 0000000..d424f0f --- /dev/null +++ b/core/conn/spj_mgmt/src/test/java/com/trafodion/mgmt/JarFileMgmtTest.java @@ -0,0 +1,27 @@ +/** +* @@@ 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 com.trafodion.mgmt; + +public class JarFileMgmtTest { + +}
