ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-6774. Ambari omits url-provided properties for single-element arrays.
Date Thu, 07 Aug 2014 17:21:44 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a716f3d7c -> be6c3bdd7


AMBARI-6774. Ambari omits url-provided properties for single-element arrays.


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

Branch: refs/heads/trunk
Commit: be6c3bdd7fb4471f0e23b53739c71c0c0ecec03f
Parents: a716f3d
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu Aug 7 10:18:27 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu Aug 7 10:18:27 2014 -0700

----------------------------------------------------------------------
 .../persistence/PersistenceManagerImpl.java     | 30 +++++++++-----------
 .../services/PersistenceManagerImplTest.java    | 13 ++++++++-
 2 files changed, 26 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/be6c3bdd/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 595ad00..1c488a8 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
@@ -67,7 +67,7 @@ public class PersistenceManagerImpl implements PersistenceManager {
       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)) {
+        if (!mapProperties.containsKey(property)) {
           mapProperties.put(property, entry.getValue());
         }
       }
@@ -79,25 +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...
+    Map<Resource.Type, String> mapResourceIds = resource.getKeyValueMap();
+    Resource.Type type = resource.getResourceDefinition().getType();
+    Schema schema = m_controller.getSchema(type);
+
     Set<NamedPropertySet> setProperties = requestBody.getNamedPropertySets();
-    if (setProperties.size() > 1) {
-      Map<Resource.Type, String> mapResourceIds = resource.getKeyValueMap();
-      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());
-          }
+
+    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());
+
+    return m_controller.updateResources(type, createControllerRequest(requestBody), resource.getQuery().getPredicate());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/be6c3bdd/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistenceManagerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistenceManagerImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistenceManagerImplTest.java
index f98ada8..82bd6ec 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistenceManagerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistenceManagerImplTest.java
@@ -197,6 +197,13 @@ public class PersistenceManagerImplTest {
     Predicate predicate = createMock(Predicate.class);
     RequestBody body = new RequestBody();
 
+    String clusterId = "clusterId";
+    String serviceId = "serviceId";
+
+    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
+    mapResourceIds.put(Resource.Type.Cluster, clusterId);
+    mapResourceIds.put(Resource.Type.Service, serviceId);
+
     Map<String, Object> mapProperties = new HashMap<String, Object>();
     mapProperties.put(PropertyHelper.getPropertyId("foo", "bar"), "value");
     NamedPropertySet namedPropSet = new NamedPropertySet("", mapProperties);
@@ -206,10 +213,14 @@ public class PersistenceManagerImplTest {
     setExpected.add(mapProperties);
 
     //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition);
+    expect(resource.getKeyValueMap()).andReturn(mapResourceIds);
+    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).atLeastOnce();
+    expect(controller.getSchema(Resource.Type.Component)).andReturn(schema);
     expect(resourceDefinition.getType()).andReturn(Resource.Type.Component);
     expect(resource.getQuery()).andReturn(query);
     expect(query.getPredicate()).andReturn(predicate);
+    expect(schema.getKeyPropertyId(Resource.Type.Cluster)).andReturn(clusterId);
+    expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn(serviceId);
 
     expect(controller.updateResources(Resource.Type.Component, serverRequest, predicate)).andReturn(new
RequestStatusImpl(null));
 


Mime
View raw message