ExecutionStatus.java 3.6 KB
Newer Older
L
ligang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Q
qiaozhanwei 已提交
17
package org.apache.dolphinscheduler.common.enums;
L
ligang 已提交
18 19


20 21
import com.baomidou.mybatisplus.annotation.EnumValue;

22 23
import java.util.HashMap;

L
ligang 已提交
24
/**
L
lipan.zhao 已提交
25
 * running status for workflow and task nodes
L
ligang 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 *
 */
public enum ExecutionStatus {

    /**
     * status:
     * 0 submit success
     * 1 running
     * 2 ready pause
     * 3 pause
     * 4 ready stop
     * 5 stop
     * 6 failure
     * 7 success
     * 8 need fault tolerance
     * 9 kill
     * 10 waiting thread
     * 11 waiting depend node complete
     */
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    SUBMITTED_SUCCESS(0, "submit success"),
    RUNNING_EXEUTION(1, "running"),
    READY_PAUSE(2, "ready pause"),
    PAUSE(3, "pause"),
    READY_STOP(4, "ready stop"),
    STOP(5, "stop"),
    FAILURE(6, "failure"),
    SUCCESS(7, "success"),
    NEED_FAULT_TOLERANCE(8, "need fault tolerance"),
    KILL(9, "kill"),
    WAITTING_THREAD(10, "waiting thread"),
    WAITTING_DEPEND(11, "waiting depend node complete");

    ExecutionStatus(int code, String descp){
        this.code = code;
        this.descp = descp;
    }

    @EnumValue
    private final int code;
    private final String descp;
L
ligang 已提交
66

67 68 69 70 71 72 73
    private static HashMap<Integer, ExecutionStatus> EXECUTION_STATUS_MAP=new HashMap<>();

    static {
       for (ExecutionStatus executionStatus:ExecutionStatus.values()){
           EXECUTION_STATUS_MAP.put(executionStatus.code,executionStatus);
       }
    }
L
ligang 已提交
74 75 76

 /**
  * status is success
D
dailidong 已提交
77
  * @return status
L
ligang 已提交
78 79 80 81 82 83 84
  */
   public boolean typeIsSuccess(){
     return this == SUCCESS;
   }

 /**
  * status is failure
D
dailidong 已提交
85
  * @return status
L
ligang 已提交
86 87
  */
   public boolean typeIsFailure(){
J
JinyLeeChina 已提交
88
     return this == FAILURE || this == NEED_FAULT_TOLERANCE || this == KILL;
L
ligang 已提交
89 90 91 92
   }

 /**
  * status is finished
D
dailidong 已提交
93
  * @return status
L
ligang 已提交
94 95 96 97
  */
   public boolean typeIsFinished(){

       return typeIsSuccess() || typeIsFailure() || typeIsCancel() || typeIsPause()
98
               || typeIsWaittingThread();
L
ligang 已提交
99 100 101 102
   }

    /**
     * status is waiting thread
D
dailidong 已提交
103
     * @return status
L
ligang 已提交
104
     */
105
   public boolean typeIsWaittingThread(){
L
ligang 已提交
106 107 108 109 110
       return this == WAITTING_THREAD;
   }

    /**
     * status is pause
D
dailidong 已提交
111
     * @return status
L
ligang 已提交
112 113 114 115 116 117 118
     */
   public boolean typeIsPause(){
       return this == PAUSE;
   }

    /**
     * status is running
D
dailidong 已提交
119
     * @return status
L
ligang 已提交
120 121 122 123 124 125 126
     */
   public boolean typeIsRunning(){
       return this == RUNNING_EXEUTION || this == WAITTING_DEPEND;
   }

    /**
     * status is cancel
D
dailidong 已提交
127
     * @return status
L
ligang 已提交
128
     */
129 130 131
    public boolean typeIsCancel(){
        return this == KILL || this == STOP ;
    }
L
ligang 已提交
132

D
DK.Pino 已提交
133 134 135
    public int getCode() {
        return code;
    }
L
ligang 已提交
136

D
DK.Pino 已提交
137 138 139
    public String getDescp() {
        return descp;
    }
T
Tboy 已提交
140 141

    public static ExecutionStatus of(int status){
142 143 144
       if(EXECUTION_STATUS_MAP.containsKey(status)){
           return EXECUTION_STATUS_MAP.get(status);
       }
T
Tboy 已提交
145 146
        throw new IllegalArgumentException("invalid status : " + status);
    }
L
ligang 已提交
147
}