Repository: ambari
Updated Branches:
  refs/heads/trunk 5b72f0b54 -> 3b1fcf36a


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


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

Branch: refs/heads/trunk
Commit: 3b1fcf36a6771a989f4b188f7018ea2a574f68df
Parents: 5b72f0b
Author: John Speidel <[email protected]>
Authored: Wed Mar 19 17:46:44 2014 -0400
Committer: John Speidel <[email protected]>
Committed: Wed Mar 19 18:39:16 2014 -0400

----------------------------------------------------------------------
 .../internal/ClusterResourceProvider.java       | 31 +++++++++++++++-----
 .../internal/RequestStageContainer.java         | 14 +++++++--
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  6 ++--
 .../internal/RequestStageContainerTest.java     |  9 +++---
 4 files changed, 42 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3b1fcf36/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 cc4585d..8afee6e 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
@@ -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", "[email protected]");
+    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", "[email protected]");
-    globalProperties.put("nagios_web_password", "admin");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3b1fcf36/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestStageContainer.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestStageContainer.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestStageContainer.java
index 1d5ffbd..e8b9adf 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestStageContainer.java
+++ 
b/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();
+          }
+        }
       }
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3b1fcf36/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql 
b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index a585e0a..afe6497 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/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);

http://git-wip-us.apache.org/repos/asf/ambari/blob/3b1fcf36/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestStageContainerTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestStageContainerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestStageContainerTest.java
index 5201653..8c58517 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestStageContainerTest.java
+++ 
b/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();

Reply via email to