blob: 8b08369f4464e1ee7d6210503a078c361f3cbf05 [file] [log] [blame]
#! /usr/bin/env 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.
# Start: Resolve Script Directory
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$bin/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
script=$( basename "$SOURCE" )
# Stop: Resolve Script Directory
. "$bin"/impl/config.sh
export CLASSPATH
# stop if any command fails
set -e
APP=$2
APP_DIR=$FLUO_HOME/apps/$APP
APP_CONF_DIR=$APP_DIR/conf
APP_LIB_DIR=$APP_DIR/lib
function copy_config {
if [ -f $FLUO_CONF_DIR/$1 ]; then
cp $FLUO_CONF_DIR/$1 $APP_CONF_DIR/
elif [ -f $FLUO_CONF_DIR/examples/$1 ]; then
cp FLUO_CONF_DIR/examples/$1 $APP_CONF_DIR
else
echo "Config file $1 not found in $FLUO_CONF_DIR or $FLUO_CONF_DIR/examples"
exit 1
fi
}
function print_usage {
echo -e "Usage: fluo <command> (<argument> ...)\n"
echo -e "Possible commands:\n"
echo " list Lists all Fluo applications in Fluo instance"
echo " new <app> Creates configuration for new application in apps/"
echo " init <app> Initializes Fluo application using configuration in apps/<app>/conf/fluo.properties"
echo " start <app> Starts Fluo application on cluster"
echo " stop <app> Stops Fluo application on cluster"
echo " kill <app> Kills Fluo application on cluster"
echo " status <app> Prints status of Fluo application"
echo " info <app> Prints information about containers of Fluo application"
echo " scan <app> Prints snapshot of data in Fluo application"
echo " classpath Prints the classpath setup in fluo-env.sh"
echo " wait <app> Waits until all notifications are processed"
echo " version Prints the version of Fluo"
echo " exec <app> <class> {<argument>}";
echo " "
exit 1
}
function validate_app {
if [ -z "$APP" ]; then
echo -e "The application name (set by <app>) cannot be an empty string!\n"
print_usage
fi
if [[ $APP = *"-h"* ]]; then
print_usage
fi
}
function validate_app_full {
validate_app
java org.apache.fluo.cluster.util.ValidateAppName $APP
if [[ ! -d $APP_DIR || ! -d $APP_CONF_DIR || ! -d $APP_LIB_DIR ]]; then
echo "ERROR - The Fluo '$APP' application needs to be configured in apps/ with a conf/ and lib/ directory. Use 'fluo new $APP' to create this configuration"
exit 1
fi
}
function check_hadoop {
if [[ -z $HADOOP_PREFIX ]]; then
echo "HADOOP_PREFIX needs to be set!"
exit 1
fi
if [ ! -d "$HADOOP_PREFIX" ]; then
echo "HADOOP_PREFIX=$HADOOP_PREFIX is not a valid directory. Please correct it in your .bashrc or fluo-env.sh"
exit 1
fi
}
case "$1" in
new)
validate_app
java org.apache.fluo.cluster.util.ValidateAppName $APP
if [ -d $APP_DIR ]; then
echo "The Fluo '$APP' application already has a directory in apps/"
exit 1
fi
mkdir -p $APP_DIR
mkdir -p $APP_CONF_DIR
mkdir -p $APP_LIB_DIR
copy_config fluo.properties
$SED "s/fluo.client.application.name=/fluo.client.application.name=$APP/g" $APP_CONF_DIR/fluo.properties
copy_config logback.xml
;;
init)
validate_app_full
check_hadoop
if [[ $@ != *"-h"* && $@ != *"-u"* ]]; then
echo "Copying Fluo jars to HDFS at /fluo/lib to be accessible by Accumulo for iterators"
$HADOOP_PREFIX/bin/hdfs dfs -mkdir -p /fluo/lib
echo "Copying `ls $FLUO_HOME/lib/fluo-api-*.jar` to HDFS"
$HADOOP_PREFIX/bin/hdfs dfs -copyFromLocal -f $FLUO_HOME/lib/fluo-api-*.jar /fluo/lib/
echo "Copying `ls $FLUO_HOME/lib/fluo-accumulo-*.jar` to HDFS"
$HADOOP_PREFIX/bin/hdfs dfs -copyFromLocal -f $FLUO_HOME/lib/fluo-accumulo-*.jar /fluo/lib/
fi
export CLASSPATH="$APP_LIB_DIR/*:$CLASSPATH"
java org.apache.fluo.cluster.command.FluoCommand $FLUO_HOME $HADOOP_PREFIX "$@"
;;
start)
validate_app_full
check_hadoop
export CLASSPATH="$APP_LIB_DIR/*:$CLASSPATH"
java org.apache.fluo.cluster.command.FluoCommand $FLUO_HOME $HADOOP_PREFIX "$@"
;;
stop|kill|status|info|scan|wait)
validate_app
check_hadoop
java org.apache.fluo.cluster.command.FluoCommand $FLUO_HOME $HADOOP_PREFIX "$@"
;;
list)
check_hadoop
java org.apache.fluo.cluster.command.FluoCommand $FLUO_HOME $HADOOP_PREFIX $1 app ${*:2}
;;
classpath)
echo "$CLASSPATH"
;;
exec)
export CLASSPATH="$APP_LIB_DIR/*:$CLASSPATH"
java org.apache.fluo.cluster.command.FluoCommand $FLUO_HOME $HADOOP_PREFIX "$@"
;;
version)
echo "$FLUO_VERSION"
;;
*)
print_usage
esac