#!/bin/bash # # 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. # friendly message for those who forget to tell us what to do if [ $# = 0 ]; then echo "Usage: giraph [-D] " echo "At a minimum one must provide a path to the jar containing the vertex to be executed." exit 1 fi # resolve links - $0 may be a softlink THIS="$0" while [ -h "$THIS" ]; do ls=`ls -ld "$THIS"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '.*/.*' > /dev/null; then THIS="$link" else THIS=`dirname "$THIS"`/"$link" fi done # some directories THIS_DIR=`dirname "$THIS"` GIRAPH_HOME=`cd "$THIS_DIR/.." ; pwd` # extra properties to send straight to Hadoop HADOOP_PROPERTIES= while [ $1 ] && [ ${1:0:2} == "-D" ] ; do HADOOP_PROPERTIES="$1 $HADOOP_PROPERTIES" shift done USER_JAR=$1 shift if [ ! -e "$USER_JAR" ]; then echo "Can't find user jar (${USER_JAR}) to execute." exit 1 fi # add user jar to classpath CLASSPATH=${USER_JAR} # add Giraph conf dir to classpath CLASSPATH=$CLASSPATH:$GIRAPH_HOME/conf CLASS=org.apache.giraph.GiraphRunner # so that filenames w/ spaces are handled correctly in loops below IFS= # add release dependencies to CLASSPATH if [ -d "$GIRAPH_HOME/lib" ]; then for f in $GIRAPH_HOME/lib/*.jar; do CLASSPATH=${CLASSPATH}:$f done for f in $GIRAPH_HOME/giraph*.jar ; do if [ -e "$f" ]; then JAR=$f CLASSPATH=${CLASSPATH}:$f break fi done else echo "No lib directory, assuming dev environment" if [ ! -d "$GIRAPH_HOME/target" ]; then echo "No target directory. Build Giraph jar before proceeding." exit 1 fi CLASSPATH2=`mvn dependency:build-classpath | grep -v "[INFO]"` CLASSPATH=$CLASSPATH:$CLASSPATH2 for f in $GIRAPH_HOME/giraph/target/giraph*.jar; do if [ -e "$f" ]; then JAR=$f break fi done fi # restore ordinary behaviour unset IFS if [ "$JAR" = "" ] ; then echo "Can't find Giraph jar." exit 1 fi if [ "$HADOOP_CONF_DIR" = "" ] ; then HADOOP_CONF_DIR=$HADOOP_HOME/conf echo "No HADOOP_CONF_DIR set, using $HADOOP_HOME/conf " else echo "HADOOP_CONF_DIR=$HADOOP_CONF_DIR" fi # Giraph's jars to add to distributed cache via -libjar, which are csv rather than :sv GIRAPH_JARS=`echo ${JAR}:${CLASSPATH}|sed s/:/,/g` export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$CLASSPATH exec "$HADOOP_HOME/bin/hadoop" --config $HADOOP_CONF_DIR jar $JAR $CLASS $HADOOP_PROPERTIES -libjars $GIRAPH_JARS "$@"