public static boolean isValidStateTransition(State startState, State desiredState) {
    switch(desiredState) {
      case INSTALLED:
        if (startState == State.INIT
            || startState == State.UNINSTALLED
            || startState == State.INSTALLED
            || startState == State.INSTALLING
            || startState == State.STARTED
            || startState == State.INSTALL_FAILED
            || startState == State.UPGRADING
            || startState == State.STOPPING
            || startState == State.UNKNOWN
            || startState == State.DISABLED) {
          return true;
        }
        break;
      case STARTED:
        if (startState == State.INSTALLED
            || startState == State.STARTING
            || startState == State.STARTED) {
          return true;
        }
        break;
      case UNINSTALLED:
        if (startState == State.INSTALLED
            || startState == State.UNINSTALLED
            || startState == State.UNINSTALLING) {
          return true;
        }
        break;
      case INIT:
        if (startState == State.UNINSTALLED
            || startState == State.INIT
            || startState == State.WIPING_OUT) {
          return true;
        }
        break;
      case DISABLED:
        if (startState == State.INSTALLED
            || startState == State.INSTALL_FAILED
            || startState == State.UNKNOWN) {
          return true;
        }
        break;
    }
    return false;
  }
Utility method to determine whether or not a valid transition can be made from the given states.

@param startState    the starting state
@param desiredState  the desired state

@return true iff a valid transition can be made from the starting state to the desired state
ambari-server/src/main/java/org/apache/ambari/server/state/State.java