ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject git commit: AMBARI-5803. Implement Slider Apps View status endpoint - direct API. (srimanth)
Date Mon, 19 May 2014 23:40:33 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 9312b89d0 -> e03d24283


AMBARI-5803. Implement Slider Apps View status endpoint - direct API. (srimanth)


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

Branch: refs/heads/trunk
Commit: e03d242834f1855f0472670fb3d3511952e7f3e4
Parents: 9312b89
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Mon May 19 15:53:43 2014 -0700
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Mon May 19 16:27:49 2014 -0700

----------------------------------------------------------------------
 contrib/views/slider/pom.xml                    |   8 +
 .../slider/SliderAppsViewControllerImpl.java    |  81 ++++---
 .../view/slider/clients/AmbariClient.java       |  39 ++++
 .../view/slider/clients/AmbariCluster.java      |  52 +++++
 .../view/slider/clients/AmbariClusterInfo.java  |  40 ++++
 .../view/slider/clients/AmbariHostInfo.java     |  32 +++
 .../slider/clients/AmbariInternalClient.java    | 209 +++++++++++++++++++
 .../view/slider/clients/AmbariServiceInfo.java  |  42 ++++
 .../view/slider/rest/client/AmbariCluster.java  |  52 -----
 .../slider/rest/client/AmbariClusterInfo.java   |  40 ----
 .../slider/rest/client/AmbariHttpClient.java    |  49 +----
 .../view/slider/rest/client/AmbariService.java  |  42 ----
 12 files changed, 467 insertions(+), 219 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/views/slider/pom.xml b/contrib/views/slider/pom.xml
index 477669f..de7c3a5 100644
--- a/contrib/views/slider/pom.xml
+++ b/contrib/views/slider/pom.xml
@@ -93,12 +93,19 @@
 		<dependency>
 			<groupId>org.apache.ambari</groupId>
 			<artifactId>ambari-views</artifactId>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>com.google.code.gson</groupId>
 			<artifactId>gson</artifactId>
 			<version>2.2.2</version>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.ambari</groupId>
+			<artifactId>ambari-server</artifactId>
+			<version>${ambari.version}</version>
+			<scope>provided</scope>
+		</dependency>
 	</dependencies>
 
 	<repositories>
@@ -114,6 +121,7 @@
 		<nodejs.directory>${basedir}/target/nodejs</nodejs.directory>
 		<npm.version>1.4.3</npm.version>
 		<ui.directory>${basedir}/src/main/resources/ui</ui.directory>
+		<ambari.version>1.3.0-SNAPSHOT</ambari.version>
 	</properties>
 	<build>
 		<plugins>

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/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 57275fc..c6461a5 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
@@ -23,10 +23,11 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.slider.rest.client.AmbariCluster;
-import org.apache.ambari.view.slider.rest.client.AmbariClusterInfo;
-import org.apache.ambari.view.slider.rest.client.AmbariHttpClient;
-import org.apache.ambari.view.slider.rest.client.AmbariService;
+import org.apache.ambari.view.slider.clients.AmbariClient;
+import org.apache.ambari.view.slider.clients.AmbariCluster;
+import org.apache.ambari.view.slider.clients.AmbariClusterInfo;
+import org.apache.ambari.view.slider.clients.AmbariServiceInfo;
+import org.apache.log4j.Logger;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -34,63 +35,55 @@ import com.google.inject.Singleton;
 @Singleton
 public class SliderAppsViewControllerImpl implements SliderAppsViewController {
 
+	private static final Logger logger = Logger
+	    .getLogger(SliderAppsViewControllerImpl.class);
 	@Inject
 	private ViewContext viewContext;
-	private AmbariHttpClient ambariClient;
-
-	private AmbariHttpClient getAmbariClient() {
-		// TODO Calculate Ambari location dynamically
-		if (ambariClient == null)
-			ambariClient = new AmbariHttpClient("http://localhost:8080",
-			    viewContext.getUsername(), "admin");
-		return ambariClient;
-	}
+	@Inject
+	private AmbariClient ambariClient;
 
 	@Override
 	public ViewStatus getViewStatus() {
 		ViewStatus status = new ViewStatus();
 		List<String> viewErrors = new ArrayList<String>();
 
-		AmbariHttpClient client = getAmbariClient();
-		AmbariClusterInfo clusterInfo = client.getClusterInfo();
+		AmbariClusterInfo clusterInfo = ambariClient.getClusterInfo();
 		if (clusterInfo != null) {
-			AmbariCluster cluster = client.getCluster(clusterInfo);
-			List<String> services = cluster.getServices();
-			if (services != null && services.size() > 0) {
-				boolean zkFound = services.indexOf("ZOOKEEPER") > -1;
-				boolean hdfsFound = services.indexOf("HDFS") > -1;
-				boolean yarnFound = services.indexOf("YARN") > -1;
-				if (!hdfsFound) {
+			AmbariCluster cluster = ambariClient.getCluster(clusterInfo);
+			List<AmbariServiceInfo> services = cluster.getServices();
+			if (services != null && !services.isEmpty()) {
+				AmbariServiceInfo hdfsService = null, yarnService = null, zkService = null;
+				for (AmbariServiceInfo service : services) {
+					if ("HDFS".equals(service.getId())) {
+						hdfsService = service;
+					} else if ("YARN".equals(service.getId())) {
+						yarnService = service;
+					} else if ("ZOOKEEPER".equals(service.getId())) {
+						zkService = service;
+					}
+				}
+				if (hdfsService == null) {
 					viewErrors.add("Slider applications view requires HDFS service");
 				} else {
-					AmbariService service = client.getService(clusterInfo, "HDFS");
-					if (service != null) {
-						if (!service.isStarted()) {
-							viewErrors
-							    .add("Slider applications view requires HDFS service to be started");
-						}
+					if (!hdfsService.isStarted()) {
+						viewErrors
+						    .add("Slider applications view requires HDFS service to be started");
 					}
 				}
-				if (!yarnFound) {
+				if (yarnService == null) {
 					viewErrors.add("Slider applications view requires YARN service");
 				} else {
-					AmbariService service = client.getService(clusterInfo, "YARN");
-					if (service != null) {
-						if (!service.isStarted()) {
-							viewErrors
-							    .add("Slider applications view requires YARN service to be started");
-						}
+					if (!yarnService.isStarted()) {
+						viewErrors
+						    .add("Slider applications view requires YARN service to be started");
 					}
 				}
-				if (!zkFound) {
+				if (zkService == null) {
 					viewErrors.add("Slider applications view requires ZooKeeper service");
 				} else {
-					AmbariService service = client.getService(clusterInfo, "ZOOKEEPER");
-					if (service != null) {
-						if (!service.isStarted()) {
-							viewErrors
-							    .add("Slider applications view requires ZooKeeper service to be started");
-						}
+					if (!zkService.isStarted()) {
+						viewErrors
+						    .add("Slider applications view requires ZooKeeper service to be started");
 					}
 				}
 			} else {
@@ -100,8 +93,8 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
 			// Check security
 			if (cluster.getDesiredConfigs() != null
 			    && cluster.getDesiredConfigs().containsKey("global")) {
-				Map<String, String> globalConfig = client.getConfiguration(clusterInfo,
-				    "global", cluster.getDesiredConfigs().get("global"));
+				Map<String, String> globalConfig = ambariClient.getConfiguration(
+				    clusterInfo, "global", cluster.getDesiredConfigs().get("global"));
 				if (globalConfig != null
 				    && globalConfig.containsKey("security_enabled")) {
 					String securityValue = globalConfig.get("security_enabled");

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClient.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClient.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClient.java
new file mode 100644
index 0000000..da3c25b
--- /dev/null
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClient.java
@@ -0,0 +1,39 @@
+/**
+ * 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.slider.clients;
+
+import java.util.Map;
+
+import com.google.inject.ImplementedBy;
+
+@ImplementedBy(AmbariInternalClient.class)
+public interface AmbariClient {
+
+	public AmbariCluster getCluster(AmbariClusterInfo clusterInfo);
+
+	/**
+	 * Provides the first cluster defined on this Ambari server.
+	 * 
+	 * @return
+	 */
+	public AmbariClusterInfo getClusterInfo();
+
+	public Map<String, String> getConfiguration(AmbariClusterInfo cluster,
+	    String configType, String configTag);
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariCluster.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariCluster.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariCluster.java
new file mode 100644
index 0000000..2ca2f16
--- /dev/null
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariCluster.java
@@ -0,0 +1,52 @@
+/**
+ * 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.slider.clients;
+
+import java.util.List;
+import java.util.Map;
+
+public class AmbariCluster extends AmbariClusterInfo {
+	private Map<String, String> desiredConfigs;
+	private List<AmbariServiceInfo> services;
+	private List<AmbariHostInfo> hosts;
+
+	public Map<String, String> getDesiredConfigs() {
+		return desiredConfigs;
+	}
+
+	public void setDesiredConfigs(Map<String, String> desiredConfigs) {
+		this.desiredConfigs = desiredConfigs;
+	}
+
+	public List<AmbariServiceInfo> getServices() {
+		return services;
+	}
+
+	public void setServices(List<AmbariServiceInfo> services) {
+		this.services = services;
+	}
+
+	public List<AmbariHostInfo> getHosts() {
+		return hosts;
+	}
+
+	public void setHosts(List<AmbariHostInfo> hosts) {
+		this.hosts = hosts;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClusterInfo.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClusterInfo.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClusterInfo.java
new file mode 100644
index 0000000..a532b52
--- /dev/null
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariClusterInfo.java
@@ -0,0 +1,40 @@
+/**
+ * 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.slider.clients;
+
+public class AmbariClusterInfo {
+	private String name;
+	private String version;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getVersion() {
+		return version;
+	}
+
+	public void setVersion(String version) {
+		this.version = version;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariHostInfo.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariHostInfo.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariHostInfo.java
new file mode 100644
index 0000000..f522cf3
--- /dev/null
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariHostInfo.java
@@ -0,0 +1,32 @@
+/**
+ * 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.slider.clients;
+
+public class AmbariHostInfo {
+
+	private String hostName;
+
+	public String getHostName() {
+		return hostName;
+	}
+
+	public void setHostName(String hostName) {
+		this.hostName = hostName;
+	}
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariInternalClient.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariInternalClient.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariInternalClient.java
new file mode 100644
index 0000000..86c760f
--- /dev/null
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariInternalClient.java
@@ -0,0 +1,209 @@
+/**
+ * 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.slider.clients;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.controller.predicate.AndPredicate;
+import org.apache.ambari.server.controller.predicate.EqualsPredicate;
+import org.apache.ambari.server.controller.spi.ClusterController;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.state.DesiredConfig;
+import org.apache.ambari.server.state.State;
+import org.apache.log4j.Logger;
+
+import com.google.inject.Singleton;
+
+@Singleton
+public class AmbariInternalClient implements AmbariClient {
+
+	private static final Logger logger = Logger
+	    .getLogger(AmbariInternalClient.class);
+
+	@Override
+	public AmbariCluster getCluster(AmbariClusterInfo clusterInfo) {
+		ClusterController clusterController = ClusterControllerHelper
+		    .getClusterController();
+		try {
+			EqualsPredicate<String> clusterPredicate = new EqualsPredicate<String>(
+			    "Clusters/cluster_name", clusterInfo.getName());
+			Set<Resource> clusterResources = clusterController.getResources(
+			    Resource.Type.Cluster, PropertyHelper.getReadRequest(),
+			    clusterPredicate);
+			if (!clusterResources.isEmpty()) {
+				Resource clusterResource = clusterResources.iterator().next();
+				AmbariCluster cluster = new AmbariCluster();
+				cluster.setName(clusterResource.getPropertyValue(
+				    "Clusters/cluster_name").toString());
+				cluster.setVersion(clusterResource.getPropertyValue("Clusters/version")
+				    .toString());
+				Map<String, String> desiredConfigsMap = new HashMap<String, String>();
+				Map<String, Object> desiredConfigsMapResource = clusterResource
+				    .getPropertiesMap().get("Clusters/desired_configs");
+				for (Map.Entry<String, Object> siteEntry : desiredConfigsMapResource
+				    .entrySet()) {
+					desiredConfigsMap.put(siteEntry.getKey(),
+					    ((DesiredConfig) siteEntry.getValue()).getVersion());
+				}
+				cluster.setDesiredConfigs(desiredConfigsMap);
+
+				EqualsPredicate<String> serviceClusterPredicate = new EqualsPredicate<String>(
+				    "ServiceInfo/cluster_name", cluster.getName());
+				EqualsPredicate<String> hostClusterPredicate = new EqualsPredicate<String>(
+				    "Hosts/cluster_name", cluster.getName());
+				Set<Resource> serviceResources = clusterController.getResources(
+				    Resource.Type.Service, PropertyHelper.getReadRequest(),
+				    serviceClusterPredicate);
+				Set<Resource> hostResources = clusterController.getResources(
+				    Resource.Type.Host, PropertyHelper.getReadRequest(),
+				    hostClusterPredicate);
+				List<AmbariServiceInfo> servicesList = new ArrayList<AmbariServiceInfo>();
+				List<AmbariHostInfo> hostsList = new ArrayList<AmbariHostInfo>();
+				for (Resource serviceResource : serviceResources) {
+					AmbariServiceInfo service = new AmbariServiceInfo();
+					service.setId(serviceResource.getPropertyValue(
+					    "ServiceInfo/service_name").toString());
+					service.setStarted(State.STARTED.toString().equals(
+					    serviceResource.getPropertyValue("ServiceInfo/state")));
+					servicesList.add(service);
+				}
+				for (Resource hostResource : hostResources) {
+					AmbariHostInfo host = new AmbariHostInfo();
+					host.setHostName(hostResource.getPropertyValue("Hosts/host_name")
+					    .toString());
+					hostsList.add(host);
+				}
+				cluster.setServices(servicesList);
+				cluster.setHosts(hostsList);
+				return cluster;
+			}
+		} catch (UnsupportedPropertyException e) {
+			logger.warn(
+			    "Unable to determine Ambari cluster details - "
+			        + clusterInfo.getName(), e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (NoSuchResourceException e) {
+			logger.warn(
+			    "Unable to determine Ambari cluster details - "
+			        + clusterInfo.getName(), e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (NoSuchParentResourceException e) {
+			logger.warn(
+			    "Unable to determine Ambari cluster details - "
+			        + clusterInfo.getName(), e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (SystemException e) {
+			logger.warn(
+			    "Unable to determine Ambari cluster details - "
+			        + clusterInfo.getName(), e);
+			throw new RuntimeException(e.getMessage(), e);
+		}
+		return null;
+	}
+
+	@Override
+	public AmbariClusterInfo getClusterInfo() {
+		ClusterController clusterController = ClusterControllerHelper
+		    .getClusterController();
+		try {
+			Set<Resource> resources = clusterController.getResources(
+			    Resource.Type.Cluster, PropertyHelper.getReadRequest(), null);
+			if (resources.size() > 0) {
+				Resource clusterResource = resources.iterator().next();
+				AmbariClusterInfo clusterInfo = new AmbariClusterInfo();
+				clusterInfo.setName(clusterResource.getPropertyValue(
+				    "Clusters/cluster_name").toString());
+				clusterInfo.setVersion(clusterResource.getPropertyValue(
+				    "Clusters/version").toString());
+				return clusterInfo;
+			}
+		} catch (UnsupportedPropertyException e) {
+			logger.warn("Unable to determine Ambari cluster", e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (NoSuchResourceException e) {
+			logger.warn("Unable to determine Ambari cluster", e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (NoSuchParentResourceException e) {
+			logger.warn("Unable to determine Ambari cluster", e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (SystemException e) {
+			logger.warn("Unable to determine Ambari cluster", e);
+			throw new RuntimeException(e.getMessage(), e);
+		}
+		return null;
+	}
+
+	@Override
+	public Map<String, String> getConfiguration(AmbariClusterInfo cluster,
+	    String configType, String configTag) {
+		ClusterController clusterController = ClusterControllerHelper
+		    .getClusterController();
+		try {
+			EqualsPredicate<String> clusterPredicate = new EqualsPredicate<String>(
+			    "Config/cluster_name", cluster.getName());
+			EqualsPredicate<String> typePredicate = new EqualsPredicate<String>(
+			    "type", configType);
+			EqualsPredicate<String> tagPredicate = new EqualsPredicate<String>("tag",
+			    configTag);
+			AndPredicate typeTagPredicate = new AndPredicate(typePredicate,
+			    tagPredicate);
+			AndPredicate configsPredicate = new AndPredicate(clusterPredicate,
+			    typeTagPredicate);
+
+			Set<Resource> configResources = clusterController.getResources(
+			    Resource.Type.Configuration, PropertyHelper.getReadRequest(),
+			    configsPredicate);
+			if (!configResources.isEmpty()) {
+				Resource configResource = configResources.iterator().next();
+				Map<String, String> configs = new HashMap<String, String>();
+				Object props = configResource.getPropertiesMap().get("properties");
+				if (props instanceof Map) {
+					@SuppressWarnings("unchecked")
+					Map<String, String> propsMap = (Map<String, String>) props;
+					configs.putAll(propsMap);
+				}
+				return configs;
+			}
+		} catch (UnsupportedPropertyException e) {
+			logger.warn("Unable to determine Ambari cluster configuration", e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (NoSuchResourceException e) {
+			logger.warn("Unable to determine Ambari cluster configuration", e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (NoSuchParentResourceException e) {
+			logger.warn("Unable to determine Ambari cluster configuration", e);
+			throw new RuntimeException(e.getMessage(), e);
+		} catch (SystemException e) {
+			logger.warn("Unable to determine Ambari cluster configuration", e);
+			throw new RuntimeException(e.getMessage(), e);
+		}
+		return null;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java
new file mode 100644
index 0000000..7b7009c
--- /dev/null
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java
@@ -0,0 +1,42 @@
+/**
+ * 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.slider.clients;
+
+public class AmbariServiceInfo {
+
+	private String id;
+	private boolean started;
+
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	public boolean isStarted() {
+	  return started;
+  }
+
+	public void setStarted(boolean started) {
+	  this.started = started;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariCluster.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariCluster.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariCluster.java
deleted file mode 100644
index 381a65d..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariCluster.java
+++ /dev/null
@@ -1,52 +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.slider.rest.client;
-
-import java.util.List;
-import java.util.Map;
-
-public class AmbariCluster extends AmbariClusterInfo {
-	private Map<String, String> desiredConfigs;
-	private List<String> services;
-	private List<String> hosts;
-
-	public Map<String, String> getDesiredConfigs() {
-		return desiredConfigs;
-	}
-
-	public void setDesiredConfigs(Map<String, String> desiredConfigs) {
-		this.desiredConfigs = desiredConfigs;
-	}
-
-	public List<String> getServices() {
-		return services;
-	}
-
-	public void setServices(List<String> services) {
-		this.services = services;
-	}
-
-	public List<String> getHosts() {
-		return hosts;
-	}
-
-	public void setHosts(List<String> hosts) {
-		this.hosts = hosts;
-	}
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariClusterInfo.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariClusterInfo.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariClusterInfo.java
deleted file mode 100644
index 56f57a3..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariClusterInfo.java
+++ /dev/null
@@ -1,40 +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.slider.rest.client;
-
-public class AmbariClusterInfo {
-	private String name;
-	private String version;
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public String getVersion() {
-		return version;
-	}
-
-	public void setVersion(String version) {
-		this.version = version;
-	}
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/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 b4c780d..f23950c 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
@@ -24,6 +24,11 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ambari.view.slider.clients.AmbariClient;
+import org.apache.ambari.view.slider.clients.AmbariCluster;
+import org.apache.ambari.view.slider.clients.AmbariClusterInfo;
+import org.apache.ambari.view.slider.clients.AmbariHostInfo;
+import org.apache.ambari.view.slider.clients.AmbariServiceInfo;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.log4j.Logger;
 
@@ -31,7 +36,7 @@ import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 
-public class AmbariHttpClient extends BaseHttpClient {
+public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
 
 	private static final Logger logger = Logger.getLogger(AmbariHttpClient.class);
 
@@ -86,22 +91,10 @@ public class AmbariHttpClient extends BaseHttpClient {
 					}
 					cluster.setDesiredConfigs(desiredConfigs);
 					// services
-					List<String> services = new ArrayList<String>();
-					JsonArray servicesArray = jsonElement.getAsJsonObject()
-					    .get("services").getAsJsonArray();
-					for (JsonElement entry : servicesArray) {
-						services.add(entry.getAsJsonObject().get("ServiceInfo")
-						    .getAsJsonObject().get("service_name").getAsString());
-					}
+					List<AmbariServiceInfo> services = new ArrayList<AmbariServiceInfo>();
 					cluster.setServices(services);
 					// hosts
-					List<String> hosts = new ArrayList<String>();
-					JsonArray hostsArray = jsonElement.getAsJsonObject().get("hosts")
-					    .getAsJsonArray();
-					for (JsonElement entry : hostsArray) {
-						hosts.add(entry.getAsJsonObject().get("Hosts").getAsJsonObject()
-						    .get("host_name").getAsString());
-					}
+					List<AmbariHostInfo> hosts = new ArrayList<AmbariHostInfo>();
 					cluster.setHosts(hosts);
 					return cluster;
 				}
@@ -118,32 +111,6 @@ public class AmbariHttpClient extends BaseHttpClient {
 		return null;
 	}
 
-	public AmbariService getService(AmbariClusterInfo clusterInfo,
-	    String serviceId) {
-		if (clusterInfo != null) {
-			try {
-				JsonElement jsonElement = doGetJson("/api/v1/clusters/"
-				    + clusterInfo.getName() + "/services/" + serviceId);
-				if (jsonElement != null) {
-					AmbariService service = new AmbariService();
-					String serviceState = jsonElement.getAsJsonObject()
-					    .get("ServiceInfo").getAsJsonObject().get("state").getAsString();
-					service.setStarted("STARTED".equals(serviceState));
-					return service;
-				}
-			} catch (HttpException e) {
-				logger.warn(
-				    "Unable to determine Ambari service details - " + serviceId, e);
-				throw new RuntimeException(e.getMessage(), e);
-			} catch (IOException e) {
-				logger.warn(
-				    "Unable to determine Ambari cluster details - " + serviceId, e);
-				throw new RuntimeException(e.getMessage(), e);
-			}
-		}
-		return null;
-	}
-
 	public Map<String, String> getConfiguration(AmbariClusterInfo cluster,
 	    String configType, String configTag) {
 		if (cluster != null && configType != null && configTag != null) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/e03d2428/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariService.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariService.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariService.java
deleted file mode 100644
index 527ea2d..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariService.java
+++ /dev/null
@@ -1,42 +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.slider.rest.client;
-
-public class AmbariService {
-
-	private String id;
-	private boolean started;
-
-	public String getId() {
-		return id;
-	}
-
-	public void setId(String id) {
-		this.id = id;
-	}
-
-	public boolean isStarted() {
-	  return started;
-  }
-
-	public void setStarted(boolean started) {
-	  this.started = started;
-  }
-
-}


Mime
View raw message