import { logger } from '../lib/Utils' ; import { NodeStatus } from '../third_party/mlmd/argo_template' ; export const statusBgColors = { error : '#fce8e6' , notStarted : '#f7f7f7' , running : '#e8f0fe' , succeeded : '#e6f4ea' , cached : '#e6f4ea' , terminatedOrSkipped : '#f1f3f4' , warning : '#fef7f0' , } ; export enum NodePhase { ERROR = 'Error' , FAILED = 'Failed' , PENDING = 'Pending' , RUNNING = 'Running' , SKIPPED = 'Skipped' , SUCCEEDED = 'Succeeded' , COMPLETED = 'Completed' , EVALUATIONSUCCESS = 'EvaluationSuccess' , CACHED = 'Cached' , TERMINATING = 'Terminating' , PIPELINERUNTIMEOUT = 'PipelineRunTimeout' , COULDNTGETCONDITION = 'CouldntGetCondition' , CONDITIONCHECKFAILED = 'ConditionCheckFailed' , PIPELINERUNCANCELLED = 'PipelineRunCancelled' , PIPELINERUNCOULDNTCANCEL = 'PipelineRunCouldntCancel' , CANCELLED = 'Cancelled' , STOPPEDRUNFINALLY = 'StoppedRunFinally' , CANCELLEDRUNFINALLY = 'CancelledRunFinally' , PIPELINERUNSTOPPING = 'PipelineRunStopping' , TASKRUNCANCELLED = 'TaskRunCancelled' , TASKRUNCOULDNTCANCEL = 'TaskRunCouldntCancel' , TERMINATED = 'Terminated' , UNKNOWN = 'Unknown' , OMITTED = 'Omitted' } export function hasFinished ( status ? ) { switch ( status ) { case NodePhase . COMPLETED : case NodePhase . SUCCEEDED : case NodePhase . EVALUATIONSUCCESS : case NodePhase . CACHED : case NodePhase . FAILED : case NodePhase . ERROR : case NodePhase . SKIPPED : case NodePhase . TERMINATED : case NodePhase . OMITTED : return true ; case NodePhase . PENDING : case NodePhase . RUNNING : case NodePhase . TERMINATING : case NodePhase . UNKNOWN : return false ; default : return false ; } } export function statusToBgColor ( status ? , nodeMessage ? ) { status = checkIfTerminated ( status , nodeMessage ) ; switch ( status ) { case NodePhase . ERROR : case NodePhase . FAILED : return statusBgColors . error ; case NodePhase . PENDING : return statusBgColors . notStarted ; case NodePhase . TERMINATING : case NodePhase . RUNNING : return statusBgColors . running ; case NodePhase . SUCCEEDED : return statusBgColors . succeeded ; case NodePhase . EVALUATIONSUCCESS : return statusBgColors . succeeded ; case NodePhase . CACHED : return statusBgColors . cached ; case NodePhase . SKIPPED : case NodePhase . TERMINATED : return statusBgColors . terminatedOrSkipped ; case NodePhase . UNKNOWN : default : logger . verbose ( 'Unknown node phase:' , status ) ; return statusBgColors . notStarted ; } } export function checkIfTerminated ( status ? , nodeMessage ? ) { if ( status === NodePhase . FAILED && nodeMessage === 'terminated' ) { status = NodePhase . TERMINATED ; } return status ; } export function parseNodePhase ( node ) { if ( node . phase !== 'Succeeded' ) { return node . phase as NodePhase ; } return wasNodeCached ( node ) ? NodePhase . CACHED : NodePhase . SUCCEEDED ; } function wasNodeCached ( node ) { const artifacts = node . outputs ?. artifacts ; return ! artifacts || ! node . id || node . type !== 'Pod' ? false : artifacts . some ( artifact => artifact . s3 && ! artifact . s3 . key . includes ( node . id ) ) ; } export function statusToPhase ( nodeStatus ) { if ( ! nodeStatus ) return 'Unknown' as NodePhase ; else if ( nodeStatus === 'Completed' || nodeStatus === 'EvaluationSuccess' ) return 'Succeeded' as NodePhase ; else if ( nodeStatus === 'ConditionCheckFailed' ) return 'Skipped' as NodePhase ; else if ( nodeStatus === 'CouldntGetCondition' ) return 'Error' as NodePhase ; else if ( nodeStatus === 'PipelineRunStopping' ) return 'Running' as NodePhase ; else if ( nodeStatus === 'PipelineRunCancelled' || nodeStatus === 'PipelineRunCouldntCancel' || nodeStatus === 'TaskRunCancelled' || nodeStatus === 'TaskRunCouldntCancel' || nodeStatus === 'Cancelled' || nodeStatus === 'StoppedRunFinally' || nodeStatus === 'CancelledRunFinally' ) return 'Terminated' as NodePhase ; return nodeStatus as NodePhase ; }