0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 package org.apache.hive.service.cli;
0020
0021 import org.apache.hive.service.rpc.thrift.TOperationState;
0022
0023
0024
0025
0026
0027 public enum OperationState {
0028 INITIALIZED(TOperationState.INITIALIZED_STATE, false),
0029 RUNNING(TOperationState.RUNNING_STATE, false),
0030 FINISHED(TOperationState.FINISHED_STATE, true),
0031 CANCELED(TOperationState.CANCELED_STATE, true),
0032 CLOSED(TOperationState.CLOSED_STATE, true),
0033 ERROR(TOperationState.ERROR_STATE, true),
0034 UNKNOWN(TOperationState.UKNOWN_STATE, false),
0035 PENDING(TOperationState.PENDING_STATE, false),
0036 TIMEDOUT(TOperationState.TIMEDOUT_STATE, true);
0037
0038 private final TOperationState tOperationState;
0039 private final boolean terminal;
0040
0041 OperationState(TOperationState tOperationState, boolean terminal) {
0042 this.tOperationState = tOperationState;
0043 this.terminal = terminal;
0044 }
0045
0046
0047 public static OperationState getOperationState(TOperationState tOperationState) {
0048 return OperationState.values()[tOperationState.getValue()];
0049 }
0050
0051 public static void validateTransition(OperationState oldState,
0052 OperationState newState)
0053 throws HiveSQLException {
0054 switch (oldState) {
0055 case INITIALIZED:
0056 switch (newState) {
0057 case PENDING:
0058 case RUNNING:
0059 case CANCELED:
0060 case CLOSED:
0061 case TIMEDOUT:
0062 return;
0063 }
0064 break;
0065 case PENDING:
0066 switch (newState) {
0067 case RUNNING:
0068 case FINISHED:
0069 case CANCELED:
0070 case ERROR:
0071 case CLOSED:
0072 case TIMEDOUT:
0073 return;
0074 }
0075 break;
0076 case RUNNING:
0077 switch (newState) {
0078 case FINISHED:
0079 case CANCELED:
0080 case ERROR:
0081 case CLOSED:
0082 case TIMEDOUT:
0083 return;
0084 }
0085 break;
0086 case FINISHED:
0087 case CANCELED:
0088 case TIMEDOUT:
0089 case ERROR:
0090 if (OperationState.CLOSED.equals(newState)) {
0091 return;
0092 }
0093 break;
0094 default:
0095
0096 }
0097 throw new HiveSQLException("Illegal Operation state transition " +
0098 "from " + oldState + " to " + newState);
0099 }
0100
0101 public void validateTransition(OperationState newState)
0102 throws HiveSQLException {
0103 validateTransition(this, newState);
0104 }
0105
0106 public TOperationState toTOperationState() {
0107 return tOperationState;
0108 }
0109
0110 public boolean isTerminal() {
0111 return terminal;
0112 }
0113 }