Back to home page

OSCL-LXR

 
 

    


0001 /**
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements.  See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership.  The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License.  You may obtain a copy of the License at
0009  *
0010  *     http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
0017  */
0018 
0019 package org.apache.hive.service.cli;
0020 
0021 import org.apache.hive.service.rpc.thrift.TOperationState;
0022 
0023 /**
0024  * OperationState.
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   // must be sync with TOperationState in order
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       // fall-through
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 }