ソースを参照

AMBARI-5145. Fixed an issue that could result in a NPE when deploying a cluster via a blueprint.

John Speidel 11 年 前
コミット
3b1fcf36a6

+ 23 - 8
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java

@@ -720,15 +720,30 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
     }
     // AMBARI-4921
     //todo: hard-coding default values for required global config properties which are not in stack definition
-    Map<String, String> globalProperties = mapClusterConfigurations.get("global");
-    if (globalProperties == null) {
-      globalProperties = new HashMap<String, String>();
-      mapClusterConfigurations.put("global", globalProperties);
+    ensureProperty("global", "user_group", "hadoop");
+    ensureProperty("global", "nagios_contact", "default@REPLACEME.NOWHERE");
+    ensureProperty("global", "nagios_web_password", "admin");
+    ensureProperty("global", "smokeuser", "ambari-qa");
+  }
+
+  /**
+   * Ensure that the specified property exists.
+   * If not, set a default value.
+   *
+   * @param type          config type
+   * @param property      property name
+   * @param defaultValue  default value
+   */
+  private void ensureProperty(String type, String property, String defaultValue) {
+    Map<String, String> properties = mapClusterConfigurations.get(type);
+    if (properties == null) {
+      properties = new HashMap<String, String>();
+      mapClusterConfigurations.put(type, properties);
+    }
+
+    if (! properties.containsKey(property)) {
+      properties.put(property, defaultValue);
     }
-    globalProperties.put("user_group", "hadoop");
-    globalProperties.put("smokeuser", "ambari-qa");
-    globalProperties.put("nagios_contact", "default@REPLACEME.NOWHERE");
-    globalProperties.put("nagios_web_password", "admin");
   }
 
   /**

+ 11 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestStageContainer.java

@@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Map;
 
 /**
  * Contains stages associated with a request.
@@ -132,9 +133,16 @@ public class RequestStageContainer {
     ListIterator<Stage> iterator = stages.listIterator(stages.size());
     while (lastCommand == null && iterator.hasPrevious()) {
       Stage stage = iterator.previous();
-      HostRoleCommand hostRoleCommand = stage.getHostRoleCommand(host, component);
-      if (hostRoleCommand != null && hostRoleCommand.getRoleCommand() != RoleCommand.SERVICE_CHECK) {
-        lastCommand = hostRoleCommand.getRoleCommand();
+
+      Map<String, Map<String, HostRoleCommand>> stageCommands = stage.getHostRoleCommands();
+      if (stageCommands != null) {
+        Map<String, HostRoleCommand> hostCommands = stageCommands.get(host);
+        if (hostCommands != null) {
+          HostRoleCommand roleCommand = hostCommands.get(component);
+          if (roleCommand != null && roleCommand.getRoleCommand() != RoleCommand.SERVICE_CHECK) {
+            lastCommand = roleCommand.getRoleCommand();
+          }
+        }
       }
     }
 

+ 3 - 3
ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql

@@ -81,9 +81,9 @@ ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_cgccm_gid FOREIGN KE
 ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_cgid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id);
 ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_hname FOREIGN KEY (host_name) REFERENCES hosts (host_name);
 ALTER TABLE requestschedulebatchrequest ADD CONSTRAINT FK_rsbatchrequest_schedule_id FOREIGN KEY (schedule_id) REFERENCES requestschedule (schedule_id);
-ALTER TABLE hostgroup ADD FOREIGN KEY (blueprint_name) REFERENCES ambari.blueprint(blueprint_name);
-ALTER TABLE hostgroup_component ADD FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES ambari.hostgroup(blueprint_name, name);
-ALTER TABLE blueprint_configuration ADD FOREIGN KEY (blueprint_name) REFERENCES ambari.blueprint(blueprint_name);
+ALTER TABLE hostgroup ADD FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name);
+ALTER TABLE hostgroup_component ADD FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup(blueprint_name, name);
+ALTER TABLE blueprint_configuration ADD FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name);
 ALTER TABLE requestresourcefilter ADD CONSTRAINT FK_requestresourcefilter_req_id FOREIGN KEY (request_id) REFERENCES request (request_id);
 
 INSERT INTO ambari_sequences(sequence_name, value) values ('host_role_command_id_seq', 0);

+ 5 - 4
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestStageContainerTest.java

@@ -34,6 +34,7 @@ import org.junit.Test;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.createStrictMock;
@@ -114,10 +115,10 @@ public class RequestStageContainerTest {
     stages.add(stage4);
 
     //expectations
-    expect(stage1.getHostRoleCommand(hostname, componentName)).andReturn(command1).anyTimes();
-    expect(stage2.getHostRoleCommand(hostname, componentName)).andReturn(command2).anyTimes();
-    expect(stage3.getHostRoleCommand(hostname, componentName)).andReturn(command3).anyTimes();
-    expect(stage4.getHostRoleCommand(hostname, componentName)).andReturn(null).anyTimes();
+    expect(stage1.getHostRoleCommands()).andReturn(Collections.singletonMap(hostname, Collections.singletonMap(componentName, command1))).anyTimes();
+    expect(stage2.getHostRoleCommands()).andReturn(Collections.singletonMap(hostname, Collections.singletonMap(componentName, command2))).anyTimes();
+    expect(stage3.getHostRoleCommands()).andReturn(Collections.singletonMap(hostname, Collections.singletonMap(componentName, command3))).anyTimes();
+    expect(stage4.getHostRoleCommands()).andReturn(Collections.<String, Map<String, HostRoleCommand>>emptyMap()).anyTimes();
 
     expect(command3.getRoleCommand()).andReturn(RoleCommand.SERVICE_CHECK).anyTimes();
     expect(command2.getRoleCommand()).andReturn(RoleCommand.INSTALL).anyTimes();