# Usage: lsapp application_1537193066945_0202
# Ex. Output:
#     Application ID: application_1537193066945_0202
#     AM Node: ip-172-28-115-72 - i-0dc1a1053af30c34c
#     AM Container: container_1537193066945_0202_01_000001
#     Application Runtime: 2018-09-27 12:48:00,390 - 2018-09-27 12:48:53,201

function lsapp() {
    appID=$1
    appLogs=$(sift -riz --no-filename --ipath=resourcemanager -e "$appID")
    baseLog=$(echo $appLogs | sift -riz --no-filename --ipath=resourcemanager -e "$appID.*MasterContainer")
    AMContainerID=$(echo $baseLog | sift --only-matching -e "container_(\d|_)+")
    AMNode=$(echo $baseLog | sift --only-matching -e "ip-(\d|-)+")
    ICLog=$(sift -rizl --limit=1 --file-matches=InstanceJointStatusMap --ipath=daemons/instance-controller $AMNode | sort | tail -1)
    AMInstanceID=$(sift -riz --limit=1 $AMNode $ICLog | awk '{print $1}')
    startTime=$(echo $appLogs | sift -riz --no-filename --ipath=resourcemanager -e "$appID.*to submitted" | awk '{print $1, $2}')
    endTime=$(echo $appLogs | sift -riz --no-filename --ipath=resourcemanager -e "application removed.*$appID.* queue" | awk '{print $1, $2}')
    echo Application ID: $appID
    echo AM Node: $AMNode - $AMInstanceID
    echo AM Container: $AMContainerID
    echo Application Runtime: $startTime - $endTime
}
