public boolean isKdcReachable(final String server, final int port, final ConnectionProtocol connectionProtocol) {
    int timeoutMillis = connectionTimeout * 1000;
    final KdcConfig config = KdcConfig.getDefaultConfig();
    config.setHostName(server);
    config.setKdcPort(port);
    config.setUseUdp(ConnectionProtocol.UDP == connectionProtocol);
    config.setTimeout(timeoutMillis);

    FutureTask<Boolean> future = new FutureTask<>(new Callable<Boolean>() {
      @Override
      public Boolean call() {
        Boolean success;

        try {
          KdcConnection connection = getKdcConnection(config);
          // we are only testing whether we can communicate with server and not
          // validating credentials
          connection.getTgt("noUser@noRealm", "noPassword");

          LOG.info(String.format("Encountered no Exceptions while testing connectivity to the KDC:\n" +
              "**** Host: %s:%d (%s)",
            server, port, connectionProtocol.name()));
          success = true;
        } catch (KerberosException e) {
          KrbError error = e.getError();
          ErrorType errorCode = error.getErrorCode();

          String errorCodeMessage;
          int errorCodeCode;
          if (errorCode != null) {
            errorCodeMessage = errorCode.getMessage();
            errorCodeCode = errorCode.getValue();
          } else {
            errorCodeMessage = "<Not Specified>";
            errorCodeCode = -1;
          }

          // unfortunately, need to look at msg as error 60 is a generic error code
          //todo: evaluate other error codes to provide better information
          //todo: as there may be other error codes where we should return false
          success = !(errorCodeCode == ErrorType.KRB_ERR_GENERIC.getValue() &&
            errorCodeMessage.contains("TimeOut"));

          if (!success || LOG.isDebugEnabled()) {
            KerberosMessageType messageType = error.getMessageType();

            String messageTypeMessage;
            int messageTypeCode;
            if (messageType != null) {
              messageTypeMessage = messageType.getMessage();
              messageTypeCode = messageType.getValue();
            } else {
              messageTypeMessage = "<Not Specified>";
              messageTypeCode = -1;
            }

            String message = String.format("Received KerberosException while testing connectivity to the KDC: %s\n" +
                "**** Host:    %s:%d (%s)\n" +
                "**** Error:   %s\n" +
                "**** Code:    %d (%s)\n" +
                "**** Message: %d (%s)",
              e.getLocalizedMessage(), server, port, connectionProtocol.name(), error.getEText(), errorCodeCode,
              errorCodeMessage, messageTypeCode, messageTypeMessage);

            if (LOG.isDebugEnabled()) {
              LOG.info(message, e);
            } else {
              LOG.info(message);
            }
          }
        } catch (Throwable e) {
          LOG.info(String.format("Received Exception while testing connectivity to the KDC: %s\n**** Host: %s:%d (%s)",
            e.getLocalizedMessage(), server, port, connectionProtocol.name()), e);

          // some bad unexpected thing occurred
          throw new RuntimeException(e);
        }

        return success;
      }
    });

    new Thread(future, "ambari-kdc-verify").start();
    Boolean result;
    try {
      // timeout after specified timeout
      result = future.get(timeoutMillis, TimeUnit.MILLISECONDS);

      if (result) {
        LOG.info(String.format("Successfully connected to the KDC server at %s:%d over %s",
            server, port, connectionProtocol.name()));
      } else {
        LOG.warn(String.format("Failed to connect to the KDC server at %s:%d over %s",
            server, port, connectionProtocol.name()));
      }
    } catch (InterruptedException e) {
      String message = String.format("Interrupted while trying to communicate with KDC server at %s:%d over %s",
          server, port, connectionProtocol.name());
      if (LOG.isDebugEnabled()) {
        LOG.warn(message, e);
      } else {
        LOG.warn(message);
      }

      result = false;
      future.cancel(true);
    } catch (ExecutionException e) {
      String message = String.format("An unexpected exception occurred while attempting to communicate with the KDC server at %s:%d over %s",
          server, port, connectionProtocol.name());
      if (LOG.isDebugEnabled()) {
        LOG.warn(message, e);
      } else {
        LOG.warn(message);
      }

      result = false;
    } catch (TimeoutException e) {
      String message = String.format("Timeout occurred while attempting to to communicate with KDC server at %s:%d over %s",
          server, port, connectionProtocol.name());
      if (LOG.isDebugEnabled()) {
        LOG.warn(message, e);
      } else {
        LOG.warn(message);
      }

      result = false;
      future.cancel(true);
    }

    return result;
  }
Attempt to communicate with KDC server over a specified communication protocol (TCP or UDP).

@param server         KDC hostname or IP address
@param port           KDC server port
@param connectionProtocol the type of connection to use
@return true if communication is successful; false otherwise
ambari-server/src/main/java/org/apache/ambari/server/KdcServerConnectionVerification.java