Repository: incubator-hawq
Updated Branches:
  refs/heads/master 5f972f9be -> 634e0cdac


HAWQ-1531. Templetized PXF user and log directories.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/634e0cda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/634e0cda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/634e0cda

Branch: refs/heads/master
Commit: 634e0cdac3478600fe567f2fefd0ddaa8cf3db50
Parents: 5f972f9
Author: Oleksandr Diachenko <[email protected]>
Authored: Fri Sep 29 12:33:50 2017 -0700
Committer: Oleksandr Diachenko <[email protected]>
Committed: Fri Sep 29 12:33:50 2017 -0700

----------------------------------------------------------------------
 pxf/Makefile                                    |   5 +
 pxf/README.md                                   |   9 ++
 pxf/build.gradle                                |  19 ++-
 pxf/gradle.properties                           |   2 +-
 pxf/gradle/profiles/gpdb.properties             |  20 +++
 pxf/gradle/profiles/hawq.properties             |  20 +++
 .../templates/pxf-private.classpath.template    |  80 ++++++++++
 .../src/configs/tomcat/bin/setenv.sh            |   4 +-
 .../src/main/resources/pxf-log4j.properties     |   2 +-
 pxf/pxf-service/src/scripts/pxf-env.sh          |  18 ++-
 pxf/pxf-service/src/scripts/pxf-service         | 152 +++++++++++++++++--
 11 files changed, 306 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/Makefile
----------------------------------------------------------------------
diff --git a/pxf/Makefile b/pxf/Makefile
index da83cc8..3ac38b1 100644
--- a/pxf/Makefile
+++ b/pxf/Makefile
@@ -42,6 +42,10 @@ ifneq "$(PXF_VERSION)" ""
     BUILD_PARAMS+= -Pversion="$(PXF_VERSION)"
 endif
 
+ifneq "$(DATABASE)" ""
+    BUILD_PARAMS+= -Ddatabase="$(DATABASE)"
+endif
+
 help:
        @echo 
        @echo "help it is then"
@@ -51,6 +55,7 @@ help:
        @echo   "  -  -  LICENSE=<license info> - add license info to created 
RPMs"
        @echo   "  -  -  VENDOR=<vendor name> - add vendor name to created RPMs"
        @echo   "  -  -  PLUGINS_EXCLUDE_RPM=plugin1, plugin2,... - do not 
build and RPM for given comma-separated list of plugins"
+       @echo   "  -  -  DATABASE=build pxf for specific database(HAWQ is 
default, other databases are defined under gradle/profiles)"
        @echo   "  - tomcat - builds tomcat rpm from downloaded tarball"
        @echo   "  -  -  LICENSE and VENDOR parameters can be used as well"
        @echo   "  - install - setup PXF along with tomcat in the configured 
deployPath"

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/README.md
----------------------------------------------------------------------
diff --git a/pxf/README.md b/pxf/README.md
index 540e761..e51d83c 100644
--- a/pxf/README.md
+++ b/pxf/README.md
@@ -35,4 +35,13 @@ Building
     ./gradlew clean build [buildRpm] [distTar]
 
     For all available tasks run: ./gradlew tasks
+    
 
+Building for a specific database
+================================
+
+PXF could be built for a diffent databases, currently HAWQ and Greenplum are 
supported.
+Configuration for target databases are stored in **gradle/profiles**.
+HAWQ is a default database. To build it for Greenplum:
+
+    ./gradlew clean build [buildRpm] [distTar] -Ddatabase="gpdb"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/build.gradle
----------------------------------------------------------------------
diff --git a/pxf/build.gradle b/pxf/build.gradle
index 52e4020..6ac55b7 100644
--- a/pxf/build.gradle
+++ b/pxf/build.gradle
@@ -19,6 +19,13 @@
 
 import org.apache.tools.ant.filters.ReplaceTokens
 
+// Get database property, use HAWQ as a default database
+def database = System.getProperty("database", "hawq");
+def databaseFileName = "gradle/profiles/" + database + ".properties";
+assert file(databaseFileName).exists()
+def databaseProperties = new Properties()
+file(databaseFileName).withInputStream { databaseProperties.load(it) }
+
 buildscript {
     repositories {
         // mavenCentral without https:
@@ -263,6 +270,10 @@ project('pxf-service') {
         from('src/scripts/pxf-env.sh') {
             fileMode 0755
             fileType NOREPLACE
+            filter(ReplaceTokens,
+                    tokens: ['pxfLogDir'     : databaseProperties.pxfLogDir,
+                             'pxfRunDir'     : databaseProperties.pxfRunDir,
+                             'pxfDefaultUser': 
databaseProperties.pxfDefaultUser])
             into "/etc/pxf-${project.version}/conf"
         }
         
@@ -612,8 +623,14 @@ task install(type: Copy, dependsOn: [subprojects.build, 
tomcatGet]) {
     from("${tomcatTargetDir}/${tomcatName}") { into 'apache-tomcat' }
     from("pxf-service/src/main/resources") { into 'conf' }
     from("pxf-service/src/configs/pxf-site.xml") { into 'conf' }
-    from("pxf-service/src/scripts/pxf-env.sh") { into 'conf' }
+    from("pxf-service/src/scripts/pxf-env.sh") {
+        filter(ReplaceTokens,
+                tokens: ['pxfLogDir'     : databaseProperties.pxfLogDir,
+                         'pxfRunDir'     : databaseProperties.pxfRunDir,
+                         'pxfDefaultUser': databaseProperties.pxfDefaultUser]) 
into 'conf'
+    }
     from("pxf-service/src/configs/tomcat") { into 'tomcat-templates' }
+    from("pxf-service/src/configs/templates") { into 'conf-templates' }
 }
 
 task bundle(type: Tar) {

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/gradle.properties
----------------------------------------------------------------------
diff --git a/pxf/gradle.properties b/pxf/gradle.properties
index 82190ea..06dcaba 100644
--- a/pxf/gradle.properties
+++ b/pxf/gradle.properties
@@ -24,4 +24,4 @@ hbaseVersionJar=1.1.2
 hbaseVersionRPM=1.1.2
 tomcatVersion=7.0.62
 pxfProtocolVersion=v15
-osFamily=el6
+osFamily=el6
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/gradle/profiles/gpdb.properties
----------------------------------------------------------------------
diff --git a/pxf/gradle/profiles/gpdb.properties 
b/pxf/gradle/profiles/gpdb.properties
new file mode 100644
index 0000000..22b095f
--- /dev/null
+++ b/pxf/gradle/profiles/gpdb.properties
@@ -0,0 +1,20 @@
+# 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.
+
+pxfDefaultUser=gpadmin
+pxfLogDir=${PXF_HOME}/logs
+pxfRunDir=${PXF_HOME}/run
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/gradle/profiles/hawq.properties
----------------------------------------------------------------------
diff --git a/pxf/gradle/profiles/hawq.properties 
b/pxf/gradle/profiles/hawq.properties
new file mode 100644
index 0000000..e92c839
--- /dev/null
+++ b/pxf/gradle/profiles/hawq.properties
@@ -0,0 +1,20 @@
+# 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.
+
+pxfDefaultUser=pxf
+pxfLogDir=/var/log/pxf
+pxfRunDir=/var/run/pxf
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/pxf-service/src/configs/templates/pxf-private.classpath.template
----------------------------------------------------------------------
diff --git 
a/pxf/pxf-service/src/configs/templates/pxf-private.classpath.template 
b/pxf/pxf-service/src/configs/templates/pxf-private.classpath.template
new file mode 100644
index 0000000..d5d1910
--- /dev/null
+++ b/pxf/pxf-service/src/configs/templates/pxf-private.classpath.template
@@ -0,0 +1,80 @@
+# 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.
+
+##################################################################
+# This file contains the internal classpaths required to run PXF.
+# Edit to set the base paths according to your specific package layout
+# Adding new resources should be done using pxf-public.classpath file.
+##################################################################
+
+# PXF Configuration
+PXF_HOME/conf
+
+# PXF Libraries
+PXF_HOME/lib/pxf-hbase-*[0-9].jar
+PXF_HOME/lib/pxf-hdfs-*[0-9].jar
+PXF_HOME/lib/pxf-hive-*[0-9].jar
+PXF_HOME/lib/pxf-json-*[0-9].jar
+PXF_HOME/lib/pxf-jdbc-*[0-9].jar
+
+# Hadoop/Hive/HBase configurations
+HADOOP_HOME/etc/hadoop
+HIVE_HOME/conf
+HBASE_HOME/conf
+
+# Hadoop Libraries
+HADOOP_HOME/share/hadoop/common/hadoop-common-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/hadoop-auth-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/asm-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/avro-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/commons-cli-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/commons-codec-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/commons-collections-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/commons-configuration-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/commons-io-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/commons-lang-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/commons-logging-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/guava-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/htrace-core*.jar
+HADOOP_HOME/share/hadoop/common/lib/jetty-*.jar
+HADOOP_HOME/share/hadoop/common/lib/jersey-core-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/jersey-server-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/log4j-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/protobuf-java-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/slf4j-api-*[0-9].jar
+HADOOP_HOME/share/hadoop/common/lib/snappy-java-*[0-9].jar
+HADOOP_HOME/share/hadoop/hdfs/hadoop-hdfs-*[0-9].jar
+HADOOP_HOME/share/hadoop/hdfs/lib/jackson-core-asl-*[0-9].jar
+HADOOP_HOME/share/hadoop/hdfs/lib/jackson-mapper-asl-*[0-9].jar
+HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-*[0-9].jar
+# CDH only Library
+HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-common-*[0-9].jar
+
+# Hive Libraries
+HIVE_HOME/lib/antlr-runtime*.jar
+HIVE_HOME/lib/datanucleus-api-jdo*.jar
+HIVE_HOME/lib/datanucleus-core*.jar
+HIVE_HOME/lib/hive-exec*.jar
+HIVE_HOME/lib/hive-metastore*.jar
+HIVE_HOME/lib/jdo-api*.jar
+HIVE_HOME/lib/libfb303*.jar
+
+# HBase Libraries
+HBASE_HOME/lib/hbase-client*.jar
+HBASE_HOME/lib/hbase-common*.jar
+HBASE_HOME/lib/hbase-protocol*.jar
+HBASE_HOME/lib/htrace-core*.jar
+HBASE_HOME/lib/netty*.jar
+HBASE_HOME/lib/zookeeper*.jar
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/pxf-service/src/configs/tomcat/bin/setenv.sh
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/configs/tomcat/bin/setenv.sh 
b/pxf/pxf-service/src/configs/tomcat/bin/setenv.sh
index a9a69cf..0fade3c 100644
--- a/pxf/pxf-service/src/configs/tomcat/bin/setenv.sh
+++ b/pxf/pxf-service/src/configs/tomcat/bin/setenv.sh
@@ -22,7 +22,7 @@
 AGENT_PATHS=""
 JAVA_AGENTS=""
 JAVA_LIBRARY_PATH=""
-JVM_OPTS="-Xmx512M -Xss256K"
+JVM_OPTS="-Xmx512M -Xss256K -Dpxf.log.dir=$CATALINA_BASE/logs"
 JAVA_OPTS="$JVM_OPTS $AGENT_PATHS $JAVA_AGENTS $JAVA_LIBRARY_PATH"
 CATALINA_PID="$CATALINA_BASE/logs/catalina.pid"
-
+CATALINA_OUT="$CATALINA_BASE/logs/catalina.out"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/pxf-service/src/main/resources/pxf-log4j.properties
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/resources/pxf-log4j.properties 
b/pxf/pxf-service/src/main/resources/pxf-log4j.properties
index a36335a..f6bb0ea 100644
--- a/pxf/pxf-service/src/main/resources/pxf-log4j.properties
+++ b/pxf/pxf-service/src/main/resources/pxf-log4j.properties
@@ -23,7 +23,7 @@ log4j.rootLogger=INFO, ROLLINGFILE
 
 log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
 # use the same value directory as set for $PXF_LOGDIR
-log4j.appender.ROLLINGFILE.File=/var/log/pxf/pxf-service.log
+log4j.appender.ROLLINGFILE.File=${pxf.log.dir}/pxf-service.log
 log4j.appender.ROLLINGFILE.MaxFileSize=10MB
 log4j.appender.ROLLINGFILE.MaxBackupIndex=10
 log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/pxf-service/src/scripts/pxf-env.sh
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/scripts/pxf-env.sh 
b/pxf/pxf-service/src/scripts/pxf-env.sh
index ba9b368..284f08d 100644
--- a/pxf/pxf-service/src/scripts/pxf-env.sh
+++ b/pxf/pxf-service/src/scripts/pxf-env.sh
@@ -6,9 +6,9 @@
 # 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
@@ -16,6 +16,11 @@
 # specific language governing permissions and limitations
 # under the License.
 
+PARENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
+
+# Default PXF_HOME
+export PXF_HOME=${PXF_HOME:=$PARENT_SCRIPT_DIR}
+
 # Path to HDFS native libraries
 export LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:${LD_LIBRARY_PATH}
 
@@ -23,14 +28,13 @@ export 
LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:${LD_LIBRARY_PATH}
 export JAVA_HOME=${JAVA_HOME:=/usr/java/default}
 
 # Path to Log directory
-export PXF_LOGDIR=/var/log/pxf
-export CATALINA_OUT=${PXF_LOGDIR}/catalina.out
+export PXF_LOGDIR=@pxfLogDir@
 
 # Path to Run directory
-export PXF_RUNDIR=/var/run/pxf
+export PXF_RUNDIR=@pxfRunDir@
 
 # Configured user
-export PXF_USER=pxf
+export PXF_USER=${PXF_USER:-@pxfDefaultUser@}
 
 # Port
-export PXF_PORT=51200
\ No newline at end of file
+export PXF_PORT=${PXF_PORT:-51200}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/634e0cda/pxf/pxf-service/src/scripts/pxf-service
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/scripts/pxf-service 
b/pxf/pxf-service/src/scripts/pxf-service
index 39d167e..e36931e 100644
--- a/pxf/pxf-service/src/scripts/pxf-service
+++ b/pxf/pxf-service/src/scripts/pxf-service
@@ -22,7 +22,8 @@
 
 
 if [ -z $PXF_HOME ]; then
-    env_script=/etc/pxf/conf/pxf-env.sh
+    parent_script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
+    env_script=$parent_script_dir/conf/pxf-env.sh
 else
     env_script=$PXF_HOME/conf/pxf-env.sh
 fi
@@ -56,13 +57,6 @@ fi
 
 curl=`which curl`
 
-
-# validate JAVA_HOME
-if [ ! -x $JAVA_HOME/bin/java ]; then
-       echo ERROR: \$JAVA_HOME is invalid
-       exit 1
-fi
-
 #
 # createInstance creates a tomcat instance 
 # configuration files 
@@ -113,7 +107,9 @@ function configureInstance()
        # set pid
        catalinaEnv=$instance_root/$instance_name/bin/setenv.sh
        cat $catalinaEnv | \
-       sed -e 
"s|^[[:blank:]]*CATALINA_PID=.*$|CATALINA_PID=$PXF_RUNDIR/catalina.pid|g" \
+       sed -e 
"s|^[[:blank:]]*CATALINA_PID=.*$|CATALINA_PID=$PXF_RUNDIR/catalina.pid|g" | \
+       sed -e "s|-Dpxf.log.dir=[^[:space:]^\"]*|-Dpxf.log.dir=$PXF_LOGDIR |g" 
| \
+       sed -e 
"s|^[[:blank:]]*CATALINA_OUT=.*$|CATALINA_OUT=$PXF_LOGDIR/catalina.out|g" \
        > ${catalinaEnv}.tmp
        rm $catalinaEnv
        mv ${catalinaEnv}.tmp $catalinaEnv
@@ -208,10 +204,24 @@ function doInit()
                echo WARNING: instance already exists in $instance_root, 
nothing to do...
                return 0
        fi
-
-    createInstance || return 1
+       # Generate private classpath file only if user specified hadoop_home 
option
+       # Otherwise use default file
+    if [ ! -z $hadoop_home ]; then
+        generatePrivateClasspath || return 1
+    else
+        if [ ! -z $hbase_home ]; then
+            echo WARNING: hbase_home option will be ignored, please specify 
hadoop_home
+        fi
+        if [ ! -z $hive_home ]; then
+            echo WARNING: hive_home option will be ignored, please specify 
hadoop_home
+        fi
+    fi
+       createInstance || return 1
        configureInstance || return 1
        deployWebapp || return 1
+       createLogsDir || return 1
+       createRunDir  || return 1
+
 }
 
 #
@@ -247,13 +257,99 @@ function commandWebapp()
 {
     command=$1
     pushd $instance_root
-    su $pxf_user -c "$instance_root/$instance_name/bin/catalina.sh $command"
+    sudo -u $pxf_user $instance_root/$instance_name/bin/catalina.sh $command
     if [ $? -ne 0 ]; then
         return 1
     fi
     popd
 }
 
+function createLogsDir()
+{
+    mkdir -p $PXF_LOGDIR
+    chown -R $instance_owner $PXF_LOGDIR
+    chmod 700 $PXF_LOGDIR
+    return 0
+}
+
+function createRunDir()
+{
+    mkdir -p $PXF_RUNDIR
+    chown -R $instance_owner $PXF_RUNDIR
+    chmod 700 $PXF_RUNDIR
+    return 0
+}
+
+function generatePrivateClasspath()
+{
+    echo "Generating private classpath file..."
+    #Create intial version of the file
+    sed -e "s|PXF_HOME|$PXF_HOME|g" 
$PXF_HOME/conf-templates/pxf-private.classpath.template > 
$PXF_HOME/conf/pxf-private.classpath
+    #Make sure $hadoop_home is defined
+    if [ -z $hadoop_home ]; then
+        echo ERROR: cant generate private classpath without hadoop_home value
+        return 1
+    fi
+    #Substitute HADOOP_HOME value
+    sed -i -e "s|HADOOP_HOME|$hadoop_home|g" 
$PXF_HOME/conf/pxf-private.classpath
+    if [ ! -z $hbase_home ]; then
+        #Substitute HBASE_HOME if hbase_home was set
+        sed -i -e "s|HBASE_HOME|$hbase_home|g" 
$PXF_HOME/conf/pxf-private.classpath
+    else
+        #Delete lines with HBASE_HOME if hbase_home wasn't set
+        sed -i  "/HBASE_HOME/d" $PXF_HOME/conf/pxf-private.classpath
+    fi
+    if [ ! -z $hive_home ]; then
+        #Substitute HIVE_HOME if hive_home was set
+        sed -i -e "s|HIVE_HOME|$hive_home|g" 
$PXF_HOME/conf/pxf-private.classpath
+    else
+        #Delete lines with HIVE_HOME if hive_home wasn't set
+        sed -i  "/HIVE_HOME/d" $PXF_HOME/conf/pxf-private.classpath
+    fi
+}
+
+function printUsage()
+{
+    echo $"Usage: $0 {start|stop|restart|init --hadoop-home HADOOP_LOCATION 
[--hive-home HIVE_LOCATION --hbase-home HBASE_LOCATION]|status}"
+
+}
+
+function validateParameters()
+{
+
+    # validate curl
+    which curl &> /dev/null
+    if [ "$?" -ne "0" ]
+    then
+        echo "ERROR: curl is not installed, please install"
+        exit 1
+    fi
+
+    # validate unzip
+    which unzip &> /dev/null
+    if [ "$?" -ne "0" ]
+    then
+        echo "ERROR: unzip is not installed, please install"
+        exit 1
+    fi
+
+    # validate pxf user
+    id $pxf_user  &> /dev/null;
+    if [ "$?" -ne "0" ]
+    then
+        echo "ERROR: User $pxf_user doesn't exist. Please set valid user via 
\$PXF_USER variable"
+        exit 1
+    fi
+
+    # validate JAVA_HOME
+    if [ ! -x $JAVA_HOME/bin/java ]; then
+        echo ERROR: \$JAVA_HOME is invalid
+        exit 1
+    fi
+
+    return 0
+}
+
 # 
 # doStart handles start command
 # command is executed as the user $pxf_user
@@ -297,24 +393,54 @@ command=$1
 
 case "$command" in
        "init" )
+               shift
+               while [[ $# -gt 1 ]]
+               do
+                       name="$1"
+                       value="$2"
+                       case $name in
+                               --hadoop-home)
+                               hadoop_home="$2"
+                               shift
+                               ;;
+                               --hive-home)
+                                hive_home="$2"
+                                shift
+                                ;;
+                               --hbase-home)
+                                hbase_home="$2"
+                                shift
+                                ;;
+                               *)
+                                echo "$name is an unknown option"
+                                printUsage
+                                exit 1
+                       esac
+                       shift
+               done
+               validateParameters
                doInit
                ;;
        "start" )
+               validateParameters
                doStart
                ;;
        "stop" )
+               validateParameters
                doStop
                ;;
        "restart" )
+               validateParameters
                doStop
                sleep 1s
                doStart
                ;;
        "status" )
+               validateParameters
                doStatus
                ;;
        * )
-               echo $"Usage: $0 {start|stop|restart|init|status}"
+               printUsage
                exit 2
                ;;
 esac

Reply via email to