#!/bin/bash

startTime=$1

endTime=$2

numPartitions=$3

if [ $# == 2 ]; then
    endTime=$2
elif [ $# == 3 ]; then
    endTime=$2
    numPartitions=$3
fi

echo "startTime is "${startTime}" ,endTime is "${endTime}" ,numPartitions is "${numPartitions}

APP_NAME=azkaban.platform.acreage_${startTime}_${endTime}

executor_cores=1

num_executors=8

executor_memory=1G

JAR_PATH=../lib/uml-azkaban-platform-calculation-acreage-1.0.0.jar

MAIN_CLASS=com.uml.tech.app.SparkApp

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

config=../resources/application.properties

echo "start submit spark application ......"

spark-submit \
  --master yarn \
  --deploy-mode cluster \
  --class ${MAIN_CLASS} \
  --conf spark.app.name=${APP_NAME} \
  --jars ${LIBJARS} \
  --files ${config} \
  --conf spark.serializer=org.apache.spark.serializer.KryoSerializer \
  --conf spark.shuffle.consolidateFiles=true \
  --conf spark.shuffle.memoryFraction=0.4 \
  --conf spark.storage.memoryFraction=0.3 \
  --conf spark.driver.memory=3G \
  --executor-cores ${executor_cores} \
  --num-executors ${num_executors} \
  --executor-memory ${executor_memory} \
  ${JAR_PATH} \
  ${startTime} ${numPartitions} ${endTime}
