前提:
Yarn的Kill和发送信号,Oozie,不是优雅关闭,CDH的关闭是优雅关闭,现在打算弃用CDH,所以基于代码实现监听外部文件系统实现优雅关闭。
一、
1.实现代码
val hdfsStopPath :String = args(1)
var stopFlag = false
while (!stopFlag) {
//每分钟检测一次
//println("当前检测时间" + new Date())
ssc.awaitTerminationOrTimeout(60000)
val fs = FileSystem.get(sc.hadoopConfiguration)
//正在运行且存在停止程序文件标志,并删除标志文件表明接收删除命令
if (!stopFlag && fs.exists(new Path(hdfsStopPath))) {
stopFlag = true
fs.delete(new Path(hdfsStopPath), true)
println(new Date()+": app is stopGracefully......")
ssc.stop(true, true)
}
}
2.创建文件
hdfs dfs -mkdir /user/sparkGraceStop/xxxMain