private String getErrors(StringBuilder outSB, StringBuilder errSB, Set<InfoTuple> errors) {

    errSB.append("Finalization will not be able to completed because of the following version inconsistencies:");
    errSB.append(System.lineSeparator());

    Set<String> hosts = new TreeSet<>();
    Map<String, JsonArray> hostDetails = new HashMap<>();

    for (InfoTuple tuple : errors) {
      errSB.append("  ");
      errSB.append(tuple.hostName).append(": ");
      errSB.append(System.lineSeparator()).append("    ");
      errSB.append(tuple.serviceName).append('/').append(tuple.componentName);
      errSB.append(" reports ").append(StringUtils.trimToEmpty(tuple.currentVersion));
      errSB.append(" but expects ").append(tuple.targetVersion);
      errSB.append(System.lineSeparator());

      hosts.add(tuple.hostName);

      if (!hostDetails.containsKey(tuple.hostName)) {
        hostDetails.put(tuple.hostName, new JsonArray());
      }

      JsonObject obj = new JsonObject();
      obj.addProperty("service", tuple.serviceName);
      obj.addProperty("component", tuple.componentName);
      obj.addProperty("version", tuple.currentVersion);
      obj.addProperty("targetVersion", tuple.targetVersion);

      hostDetails.get(tuple.hostName).add(obj);
    }

    JsonArray hostJson = new JsonArray();
    for (String h : hosts) {
      hostJson.add(new JsonPrimitive(h));
    }

    JsonObject valueJson = new JsonObject();
    for (Entry<String, JsonArray> entry : hostDetails.entrySet()) {
      valueJson.add(entry.getKey(), entry.getValue());
    }

    outSB.append(String.format("There were errors on the following hosts: %s",
        StringUtils.join(hosts, ", ")));

    JsonObject obj = new JsonObject();
    obj.add("hosts", hostJson);
    obj.add("host_detail", valueJson);

    return obj.toString();
  }
Action that checks component versions to ensure {@link FinalizeUpgradeAction} will
complete successfully.
ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckAction.java