Преглед изворни кода

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

Srimanth Gunturi пре 10 година
родитељ
комит
cae2fc4d5b

+ 4 - 0
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;
 }

+ 38 - 6
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);
+  }
+
 }

+ 19 - 2
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

+ 8 - 1
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 {
       }
     }
   }
-
 }