You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by js...@apache.org on 2015/06/12 00:28:44 UTC
ambari git commit: AMBARI-11867. Fix adding of host to config group
during blueprint provisioning
Repository: ambari
Updated Branches:
refs/heads/trunk dc25acbc9 -> 043e35a6b
AMBARI-11867. Fix adding of host to config group during blueprint provisioning
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/043e35a6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/043e35a6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/043e35a6
Branch: refs/heads/trunk
Commit: 043e35a6b5bf970406b1d935edeb7ee06e4e9936
Parents: dc25acb
Author: John Speidel <js...@hortonworks.com>
Authored: Thu Jun 11 17:13:35 2015 -0400
Committer: John Speidel <js...@hortonworks.com>
Committed: Thu Jun 11 18:28:39 2015 -0400
----------------------------------------------------------------------
.../server/state/configgroup/ConfigGroup.java | 8 +++++---
.../state/configgroup/ConfigGroupImpl.java | 2 +-
.../ambari/server/topology/AmbariContext.java | 10 +++++++---
.../server/topology/AmbariContextTest.java | 21 +++++++++++++++++++-
4 files changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/043e35a6/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroup.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroup.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroup.java
index 4c806e5..7ed7ba5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroup.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroup.java
@@ -18,7 +18,6 @@
package org.apache.ambari.server.state.configgroup;
-import com.google.inject.persist.Transactional;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.ConfigGroupResponse;
import org.apache.ambari.server.state.Config;
@@ -96,10 +95,14 @@ public interface ConfigGroup {
* Persist the Config group along with the related host and config mapping
* entities to the persistence store
*/
- @Transactional
void persist();
/**
+ * Persist the host mapping entity to the persistence store
+ */
+ void persistHostMapping();
+
+ /**
* Delete config group and the related host and config mapping
* entities from the persistence store
*/
@@ -130,7 +133,6 @@ public interface ConfigGroup {
/**
* Refresh Config group and the host and config mappings for the group
*/
- @Transactional
public void refresh();
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/043e35a6/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
index d322735..3b83f61 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
@@ -361,7 +361,7 @@ public class ConfigGroupImpl implements ConfigGroup {
* @throws Exception
*/
@Transactional
- void persistHostMapping() {
+ public void persistHostMapping() {
if (isPersisted) {
// Delete existing mappings and create new ones
configGroupHostMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
http://git-wip-us.apache.org/repos/asf/ambari/blob/043e35a6/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
index 091018a..42676aa 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
@@ -405,13 +405,17 @@ public class AmbariContext {
for (ConfigGroup group : configGroups.values()) {
if (group.getName().equals(qualifiedGroupName)) {
try {
- group.addHost(clusters.getHost(hostName));
- group.persist();
+ Host host = clusters.getHost(hostName);
addedHost = true;
+ if (! group.getHosts().containsKey(host.getHostId())) {
+ group.addHost(host);
+ group.persistHostMapping();
+ }
+
} catch (AmbariException e) {
// shouldn't occur, this host was just added to the cluster
throw new RuntimeException(String.format(
- "Unable to obtain newly created host '%s' from cluster '%s'", hostName, topology.getClusterName()));
+ "An error occurred while registering host '%s' with config group '%s' ", hostName, group.getName()), e);
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/043e35a6/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
index 1a234da..4ebf9a9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
@@ -194,6 +194,9 @@ public class AmbariContextTest {
expect(clusters.getHost(HOST1)).andReturn(host1).anyTimes();
expect(clusters.getHost(HOST2)).andReturn(host2).anyTimes();
+ expect(host1.getHostId()).andReturn(1L).anyTimes();
+ expect(host2.getHostId()).andReturn(2L).anyTimes();
+
expect(group1Info.getConfiguration()).andReturn(group1Configuration).anyTimes();
expect(group1Info.getHostNames()).andReturn(group1Hosts).anyTimes();
@@ -353,8 +356,24 @@ public class AmbariContextTest {
// test specific expectations
expect(cluster.getConfigGroups()).andReturn(configGroups).once();
+ expect(configGroup1.getHosts()).andReturn(Collections.singletonMap(2L, host2)).once();
configGroup1.addHost(host1);
- configGroup1.persist();
+ configGroup1.persistHostMapping();
+
+ // replay all mocks
+ replayAll();
+
+ // test
+ context.registerHostWithConfigGroup(HOST1, topology, HOST_GROUP_1);
+ }
+
+ @Test
+ public void testRegisterHostWithConfigGroup_registerWithExistingConfigGroup_hostAlreadyRegistered() throws Exception {
+ // test specific expectations
+ expect(cluster.getConfigGroups()).andReturn(configGroups).once();
+
+ expect(configGroup1.getHosts()).andReturn(Collections.singletonMap(1L, host1)).once();
+ // addHost and persistHostMapping shouldn't be called since host is already registerd with group
// replay all mocks
replayAll();