commit a066c95c6077df08590d0b5c0f1a963f98582f44 Author: Eric Yang Date: Thu Jun 27 12:36:32 2019 -0400 YARN-9648. Improve server side error for YARN ApiServiceClient. Contributed by Eric Yang diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/client/ApiServiceClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/client/ApiServiceClient.java index 834bb03..237748c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/client/ApiServiceClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/client/ApiServiceClient.java @@ -29,6 +29,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; +import org.codehaus.jettison.json.JSONObject; import com.google.common.base.Preconditions; import org.apache.commons.codec.binary.Base64; @@ -52,7 +53,6 @@ import org.apache.hadoop.yarn.service.api.records.ContainerState; import org.apache.hadoop.yarn.service.api.records.Service; import org.apache.hadoop.yarn.service.api.records.ServiceState; -import org.apache.hadoop.yarn.service.api.records.ServiceStatus; import org.apache.hadoop.yarn.service.conf.RestApiConstants; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; import org.apache.hadoop.yarn.util.RMHAUtils; @@ -264,6 +264,7 @@ private ClientConfig getClientConfig() { private int processResponse(ClientResponse response) { response.bufferEntity(); String output; + JSONObject json; if (response.getStatus() == 401) { LOG.error("Authentication required"); return EXIT_EXCEPTION_THROWN; @@ -273,13 +274,16 @@ private int processResponse(ClientResponse response) { return EXIT_EXCEPTION_THROWN; } try { - ServiceStatus ss = response.getEntity(ServiceStatus.class); - output = ss.getDiagnostics(); + json = response.getEntity(JSONObject.class); + if (json.has("diagnostics")) { + output = json.getString("diagnostics"); + } else if (json.has("message")) { + output = json.getString("message"); + } else { + output = json.toString(); + } } catch (Throwable t) { - output = response.getEntity(String.class); - } - if (output==null) { - output = response.getEntity(String.class); + output = t.getMessage(); } if (response.getStatus() <= 299) { LOG.info(output);