#!/bin/bash
if [ $# == 1 ] ; then
  tag=$1
  daytime=`date -d "1 day ago" "+%Y%m%d"`
elif [ $# == 2 ] ; then
  tag=$1
  daytime=$2
else
  echo "输入参数错误 ！"
  exit
fi

echo "dayTime is ""${daytime}"

echo "tag is ""${tag}"

sh dir.sh "${daytime}"

numPartitions=100

JAR_PATH=../lib/azkaban-alarm-extract-1.0.0.jar

MAIN_CLASS=uml.tech.bigdata.spark.SparkApp

executor_cores=1

num_executors=4

executor_memory=2G

for jar in ../lib/*.jar
do
  if [ ${jar} != ${JAR_PATH} ] ; then
    LIBJARS=${jar},${LIBJARS}
  fi
done

appName="azkaban-alarm-farm-"${tag}"."${daytime}

echo "app name : "${appName}

spark-submit \
  --master yarn \
  --deploy-mode cluster \
  --class ${MAIN_CLASS} \
  --conf spark.app.name=${appName} \
  --jars ${LIBJARS} \
  --conf spark.serializer=org.apache.spark.serializer.KryoSerializer \
  --conf spark.driver.memory=2G \
  --executor-cores ${executor_cores} \
  --num-executors ${num_executors} \
  --executor-memory ${executor_memory} \
  --conf "spark.executor.extraClassPath=hutool-all-5.8.5.jar" \
  --conf "spark.driver.extraClassPath=hutool-all-5.8.5.jar" \
  ${JAR_PATH} \
  ${tag} ${daytime} ${numPartitions}
