private static String constructDiagnostics(AppStatusBuilder appStatusBuilder) {
    StringBuilder sb = new StringBuilder();

    switch (appStatusBuilder.getState()) {
    case APP_NOT_FOUND:
      sb.append("LLAP status unknown. Awaiting app launch");
      break;
    case LAUNCHING:
      // This is a catch all state - when containers have not started yet, or LLAP has not started yet.
      if (StringUtils.isNotBlank(appStatusBuilder.getAmInfo().getAppId())) {
        sb.append("LLAP Starting up with AppId=").append(appStatusBuilder.getAmInfo().getAppId()).append(".");
        if (appStatusBuilder.getDesiredInstances() != null) {
          sb.append(" Started 0/").append(appStatusBuilder.getDesiredInstances()).append(" instances");
        }

        String containerDiagnostics = constructCompletedContainerDiagnostics(
            appStatusBuilder.getCompletedInstances());
        if (StringUtils.isNotEmpty(containerDiagnostics)) {
          sb.append("\n").append(containerDiagnostics);
        }
      } else {
        sb.append("Awaiting LLAP startup");
      }
      break;
    case RUNNING_PARTIAL:
      sb.append("LLAP Starting up with ApplicationId=").append(appStatusBuilder.getAmInfo().getAppId());
      sb.append(" Started").append(appStatusBuilder.getLiveInstances()).append("/")
        .append(appStatusBuilder.getDesiredInstances()).append(" instances");
      String containerDiagnostics = constructCompletedContainerDiagnostics(appStatusBuilder.getCompletedInstances());
      if (StringUtils.isNotEmpty(containerDiagnostics)) {
        sb.append("\n").append(containerDiagnostics);
      }

      // TODO HIVE-15865: Include information about pending requests, and last
      // allocation time once YARN Service provides this information.
      break;
    case RUNNING_ALL:
      sb.append("LLAP Application running with ApplicationId=").append(appStatusBuilder.getAmInfo().getAppId());
      break;
    case COMPLETE:
      sb.append("LLAP Application already complete. ApplicationId=").append(appStatusBuilder.getAmInfo().getAppId());
      containerDiagnostics = constructCompletedContainerDiagnostics(appStatusBuilder.getCompletedInstances());
      if (StringUtils.isNotEmpty(containerDiagnostics)) {
        sb.append("\n").append(containerDiagnostics);
      }

      break;
    case UNKNOWN:
      sb.append("LLAP status unknown");
      break;
    default:
      throw new IllegalStateException("Unknown State: " + appStatusBuilder.getState());
    }
    if (StringUtils.isNotBlank(appStatusBuilder.getDiagnostics())) {
      sb.append("\n").append(appStatusBuilder.getDiagnostics());
    }

    return sb.toString();
  }
Helper method to construct a diagnostic message from a complete AppStatusBuilder.
llap-server/src/java/org/apache/hadoop/hive/llap/cli/status/LlapStatusServiceDriver.java