incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject git commit: AMBARI-2645 - API: Security wizard should support an aggregated call for applying multiple configuration to the cluster.
Date Mon, 15 Jul 2013 14:27:04 GMT
Updated Branches:
  refs/heads/trunk e0435fafe -> 2e11b88d1


AMBARI-2645 - API: Security wizard should support an aggregated call for applying multiple
configuration to the cluster.


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

Branch: refs/heads/trunk
Commit: 2e11b88d11d50d192d3dfae04bafb2a22c6aee0f
Parents: e0435fa
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Fri Jul 12 19:56:32 2013 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Mon Jul 15 10:19:04 2013 -0400

----------------------------------------------------------------------
 .../persistence/PersistenceManagerImpl.java     | 17 ++++++
 .../controller/AmbariManagementController.java  |  6 +-
 .../AmbariManagementControllerImpl.java         | 25 ++++++---
 .../internal/ClusterResourceProvider.java       | 27 ++++-----
 .../AmbariManagementControllerTest.java         | 59 ++++++++++----------
 .../internal/AbstractResourceProviderTest.java  | 42 ++++++++++++++
 .../internal/ClusterResourceProviderTest.java   | 46 +++++++++++----
 7 files changed, 158 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/2e11b88d/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java
index 0f38ef3..5f868a0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java
@@ -79,6 +79,23 @@ public class PersistenceManagerImpl implements PersistenceManager {
   public RequestStatus update(ResourceInstance resource, RequestBody requestBody)
       throws UnsupportedPropertyException, SystemException, NoSuchParentResourceException,
NoSuchResourceException {
 
+    // Allow for multiple property sets in an update request body...
+    Set<NamedPropertySet> setProperties = requestBody.getNamedPropertySets();
+    if (setProperties.size() > 1) {
+      Map<Resource.Type, String> mapResourceIds = resource.getIds();
+      Resource.Type type = resource.getResourceDefinition().getType();
+      Schema schema = m_controller.getSchema(type);
+
+      for (NamedPropertySet propertySet : setProperties) {
+        for (Map.Entry<Resource.Type, String> entry : mapResourceIds.entrySet()) {
+          Map<String, Object> mapProperties = propertySet.getProperties();
+          String property = schema.getKeyPropertyId(entry.getKey());
+          if (! mapProperties.containsKey(property)) {
+            mapProperties.put(property, entry.getValue());
+          }
+        }
+      }
+    }
     return m_controller.updateResources(resource.getResourceDefinition().getType(),
         createControllerRequest(requestBody), resource.getQuery().getPredicate());
   }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/2e11b88d/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
index 86cd78c..4d7a55e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
@@ -231,7 +231,7 @@ public interface AmbariManagementController {
    * values carried by the given request object.
    *
    *
-   * @param request           request object which defines which cluster to
+   * @param requests          request objects which define which cluster to
    *                          update and the values to set
    * @param requestProperties request specific properties independent of resource
    *
@@ -239,8 +239,8 @@ public interface AmbariManagementController {
    *
    * @throws AmbariException thrown if the resource cannot be updated
    */
-  public RequestStatusResponse updateCluster(ClusterRequest request,
-                                             Map<String, String> requestProperties)
+  public RequestStatusResponse updateClusters(Set<ClusterRequest> requests,
+                                              Map<String, String> requestProperties)
       throws AmbariException;
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/2e11b88d/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 6bb59d6..1bd20cb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -19,7 +19,6 @@
 package org.apache.ambari.server.controller;
 
 import java.io.File;
-import java.io.IOException;
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -53,11 +52,8 @@ import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.controller.internal.URLStreamProvider;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
-import org.apache.ambari.server.orm.dao.MetainfoDAO;
-import org.apache.ambari.server.orm.entities.MetainfoEntity;
 import org.apache.ambari.server.security.authorization.AuthorizationHelper;
 import org.apache.ambari.server.security.authorization.User;
 import org.apache.ambari.server.security.authorization.Users;
@@ -94,7 +90,6 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostUpgradeEvent;
 import org.apache.ambari.server.utils.StageUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -1436,9 +1431,25 @@ public class AmbariManagementControllerImpl implements
   }
 
   @Override
-  public synchronized RequestStatusResponse updateCluster(ClusterRequest request,
-                                                          Map<String, String> requestProperties)
+  public synchronized RequestStatusResponse updateClusters(Set<ClusterRequest> requests,
+                                                           Map<String, String> requestProperties)
       throws AmbariException {
+
+    RequestStatusResponse response = null;
+
+    // We have to allow for multiple requests to account for multiple
+    // configuration updates (create multiple configuration resources)...
+    for (ClusterRequest request : requests) {
+      // TODO : Is there ever a real world case where we could have multiple non-null responses?
+      response = updateCluster(request, requestProperties);
+    }
+    return response;
+  }
+
+  private synchronized RequestStatusResponse updateCluster(ClusterRequest request,
+                                                           Map<String, String> requestProperties)
+      throws AmbariException {
+
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()) {
       throw new IllegalArgumentException("Invalid arguments, cluster name"

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/2e11b88d/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
index 3091ee8..210a9a4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
@@ -140,20 +140,21 @@ class ClusterResourceProvider extends AbstractControllerResourceProvider
{
   public RequestStatus updateResources(final Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException
{
 
-    RequestStatusResponse response = null;
-    Set<Map<String, Object>> propertyMaps = getPropertyMaps(request.getProperties().iterator().next(),
predicate);
-    if (propertyMaps.size() > 1) {
-      throw new SystemException("Single update request cannot modify multiple clusters.",
null);
-    }
-    for (Map<String, Object> propertyMap : propertyMaps) {
-      final ClusterRequest clusterRequest = getRequest(propertyMap);
-      response = modifyResources(new Command<RequestStatusResponse>() {
-        @Override
-        public RequestStatusResponse invoke() throws AmbariException {
-          return getManagementController().updateCluster(clusterRequest, request.getRequestInfoProperties());
-        }
-      });
+    final Set<ClusterRequest>   requests = new HashSet<ClusterRequest>();
+    RequestStatusResponse       response;
+
+    for (Map<String, Object> requestPropertyMap : request.getProperties()) {
+      Set<Map<String, Object>> propertyMaps = getPropertyMaps(requestPropertyMap,
predicate);
+      for (Map<String, Object> propertyMap : propertyMaps) {
+        requests.add(getRequest(propertyMap));
+      }
     }
+    response = modifyResources(new Command<RequestStatusResponse>() {
+      @Override
+      public RequestStatusResponse invoke() throws AmbariException {
+        return getManagementController().updateClusters(requests, request.getRequestInfoProperties());
+      }
+    });
     notifyUpdate(Resource.Type.Cluster, request, predicate);
     return getRequestStatus(response);
   }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/2e11b88d/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 95150c3..59886d0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -57,7 +57,6 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.MetainfoDAO;
 import org.apache.ambari.server.orm.dao.RoleDAO;
 import org.apache.ambari.server.orm.entities.RoleEntity;
 import org.apache.ambari.server.security.authorization.Users;
@@ -3685,7 +3684,7 @@ public class AmbariManagementControllerTest {
     ClusterRequest cr = new ClusterRequest(null, clusterName, null, null);
     cr.setDesiredConfig(new ConfigurationRequest(clusterName, "global",
         "v1", configs));
-    controller.updateCluster(cr, Collections.<String,String>emptyMap());
+    controller.updateClusters(Collections.singleton(cr), Collections.<String, String>emptyMap());
 
     Set<ServiceRequest> sReqs = new HashSet<ServiceRequest>();
     Map<String, String> configVersions = new HashMap<String, String>();
@@ -4503,10 +4502,10 @@ public class AmbariManagementControllerTest {
 
     ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr1);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
     crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr2);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
 
     // Install
     long requestId1 = installService(clusterName, serviceName1, true, false);
@@ -4529,7 +4528,7 @@ public class AmbariManagementControllerTest {
       configs);
     crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr3);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
 
     // Stop HDFS & MAPREDUCE
     stopService(clusterName, serviceName1, false, false);
@@ -4658,10 +4657,10 @@ public class AmbariManagementControllerTest {
 
     ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr1);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
     crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr2);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
 
     installService(clusterName, serviceName, false, false);
     startService(clusterName, serviceName, false, false);
@@ -4684,7 +4683,7 @@ public class AmbariManagementControllerTest {
       configs);
     crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr3);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
 
     id = startService(clusterName, serviceName, false, true);
     List<Stage> stages = actionDB.getAllStages(id);
@@ -5040,7 +5039,7 @@ public class AmbariManagementControllerTest {
       configs);
     ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr1);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
 
     // Install
     installService(clusterName, serviceName, false, false);
@@ -5121,14 +5120,14 @@ public class AmbariManagementControllerTest {
       configs);
     ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr1);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
     Map<String, String> props = new HashMap<String, String>();
     props.put("datanodes", host2);
     cr2 = new ConfigurationRequest(clusterName, "hdfs-exclude-file", "tag1",
       props);
     crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr2);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
 
     // Start
     startService(clusterName, serviceName, false, false);
@@ -5221,10 +5220,10 @@ public class AmbariManagementControllerTest {
 
     ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr1);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
     crReq = new ClusterRequest(null, clusterName, null, null);
     crReq.setDesiredConfig(cr2);
-    controller.updateCluster(crReq, null);
+    controller.updateClusters(Collections.singleton(crReq), null);
 
     // Install
     installService(clusterName, serviceName, false, false);
@@ -5655,7 +5654,7 @@ public class AmbariManagementControllerTest {
 
     ClusterRequest r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.0.1", null);
     try {
-      controller.updateCluster(r, mapRequestProps);
+      controller.updateClusters(Collections.singleton(r), mapRequestProps);
       fail("Update cluster should fail");
     } catch (AmbariException e) {
       Assert.assertTrue(e.getMessage().contains("must be greater than current version"));
@@ -5663,7 +5662,7 @@ public class AmbariManagementControllerTest {
 
     r = new ClusterRequest(c.getClusterId(), clusterName, "HDPLocal-1.2.2", null);
     try {
-      controller.updateCluster(r, mapRequestProps);
+      controller.updateClusters(Collections.singleton(r), mapRequestProps);
       fail("Update cluster should fail");
     } catch (AmbariException e) {
       Assert.assertTrue(e.getMessage().contains("Upgrade not possible between different stacks"));
@@ -5671,7 +5670,7 @@ public class AmbariManagementControllerTest {
 
     r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
     try {
-      controller.updateCluster(r, mapRequestProps);
+      controller.updateClusters(Collections.singleton(r), mapRequestProps);
       fail("Update cluster should fail");
     } catch (AmbariException e) {
       Assert.assertTrue(e.getMessage().contains("Upgrade needs all services to be stopped"));
@@ -5683,7 +5682,7 @@ public class AmbariManagementControllerTest {
 
     r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
     try {
-      controller.updateCluster(r, mapRequestProps);
+      controller.updateClusters(Collections.singleton(r), mapRequestProps);
       fail("Update cluster should fail");
     } catch (AmbariException e) {
       Assert.assertTrue(e.getMessage().contains("Upgrade needs all services to be stopped"));
@@ -5692,7 +5691,7 @@ public class AmbariManagementControllerTest {
 
     c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
         .setState(State.INSTALLED);
-    controller.updateCluster(r, mapRequestProps);
+    controller.updateClusters(Collections.singleton(r), mapRequestProps);
     StackId expectedStackId = new StackId("HDP-0.2");
     Assert.assertTrue(expectedStackId.equals(c.getDesiredStackVersion()));
     Assert.assertTrue(expectedStackId.equals(c.getService(serviceName).getDesiredStackVersion()));
@@ -5712,7 +5711,7 @@ public class AmbariManagementControllerTest {
 
     // Fail as another request is active
     try {
-      controller.updateCluster(r, mapRequestProps);
+      controller.updateClusters(Collections.singleton(r), mapRequestProps);
       fail("Update cluster should fail");
     } catch (AmbariException e) {
       Assert.assertTrue(e.getMessage().contains("A prior upgrade request with id"));
@@ -5729,17 +5728,17 @@ public class AmbariManagementControllerTest {
         .setState(State.INSTALLED);
     c.setCurrentStackVersion(expectedStackId);
     r = new ClusterRequest(c.getClusterId(), clusterName, "", null);
-    controller.updateCluster(r, mapRequestProps);
+    controller.updateClusters(Collections.singleton(r), mapRequestProps);
     Assert.assertEquals(State.INSTALLED, sc.getServiceComponentHost(host1).getState());
     Assert.assertEquals(State.INSTALLED, sc.getServiceComponentHost(host2).getState());
 
     r = new ClusterRequest(c.getClusterId(), clusterName, null, null);
-    controller.updateCluster(r, mapRequestProps);
+    controller.updateClusters(Collections.singleton(r), mapRequestProps);
     Assert.assertEquals(State.INSTALLED, sc.getServiceComponentHost(host1).getState());
     Assert.assertEquals(State.INSTALLED, sc.getServiceComponentHost(host2).getState());
 
     r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
-    controller.updateCluster(r, mapRequestProps);
+    controller.updateClusters(Collections.singleton(r), mapRequestProps);
     Assert.assertEquals(State.INSTALLED, sc.getServiceComponentHost(host1).getState());
     Assert.assertEquals(State.INSTALLED, sc.getServiceComponentHost(host2).getState());
   }
@@ -5757,7 +5756,7 @@ public class AmbariManagementControllerTest {
     c.setDesiredStackVersion(currentStackId);
     ClusterRequest r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.3", null);
     try {
-      controller.updateCluster(r, mapRequestProps);
+      controller.updateClusters(Collections.singleton(r), mapRequestProps);
     } catch (AmbariException e) {
       Assert.assertTrue(e.getMessage().contains("Illegal request to upgrade to"));
     }
@@ -5768,7 +5767,7 @@ public class AmbariManagementControllerTest {
     c.refresh();
     r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
     try {
-      controller.updateCluster(r, mapRequestProps);
+      controller.updateClusters(Collections.singleton(r), mapRequestProps);
     } catch (AmbariException e) {
       Assert.assertTrue(e.getMessage().contains("Upgrade is not allowed from"));
     }
@@ -5823,7 +5822,7 @@ public class AmbariManagementControllerTest {
     resetServiceState(pigServiceName, currentStackId, c);
 
     ClusterRequest r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
-    RequestStatusResponse trackAction = controller.updateCluster(r, mapRequestProps);
+    RequestStatusResponse trackAction = controller.updateClusters(Collections.singleton(r),
mapRequestProps);
     List<Stage> stages = actionDB.getAllStages(trackAction.getRequestId());
 
     // Upgrade a cluster with one service
@@ -5849,7 +5848,7 @@ public class AmbariManagementControllerTest {
     // Upgrade a cluster with two service
     actionDB.abortOperation(trackAction.getRequestId());
     r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
-    trackAction = controller.updateCluster(r, mapRequestProps);
+    trackAction = controller.updateClusters(Collections.singleton(r), mapRequestProps);
     stages = actionDB.getAllStages(trackAction.getRequestId());
 
     expectedTasks.expectTask(Role.JOBTRACKER, host1);
@@ -5859,7 +5858,7 @@ public class AmbariManagementControllerTest {
 
     // Upgrade again
     actionDB.abortOperation(trackAction.getRequestId());
-    trackAction = controller.updateCluster(r, mapRequestProps);
+    trackAction = controller.updateClusters(Collections.singleton(r), mapRequestProps);
     stages = actionDB.getAllStages(trackAction.getRequestId());
     validateGeneratedStages(stages, 5, expectedTasks);
 
@@ -5874,7 +5873,7 @@ public class AmbariManagementControllerTest {
         .setStackVersion(desiredStackId);
 
     actionDB.abortOperation(trackAction.getRequestId());
-    trackAction = controller.updateCluster(r, mapRequestProps);
+    trackAction = controller.updateClusters(Collections.singleton(r), mapRequestProps);
     stages = actionDB.getAllStages(trackAction.getRequestId());
     validateGeneratedStages(stages, 5, expectedTasks);
 
@@ -5883,7 +5882,7 @@ public class AmbariManagementControllerTest {
     c.getService(mrServiceName).getServiceComponent(mrTaskTrackerComp).getServiceComponentHost(host2)
         .setState(State.UPGRADING);
     actionDB.abortOperation(trackAction.getRequestId());
-    trackAction = controller.updateCluster(r, mapRequestProps);
+    trackAction = controller.updateClusters(Collections.singleton(r), mapRequestProps);
     stages = actionDB.getAllStages(trackAction.getRequestId());
     validateGeneratedStages(stages, 5, expectedTasks);
 
@@ -5903,7 +5902,7 @@ public class AmbariManagementControllerTest {
     resetServiceState(pigServiceName, currentStackId, c);
 
     actionDB.abortOperation(trackAction.getRequestId());
-    trackAction = controller.updateCluster(r, mapRequestProps);
+    trackAction = controller.updateClusters(Collections.singleton(r), mapRequestProps);
     stages = actionDB.getAllStages(trackAction.getRequestId());
 
     expectedTasks.resetAll();

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/2e11b88d/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java
index e33d2a1..c99af91 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java
@@ -145,6 +145,13 @@ public class AbstractResourceProviderTest {
       return null;
     }
 
+    public static Set<ClusterRequest> getClusterRequestSet(
+        Long clusterId, String clusterName, String stackVersion, Set<String> hostNames)
+    {
+      EasyMock.reportMatcher(new ClusterRequestSetMatcher(clusterId, clusterName, stackVersion,
hostNames));
+      return null;
+    }
+
     public static ConfigurationRequest getConfigurationRequest(
         String clusterName, String type, String tag, Map<String, String> configs)
     {
@@ -242,6 +249,41 @@ public class AbstractResourceProviderTest {
   }
 
   /**
+   * Matcher for a ClusterRequest set.
+   */
+  public static class ClusterRequestSetMatcher extends ClusterRequest implements IArgumentMatcher
{
+
+    public ClusterRequestSetMatcher(Long clusterId, String clusterName, String stackVersion,
Set<String> hostNames) {
+      super(clusterId, clusterName, stackVersion, hostNames);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return eq(((ClusterRequest) request).getClusterId(), getClusterId()) &&
+          eq(((ClusterRequest) request).getClusterName(), getClusterName()) &&
+          eq(((ClusterRequest) request).getStackVersion(), getStackVersion()) &&
+          eq(((ClusterRequest) request).getHostNames(), getHostNames());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("ClusterRequestSetMatcher(").append(super.toString()).append(")");
+    }
+  }
+
+  /**
    * Matcher for a ConfigurationRequest.
    */
   public static class ConfigurationRequestMatcher extends ConfigurationRequest implements
IArgumentMatcher {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/2e11b88d/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
index 9f0dbff..96a9814 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
@@ -204,11 +204,11 @@ public class ClusterResourceProviderTest {
 
     // set expectations
     expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(nameResponse).once();
-    expect(managementController.updateCluster(
-        AbstractResourceProviderTest.Matcher.getClusterRequest(102L, "Cluster102", "HDP-0.1",
null), eq(mapRequestProps))).
+    expect(managementController.updateClusters(
+        AbstractResourceProviderTest.Matcher.getClusterRequestSet(102L, "Cluster102", "HDP-0.1",
null), eq(mapRequestProps))).
         andReturn(response).once();
-    expect(managementController.updateCluster(
-        AbstractResourceProviderTest.Matcher.getClusterRequest(103L, null, "HDP-0.1", null),
eq(mapRequestProps))).
+    expect(managementController.updateClusters(
+        AbstractResourceProviderTest.Matcher.getClusterRequestSet(103L, null, "HDP-0.1",
null), eq(mapRequestProps))).
         andReturn(response).once();
 
     // replay
@@ -264,9 +264,9 @@ public class ClusterResourceProviderTest {
     mapRequestProps.put("context", "Called from a test");
 
     // set expectations
-    expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(nameResponse).once();
-    expect(managementController.updateCluster(EasyMock.anyObject(ClusterRequest.class),
-        eq(mapRequestProps))).andReturn(response).once();
+    expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(nameResponse).times(2);
+    expect(managementController.updateClusters(Collections.singleton(EasyMock.anyObject(ClusterRequest.class)),
+        eq(mapRequestProps))).andReturn(response).times(1);
 
     // replay
     replay(managementController, response);
@@ -279,9 +279,23 @@ public class ClusterResourceProviderTest {
     properties.put(PropertyHelper.getPropertyId("Clusters.desired_config.properties", "a"),
"b");
     properties.put(PropertyHelper.getPropertyId("Clusters.desired_config.properties", "x"),
"y");
 
+
+    Map<String, Object> properties2 = new LinkedHashMap<String, Object>();
+
+    properties2.put(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, "Cluster100");
+    properties2.put(PropertyHelper.getPropertyId("Clusters.desired_config", "type"), "mapred-site");
+    properties2.put(PropertyHelper.getPropertyId("Clusters.desired_config", "tag"), "versio99");
+    properties2.put(PropertyHelper.getPropertyId("Clusters.desired_config.properties", "foo"),
"A1");
+    properties2.put(PropertyHelper.getPropertyId("Clusters.desired_config.properties", "bar"),
"B2");
+
+    Set<Map<String, Object>> propertySet = new HashSet<Map<String, Object>>();
+
+    propertySet.add(properties);
+    propertySet.add(properties2);
+
     // create the request
-    Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps);
-    
+    Request request = new RequestImpl(null, propertySet, mapRequestProps, null);
+
     Predicate  predicate = new PredicateBuilder().property(
         ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").toPredicate();
     
@@ -290,12 +304,22 @@ public class ClusterResourceProviderTest {
         PropertyHelper.getPropertyIds(Resource.Type.Cluster),
         PropertyHelper.getKeyPropertyIds(Resource.Type.Cluster),
         managementController);
-    
+
+    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+
+    ((ObservableResourceProvider)provider).addObserver(observer);
+
     provider.updateResources(request, predicate);
 
+    ResourceProviderEvent lastEvent = observer.getLastEvent();
+    Assert.assertNotNull(lastEvent);
+    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
+    Assert.assertEquals(ResourceProviderEvent.Type.Update, lastEvent.getType());
+    Assert.assertEquals(request, lastEvent.getRequest());
+    Assert.assertEquals(predicate, lastEvent.getPredicate());
+
     // verify
     verify(managementController, response);
-
   }
 
   @Test


Mime
View raw message