ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject ambari git commit: AMBARI-10151. Deregister Stack Version error if it has been already INSTALLED or INSTALL_FAILED on some cluster.(vbrodetskyi)
Date Tue, 24 Mar 2015 14:52:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 86f5870e6 -> 2cb80ce3f


AMBARI-10151. Deregister Stack Version error if it has been already INSTALLED or INSTALL_FAILED
on some cluster.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: 2cb80ce3f5b80fb0d0c90b2159a631a75ef3a266
Parents: 86f5870
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Tue Mar 24 16:52:25 2015 +0200
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Tue Mar 24 16:52:25 2015 +0200

----------------------------------------------------------------------
 .../orm/entities/RepositoryVersionEntity.java   |  9 ++++
 .../orm/dao/RepositoryVersionDAOTest.java       | 52 ++++++++++++++++++--
 2 files changed, 57 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2cb80ce3/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
index 78cc277..0c52a0b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
@@ -41,6 +41,9 @@ import org.slf4j.LoggerFactory;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
+import java.util.Collection;
+import javax.persistence.CascadeType;
+import javax.persistence.OneToMany;
 
 @Entity
 @Table(name = "repo_version", uniqueConstraints = {
@@ -88,6 +91,12 @@ public class RepositoryVersionEntity {
   @Lob
   @Column(name = "repositories")
   private String operatingSystems;
+  
+  @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "repositoryVersion")
+  private Collection<ClusterVersionEntity> clusterVersionEntities;
+  
+  @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "repositoryVersion")
+  private Collection<HostVersionEntity> hostVersionEntities;
 
   // ----- RepositoryVersionEntity -------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2cb80ce3/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
index 6cdadea..09c8453 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
@@ -18,18 +18,21 @@
 
 package org.apache.ambari.server.orm.dao;
 
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
+import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.state.RepositoryVersionState;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
-
 /**
  * RepositoryVersionDAO unit tests.
  */
@@ -37,11 +40,20 @@ public class RepositoryVersionDAOTest {
 
   private static Injector injector;
   private RepositoryVersionDAO repositoryVersionDAO;
+  private ClusterVersionDAO clusterVersionDAO;
+  private HostVersionDAO hostVersionDAO;
+  
+  private ClusterDAO clusterDAO;
+  private OrmTestHelper helper;
 
   @Before
   public void before() {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
+    clusterVersionDAO = injector.getInstance(ClusterVersionDAO.class);
+    hostVersionDAO = injector.getInstance(HostVersionDAO.class);
+    clusterDAO = injector.getInstance(ClusterDAO.class);
+    helper = injector.getInstance(OrmTestHelper.class);    
     injector.getInstance(GuiceJpaInitializer.class);
   }
 
@@ -76,6 +88,38 @@ public class RepositoryVersionDAOTest {
     Assert.assertEquals(1, repositoryVersionDAO.findByStack("stack").size());
   }
 
+  @Test
+  public void testDelete() {
+    createSingleRecord();
+    Assert.assertNotNull(repositoryVersionDAO.findByStackAndVersion("stack", "version"));
+    final RepositoryVersionEntity entity = repositoryVersionDAO.findByStackAndVersion("stack",
"version");
+    repositoryVersionDAO.remove(entity);
+    Assert.assertNull(repositoryVersionDAO.findByStackAndVersion("stack", "version"));
+  }  
+
+  @Test
+  public void testDeleteCascade() {   
+    long clusterId = helper.createCluster();
+    ClusterEntity cluster = clusterDAO.findById(clusterId);
+    createSingleRecord();
+    final RepositoryVersionEntity entity = repositoryVersionDAO.findByStackAndVersion("stack",
"version");
+    
+    ClusterVersionEntity cvA = new ClusterVersionEntity(cluster, entity, RepositoryVersionState.INSTALLED,
System.currentTimeMillis(), System.currentTimeMillis(), "admin");
+    clusterVersionDAO.create(cvA);
+    long cvAId = cvA.getId();
+    cvA = clusterVersionDAO.findByPK(cvAId);
+    Assert.assertNotNull(cvA.getRepositoryVersion());
+    final RepositoryVersionEntity newEntity = repositoryVersionDAO.findByStackAndVersion("stack",
"version");
+    try {
+      repositoryVersionDAO.remove(newEntity);
+    } catch (Exception e) {
+      //Cascade deletion will fail because absent integrity in in-memory DB
+      Assert.assertNotNull(clusterVersionDAO.findByPK(cvAId));
+    } 
+    //
+   
+  }    
+  
   @After
   public void after() {
     injector.getInstance(PersistService.class).stop();


Mime
View raw message