Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 3b525a7cb -> 0d22cd045


Batch requests(Rolling Restart, HSI enable/disable, decommission/recommission) 
not working when Ambari is configured with Knox proxy. (jaimin)


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

Branch: refs/heads/branch-2.6
Commit: 0d22cd045d915e5c495e3935b66ea300cf591874
Parents: 3b525a7
Author: Jaimin Jetly <jai...@hortonworks.com>
Authored: Mon Sep 18 10:59:35 2017 -0700
Committer: Jaimin Jetly <jai...@hortonworks.com>
Committed: Mon Sep 18 11:16:27 2017 -0700

----------------------------------------------------------------------
 .../scheduler/ExecutionScheduleManager.java     | 23 +++++++++++--
 .../scheduler/ExecutionScheduleManagerTest.java | 36 ++++++++++++++++++++
 ambari-web/app/controllers/main/host/details.js | 16 ++++-----
 ambari-web/app/controllers/main/service/item.js |  4 +--
 .../configs/component_actions_by_configs.js     | 10 +++---
 .../app/utils/batch_scheduled_requests.js       |  2 +-
 6 files changed, 73 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0d22cd04/ambari-server/src/main/java/org/apache/ambari/server/scheduler/ExecutionScheduleManager.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/scheduler/ExecutionScheduleManager.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/scheduler/ExecutionScheduleManager.java
index dbce272..48c63d3 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/scheduler/ExecutionScheduleManager.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/scheduler/ExecutionScheduleManager.java
@@ -47,6 +47,7 @@ import org.apache.ambari.server.state.scheduler.BatchSettings;
 import org.apache.ambari.server.state.scheduler.RequestExecution;
 import org.apache.ambari.server.state.scheduler.Schedule;
 import org.apache.ambari.server.utils.DateUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.text.StrBuilder;
 import org.quartz.CronExpression;
 import org.quartz.JobDetail;
@@ -70,6 +71,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.regex.Pattern;
 import static org.quartz.CronScheduleBuilder.cronSchedule;
 import static org.quartz.JobBuilder.newJob;
 import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
@@ -108,6 +110,8 @@ public class ExecutionScheduleManager {
   protected static final String REQUESTS_TIMEDOUT_TASKS_KEY = 
"timed_out_task_count";
   protected static final String REQUESTS_TOTAL_TASKS_KEY = "task_count";
 
+  protected static final Pattern CONTAINS_API_VERSION_PATTERN = 
Pattern.compile("^/?" + DEFAULT_API_PATH+ ".*");
+
   @Inject
   public ExecutionScheduleManager(Configuration configuration,
                                   ExecutionScheduler executionScheduler,
@@ -657,7 +661,7 @@ public class ExecutionScheduleManager {
   }
 
   protected BatchRequestResponse performApiGetRequest(String relativeUri, 
boolean queryAllFields) {
-    WebResource webResource = ambariWebResource.path(relativeUri);
+    WebResource webResource = extendApiResource(ambariWebResource, 
relativeUri);
     if (queryAllFields) {
       webResource = webResource.queryParam("fields", "*");
     }
@@ -673,7 +677,8 @@ public class ExecutionScheduleManager {
   protected BatchRequestResponse performApiRequest(String relativeUri, String 
body, String method, Integer userId) {
     ClientResponse response;
     try {
-      response = ambariWebResource.path(relativeUri).header(USER_ID_HEADER, 
userId).method(method, ClientResponse.class, body);
+      response = extendApiResource(ambariWebResource, relativeUri)
+          .header(USER_ID_HEADER, userId).method(method, ClientResponse.class, 
body);
     } catch (UniformInterfaceException e) {
       response = e.getResponse();
     }
@@ -789,5 +794,19 @@ public class ExecutionScheduleManager {
       requestExecution.updateStatus(RequestExecution.Status.COMPLETED);
     }
   }
+
+  /**
+   * Returns the absolute web resource with {@link #DEFAULT_API_PATH}
+   * @param webResource Ambari WebResource as provided by the client {@link 
#ambariWebResource}
+   * @param relativeUri relative request URI
+   * @return  Extended WebResource
+   */
+  protected WebResource extendApiResource(WebResource webResource, String 
relativeUri) {
+    WebResource result = webResource;
+    if (StringUtils.isNotEmpty(relativeUri) && 
!CONTAINS_API_VERSION_PATTERN.matcher(relativeUri).matches()) {
+      result = webResource.path(DEFAULT_API_PATH);
+    }
+    return result.path(relativeUri);
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d22cd04/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
index 28956d6..de771b3 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
@@ -25,6 +25,8 @@ import com.google.inject.Injector;
 import com.google.inject.Module;
 import com.google.inject.persist.Transactional;
 import com.google.inject.util.Modules;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
 import junit.framework.Assert;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.H2DatabaseCleaner;
@@ -66,6 +68,7 @@ import org.quartz.impl.matchers.GroupMatcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -634,4 +637,37 @@ public class ExecutionScheduleManagerTest {
 
     verify(scheduleManagerMock, executionJob, context, jobDataMap, jobDetail);
   }
+
+  @Test
+  public void testExtendApiResource() throws NoSuchMethodException, 
InvocationTargetException, IllegalAccessException {
+    WebResource webResource = 
Client.create().resource("http://localhost:8080/";);
+
+    String clustersEndpoint = "http://localhost:8080/api/v1/clusters";;
+
+    Clusters clustersMock = createMock(Clusters.class);
+
+    Configuration configurationMock = createNiceMock(Configuration.class);
+    ExecutionScheduler executionSchedulerMock = 
createMock(ExecutionScheduler.class);
+    InternalTokenStorage tokenStorageMock = 
createMock(InternalTokenStorage.class);
+    ActionDBAccessor actionDBAccessorMock = createMock(ActionDBAccessor.class);
+    Gson gson = new Gson();
+
+    replay(clustersMock, configurationMock, executionSchedulerMock, 
tokenStorageMock,
+      actionDBAccessorMock);
+
+    ExecutionScheduleManager scheduleManager =
+      new ExecutionScheduleManager(configurationMock, executionSchedulerMock,
+        tokenStorageMock, clustersMock, actionDBAccessorMock, gson);
+    
+    assertEquals(clustersEndpoint,
+      scheduleManager.extendApiResource(webResource, 
"clusters").getURI().toString());
+    assertEquals(clustersEndpoint,
+      scheduleManager.extendApiResource(webResource, 
"/clusters").getURI().toString());
+    assertEquals(clustersEndpoint,
+      scheduleManager.extendApiResource(webResource, 
"/api/v1/clusters").getURI().toString());
+    assertEquals(clustersEndpoint,
+      scheduleManager.extendApiResource(webResource, 
"api/v1/clusters").getURI().toString());
+    assertEquals("http://localhost:8080/";,
+      scheduleManager.extendApiResource(webResource, "").getURI().toString());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d22cd04/ambari-web/app/controllers/main/host/details.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host/details.js 
b/ambari-web/app/controllers/main/host/details.js
index aaa637f..55ce1ef 100644
--- a/ambari-web/app/controllers/main/host/details.js
+++ b/ambari-web/app/controllers/main/host/details.js
@@ -2068,7 +2068,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
       {
         "order_id": 1,
         "type": "POST",
-        "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/requests",
+        "uri": "/clusters/" + App.get('clusterName') + "/requests",
         "RequestBodyInfo": {
           "RequestInfo": {
             "context": 
Em.I18n.t('hosts.host.regionserver.decommission.batch1'),
@@ -2096,7 +2096,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
       batches.push({
         "order_id": id,
         "type": "PUT",
-        "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/hosts/" + hAray[i] + "/host_components/" + slaveType,
+        "uri": "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + 
"/host_components/" + slaveType,
         "RequestBodyInfo": {
           "RequestInfo": {
             context: Em.I18n.t('hosts.host.regionserver.decommission.batch2'),
@@ -2120,7 +2120,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
     batches.push({
       "order_id": id,
       "type": "POST",
-      "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/requests",
+      "uri": "/clusters/" + App.get('clusterName') + "/requests",
       "RequestBodyInfo": {
         "RequestInfo": {
           "context": Em.I18n.t('hosts.host.regionserver.decommission.batch3'),
@@ -2207,7 +2207,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
       {
         "order_id": 1,
         "type": "POST",
-        "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + 
"/requests",
+        "uri": "/clusters/" + App.get('clusterName') + "/requests",
         "RequestBodyInfo": {
           "RequestInfo": {
             "context": context_1,
@@ -2232,7 +2232,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
       batches.push({
         "order_id": id,
         "type": "PUT",
-        "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/hosts/" + hAray[i] + "/host_components/" + slaveType,
+        "uri": "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + 
"/host_components/" + slaveType,
         "RequestBodyInfo": {
           "RequestInfo": {
             context: startContext,
@@ -2976,7 +2976,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
       {
         "order_id": 1,
         "type": "PUT",
-        "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/hosts/" + hostName + "/host_components",
+        "uri": "/clusters/" + App.get('clusterName') + "/hosts/" + hostName + 
"/host_components",
         "RequestBodyInfo": {
           "RequestInfo": {
             context: Em.I18n.t('hosts.host.recover.initAllComponents.context'),
@@ -2998,7 +2998,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
       {
         "order_id": 2,
         "type": "PUT",
-        "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/hosts/" + hostName + "/host_components",
+        "uri": "/clusters/" + App.get('clusterName') + "/hosts/" + hostName + 
"/host_components",
         "RequestBodyInfo": {
           "RequestInfo": {
             context: 
Em.I18n.t('hosts.host.recover.installAllComponents.context'),
@@ -3021,7 +3021,7 @@ App.MainHostDetailsController = 
Em.Controller.extend(App.SupportClientConfigsDow
       batches.push({
         "order_id": 3,
         "type": "PUT",
-        "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName'),
+        "uri": "/clusters/" + App.get('clusterName'),
         "RequestBodyInfo": {
           "RequestInfo": {
             context: Em.I18n.t('hosts.host.recover.regenerateKeytabs.context'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d22cd04/ambari-web/app/controllers/main/service/item.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/item.js 
b/ambari-web/app/controllers/main/service/item.js
index 4e1b6fc..f0d6787 100644
--- a/ambari-web/app/controllers/main/service/item.js
+++ b/ambari-web/app/controllers/main/service/item.js
@@ -655,7 +655,7 @@ App.MainServiceItemController = 
Em.Controller.extend(App.SupportClientConfigsDow
     var batches = [{
       "order_id": 1,
       "type": "POST",
-      "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + 
"/requests",
+      "uri": "/clusters/" + App.get('clusterName') + "/requests",
       "RequestBodyInfo": {
         "RequestInfo": {
           "context": "Refresh YARN Capacity Scheduler",
@@ -671,7 +671,7 @@ App.MainServiceItemController = 
Em.Controller.extend(App.SupportClientConfigsDow
     }, {
       "order_id": 2,
       "type": "POST",
-      "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + 
"/requests",
+      "uri": "/clusters/" + App.get('clusterName') + "/requests",
       "RequestBodyInfo": {
         "RequestInfo": {"context": "Restart LLAP", "command": "RESTART_LLAP"},
         "Requests/resource_filters": [{

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d22cd04/ambari-web/app/mixins/main/service/configs/component_actions_by_configs.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/app/mixins/main/service/configs/component_actions_by_configs.js 
b/ambari-web/app/mixins/main/service/configs/component_actions_by_configs.js
index 2220ecd..d3bcc36 100644
--- a/ambari-web/app/mixins/main/service/configs/component_actions_by_configs.js
+++ b/ambari-web/app/mixins/main/service/configs/component_actions_by_configs.js
@@ -303,7 +303,7 @@ App.ComponentActionsByConfigs = Em.Mixin.create({
 
     return  {
       "type": 'POST',
-      "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/hosts",
+      "uri": "/clusters/" + App.get('clusterName') + "/hosts",
       "RequestBodyInfo": {
         "RequestInfo": {
           "query": query
@@ -356,7 +356,7 @@ App.ComponentActionsByConfigs = Em.Mixin.create({
 
     return  {
       "type": 'PUT',
-      "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/hosts/" + hostName + "/host_components",
+      "uri": "/clusters/" + App.get('clusterName') + "/hosts/" + hostName + 
"/host_components",
       "RequestBodyInfo": {
         "RequestInfo": {
           "context": context,
@@ -387,7 +387,7 @@ App.ComponentActionsByConfigs = Em.Mixin.create({
   getDeleteHostComponentRequest: function(hostName, component) {
     return {
       "type": 'DELETE',
-      "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/hosts/" + hostName + "/host_components/" + component
+      "uri": "/clusters/" + App.get('clusterName') + "/hosts/" + hostName + 
"/host_components/" + component
     }
   },
 
@@ -405,7 +405,7 @@ App.ComponentActionsByConfigs = Em.Mixin.create({
       if (!serviceComponents.contains(_componentName)) {
         batches.push({
           "type": 'POST',
-          "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') 
+ "/services/" + serviceName + "/components/" + _componentName
+          "uri": "/clusters/" + App.get('clusterName') + "/services/" + 
serviceName + "/components/" + _componentName
         });
       }
     });
@@ -432,7 +432,7 @@ App.ComponentActionsByConfigs = Em.Mixin.create({
       this.isYarnQueueRefreshed = true;
       batches.push({
         "type": 'POST',
-        "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + 
"/requests",
+        "uri": "/clusters/" + App.get('clusterName') + "/requests",
         "RequestBodyInfo": {
           "RequestInfo": {
             "context": 
Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d22cd04/ambari-web/app/utils/batch_scheduled_requests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/batch_scheduled_requests.js 
b/ambari-web/app/utils/batch_scheduled_requests.js
index 6d1e721..c3201e4 100644
--- a/ambari-web/app/utils/batch_scheduled_requests.js
+++ b/ambari-web/app/utils/batch_scheduled_requests.js
@@ -347,7 +347,7 @@ module.exports = {
         batches.push({
           "order_id" : count + 1,
           "type" : "POST",
-          "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + 
"/requests",
+          "uri" : "/clusters/" + App.get('clusterName') + "/requests",
           "RequestBodyInfo" : {
             "RequestInfo" : {
               "context" : "_PARSE_.ROLLING-RESTART." + componentName + "." + 
(count + 1) + "." + batchCount,

Reply via email to