#! /bin/bash

# # # # # # # # # # # # # # # # # # # # # #
# @file    :extract_device_age_v2.sh
# @author  :wangjf
# @revision:2018-8-17 15:15:42
# # # # # # # # # # # # # # # # # # # # # #

source ../dmp_env.sh

LOG_TIME=$(date +%Y%m%d -d "-1 day $ScheduleTime")
date_path=$(date +'%Y/%m/%d' -d "-1 day $ScheduleTime")


INSTALL_3S_INPUT="${DM_INSTALL_LIST}/$date_path/3s"
ADN_INSTALL_INPUT="${DM_INSTALL_LIST}/$date_path/adn_install"
ADN_REQUEST_INPUT="${DM_INSTALL_LIST}/$date_path/adn_request_sdk"
DSP_REQUEST_INPUT="${DM_INSTALL_LIST}/$date_path/dsp_req"
GA_INSTALL_INPUT=$(get_recently_dir "${DM_INSTALL_LIST}" "${LOG_TIME}" "ga")
OTHER_INPUT=$(get_recently_dir "${DM_INSTALL_LIST}" "${LOG_TIME}" "other")

OUTPUT_PATH="${AGE_EXTRACT_DEVICE_PATH}_v2/${date_path}/"

check_await ${INSTALL_3S_INPUT}/_SUCCESS
check_await ${ADN_INSTALL_INPUT}/_SUCCESS
check_await ${ADN_REQUEST_INPUT}/_SUCCESS
check_await ${DSP_REQUEST_INPUT}/_SUCCESS

REDUCE_NUM=$(calculate_reduce_num "${ADN_INSTALL_INPUT};${ADN_REQUEST_INPUT};${DSP_REQUEST_INPUT};${GA_INSTALL_INPUT};${OTHER_INPUT};${INSTALL_3S_INPUT}")

hadoop fs -rm -r ${OUTPUT_PATH}
hadoop jar ../${JAR} mobvista.dmp.datasource.age.mapreduce.ExtractDeviceMRV2 \
    -Dmapreduce.job.reduces=${REDUCE_NUM} \
     -Dmapreduce.input.fileinputformat.inputdir="${ADN_INSTALL_INPUT},${ADN_REQUEST_INPUT},${DSP_REQUEST_INPUT},${GA_INSTALL_INPUT},${OTHER_INPUT}" \
    ${INSTALL_3S_INPUT} ${OUTPUT_PATH} || exit 1
echo "[extract device End!]"
