#!/bin/bash

outputDir=/spark/can

durations=1800000

JAR_PATH=../lib/uml-stream-hdfs-ne-4.0.0.jar

MAIN_CLASS=com.uml.tech.spark.StreamingApp

APP_NAME=stream.hdfs.ne_

APP_VERSION=2020.01.17

executor_cores=2

num_executors=8

executor_memory=4G

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

config=../resources/application.properties



appId=`yarn application -list | grep ${APP_NAME} | awk '{print $1}'`

if [ "${appId}" != "" ] ; then
  echo `yarn application -kill ${appId}`
fi

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

spark-submit \
  --master yarn \
  --deploy-mode cluster \
  --class ${MAIN_CLASS} \
  --conf spark.app.name=${APP_NAME}${APP_VERSION} \
  --jars ${LIBJARS} \
  --files ${config} \
  --executor-cores ${executor_cores} \
  --num-executors ${num_executors} \
  --executor-memory ${executor_memory} \
  --conf spark.yarn.maxAppAttempts=5 \
  --conf spark.executor.extraJavaOptions=" -XX:+UseG1GC" \
  --conf spark.streaming.stopGracefullyOnShutdown=true \
  --conf spark.serializer=org.apache.spark.serializer.KryoSerializer \
  --conf spark.streaming.backpressure.enabled=true \
  --conf spark.dynamicAllocation.enabled=false \
  ${JAR_PATH} \
  ${outputDir} ${durations}