ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject git commit: AMBARI-5864. Slider App endpoint should have DELETE method. (srimanth)
Date Fri, 23 May 2014 16:31:10 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 24ee41cc9 -> 546878b82


AMBARI-5864. Slider App endpoint should have DELETE method. (srimanth)


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

Branch: refs/heads/trunk
Commit: 546878b820f73fec3c92823a6e8dbd4beb183dac
Parents: 24ee41c
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Fri May 23 01:36:35 2014 -0700
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Fri May 23 09:30:52 2014 -0700

----------------------------------------------------------------------
 .../view/slider/SliderAppsResourceProvider.java | 19 +++--
 .../view/slider/SliderAppsViewController.java   | 11 +++
 .../slider/SliderAppsViewControllerImpl.java    | 74 ++++++++++++++++++--
 .../view/slider/rest/SliderAppsResource.java    | 14 ++++
 4 files changed, 108 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/546878b8/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsResourceProvider.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsResourceProvider.java
index 138a1ab..8d47769 100644
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsResourceProvider.java
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsResourceProvider.java
@@ -20,7 +20,6 @@ package org.apache.ambari.view.slider;
 
 import java.io.IOException;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -53,8 +52,16 @@ public class SliderAppsResourceProvider implements ResourceProvider<SliderApp>
{
 	@Override
 	public boolean deleteResource(String resourceId) throws SystemException,
 	    NoSuchResourceException, UnsupportedPropertyException {
-		// TODO Auto-generated method stub
-		return false;
+		try {
+			sliderController.deleteSliderApp(resourceId);
+			return true;
+		} catch (YarnException e) {
+			logger.warn("Unable to delete Slider app with id " + resourceId, e);
+			throw new SystemException(e.getMessage(), e);
+		} catch (IOException e) {
+			logger.warn("Unable to delete Slider app with id " + resourceId, e);
+			throw new SystemException(e.getMessage(), e);
+		}
 	}
 
 	@Override
@@ -62,7 +69,8 @@ public class SliderAppsResourceProvider implements ResourceProvider<SliderApp>
{
 	    throws SystemException, NoSuchResourceException,
 	    UnsupportedPropertyException {
 		try {
-			SliderApp sliderApp = sliderController.getSliderApp(resourceId, properties);
+			SliderApp sliderApp = sliderController.getSliderApp(resourceId,
+			    properties);
 			if (sliderApp == null)
 				throw new NoSuchResourceException(resourceId);
 			return sliderApp;
@@ -81,7 +89,8 @@ public class SliderAppsResourceProvider implements ResourceProvider<SliderApp>
{
 	    UnsupportedPropertyException {
 		Set<SliderApp> appSet = new HashSet<SliderApp>();
 		try {
-			List<SliderApp> sliderApps = sliderController.getSliderApps(request.getPropertyIds());
+			List<SliderApp> sliderApps = sliderController.getSliderApps(request
+			    .getPropertyIds());
 			for (SliderApp app : sliderApps)
 				appSet.add(app);
 		} catch (YarnException e) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/546878b8/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewController.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewController.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewController.java
index 90ff76c..0b368be 100644
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewController.java
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/SliderAppsViewController.java
@@ -57,4 +57,15 @@ public interface SliderAppsViewController {
 	 */
 	public List<SliderApp> getSliderApps(Set<String> properties)
 	    throws YarnException, IOException;
+
+	/**
+	 * Attempts to delete a Slider app. An unsuccessful attempt will result in
+	 * exception.
+	 * 
+	 * @param applicationId
+	 * @throws YarnException
+	 * @throws IOException
+	 */
+	public void deleteSliderApp(String applicationId) throws YarnException,
+	    IOException;
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/546878b8/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 6a884ce..8c3741f 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
@@ -19,8 +19,10 @@
 package org.apache.ambari.view.slider;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -36,16 +38,21 @@ import org.apache.ambari.view.slider.clients.AmbariServiceInfo;
 import org.apache.ambari.view.slider.rest.client.SliderAppMasterClient;
 import org.apache.ambari.view.slider.rest.client.SliderAppMasterClient.SliderAppMasterData;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
 import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.log4j.Logger;
 import org.apache.slider.api.ClusterDescription;
 import org.apache.slider.client.SliderClient;
 import org.apache.slider.common.SliderKeys;
+import org.apache.slider.common.tools.SliderFileSystem;
 import org.apache.slider.core.exceptions.UnknownApplicationInstanceException;
+import org.apache.slider.core.main.LauncherExitCodes;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -160,7 +167,7 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
 				try {
 					SliderClient sliderClient = getSliderClient();
 					ApplicationReport yarnApp = sliderClient.getApplicationReport(appId);
-					return populateSliderApp(yarnApp, properties, sliderClient);
+					return createSliderAppObject(yarnApp, properties, sliderClient);
 				} finally {
 					Thread.currentThread().setContextClassLoader(currentClassLoader);
 				}
@@ -169,16 +176,37 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
 		return null;
 	}
 
-	private SliderApp populateSliderApp(ApplicationReport yarnApp,
+	private SliderApp createSliderAppObject(ApplicationReport yarnApp,
 	    Set<String> properties, SliderClient sliderClient) {
 		if (yarnApp == null)
 			return null;
+
 		SliderApp app = new SliderApp();
+		app.setState(yarnApp.getYarnApplicationState().name());
+
+		// Valid Slider App?
+		// We want all Slider apps except the ones which properly finished.
+		if (YarnApplicationState.FINISHED.equals(yarnApp.getYarnApplicationState())) {
+			try {
+				if (sliderClient.actionExists(yarnApp.getName(), false) == LauncherExitCodes.EXIT_SUCCESS)
+					app.setState("FROZEN");
+			} catch (UnknownApplicationInstanceException e) {
+				return null; // Application not in HDFS - means it is not frozen
+			} catch (YarnException e) {
+				logger.warn(
+				    "Unable to determine frozen state for " + yarnApp.getName(), e);
+				return null;
+			} catch (IOException e) {
+				logger.warn(
+				    "Unable to determine frozen state for " + yarnApp.getName(), e);
+				return null;
+			}
+		}
+
 		app.setId(Long.toString(yarnApp.getApplicationId().getClusterTimestamp())
 		    + "_" + Integer.toString(yarnApp.getApplicationId().getId()));
 		app.setName(yarnApp.getName());
 		app.setUser(yarnApp.getUser());
-		app.setState(yarnApp.getYarnApplicationState().name());
 		app.setDiagnostics(yarnApp.getDiagnostics());
 		app.setYarnId(yarnApp.getApplicationId().toString());
 		app.setType(yarnApp.getApplicationType());
@@ -306,6 +334,18 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
 				public String getUsername() throws IOException {
 					return null;
 				}
+
+				@Override
+				protected void serviceInit(Configuration conf) throws Exception {
+					super.serviceInit(conf);
+					// Override the default FS client to set the super user.
+					FileSystem fs = FileSystem.get(FileSystem.getDefaultUri(getConfig()),
+					    getConfig(), "hdfs");
+					SliderFileSystem fileSystem = new SliderFileSystem(fs, getConfig());
+					Field fsField = SliderClient.class.getDeclaredField("sliderFileSystem");
+					fsField.setAccessible(true);
+					fsField.set(this, fileSystem);
+				}
 			};
 			try {
 				sliderClientConfiguration = client.bindArgs(sliderClientConfiguration,
@@ -383,13 +423,37 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
 		Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
 		try {
 			SliderClient sliderClient = getSliderClient();
-			List<ApplicationReport> yarnApps = sliderClient.getApplications();
+			List<ApplicationReport> yarnApps = sliderClient.listSliderInstances(null);
 			for (ApplicationReport yarnApp : yarnApps) {
-				sliderApps.add(populateSliderApp(yarnApp, properties, sliderClient));
+				SliderApp sliderAppObject = createSliderAppObject(yarnApp, properties,
+				    sliderClient);
+				if (sliderAppObject != null)
+					sliderApps.add(sliderAppObject);
 			}
 		} finally {
 			Thread.currentThread().setContextClassLoader(currentClassLoader);
 		}
 		return sliderApps;
 	}
+
+	@Override
+	public void deleteSliderApp(String applicationId) throws YarnException,
+	    IOException {
+		ClassLoader currentClassLoader = Thread.currentThread()
+		    .getContextClassLoader();
+		Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+		try {
+			Set<String> properties = new HashSet<String>();
+			properties.add("id");
+			properties.add("name");
+			SliderApp sliderApp = getSliderApp(applicationId, properties);
+			if (sliderApp == null)
+				throw new ApplicationNotFoundException(applicationId);
+
+			SliderClient sliderClient = getSliderClient();
+			sliderClient.actionDestroy(sliderApp.getName());
+		} finally {
+			Thread.currentThread().setContextClassLoader(currentClassLoader);
+		}
+	}
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/546878b8/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
index 2769f57..a221610 100644
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
@@ -18,6 +18,9 @@
 
 package org.apache.ambari.view.slider.rest;
 
+import java.io.IOException;
+
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -29,6 +32,8 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.ambari.view.ViewResourceHandler;
+import org.apache.ambari.view.slider.SliderAppsViewController;
+import org.apache.hadoop.yarn.exceptions.YarnException;
 
 import com.google.inject.Inject;
 
@@ -36,6 +41,8 @@ public class SliderAppsResource {
 
 	@Inject
 	ViewResourceHandler resourceHandler;
+	@Inject
+	SliderAppsViewController sliderAppsViewController;
 
 	@GET
 	@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@@ -51,4 +58,11 @@ public class SliderAppsResource {
 		return resourceHandler.handleRequest(headers, uri, appId);
 	}
 
+	@DELETE
+	@Path("{appId}")
+	public void deleteApp(@Context HttpHeaders headers, @Context UriInfo uri,
+	    @PathParam("appId") String appId) throws YarnException, IOException {
+		sliderAppsViewController.deleteSliderApp(appId);
+	}
+
 }


Mime
View raw message