Repository: ambari Updated Branches: refs/heads/trunk ecb5aff2f -> 7c8d4f6dc
AMBARI-7801. Slider View: YARN memory should show app-type values and use Ambari's java.home (srimanth) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7c8d4f6d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7c8d4f6d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7c8d4f6d Branch: refs/heads/trunk Commit: 7c8d4f6dc060d0b0d053dea6256baa0a5f86185f Parents: ecb5aff Author: Srimanth Gunturi <[email protected]> Authored: Wed Oct 15 13:59:45 2014 -0700 Committer: Srimanth Gunturi <[email protected]> Committed: Wed Oct 15 15:58:02 2014 -0700 ---------------------------------------------------------------------- .../slider/SliderAppsViewControllerImpl.java | 276 ++++++++++--------- .../slider/rest/client/AmbariHttpClient.java | 138 +++++++--- .../view/slider/rest/client/BaseHttpClient.java | 24 +- .../rest/client/SliderAppMasterClient.java | 30 +- 4 files changed, 272 insertions(+), 196 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7c8d4f6d/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java index f6449e2..92f95c9 100644 --- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java +++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewControllerImpl.java @@ -132,137 +132,147 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController { } AmbariHttpClient ambariClient = new AmbariHttpClient(ambariUrl, ambariUsername, ambariPassword); - AmbariClusterInfo clusterInfo = ambariClient.getClusterInfo(); - if (clusterName.equals(clusterInfo.getName())) { - AmbariCluster cluster = ambariClient.getCluster(clusterInfo); - AmbariServiceInfo hdfsServiceInfo = null; - AmbariServiceInfo yarnServiceInfo = null; - // Validate stack-version - Validation validateStackVersion = validateStackVersion(clusterInfo.getVersion()); - if (validateStackVersion != null) { - status.getValidations().add(validateStackVersion); - } - for (AmbariServiceInfo svc : cluster.getServices()) { - if ("HDFS".equals(svc.getId())) { - hdfsServiceInfo = svc; - } else if ("YARN".equals(svc.getId())) { - yarnServiceInfo = svc; + try { + AmbariClusterInfo clusterInfo = ambariClient.getClusterInfo(); + if (clusterName.equals(clusterInfo.getName())) { + AmbariCluster cluster = ambariClient.getCluster(clusterInfo); + AmbariServiceInfo hdfsServiceInfo = null; + AmbariServiceInfo yarnServiceInfo = null; + // Validate stack-version + Validation validateStackVersion = validateStackVersion(clusterInfo.getVersion()); + if (validateStackVersion != null) { + status.getValidations().add(validateStackVersion); } - } - // HDFS - if (hdfsServiceInfo != null) { - if (!hdfsServiceInfo.isStarted()) { + for (AmbariServiceInfo svc : cluster.getServices()) { + if ("HDFS".equals(svc.getId())) { + hdfsServiceInfo = svc; + } else if ("YARN".equals(svc.getId())) { + yarnServiceInfo = svc; + } + } + // HDFS + if (hdfsServiceInfo != null) { + if (!hdfsServiceInfo.isStarted()) { + status.getValidations().add( + new ViewStatus.Validation("HDFS service is not started")); + } + } else { status.getValidations().add( - new ViewStatus.Validation("HDFS service is not started")); + new ViewStatus.Validation("HDFS service is not installed")); } - } else { - status.getValidations().add( - new ViewStatus.Validation("HDFS service is not installed")); - } - // YARN - if (yarnServiceInfo != null) { - if (!yarnServiceInfo.isStarted()) { + // YARN + if (yarnServiceInfo != null) { + if (!yarnServiceInfo.isStarted()) { + status.getValidations().add( + new ViewStatus.Validation("YARN service is not started")); + } + } else { status.getValidations().add( - new ViewStatus.Validation("YARN service is not started")); + new ViewStatus.Validation("YARN service is not installed")); } - } else { - status.getValidations().add( - new ViewStatus.Validation("YARN service is not installed")); - } - // Configs - if (cluster.getDesiredConfigs().containsKey("core-site")) { - Map<String, String> coreSiteConfigs = ambariClient - .getConfiguration(cluster, "core-site", cluster - .getDesiredConfigs().get("core-site")); - newHadoopConfigs.putAll(coreSiteConfigs); - } - if (cluster.getDesiredConfigs().containsKey("cluster-env")) { - Map<String, String> clusterEnvConfigs = ambariClient - .getConfiguration(cluster, "cluster-env", cluster - .getDesiredConfigs().get("cluster-env")); - newHadoopConfigs.put("security_enabled", - clusterEnvConfigs.get("security_enabled")); - } - if (cluster.getDesiredConfigs().containsKey("hdfs-site")) { - Map<String, String> hdfsSiteConfigs = ambariClient - .getConfiguration(cluster, "hdfs-site", cluster - .getDesiredConfigs().get("hdfs-site")); - newHadoopConfigs.putAll(hdfsSiteConfigs); - } - if (cluster.getDesiredConfigs().containsKey("yarn-site")) { - Map<String, String> yarnSiteConfigs = ambariClient - .getConfiguration(cluster, "yarn-site", cluster - .getDesiredConfigs().get("yarn-site")); - newHadoopConfigs.putAll(yarnSiteConfigs); - status.getParameters().put(PROPERTY_YARN_RM_WEBAPP_URL, - newHadoopConfigs.get("yarn.resourcemanager.webapp.address")); - } - if (cluster.getDesiredConfigs().containsKey("yarn-env")) { - Map<String, String> yarnEnvConfigs = ambariClient.getConfiguration(cluster, "yarn-env", cluster - .getDesiredConfigs().get("yarn-env")); - String yarnUser = yarnEnvConfigs.get("yarn_user"); - if (yarnUser == null || yarnUser.trim().length() < 1) { - yarnUser = "yarn"; + // JAVA_HOME + Map<String, String> ambariServerConfigs = ambariClient.getAmbariServerConfigs(); + if (ambariServerConfigs.containsKey("java.home")) { + newHadoopConfigs.put("java.home", ambariServerConfigs.get("java.home")); } - newHadoopConfigs.put("yarn_user", yarnUser); - } - if (cluster.getDesiredConfigs().containsKey("zookeeper-env")) { - Map<String, String> zkEnvConfigs = ambariClient.getConfiguration( - cluster, "zookeeper-env", - cluster.getDesiredConfigs().get("zookeeper-env")); - StringBuilder zkQuorumBuilder = new StringBuilder(); - String port = zkEnvConfigs.get("clientPort"); - AmbariService zkService = ambariClient.getService(cluster, - "ZOOKEEPER"); - if (zkService != null) { - List<AmbariHostComponent> hostsList = zkService - .getComponentsToHostComponentsMap().get("ZOOKEEPER_SERVER"); - int count = 1; - for (AmbariHostComponent host : hostsList) { - zkQuorumBuilder.append(host.getHostName() + ":" + port); - if (count++ < hostsList.size()) { - zkQuorumBuilder.append(","); + // Configs + if (cluster.getDesiredConfigs().containsKey("core-site")) { + Map<String, String> coreSiteConfigs = ambariClient + .getConfiguration(cluster, "core-site", cluster + .getDesiredConfigs().get("core-site")); + newHadoopConfigs.putAll(coreSiteConfigs); + } + if (cluster.getDesiredConfigs().containsKey("cluster-env")) { + Map<String, String> clusterEnvConfigs = ambariClient + .getConfiguration(cluster, "cluster-env", cluster + .getDesiredConfigs().get("cluster-env")); + newHadoopConfigs.put("security_enabled", + clusterEnvConfigs.get("security_enabled")); + } + if (cluster.getDesiredConfigs().containsKey("hdfs-site")) { + Map<String, String> hdfsSiteConfigs = ambariClient + .getConfiguration(cluster, "hdfs-site", cluster + .getDesiredConfigs().get("hdfs-site")); + newHadoopConfigs.putAll(hdfsSiteConfigs); + } + if (cluster.getDesiredConfigs().containsKey("yarn-site")) { + Map<String, String> yarnSiteConfigs = ambariClient + .getConfiguration(cluster, "yarn-site", cluster + .getDesiredConfigs().get("yarn-site")); + newHadoopConfigs.putAll(yarnSiteConfigs); + status.getParameters().put(PROPERTY_YARN_RM_WEBAPP_URL, + newHadoopConfigs.get("yarn.resourcemanager.webapp.address")); + } + if (cluster.getDesiredConfigs().containsKey("yarn-env")) { + Map<String, String> yarnEnvConfigs = ambariClient.getConfiguration(cluster, "yarn-env", cluster + .getDesiredConfigs().get("yarn-env")); + String yarnUser = yarnEnvConfigs.get("yarn_user"); + if (yarnUser == null || yarnUser.trim().length() < 1) { + yarnUser = "yarn"; + } + newHadoopConfigs.put("yarn_user", yarnUser); + } + if (cluster.getDesiredConfigs().containsKey("zookeeper-env")) { + Map<String, String> zkEnvConfigs = ambariClient.getConfiguration( + cluster, "zookeeper-env", + cluster.getDesiredConfigs().get("zookeeper-env")); + StringBuilder zkQuorumBuilder = new StringBuilder(); + String port = zkEnvConfigs.get("clientPort"); + AmbariService zkService = ambariClient.getService(cluster, + "ZOOKEEPER"); + if (zkService != null) { + List<AmbariHostComponent> hostsList = zkService + .getComponentsToHostComponentsMap().get("ZOOKEEPER_SERVER"); + int count = 1; + for (AmbariHostComponent host : hostsList) { + zkQuorumBuilder.append(host.getHostName() + ":" + port); + if (count++ < hostsList.size()) { + zkQuorumBuilder.append(","); + } } + newHadoopConfigs.put(PROPERTY_SLIDER_ZK_QUORUM, + zkQuorumBuilder.toString()); + } else { + status.getValidations().add( + new ViewStatus.Validation( + "ZooKeeper service is not installed")); } - newHadoopConfigs.put(PROPERTY_SLIDER_ZK_QUORUM, - zkQuorumBuilder.toString()); } else { - status.getValidations().add( + status.getValidations() + .add( new ViewStatus.Validation( "ZooKeeper service is not installed")); } - } else { - status.getValidations() - .add( - new ViewStatus.Validation( - "ZooKeeper service is not installed")); - } - if (cluster.getDesiredConfigs().containsKey("ganglia-env")) { - Map<String, String> gangliaConfigs = ambariClient.getConfiguration( - cluster, "ganglia-env", - cluster.getDesiredConfigs().get("ganglia-env")); - String clustersCsv = gangliaConfigs.get("additional_clusters"); - AmbariService gangliaService = ambariClient.getService(cluster, - "GANGLIA"); - List<AmbariHostComponent> hostsList = gangliaService - .getComponentsToHostComponentsMap().get("GANGLIA_SERVER"); - if (hostsList != null && hostsList.size() > 0) { - String gangliaHostName = hostsList - .get(0).getHostName(); - newHadoopConfigs.put(PROPERTY_GANGLIA_SERVER_HOSTNAME, gangliaHostName); - status.getParameters().put(PROPERTY_GANGLIA_SERVER_HOSTNAME, gangliaHostName); + if (cluster.getDesiredConfigs().containsKey("ganglia-env")) { + Map<String, String> gangliaConfigs = ambariClient.getConfiguration( + cluster, "ganglia-env", + cluster.getDesiredConfigs().get("ganglia-env")); + String clustersCsv = gangliaConfigs.get("additional_clusters"); + AmbariService gangliaService = ambariClient.getService(cluster, + "GANGLIA"); + List<AmbariHostComponent> hostsList = gangliaService + .getComponentsToHostComponentsMap().get("GANGLIA_SERVER"); + if (hostsList != null && hostsList.size() > 0) { + String gangliaHostName = hostsList + .get(0).getHostName(); + newHadoopConfigs.put(PROPERTY_GANGLIA_SERVER_HOSTNAME, gangliaHostName); + status.getParameters().put(PROPERTY_GANGLIA_SERVER_HOSTNAME, gangliaHostName); + } + newHadoopConfigs.put(PROPERTY_GANGLIA_CUSTOM_CLUSTERS, clustersCsv); + status.getParameters().put(PROPERTY_GANGLIA_CUSTOM_CLUSTERS, clustersCsv); } - newHadoopConfigs.put(PROPERTY_GANGLIA_CUSTOM_CLUSTERS, clustersCsv); - status.getParameters().put(PROPERTY_GANGLIA_CUSTOM_CLUSTERS, clustersCsv); - } - Validation validateHDFSAccess = validateHDFSAccess(newHadoopConfigs, hdfsServiceInfo); - if (validateHDFSAccess != null) { - status.getValidations().add(validateHDFSAccess); + Validation validateHDFSAccess = validateHDFSAccess(newHadoopConfigs, hdfsServiceInfo); + if (validateHDFSAccess != null) { + status.getValidations().add(validateHDFSAccess); + } + } else { + status.getValidations().add( + new ViewStatus.Validation("Ambari cluster with ID [" + + clusterName + "] was not found on Ambari server")); } - } else { - status.getValidations().add( - new ViewStatus.Validation("Ambari cluster with ID [" - + clusterName + "] was not found on Ambari server")); + } catch (Throwable t) { + logger.warn("Exception determining view status", t); + status.getValidations().add(new ViewStatus.Validation(t.getMessage())); } } else { status @@ -276,13 +286,15 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController { new ViewStatus.Validation( "View parameters specifying Ambari details required")); } - Set<String> removeKeys = new HashSet<String>(viewContext.getInstanceData().keySet()); - for (Entry<String, String> e : newHadoopConfigs.entrySet()) { - viewContext.putInstanceData(e.getKey(), e.getValue()); - removeKeys.remove(e.getKey()); - } - for (String key : removeKeys) { - viewContext.removeInstanceData(key); + if (!newHadoopConfigs.equals(viewContext.getInstanceData())) { + Set<String> removeKeys = new HashSet<String>(viewContext.getInstanceData().keySet()); + for (Entry<String, String> e : newHadoopConfigs.entrySet()) { + viewContext.putInstanceData(e.getKey(), e.getValue()); + removeKeys.remove(e.getKey()); + } + for (String key : removeKeys) { + viewContext.removeInstanceData(key); + } } return status; } @@ -772,7 +784,7 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController { } protected Map<String, String> getHadoopConfigs() { - if(hadoopConfigs==null) { + if(hadoopConfigs==null || hadoopConfigs.isEmpty()) { hadoopConfigs = viewContext.getInstanceData(); } return hadoopConfigs; @@ -950,12 +962,14 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController { JsonElement componentJson = resourcesJson.getAsJsonObject() .get("components").getAsJsonObject() .get(component.getName()); - if (componentJson != null - && componentJson.getAsJsonObject().has( - "yarn.role.priority")) { - appTypeComponent.setPriority(Integer.parseInt(componentJson - .getAsJsonObject().get("yarn.role.priority") - .getAsString())); + if (componentJson != null && componentJson.isJsonObject()) { + JsonObject componentObj = componentJson.getAsJsonObject(); + if (componentObj.has("yarn.role.priority")) { + appTypeComponent.setPriority(Integer.parseInt(componentObj.get("yarn.role.priority").getAsString())); + } + if (componentObj.has("yarn.memory")) { + appTypeComponent.setYarnMemory(Integer.parseInt(componentObj.get("yarn.memory").getAsString())); + } } } appTypeComponent.setCategory(component.getCategory()); http://git-wip-us.apache.org/repos/asf/ambari/blob/7c8d4f6d/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java index 6229f0d..1449360 100644 --- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java +++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java @@ -19,10 +19,12 @@ 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; import java.util.Map; +import java.util.Map.Entry; import org.apache.ambari.view.slider.clients.AmbariClient; import org.apache.ambari.view.slider.clients.AmbariCluster; @@ -32,11 +34,14 @@ 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 org.apache.log4j.Logger; 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; public class AmbariHttpClient extends BaseHttpClient implements AmbariClient { @@ -45,34 +50,77 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient { public AmbariHttpClient(String url, String userId, String password) { super(url, userId, password); } + + @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. - * - * @return - */ - public AmbariClusterInfo getClusterInfo() { - try { - JsonElement jsonElement = doGetJson("/api/v1/clusters"); - JsonObject jsonObject = jsonElement.getAsJsonObject(); - JsonArray clustersArray = jsonObject.get("items").getAsJsonArray(); - if (clustersArray.size() > 0) { - AmbariClusterInfo cluster = new AmbariClusterInfo(); - JsonObject clusterObj = clustersArray.get(0).getAsJsonObject() - .get("Clusters").getAsJsonObject(); - cluster.setName(clusterObj.get("cluster_name").getAsString()); - cluster.setVersion(clusterObj.get("version").getAsString()); - return cluster; - } - } 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); - } - return null; - } + /** + * Provides the first cluster defined on this Ambari server. + * + * @return + */ + public AmbariClusterInfo getClusterInfo() { + try { + JsonElement jsonElement = doGetJson("/api/v1/clusters"); + if(jsonElement==null) { + return null; + } + JsonObject jsonObject = jsonElement.getAsJsonObject(); + JsonArray clustersArray = jsonObject.get("items").getAsJsonArray(); + if (clustersArray.size() > 0) { + AmbariClusterInfo cluster = new AmbariClusterInfo(); + JsonObject clusterObj = clustersArray.get(0).getAsJsonObject() + .get("Clusters").getAsJsonObject(); + cluster.setName(clusterObj.get("cluster_name").getAsString()); + 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); + } + return null; + } + + /** + * Provides the first cluster defined on this Ambari server. + * + * @return + */ + public Map<String, String> getAmbariServerConfigs() { + Map<String, String> configs = new HashMap<String, String>(); + try { + JsonElement jsonElement = doGetJson("/api/v1/services/AMBARI/components/AMBARI_SERVER"); + if (jsonElement != null && jsonElement.getAsJsonObject().has("RootServiceComponents") + && jsonElement.getAsJsonObject().get("RootServiceComponents").getAsJsonObject().has("properties")) { + JsonObject ambariProperties = jsonElement.getAsJsonObject().get("RootServiceComponents").getAsJsonObject().get("properties").getAsJsonObject(); + for (Entry<String, JsonElement> entry : ambariProperties.entrySet()) { + configs.put(entry.getKey(), entry.getValue().getAsString()); + } + } + } catch (HttpException e) { + logger.warn("Unable to determine Ambari clusters", e); + } catch (IOException e) { + logger.warn("Unable to determine Ambari clusters", e); + } + return configs; + } public AmbariCluster getCluster(AmbariClusterInfo clusterInfo) { if (clusterInfo != null) { @@ -120,10 +168,14 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient { cluster.setHosts(hosts); return cluster; } + } catch (IllegalStateException e) { + 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 new RuntimeException(e.getMessage(), e); + throw createRuntimeException(e); } catch (IOException e) { logger.warn("Unable to determine Ambari cluster details - " + clusterInfo.getName(), e); @@ -140,20 +192,22 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient { JsonElement jsonElement = doGetJson("/api/v1/clusters/" + cluster.getName() + "/configurations?type=" + configType + "&tag=" + configTag); - JsonObject jsonObject = jsonElement.getAsJsonObject(); - JsonArray configsArray = jsonObject.get("items").getAsJsonArray(); - if (configsArray.size() > 0) { - JsonObject propertiesObj = configsArray.get(0).getAsJsonObject() - .get("properties").getAsJsonObject(); - Map<String, String> properties = new HashMap<String, String>(); - for (Map.Entry<String, JsonElement> entry : propertiesObj.entrySet()) { - properties.put(entry.getKey(), entry.getValue().getAsString()); - } - return properties; + if (jsonElement!=null) { + JsonObject jsonObject = jsonElement.getAsJsonObject(); + JsonArray configsArray = jsonObject.get("items").getAsJsonArray(); + if (configsArray.size() > 0) { + JsonObject propertiesObj = configsArray.get(0).getAsJsonObject() + .get("properties").getAsJsonObject(); + Map<String, String> properties = new HashMap<String, String>(); + for (Map.Entry<String, JsonElement> entry : propertiesObj.entrySet()) { + properties.put(entry.getKey(), entry.getValue().getAsString()); + } + return properties; + } } } catch (HttpException e) { logger.warn("Unable to determine Ambari clusters", e); - throw new RuntimeException(e.getMessage(), e); + throw createRuntimeException(e); } catch (IOException e) { logger.warn("Unable to determine Ambari clusters", e); throw new RuntimeException(e.getMessage(), e); @@ -168,10 +222,10 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient { try { JsonElement jsonElement = doGetJson("/api/v1/clusters/" + cluster.getName() + "/services/" + serviceId + "?fields=ServiceInfo,components/host_components/HostRoles"); - JsonObject jsonObject = jsonElement.getAsJsonObject(); - if (jsonObject.has("status") && "404".equals(jsonObject.get("status").getAsString())) { + if (jsonElement == null) { return null; } + JsonObject jsonObject = jsonElement.getAsJsonObject(); AmbariService svc = new AmbariService(); JsonObject serviceInfoJsonObject = jsonObject.get("ServiceInfo").getAsJsonObject(); svc.setId(serviceInfoJsonObject.get("service_name").getAsString()); @@ -196,7 +250,7 @@ public class AmbariHttpClient extends BaseHttpClient implements AmbariClient { return svc; } catch (HttpException e) { logger.warn("Unable to determine Ambari clusters", e); - throw new RuntimeException(e.getMessage(), e); + throw createRuntimeException(e); } catch (IOException e) { logger.warn("Unable to determine Ambari clusters", e); throw new RuntimeException(e.getMessage(), e); http://git-wip-us.apache.org/repos/asf/ambari/blob/7c8d4f6d/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java index 70778af..bb2787b 100644 --- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java +++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java @@ -88,22 +88,26 @@ public class BaseHttpClient { return doGetJson(getUrl(), path); } - public JsonElement doGetJson(String url, String path) throws HttpException, + @SuppressWarnings("deprecation") + public JsonElement doGetJson(String url, String path) throws HttpException, IOException { GetMethod get = new GetMethod(url + path); if (isNeedsAuthentication()) { get.setDoAuthentication(true); } int executeMethod = getHttpClient().executeMethod(get); - switch (executeMethod) { - case HttpStatus.SC_OK: - JsonElement jsonElement = new JsonParser().parse(new JsonReader( - new InputStreamReader(get.getResponseBodyAsStream()))); - return jsonElement; - default: - break; - } - return null; + switch (executeMethod) { + case HttpStatus.SC_OK: + JsonElement jsonElement = new JsonParser().parse(new JsonReader(new InputStreamReader(get.getResponseBodyAsStream()))); + return jsonElement; + case HttpStatus.SC_NOT_FOUND: + return null; + default: + HttpException httpException = new HttpException(get.getResponseBodyAsString()); + httpException.setReason(HttpStatus.getStatusText(executeMethod)); + httpException.setReasonCode(executeMethod); + throw httpException; + } } public String doGet(String path) throws HttpException, IOException { http://git-wip-us.apache.org/repos/asf/ambari/blob/7c8d4f6d/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java index fc8f0d7..a96cc12 100644 --- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java +++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java @@ -63,13 +63,13 @@ public class SliderAppMasterClient extends BaseHttpClient { String[] splits = content.split("\r\n"); for (int i = 0; i < splits.length; i++) { String split = splits[i].trim(); - if ("Registry Web Service".equals(split)) { + if ("org.apache.slider.registry".equals(split)) { data.registryUrl = splits[i + 1].trim(); - } else if ("Application Master Web UI".equals(split)) { + } else if ("org.apache.http.UI".equals(split)) { data.uiUrl = splits[i + 1].trim(); - } else if ("Management REST API".equals(split)) { + } else if ("org.apache.slider.management".equals(split)) { data.managementUrl = splits[i + 1].trim(); - } else if ("Publisher Service".equals(split)) { + } else if ("org.apache.slider.publisher".equals(split)) { data.publisherUrl = splits[i + 1].trim(); } } @@ -87,9 +87,12 @@ public class SliderAppMasterClient extends BaseHttpClient { } public Map<String, String> getQuickLinks(String providerUrl) { + Map<String, String> quickLinks = new HashMap<String, String>(); try { + if (providerUrl == null || providerUrl.trim().length() < 1) { + return quickLinks; + } JsonElement json = super.doGetJson(providerUrl, "/slider/quicklinks"); - Map<String, String> quickLinks = new HashMap<String, String>(); if (json != null && json.getAsJsonObject() != null && json.getAsJsonObject().has("entries")) { JsonObject jsonObject = json.getAsJsonObject().get("entries") @@ -99,26 +102,29 @@ public class SliderAppMasterClient extends BaseHttpClient { quickLinks.put("JMX", entry.getValue().getAsString()); } else if ("org.apache.slider.monitor".equals(entry.getKey())) { quickLinks.put("UI", entry.getValue().getAsString()); + } else if ("org.apache.slider.metrics.ui".equals(entry.getKey())) { + quickLinks.put("Metrics UI", entry.getValue().getAsString()); } else if ("org.apache.slider.metrics".equals(entry.getKey())) { - quickLinks.put("Metrics", entry.getValue().getAsString()); + quickLinks.put("Metrics API", entry.getValue().getAsString()); } else { quickLinks.put(entry.getKey(), entry.getValue().getAsString()); } } } - return quickLinks; } catch (HttpException e) { logger.warn("Unable to determine quicklinks from " + providerUrl, e); - throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { logger.warn("Unable to determine quicklinks from " + providerUrl, e); - throw new RuntimeException(e.getMessage(), e); } + return quickLinks; } public Map<String, Map<String, String>> getConfigs(String providerUrl) { + Map<String, Map<String, String>> configsMap = new HashMap<String, Map<String, String>>(); try { - Map<String, Map<String, String>> configsMap = new HashMap<String, Map<String, String>>(); + if (providerUrl == null || providerUrl.trim().length() < 1) { + return configsMap; + } JsonElement json = super.doGetJson(providerUrl, "/slider"); if (json != null) { JsonObject configsJson = json.getAsJsonObject().get("configurations") @@ -143,14 +149,12 @@ public class SliderAppMasterClient extends BaseHttpClient { } } } - return configsMap; } catch (HttpException e) { logger.warn("Unable to determine quicklinks from " + providerUrl, e); - throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { logger.warn("Unable to determine quicklinks from " + providerUrl, e); - throw new RuntimeException(e.getMessage(), e); } + return configsMap; } public Map<String, Number[][]> getGangliaMetrics(String gangliaUrl,
