You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2014/05/15 22:34:19 UTC

git commit: AMBARI-5767. Blueprint delete throws exception. (swagle)

Repository: ambari
Updated Branches:
  refs/heads/branch-1.6.0 6fd497f17 -> 69b2c95ef


AMBARI-5767. Blueprint delete throws exception. (swagle)


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

Branch: refs/heads/branch-1.6.0
Commit: 69b2c95ef0043eb1cb78cebdd05678fc5aa4e7cb
Parents: 6fd497f
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Wed May 14 15:52:11 2014 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Thu May 15 13:34:08 2014 -0700

----------------------------------------------------------------------
 .../internal/BlueprintResourceProvider.java     | 13 +++++++------
 .../ambari/server/orm/dao/BlueprintDAO.java     |  9 +++++++++
 .../internal/BlueprintResourceProviderTest.java |  8 +++-----
 .../ambari/server/orm/dao/BlueprintDAOTest.java | 20 ++++++++++++++++++++
 4 files changed, 39 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/69b2c95e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
index 003590f..5e04141 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
@@ -212,15 +212,16 @@ public class BlueprintResourceProvider extends AbstractResourceProvider {
         new RequestImpl(null, null, null, null), predicate);
 
     for (final Resource resource : setResources) {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Deleting Blueprint, name=" +
-            resource.getPropertyValue(BLUEPRINT_NAME_PROPERTY_ID));
-      }
+      final String blueprintName =
+        (String) resource.getPropertyValue(BLUEPRINT_NAME_PROPERTY_ID);
+
+      LOG.info("Deleting Blueprint, name = " + blueprintName);
+
       modifyResources(new Command<Void>() {
         @Override
         public Void invoke() throws AmbariException {
-          dao.remove(toEntity(resource));
-          return null;
+        dao.removeByName(blueprintName);
+        return null;
         }
       });
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/69b2c95e/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
index 0cbaedc..9b58422 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
@@ -109,4 +109,13 @@ public class BlueprintDAO {
   public void remove(BlueprintEntity blueprintEntity) {
     entityManagerProvider.get().remove(merge(blueprintEntity));
   }
+
+  /**
+   * Remove entity instance by primary key
+   * @param blueprint_name Primary key: blueprint name
+   */
+  @Transactional
+  public void removeByName(String blueprint_name) {
+    entityManagerProvider.get().remove(findByName(blueprint_name));
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/69b2c95e/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
index b611551..0c35c10 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
@@ -43,6 +43,7 @@ import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.easymock.Capture;
 
+import static org.easymock.EasyMock.expectLastCall;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
@@ -263,14 +264,13 @@ public class BlueprintResourceProviderTest {
   public void testDeleteResources() throws SystemException, UnsupportedPropertyException,
                                            NoSuchParentResourceException, NoSuchResourceException {
 
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
-
     ResourceProvider provider = createProvider();
     BlueprintEntity blueprintEntity = createEntity(getTestProperties().iterator().next());
 
     // set expectations
     expect(dao.findByName(BLUEPRINT_NAME)).andReturn(blueprintEntity);
-    dao.remove(capture(entityCapture));
+    dao.removeByName(blueprintEntity.getBlueprintName());
+    expectLastCall();
     replay(dao);
 
     Predicate predicate = new EqualsPredicate<String>(
@@ -288,8 +288,6 @@ public class BlueprintResourceProviderTest {
     assertNotNull(lastEvent.getPredicate());
 
     verify(dao);
-
-    validateEntity(entityCapture.getValue(), false);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/69b2c95e/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/BlueprintDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/BlueprintDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/BlueprintDAOTest.java
index c157729..1ac20e6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/BlueprintDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/BlueprintDAOTest.java
@@ -22,9 +22,12 @@ import com.google.inject.Provider;
 import org.apache.ambari.server.orm.entities.BlueprintEntity;
 import org.junit.Before;
 import org.junit.Test;
+
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createStrictMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.reset;
 import static org.easymock.EasyMock.verify;
@@ -149,4 +152,21 @@ public class BlueprintDAOTest {
 
     verify(entityManagerProvider, entityManager);
   }
+
+  @Test
+  public void testRemoveByName() {
+    BlueprintEntity entity = new BlueprintEntity();
+    BlueprintDAO dao = new BlueprintDAO();
+    dao.entityManagerProvider = entityManagerProvider;
+
+    expect(entityManager.find(eq(BlueprintEntity.class), eq("test"))).andReturn(entity);
+    entityManager.remove(entity);
+    expectLastCall();
+
+    replay(entityManager);
+
+    dao.removeByName("test");
+
+    verify(entityManager);
+  }
 }