ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject git commit: AMBARI-7914. Slider View: Need API to verify using slider-client if application name can be used (srimanth)
Date Thu, 23 Oct 2014 05:33:06 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.7.0 4b2c827c5 -> fbb17091e


AMBARI-7914. Slider View: Need API to verify using slider-client if application name can be
used (srimanth)


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

Branch: refs/heads/branch-1.7.0
Commit: fbb17091ee83de2d8cb9ea22d93d7798347446f4
Parents: 4b2c827
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Wed Oct 22 19:43:19 2014 -0700
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Wed Oct 22 19:43:19 2014 -0700

----------------------------------------------------------------------
 .../view/slider/SliderAppsViewController.java   |  2 ++
 .../slider/SliderAppsViewControllerImpl.java    | 19 +++++++++++++++++-
 .../view/slider/rest/SliderAppsResource.java    | 21 ++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fbb17091/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 2d82bfb..4cdecf7 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
@@ -104,4 +104,6 @@ public interface SliderAppsViewController {
 
   public void flexApp(String appId, Map<String, Integer> componentsMap)
       throws YarnException, IOException, InterruptedException;
+
+  public boolean appExists(String string) throws IOException, InterruptedException, YarnException;
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbb17091/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 88afbb8..1c87d57 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
@@ -506,6 +506,23 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
   }
 
   @Override
+  public boolean appExists(final String appName) throws IOException, InterruptedException,
YarnException {
+    return invokeSliderClientRunnable(new SliderClientContextRunnable<Boolean>() {
+      @Override
+      public Boolean run(SliderClient sliderClient) throws YarnException, IOException {
+        if (appName != null) {
+          try {
+            return sliderClient.actionExists(appName, false) == SliderClient.EXIT_SUCCESS;
+          } catch (UnknownApplicationInstanceException e) {
+            return Boolean.FALSE;
+          }
+        }
+        return Boolean.FALSE;
+      }
+    });
+  }
+
+  @Override
   public SliderApp getSliderApp(final String applicationId, final Set<String> properties)
      throws YarnException, IOException, InterruptedException {
     return invokeSliderClientRunnable(new SliderClientContextRunnable<SliderApp>()
{
@@ -949,7 +966,7 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
                 String key = e.getKey();
                 String valueString = e.getValue().getAsString();
                 if ("application.def".equals(key)) {
-                  valueString = String.format(".slider/package/%1$s/%2$s", application.getName(),
appZip.getName());
+                  valueString = String.format(".slider/package/%s/%s", application.getName(),
appZip.getName());
                 }
                 configsMap.put(key, valueString);
               }

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbb17091/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 39f3184..9d17bce 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
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -36,7 +37,9 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.ambari.view.ViewResourceHandler;
@@ -61,6 +64,24 @@ public class SliderAppsResource {
   @GET
   @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
   public Response getApps(@Context HttpHeaders headers, @Context UriInfo uri) {
+    MultivaluedMap<String, String> queryParameters = uri.getQueryParameters();
+    if (queryParameters != null && queryParameters.containsKey("validateAppName"))
{
+      List<String> appNames = queryParameters.get("validateAppName");
+      if (appNames.size() > 0) {
+        try {
+          if (sliderAppsViewController.appExists(appNames.get(0))) {
+            return Response.status(Status.CONFLICT).build();
+          }
+        } catch (IOException e) {
+          logger.warn("Unable to validate cluster name", e);
+        } catch (InterruptedException e) {
+          logger.warn("Unable to validate cluster name", e);
+        } catch (YarnException e) {
+          logger.warn("Unable to validate cluster name", e);
+        }
+        return Response.ok().build();
+      }
+    }
     return resourceHandler.handleRequest(headers, uri, null);
   }
 


Mime
View raw message