Repository: ambari Updated Branches: refs/heads/trunk aaa435c36 -> 75d44052a
AMBARI-17186. Tez View: Improve proxy logging. (Sreenath Somarajapuram via dipayanb) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/75d44052 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/75d44052 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/75d44052 Branch: refs/heads/trunk Commit: 75d44052aafd9ae913ac1f02f55a215bdb8709e5 Parents: aaa435c Author: Dipayan Bhowmick <[email protected]> Authored: Fri Jun 17 08:08:13 2016 +0530 Committer: Dipayan Bhowmick <[email protected]> Committed: Fri Jun 17 08:08:13 2016 +0530 ---------------------------------------------------------------------- .../ambari/view/tez/ViewControllerImpl.java | 24 ++++++++--- .../tez/exceptions/ATSUrlFetchException.java | 32 -------------- .../tez/exceptions/ActiveRMFetchException.java | 32 -------------- .../exceptions/ConfigurationFetchException.java | 44 ++++++++++++++++++++ .../ambari/view/tez/rest/BaseProxyResource.java | 28 ++++++++++--- .../view/tez/rest/BaseRedirectionResource.java | 6 +++ 6 files changed, 91 insertions(+), 75 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/75d44052/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java index 981353b..b15fe50 100644 --- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java +++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java @@ -18,19 +18,19 @@ package org.apache.ambari.view.tez; -import java.lang.String; import java.util.HashMap; import java.util.Map; import org.apache.ambari.view.ViewContext; import org.apache.ambari.view.cluster.Cluster; -import org.apache.ambari.view.tez.exceptions.ATSUrlFetchException; -import org.apache.ambari.view.tez.exceptions.ActiveRMFetchException; +import org.apache.ambari.view.tez.exceptions.ConfigurationFetchException; import org.apache.ambari.view.utils.ambari.AmbariApi; import org.apache.ambari.view.utils.ambari.AmbariApiException; import org.slf4j.LoggerFactory; import org.slf4j.Logger; +import javax.ws.rs.core.Response; + import com.google.inject.Inject; import com.google.inject.Singleton; @@ -42,6 +42,8 @@ public class ViewControllerImpl implements ViewController { private AmbariApi ambariApi; + private static final Logger LOG = LoggerFactory.getLogger(ViewControllerImpl.class); + @Inject public ViewControllerImpl(ViewContext viewContext) { this.ambariApi = new AmbariApi(viewContext); @@ -71,7 +73,9 @@ public class ViewControllerImpl implements ViewController { try { return ambariApi.getServices().getTimelineServerUrl(); } catch (AmbariApiException ex) { - throw new ATSUrlFetchException(ex); + String message = "Failed to find YARN Timeline Server location!"; + LOG.error(message, ex); + throw new ConfigurationFetchException(message, ex); } } @@ -80,13 +84,21 @@ public class ViewControllerImpl implements ViewController { try { return ambariApi.getServices().getRMUrl(); } catch (AmbariApiException ex) { - throw new ActiveRMFetchException(ex); + String message = "Failed to find Active ResourceManager location!"; + LOG.error(message, ex); + throw new ConfigurationFetchException(message, ex); } } @Override public String getYARNProtocol() { - return ambariApi.getServices().getYARNProtocol(); + try { + return ambariApi.getServices().getYARNProtocol(); + } catch (AmbariApiException ex) { + String message = "Failed to find YARN http/https protocol configuration value!"; + LOG.error(message, ex); + throw new ConfigurationFetchException(message, ex); + } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/75d44052/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ATSUrlFetchException.java ---------------------------------------------------------------------- diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ATSUrlFetchException.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ATSUrlFetchException.java deleted file mode 100644 index 9eb7c47..0000000 --- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ATSUrlFetchException.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.view.tez.exceptions; - -import org.apache.ambari.view.utils.ambari.AmbariApiException; - -import javax.ws.rs.WebApplicationException; - -public class ATSUrlFetchException extends WebApplicationException { - - public ATSUrlFetchException(AmbariApiException ex) { - super(ex.toEntity()); - - } - -} http://git-wip-us.apache.org/repos/asf/ambari/blob/75d44052/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ActiveRMFetchException.java ---------------------------------------------------------------------- diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ActiveRMFetchException.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ActiveRMFetchException.java deleted file mode 100644 index cb6f2eb..0000000 --- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ActiveRMFetchException.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.view.tez.exceptions; - - -import org.apache.ambari.view.utils.ambari.AmbariApiException; - -import javax.ws.rs.WebApplicationException; - -public class ActiveRMFetchException extends WebApplicationException { - - public ActiveRMFetchException(AmbariApiException ex) { - super(ex.toEntity()); - - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/75d44052/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ConfigurationFetchException.java ---------------------------------------------------------------------- diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ConfigurationFetchException.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ConfigurationFetchException.java new file mode 100644 index 0000000..f9f40b8 --- /dev/null +++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ConfigurationFetchException.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.view.tez.exceptions; + +import org.apache.ambari.view.utils.ambari.AmbariApiException; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.lang.Throwable; +import java.util.HashMap; +import java.util.Map; + +public class ConfigurationFetchException extends WebApplicationException { + + public ConfigurationFetchException(String message, AmbariApiException ex) { + super(toEntity(message, ex)); + } + + private static Response toEntity(String message, AmbariApiException ex) { + Map<String, Object> json = new HashMap<>(); + int status = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); + json.put("message", String.join(". ", message, ex.getMessage()) ); + json.put("status", status); + json.put("trace", ex.getCause()); + return Response.status(status).entity(json).type(MediaType.APPLICATION_JSON).build(); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/75d44052/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java ---------------------------------------------------------------------- diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java index 619f81e..9f1581a 100644 --- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java +++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java @@ -34,6 +34,9 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import java.util.HashMap; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; +import javax.ws.rs.WebApplicationException; /** * Base class for the proxy resources @@ -42,6 +45,8 @@ public abstract class BaseProxyResource { private ProxyHelper proxyHelper; + private static final Logger LOG = LoggerFactory.getLogger(BaseProxyResource.class); + @Inject public BaseProxyResource(ProxyHelper proxyHelper) { this.proxyHelper = proxyHelper; @@ -54,13 +59,26 @@ public abstract class BaseProxyResource { String url = getProxyUrl(endpoint, uriInfo.getQueryParameters()); String response = proxyHelper.getResponse(url, new HashMap<String, String>()); - JSONObject jsonObject = (JSONObject) JSONValue.parse(response); + try { + JSONObject jsonObject = (JSONObject) JSONValue.parse(response); + + if (jsonObject == null) { + LOG.debug("Response received from URL: {} : {}", url, response); + LOG.error("Failed to parse JSON from URL: {}", url); + throw new ProxyException("Failed to parse JSON from URL : " + url + ".Internal Error.", + Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response); + } - if (jsonObject == null) { - throw new ProxyException("Failed to parse JSON from URL : " + url + ".Internal Error.", - Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response); + LOG.debug("Proxying to URL: {}", url); + return Response.ok(jsonObject).type(MediaType.APPLICATION_JSON).build(); } - return Response.ok(jsonObject).type(MediaType.APPLICATION_JSON).build(); + catch(WebApplicationException e) { + LOG.debug("Response received from URL: {} : {}", url, response); + LOG.error("Proxying to URL {} failed: ", url, e); + throw new ProxyException("Failed to proxy to : " + url + ".Internal Error.", + Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()); + } + } public abstract String getProxyUrl(String endpoint, MultivaluedMap<String, String> queryParams); http://git-wip-us.apache.org/repos/asf/ambari/blob/75d44052/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java ---------------------------------------------------------------------- diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java index 97ee01d..0250bce 100644 --- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java +++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java @@ -29,6 +29,8 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import java.net.URI; import java.net.URISyntaxException; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; /** * Base class for resources which will redirect the call to the active URL by fetching the current active URL. @@ -36,13 +38,17 @@ import java.net.URISyntaxException; */ public abstract class BaseRedirectionResource { + private static final Logger LOG = LoggerFactory.getLogger(BaseRedirectionResource.class); + @Path("/{endpoint:.+}") @GET public Response getData(@Context UriInfo uriInfo, @PathParam("endpoint") String endpoint) { String url = getProxyUrl(endpoint, uriInfo.getQueryParameters()); try { + LOG.debug("Redirecting to URL: {}", url); return Response.temporaryRedirect(new URI(url)).build(); } catch (URISyntaxException e) { + LOG.error("Redirecting to URL {} failed: ", url, e); throw new ProxyException("Failed to set the redirection url to : " + url + ".Internal Error.", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()); }
