ソースを参照

AMBARI-5723. IllegalStateException when provisioning cluster via blueprint during password validation

John Speidel 11 年 前
コミット
e5fb45aeca

+ 20 - 16
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java

@@ -313,6 +313,7 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
    * @throws UnsupportedPropertyException   if an invalid property is specified in the request
    * @throws NoSuchParentResourceException  if a necessary parent resource doesn't exist
    */
+  @SuppressWarnings("unchecked")
   private RequestStatusResponse processBlueprintCreate(Map<String, Object> properties)
       throws ResourceAlreadyExistsException, SystemException, UnsupportedPropertyException,
       NoSuchParentResourceException {
@@ -368,26 +369,29 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
     for(iter = missingPasswords.entrySet().iterator(); iter.hasNext(); ) {
       Map.Entry<String, Map<String, Collection<String>>> entry = iter.next();
       Map<String, Collection<String>> missingProps = entry.getValue();
-      Iterator<Map.Entry<String, Collection<String>>> propIter;
-      for (propIter = missingProps.entrySet().iterator(); propIter.hasNext(); ) {
-        Map.Entry<String, Collection<String>> propEntry = propIter.next();
-        String configType = propEntry.getKey();
-        Collection<String> propertySet = propEntry.getValue();
-
-        for (String property : propertySet) {
-          if (setDefaultPassword(defaultPassword, configType, property)) {
-            propIter.remove();
-          } else if (isPropertyInConfiguration(mapClusterConfigurations.get(configType), property)){
+      Iterator<Map.Entry<String, Collection<String>>> hostGroupIter;
+
+      for (hostGroupIter = missingProps.entrySet().iterator(); hostGroupIter.hasNext(); ) {
+        Map.Entry<String, Collection<String>> hgEntry = hostGroupIter.next();
+        String configType = hgEntry.getKey();
+        Collection<String> propertySet = hgEntry.getValue();
+
+        for (Iterator<String> propIter = propertySet.iterator(); propIter.hasNext(); ) {
+          String property = propIter.next();
+          if (isPropertyInConfiguration(mapClusterConfigurations.get(configType), property)){
               propIter.remove();
           } else {
-            HostGroup hostgroup = hostGroups.get(entry.getKey());
-            if (hostgroup != null) {
-              if (isPropertyInConfiguration(hostgroup.getConfigurations().get(configType), property)) {
-                propIter.remove();
-              }
+            HostGroup hg = hostGroups.get(entry.getKey());
+            if (hg != null && isPropertyInConfiguration(hg.getConfigurations().get(configType), property)) {
+              propIter.remove();
+            }  else if (setDefaultPassword(defaultPassword, configType, property)) {
+              propIter.remove();
             }
           }
         }
+        if (propertySet.isEmpty()) {
+          hostGroupIter.remove();
+        }
       }
       if (entry.getValue().isEmpty()) {
         iter.remove();
@@ -673,6 +677,7 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
    *
    * @throws IllegalArgumentException a host_group in the request doesn't match a host-group in the blueprint
    */
+  @SuppressWarnings("unchecked")
   private void applyRequestInfoToHostGroups(Map<String, Object> properties,
                                             Map<String, HostGroup> blueprintHostGroups)
                                             throws IllegalArgumentException {
@@ -703,7 +708,6 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
         throw new IllegalArgumentException("Host group '" + name + "' must contain a 'hosts' element");
       }
       for (Object oHost : hosts) {
-        @SuppressWarnings("unchecked")
         Map<String, String> mapHostProperties = (Map<String, String>) oHost;
         //add host information to host group
         String fqdn = mapHostProperties.get("fqdn");

+ 3 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java

@@ -1333,6 +1333,7 @@ public class ClusterResourceProviderTest {
     Map<String, Collection<String>> missingHGPasswords = new HashMap<String, Collection<String>>();
     Collection<String> missingPasswords = new ArrayList<String>();
     missingPasswords.add("my.missing.password");
+    missingPasswords.add("my.missing.password2");
     missingHGPasswords.put("core-site", missingPasswords);
     allMissingPasswords.put("group1", missingHGPasswords);
 
@@ -1509,13 +1510,14 @@ public class ClusterResourceProviderTest {
     assertEquals(1, hdfsConfigRequest.getProperties().size());
     assertEquals("value2", hdfsConfigRequest.getProperties().get("property2"));
     ConfigurationRequest coreConfigRequest = mapConfigRequests.get("core-site");
-    assertEquals(6, coreConfigRequest.getProperties().size());
+    assertEquals(7, coreConfigRequest.getProperties().size());
     assertEquals("value2", coreConfigRequest.getProperties().get("property1"));
     assertEquals("value3", coreConfigRequest.getProperties().get("property3"));
     assertEquals("*", coreConfigRequest.getProperties().get("hadoop.proxyuser.oozie.hosts"));
     assertEquals("users", coreConfigRequest.getProperties().get("hadoop.proxyuser.oozie.groups"));
     assertEquals("new.property.value", coreConfigRequest.getProperties().get("new.property"));
     assertEquals("foo", coreConfigRequest.getProperties().get("my.missing.password"));
+    assertEquals("foo", coreConfigRequest.getProperties().get("my.missing.password2"));
     assertNull(updateClusterPropertyMapCapture.getValue());
     assertNull(updateClusterPropertyMapCapture2.getValue());
     assertNull(updateClusterPropertyMapCapture3.getValue());