ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hit...@apache.org
Subject ambari git commit: AMBARI-17186. Tez View: Improve proxy logging. (Sreenath Somarajapuram via hitesh)
Date Fri, 24 Jun 2016 15:31:27 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 25d1cd24b -> 34dcc20a3


AMBARI-17186. Tez View: Improve proxy logging. (Sreenath Somarajapuram via hitesh)

(cherry picked from commit 8b7902240d1ffc68e09bc22ed61f35311cd9cbbf)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/34dcc20a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/34dcc20a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/34dcc20a

Branch: refs/heads/branch-2.4
Commit: 34dcc20a3cec1faf4a3090466de7d5299e97ea8c
Parents: 25d1cd2
Author: Hitesh Shah <hitesh@apache.org>
Authored: Fri Jun 24 08:26:11 2016 -0700
Committer: Hitesh Shah <hitesh@apache.org>
Committed: Fri Jun 24 08:27:29 2016 -0700

----------------------------------------------------------------------
 .../ambari/view/tez/ViewControllerImpl.java     |  34 +++---
 .../tez/exceptions/ATSUrlFetchException.java    |  32 ------
 .../tez/exceptions/ActiveRMFetchException.java  |  32 ------
 .../view/tez/exceptions/ProxyException.java     |  48 ---------
 .../view/tez/exceptions/TezWebAppException.java | 104 +++++++++++++++++++
 .../ambari/view/tez/rest/BaseProxyResource.java |  32 ++++--
 .../view/tez/rest/BaseRedirectionResource.java  |  11 +-
 .../ambari/view/tez/utils/ProxyHelper.java      |   7 +-
 8 files changed, 162 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/34dcc20a/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..8b023c2 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,21 +18,17 @@
 
 package org.apache.ambari.view.tez;
 
-import java.lang.String;
-import java.util.HashMap;
-import java.util.Map;
-
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
 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.TezWebAppException;
 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 org.slf4j.LoggerFactory;
 
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Implementation of controller to handle requests for the tez View.
@@ -42,6 +38,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 +69,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 TezWebAppException(message, ex);
     }
   }
 
@@ -80,13 +80,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 TezWebAppException(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 TezWebAppException(message, ex);
+    }
   }
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/34dcc20a/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/34dcc20a/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/34dcc20a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ProxyException.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ProxyException.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ProxyException.java
deleted file mode 100644
index aa006b2..0000000
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/ProxyException.java
+++ /dev/null
@@ -1,48 +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 javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Exception thrown by the proxy resources
- */
-
-public class ProxyException extends WebApplicationException {
-
-  public ProxyException(String message, int status) {
-    this(message, status, null);
-  }
-
-  public ProxyException(String message, int status, String trace) {
-    super(toEntity(message, status, trace));
-  }
-
-  private static Response toEntity(String message, int status, String trace) {
-    Map<String, Object> json = new HashMap<>();
-    json.put("message", message);
-    json.put("status", status);
-    json.put("trace", trace);
-    return Response.status(status).entity(json).type(MediaType.APPLICATION_JSON).build();
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/34dcc20a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/TezWebAppException.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/TezWebAppException.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/TezWebAppException.java
new file mode 100644
index 0000000..63a431b
--- /dev/null
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/exceptions/TezWebAppException.java
@@ -0,0 +1,104 @@
+/**
+ * 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.String;
+import java.lang.Throwable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
+
+/**
+ * A wrapper class for all exception in Tez View, with more meaningful error message
+ * */
+public class TezWebAppException extends WebApplicationException {
+
+  /**
+   * Creates an exception from a message with status 500:INTERNAL_SERVER_ERROR
+   * @param message String Extra message that wouldbe prefixed to the exception
+   ***/
+  public TezWebAppException(String message) {
+    super(toEntity(message, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ""));
+  }
+
+  /**
+   * Creates an exception from an exception with status 500:INTERNAL_SERVER_ERROR
+   * @param message String Extra message that wouldbe prefixed to the exception
+   * @param ex Exception to be wrapped
+   ***/
+  public TezWebAppException(String message, Exception ex) {
+    super(toEntity(message, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ex));
+  }
+
+  /**
+   * Creates an exception from an exception with custom status
+   * @param message String Extra message that wouldbe prefixed to the exception
+   * @param status int Custom status
+   * @param ex Exception to be wrapped
+   ***/
+  public TezWebAppException(String message, int status, Exception ex) {
+    super(toEntity(message, status, ex));
+  }
+
+  /**
+   * Creates an exception from message, status and trace
+   * @param message String Extra message that wouldbe prefixed to the exception
+   * @param status int Custom status
+   * @param trace String
+   ***/
+  public TezWebAppException(String message, int status, String trace) {
+    super(toEntity(message, status, trace));
+  }
+
+  /**
+   * Creates the response object with the given exception
+   *
+   * @param message String
+   * @param status int
+   * @param ex Exception
+   *
+   * @return Response
+   * */
+  private static Response toEntity(String message, int status, Exception ex) {
+    return toEntity(message + ". " + ex.getMessage(), status, ExceptionUtils.getStackTrace(ex));
+  }
+
+  /**
+   * Creates the response object
+   *
+   * @param message String
+   * @param status int
+   * @param trace String
+   *
+   * @return Response
+   * */
+  private static Response toEntity(String message, int status, String trace) {
+    Map<String, Object> json = new HashMap<>();
+    json.put("message", message);
+    json.put("status", status);
+    json.put("trace", trace);
+    return Response.status(status).entity(json).type(MediaType.APPLICATION_JSON).build();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/34dcc20a/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..2d89489 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
@@ -18,8 +18,7 @@
 
 package org.apache.ambari.view.tez.rest;
 
-import com.google.inject.Inject;
-import org.apache.ambari.view.tez.exceptions.ProxyException;
+import org.apache.ambari.view.tez.exceptions.TezWebAppException;
 import org.apache.ambari.view.tez.utils.ProxyHelper;
 import org.json.simple.JSONObject;
 import org.json.simple.JSONValue;
@@ -33,8 +32,14 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.WebApplicationException;
+import javax.inject.Inject;
+
 import java.util.HashMap;
 
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
 /**
  * Base class for the proxy resources
  */
@@ -42,6 +47,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;
@@ -52,15 +59,28 @@ public abstract class BaseProxyResource {
   @Produces({MediaType.APPLICATION_JSON})
   public Response getData(@Context UriInfo uriInfo, @PathParam("endpoint") String endpoint)
{
     String url = getProxyUrl(endpoint, uriInfo.getQueryParameters());
+
+    LOG.debug("Proxying to URL: {}", url);
     String response = proxyHelper.getResponse(url, new HashMap<String, String>());
 
     JSONObject jsonObject = (JSONObject) JSONValue.parse(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("Response received from URL: {} : {}", url, response);
+      LOG.error("Failed to parse JSON from URL: {}", url);
+      throw new TezWebAppException("Failed to parse JSON from URL : " + url + ". Internal
Error.",
+          Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response);
     }
-    return Response.ok(jsonObject).type(MediaType.APPLICATION_JSON).build();
+
+    try {
+      LOG.debug("Response received from URL: {}", url);
+      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 TezWebAppException("Failed to proxy to : " + url + ". Internal Error.", e);
+    }
+
   }
 
   public abstract String getProxyUrl(String endpoint, MultivaluedMap<String, String>
queryParams);

http://git-wip-us.apache.org/repos/asf/ambari/blob/34dcc20a/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..14c2b75 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
@@ -18,7 +18,7 @@
 
 package org.apache.ambari.view.tez.rest;
 
-import org.apache.ambari.view.tez.exceptions.ProxyException;
+import org.apache.ambari.view.tez.exceptions.TezWebAppException;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -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,15 +38,18 @@ 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) {
-      throw new ProxyException("Failed to set the redirection url to : " + url + ".Internal
Error.",
-        Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
+      LOG.error("Redirecting to URL {} failed: ", url, e);
+      throw new TezWebAppException("Failed to set the redirection url to : " + url + ". Internal
Error.", e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/34dcc20a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
index f642193..08e371f 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
@@ -22,7 +22,7 @@ package org.apache.ambari.view.tez.utils;
 import com.google.inject.Inject;
 import org.apache.ambari.view.URLConnectionProvider;
 import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.tez.exceptions.ProxyException;
+import org.apache.ambari.view.tez.exceptions.TezWebAppException;
 import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,7 +61,7 @@ public class ProxyHelper {
         if (inputStream != null) {
           trace = IOUtils.toString(inputStream);
         }
-        throw new ProxyException("Failed to fetch results by the proxy from url: " + url,
connection.getResponseCode(), trace);
+        throw new TezWebAppException("Failed to fetch results by the proxy from url: " +
url, connection.getResponseCode(), trace);
       }
 
       inputStream = connection.getInputStream();
@@ -69,8 +69,7 @@ public class ProxyHelper {
 
     } catch (IOException e) {
       LOG.error("Cannot access the url: {}", url, e);
-      throw new ProxyException("Failed to fetch results by the proxy from url: " + url +
".Internal Error.",
-        Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
+      throw new TezWebAppException("Failed to fetch results by the proxy from url: " + url
+ ". Internal Error.", e);
     } finally {
       if (inputStream != null) {
         try {


Mime
View raw message