Updated Branches: refs/heads/trunk 09c2ddae7 -> 7fd290dd5
AMBARI-2795. Error redeploying after first failure. (ncole) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/7fd290dd Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/7fd290dd Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/7fd290dd Branch: refs/heads/trunk Commit: 7fd290dd50030ad363a8f304505e52b57444e7c7 Parents: 09c2dda Author: Nate Cole <[email protected]> Authored: Fri Aug 2 14:36:28 2013 -0400 Committer: Nate Cole <[email protected]> Committed: Fri Aug 2 14:46:40 2013 -0400 ---------------------------------------------------------------------- .../orm/entities/HostRoleCommandEntity.java | 2 +- .../AmbariManagementControllerImplTest.java | 111 ++++++++++++++++++- 2 files changed, 110 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/7fd290dd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java index 50b2ec5..d7d6a42 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java @@ -107,7 +107,7 @@ public class HostRoleCommandEntity { @JoinColumns({@JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable = false), @JoinColumn(name = "stage_id", referencedColumnName = "stage_id", nullable = false)}) private StageEntity stage; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false) private HostEntity host; http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/7fd290dd/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java index da825a0..e41e5de 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java @@ -55,6 +55,7 @@ import org.apache.ambari.server.ServiceNotFoundException; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.orm.GuiceJpaInitializer; +import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Host; @@ -68,7 +69,6 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceede import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.easymock.Capture; -import org.easymock.EasyMock; import org.junit.Test; import com.google.gson.Gson; @@ -2061,5 +2061,112 @@ public class AmbariManagementControllerImplTest { } } - //todo other resources + + @Test + public void testDeleteClusterCreateHost() throws Exception { + + Injector injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + Properties properties = new Properties(); + properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "in-memory"); + + properties.setProperty(Configuration.METADETA_DIR_PATH, + "src/main/resources/stacks"); + properties.setProperty(Configuration.SERVER_VERSION_FILE, + "../version"); + properties.setProperty(Configuration.OS_VERSION_KEY, "centos6"); + + try { + install(new ControllerModule(properties)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + injector.getInstance(GuiceJpaInitializer.class); + + + String STACK_ID = "HDP-2.0.3"; + String CLUSTER_NAME = "c1"; + String HOST1 = "h1"; + String HOST2 = "h2"; + + try { + Clusters clusters = injector.getInstance(Clusters.class); + + clusters.addHost(HOST1); + Host host = clusters.getHost(HOST1); + host.setOsType("centos6"); + host.persist(); + + clusters.addHost(HOST2); + host = clusters.getHost(HOST2); + host.setOsType("centos6"); + host.persist(); + + AmbariManagementController amc = injector.getInstance(AmbariManagementController.class); + + ClusterRequest cr = new ClusterRequest(null, CLUSTER_NAME, STACK_ID, null); + amc.createCluster(cr); + + ConfigurationRequest configRequest = new ConfigurationRequest(CLUSTER_NAME, "global", "version1", + new HashMap<String, String>() {{ put("a", "b"); }}); + cr.setDesiredConfig(configRequest); + amc.updateClusters(Collections.singleton(cr), new HashMap<String, String>()); + + // add some hosts + Set<HostRequest> hrs = new HashSet<HostRequest>(); + hrs.add(new HostRequest(HOST1, CLUSTER_NAME, null)); + amc.createHosts(hrs); + + Set<ServiceRequest> serviceRequests = new HashSet<ServiceRequest>(); + serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "HDFS", null, null)); + serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "MAPREDUCE2", null, null)); + serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "YARN", null, null)); + + amc.createServices(serviceRequests); + + Set<ServiceComponentRequest> serviceComponentRequests = new HashSet<ServiceComponentRequest>(); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "NAMENODE", null, null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "SECONDARY_NAMENODE", null, null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "DATANODE", null, null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "MAPREDUCE2", "HISTORYSERVER", null, null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "YARN", "RESOURCEMANAGER", null, null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "YARN", "NODEMANAGER", null, null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "HDFS_CLIENT", null, null)); + + amc.createComponents(serviceComponentRequests); + + Set<ServiceComponentHostRequest> componentHostRequests = new HashSet<ServiceComponentHostRequest>(); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "DATANODE", HOST1, null, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "NAMENODE", HOST1, null, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "SECONDARY_NAMENODE", HOST1, null, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "HISTORYSERVER", HOST1, null, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "RESOURCEMANAGER", HOST1, null, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "NODEMANAGER", HOST1, null, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "HDFS_CLIENT", HOST1, null, null)); + + amc.createHostComponents(componentHostRequests); + + ActionRequest ar = new ActionRequest(CLUSTER_NAME, "HDFS", Role.HDFS_SERVICE_CHECK.name(), new HashMap<String, String>()); + amc.createActions(Collections.singleton(ar), null); + + // change mind, delete the cluster + amc.deleteCluster(cr); + + assertNotNull(clusters.getHost(HOST1)); + assertNotNull(clusters.getHost(HOST2)); + + HostDAO dao = injector.getInstance(HostDAO.class); + + assertNotNull(dao.findByName(HOST1)); + assertNotNull(dao.findByName(HOST2)); + + } finally { + injector.getInstance(PersistService.class).stop(); + } + + } + }
