ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-5767. Blueprint delete throws exception. (swagle)
Date Thu, 15 May 2014 20:35:10 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 42d19f377 -> 6ab57b722


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/6ab57b72
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6ab57b72
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6ab57b72

Branch: refs/heads/trunk
Commit: 6ab57b722a3e52ed39d766f65b69a56a0d0bfa4e
Parents: 42d19f3
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu May 15 13:35:02 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu May 15 13:35:02 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/6ab57b72/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/6ab57b72/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/6ab57b72/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 ddf7c06..99a1120 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
@@ -42,6 +42,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;
@@ -262,14 +263,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>(
@@ -287,8 +287,6 @@ public class BlueprintResourceProviderTest {
     assertNotNull(lastEvent.getPredicate());
 
     verify(dao);
-
-    validateEntity(entityCapture.getValue(), false);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/6ab57b72/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);
+  }
 }


Mime
View raw message