ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject git commit: AMBARI-7351. Slider View: Flex API call throws 400-Bad Request (srimanth)
Date Wed, 17 Sep 2014 02:48:35 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 19533465d -> cae2fc4d5


AMBARI-7351. Slider View: Flex API call throws 400-Bad Request (srimanth)


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

Branch: refs/heads/trunk
Commit: cae2fc4d5bdf2ea1234191e9e9cdd8d4eb299825
Parents: 1953346
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Tue Sep 16 19:41:47 2014 -0700
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Tue Sep 16 19:41:54 2014 -0700

----------------------------------------------------------------------
 .../view/slider/SliderAppsViewController.java   |  4 ++
 .../slider/SliderAppsViewControllerImpl.java    | 44 +++++++++++++++++---
 .../view/slider/rest/SliderAppsResource.java    | 21 +++++++++-
 .../ambari/view/slider/rest/client/Metric.java  |  9 +++-
 4 files changed, 69 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/cae2fc4d/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 93c63f2..64ab78c 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
@@ -20,6 +20,7 @@ package org.apache.ambari.view.slider;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.hadoop.yarn.exceptions.YarnException;
@@ -90,4 +91,7 @@ public interface SliderAppsViewController {
 
   public void thawApp(String appId) throws YarnException, IOException,
       InterruptedException;
+
+  public void flexApp(String appId, Map<String, Integer> componentsMap)
+      throws YarnException, IOException, InterruptedException;
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/cae2fc4d/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 f3c3087..5d6c368 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
@@ -26,7 +26,6 @@ import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -44,7 +43,6 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.filefilter.RegexFileFilter;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
@@ -58,6 +56,7 @@ import org.apache.slider.api.ClusterDescription;
 import org.apache.slider.client.SliderClient;
 import org.apache.slider.common.SliderKeys;
 import org.apache.slider.common.params.ActionCreateArgs;
+import org.apache.slider.common.params.ActionFlexArgs;
 import org.apache.slider.common.params.ActionFreezeArgs;
 import org.apache.slider.common.params.ActionInstallPackageArgs;
 import org.apache.slider.common.params.ActionThawArgs;
@@ -250,10 +249,12 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
                 List<SliderAppType> appTypes = getSliderAppTypes(null);
                 if (appTypes != null && appTypes.size() > 0) {
                   for (SliderAppType appType : appTypes) {
-                    logger.info("TYPE: " + appType.getTypeName() + "   "
-                        + app.getType());
-                    logger.info("VERSION: " + appType.getTypeVersion() + "   "
-                        + app.getAppVersion());
+                    if (logger.isDebugEnabled()) {
+                      logger.debug("TYPE: " + appType.getTypeName() + "   "
+                          + app.getType());
+                      logger.debug("VERSION: " + appType.getTypeVersion() + "   "
+                          + app.getAppVersion());
+                    }
                     if ((appType.getTypeName() != null && appType.getTypeName()
                         .equalsIgnoreCase(app.getType()))
                         && (appType.getTypeVersion() != null && appType
@@ -588,6 +589,8 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
                 appTypeComponent.setName(component.getName());
                 appTypeComponent.setYarnMemory(1024);
                 appTypeComponent.setYarnCpuCores(1);
+                // Updated below if present in resources.json
+                appTypeComponent.setInstanceCount(1);
                 // appTypeComponent.setPriority(component.);
                 if (component.getMinInstanceCount() != null) {
                   appTypeComponent.setInstanceCount(Integer.parseInt(component
@@ -819,4 +822,33 @@ public class SliderAppsViewControllerImpl implements SliderAppsViewController
{
     });
     logger.info("Thawed Slider App [" + appId + "] with response: " + applicationId.toString());
   }
+
+  @Override
+  public void flexApp(final String appId, final Map<String, Integer> componentsMap)
+      throws YarnException, IOException, InterruptedException {
+    ApplicationId applicationId = invokeSliderClientRunnable(new SliderClientContextRunnable<ApplicationId>()
{
+      @Override
+      public ApplicationId run(SliderClient sliderClient) throws YarnException,
+          IOException, InterruptedException {
+        Set<String> properties = new HashSet<String>();
+        properties.add("id");
+        properties.add("name");
+        final SliderApp sliderApp = getSliderApp(appId, properties);
+        if (sliderApp == null) {
+          throw new ApplicationNotFoundException(appId);
+        }
+        ActionFlexArgs flexArgs = new ActionFlexArgs();
+        flexArgs.parameters.add(sliderApp.getName());
+        for (Entry<String, Integer> e : componentsMap.entrySet()) {
+          flexArgs.componentDelegate.componentTuples.add(e.getKey());
+          flexArgs.componentDelegate.componentTuples.add(e.getValue()
+              .toString());
+        }
+        sliderClient.actionFlex(sliderApp.getName(), flexArgs);
+        return sliderClient.applicationId;
+      }
+    });
+    logger.info("Flexed Slider App [" + appId + "] with response: " + applicationId);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/cae2fc4d/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 68f363b..39f3184 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
@@ -21,6 +21,9 @@ package org.apache.ambari.view.slider.rest;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -88,11 +91,25 @@ public class SliderAppsResource {
         JsonObject requestJson = requestContent.getAsJsonObject();
         if (requestJson.has("state")) {
           String newState = requestJson.get("state").getAsString();
-          if ("FROZEN".equals(newState))
+          if ("FROZEN".equals(newState)) {
             sliderAppsViewController.freezeApp(appId);
-          else if ("RUNNING".equals(newState))
+            return Response.ok().build();
+          } else if ("RUNNING".equals(newState)) {
             sliderAppsViewController.thawApp(appId);
+            return Response.ok().build();
+          }
         } else if (requestJson.has("components")) {
+          Map<String, Integer> componentsMap = new HashMap<String, Integer>();
+          JsonObject componentsJson = requestJson.get("components")
+              .getAsJsonObject();
+          for (Entry<String, JsonElement> e : componentsJson.entrySet()) {
+            String componentName = e.getKey();
+            int instanceCount = e.getValue().getAsJsonObject()
+                .get("instanceCount").getAsInt();
+            componentsMap.put(componentName, instanceCount);
+          }
+          sliderAppsViewController.flexApp(appId, componentsMap);
+          return Response.ok().build();
         }
       }
       String sliderApp = sliderAppsViewController

http://git-wip-us.apache.org/repos/asf/ambari/blob/cae2fc4d/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
index 4bbeb2f..3f5a39d 100644
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
+++ b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
@@ -20,6 +20,7 @@ package org.apache.ambari.view.slider.rest.client;
 
 import org.apache.log4j.Logger;
 import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
 
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathExpression;
@@ -29,6 +30,7 @@ import javax.xml.xpath.XPathFactory;
 import java.util.ArrayList;
 import java.util.List;
 
+@JsonIgnoreProperties({"keyName", "matchers", "xPathExpression", "xPathExpressionComputed"})
 public class Metric {
   private static final Logger logger = Logger
       .getLogger(Metric.class);
@@ -37,9 +39,13 @@ public class Metric {
   private String metric;
   private boolean pointInTime;
   private boolean temporal;
+  @JsonIgnore
   private String keyName = null;
+  @JsonIgnore
   private List<List<String>> matchers = null;
+  @JsonIgnore
   private XPathExpression xPathExpression = null;
+  @JsonIgnore
   private boolean xPathExpressionComputed = false;
 
   private Metric() {
@@ -93,6 +99,7 @@ public class Metric {
     return xPathExpression;
   }
 
+  @JsonIgnore
   public String getJmxBeanKeyName() {
     if (keyName == null) {
       int firstIndex = metric.indexOf(SEPARATOR);
@@ -109,6 +116,7 @@ public class Metric {
    *
    * @return
    */
+  @JsonIgnore
   public List<List<String>> getMatchers() {
     if (matchers == null) {
       List<List<String>> tmpMatchers = new ArrayList<List<String>>();
@@ -146,5 +154,4 @@ public class Metric {
       }
     }
   }
-
 }


Mime
View raw message