Quellcode durchsuchen

AMBARI-17966. Remove unneeded commons-httpclient dependencies from Ambari Slider View

Sumit Mohanty vor 9 Jahren
Ursprung
Commit
5977156a07

+ 0 - 36
contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java

@@ -19,7 +19,6 @@
 package org.apache.ambari.view.slider.rest.client;
 
 import java.io.IOException;
-import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -34,14 +33,10 @@ import org.apache.ambari.view.slider.clients.AmbariHostComponent;
 import org.apache.ambari.view.slider.clients.AmbariHostInfo;
 import org.apache.ambari.view.slider.clients.AmbariService;
 import org.apache.ambari.view.slider.clients.AmbariServiceInfo;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
 
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.stream.JsonReader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,22 +48,6 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
 			ViewContext viewContext) {
 		super(url, userId, password, viewContext);
 	}
-	
-    @SuppressWarnings("deprecation")
-    private RuntimeException createRuntimeException(HttpException httpException) {
-      String message = httpException.getMessage();
-      try {
-        JsonElement jsonElement = new JsonParser().parse(new JsonReader(new StringReader(httpException.getMessage())));
-        if (jsonElement != null && jsonElement.getAsJsonObject().has("message")) {
-          message = jsonElement.getAsJsonObject().get("message").getAsString();
-        }
-      } catch (Throwable t) {
-      }
-      if (httpException.getReasonCode() != HttpStatus.SC_OK) {
-        message = httpException.getReasonCode() + " " + httpException.getReason() + ": " + message;
-      }
-      return new RuntimeException(message, httpException);
-    }
 
     /**
      * Provides the first cluster defined on this Ambari server.
@@ -91,9 +70,6 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
                 cluster.setVersion(clusterObj.get("version").getAsString());
                 return cluster;
             }
-        } catch (HttpException e) {
-            logger.warn("Unable to determine Ambari clusters", e);
-            throw createRuntimeException(e);
         } catch (IOException e) {
             logger.warn("Unable to determine Ambari clusters", e);
             throw new RuntimeException(e.getMessage(), e);
@@ -119,8 +95,6 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
             }
           }
         }
-      } catch (HttpException e) {
-        logger.warn("Unable to determine Ambari clusters", e);
       } catch (IOException e) {
         logger.warn("Unable to determine Ambari clusters", e);
       }
@@ -177,10 +151,6 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
 			  logger.warn("Unable to determine Ambari cluster details - "
 			      + clusterInfo.getName(), e);
 			  throw new RuntimeException(e.getMessage(), e);
-			} catch (HttpException e) {
-				logger.warn("Unable to determine Ambari cluster details - "
-				    + clusterInfo.getName(), e);
-				throw createRuntimeException(e);
 			} catch (IOException e) {
 				logger.warn("Unable to determine Ambari cluster details - "
 				    + clusterInfo.getName(), e);
@@ -212,9 +182,6 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
 				    return properties;
 				  }
 				}
-			} catch (HttpException e) {
-				logger.warn("Unable to determine Ambari clusters", e);
-				throw createRuntimeException(e);
 			} catch (IOException e) {
 				logger.warn("Unable to determine Ambari clusters", e);
 				throw new RuntimeException(e.getMessage(), e);
@@ -255,9 +222,6 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
             }
             svc.setComponentsToHostComponentsMap(componentsToHostComponentsMap);
             return svc;
-        } catch (HttpException e) {
-            logger.warn("Unable to determine Ambari clusters", e);
-            throw createRuntimeException(e);
         } catch (IOException e) {
             logger.warn("Unable to determine Ambari clusters", e);
             throw new RuntimeException(e.getMessage(), e);

+ 5 - 11
contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java

@@ -27,7 +27,6 @@ import java.util.Map;
 import org.apache.ambari.view.URLStreamProvider;
 import org.apache.ambari.view.ViewContext;
 import org.apache.ambari.view.utils.ambari.AmbariApi;
-import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.io.IOUtils;
 
 import com.google.gson.JsonElement;
@@ -111,12 +110,11 @@ public class BaseHttpClient {
 		this.password = password;
 	}
 
-	public JsonElement doGetJson(String path) throws HttpException, IOException {
+	public JsonElement doGetJson(String path) throws IOException {
 		return doGetJson(getUrl(), path);
 	}
 
-	public JsonElement doGetJson(String url, String path) throws HttpException,
-			IOException {
+	public JsonElement doGetJson(String url, String path) throws IOException {
 		InputStream inputStream = null;
 		try {
 			Map<String, String> headers = new HashMap<String, String>();
@@ -129,16 +127,14 @@ public class BaseHttpClient {
 			}
 		} catch (IOException e) {
 			logger.error("Error while reading from url " + url + path, e);
-			HttpException httpException = new HttpException(
-					e.getLocalizedMessage());
-			throw httpException;
+			throw e;
 		}
 		JsonElement jsonElement = new JsonParser().parse(new JsonReader(
 				new InputStreamReader(inputStream)));
 		return jsonElement;
 	}
 
-	public String doGet(String path) throws HttpException, IOException {
+	public String doGet(String path) throws IOException {
 		String response = null;
 		try {
 			InputStream inputStream = null;
@@ -154,9 +150,7 @@ public class BaseHttpClient {
 			response = IOUtils.toString(inputStream);
 		} catch (IOException e) {
 			logger.error("Error while reading from url " + getUrl() + path, e);
-			HttpException httpException = new HttpException(
-					e.getLocalizedMessage());
-			throw httpException;
+			throw e;
 		}
 		return response;
 	}

+ 0 - 8
contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java

@@ -34,7 +34,6 @@ import org.apache.ambari.view.slider.MetricsHolder;
 import org.apache.ambari.view.slider.SliderAppType;
 import org.apache.ambari.view.slider.SliderAppTypeComponent;
 import org.apache.ambari.view.slider.TemporalInfo;
-import org.apache.commons.httpclient.HttpException;
 import org.apache.ambari.view.slider.SliderAppsViewController;
 
 import com.google.gson.JsonElement;
@@ -77,9 +76,6 @@ public class SliderAppMasterClient extends BaseHttpClient {
           return data;
         }
       }
-    } catch (HttpException e) {
-      logger.warn("Unable to determine Ambari clusters", e);
-      throw new RuntimeException(e.getMessage(), e);
     } catch (IOException e) {
       logger.warn("Unable to determine Ambari clusters", e);
       throw new RuntimeException(e.getMessage(), e);
@@ -112,8 +108,6 @@ public class SliderAppMasterClient extends BaseHttpClient {
           }
         }
       }
-    } catch (HttpException e) {
-      logger.warn("Unable to determine quicklinks from " + providerUrl, e);
     } catch (IOException e) {
       logger.warn("Unable to determine quicklinks from " + providerUrl, e);
     }
@@ -150,8 +144,6 @@ public class SliderAppMasterClient extends BaseHttpClient {
           }
         }
       }
-    } catch (HttpException e) {
-      logger.warn("Unable to determine quicklinks from " + providerUrl, e);
     } catch (IOException e) {
       logger.warn("Unable to determine quicklinks from " + providerUrl, e);
     }