ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject ambari git commit: AMBARI-11540 - Views : Can't create instance (intermittent) (tbeerbower)
Date Fri, 29 May 2015 20:27:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 5767697ca -> 8f077e154


AMBARI-11540 - Views : Can't create instance (intermittent) (tbeerbower)


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

Branch: refs/heads/trunk
Commit: 8f077e15416d1627ce15536e27c3f0626d19d9b0
Parents: 5767697
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Fri May 29 15:54:16 2015 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Fri May 29 16:27:36 2015 -0400

----------------------------------------------------------------------
 .../apache/ambari/server/view/ViewRegistry.java | 21 ++++++++++----------
 .../ambari/server/view/ViewRegistryTest.java    | 16 +++++++--------
 2 files changed, 18 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8f077e15/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
index b3ae2d0..ae68096 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
@@ -501,7 +501,6 @@ public class ViewRegistry {
    *                                   does not exist
    * @throws SystemException           if the instance can not be installed
    */
-  @Transactional
   public void installViewInstance(ViewInstanceEntity instanceEntity)
       throws ValidationException, IllegalArgumentException, SystemException {
     ViewEntity viewEntity = getDefinition(instanceEntity.getViewName());
@@ -520,18 +519,9 @@ public class ViewRegistry {
         instanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_CREATE);
 
         ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findByName(ViewEntity.getViewName(viewName,
version));
-        // create an admin resource to represent this view instance
-        instanceEntity.setResource(createViewInstanceResource(resourceTypeEntity));
-
-        instanceDAO.merge(instanceEntity);
 
-        ViewInstanceEntity persistedInstance = instanceDAO.findByName(ViewEntity.getViewName(viewName,
version), instanceName);
-        if (persistedInstance == null) {
-          String message = "Instance  " + instanceEntity.getViewName() + " can not be found.";
+        ViewInstanceEntity persistedInstance = mergeViewInstance(instanceEntity, resourceTypeEntity);
 
-          LOG.error(message);
-          throw new IllegalStateException(message);
-        }
         instanceEntity.setViewInstanceId(persistedInstance.getViewInstanceId());
         instanceEntity.setResource(persistedInstance.getResource());
 
@@ -1370,6 +1360,15 @@ public class ViewRegistry {
     instance1.setProperties(instance2.getProperties());
   }
 
+  // create an admin resource for the given view instance entity and merge it
+  @Transactional
+  private ViewInstanceEntity mergeViewInstance(ViewInstanceEntity instanceEntity, ResourceTypeEntity
resourceTypeEntity) {
+    // create an admin resource to represent this view instance
+    instanceEntity.setResource(createViewInstanceResource(resourceTypeEntity));
+
+    return instanceDAO.merge(instanceEntity);
+  }
+
   // create an admin resource to represent a view instance
   private ResourceEntity createViewInstanceResource(ResourceTypeEntity resourceTypeEntity)
{
     ResourceEntity resourceEntity = new ResourceEntity();

http://git-wip-us.apache.org/repos/asf/ambari/blob/8f077e15/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
index c66a9ce..a8c938f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
@@ -809,13 +809,14 @@ public class ViewRegistryTest {
     ViewConfig config = ViewConfigTest.getConfig(xml_valid_instance);
     ViewEntity viewEntity = getViewEntity(config, ambariConfig, getClass().getClassLoader(),
"");
     ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, config.getInstances().get(0));
+    ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity();
 
-    expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(null);
-    expect(viewInstanceDAO.findByName("MY_VIEW{1.0.0}", viewInstanceEntity.getInstanceName())).andReturn(viewInstanceEntity);
+    expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(viewInstanceEntity);
+    expect(resourceTypeDAO.findByName("MY_VIEW{1.0.0}")).andReturn(resourceTypeEntity);
 
     handlerList.addViewInstance(viewInstanceEntity);
 
-    replay(viewDAO, viewInstanceDAO, securityHelper, handlerList);
+    replay(viewDAO, viewInstanceDAO, resourceTypeDAO, securityHelper, handlerList);
 
     registry.addDefinition(viewEntity);
     registry.installViewInstance(viewInstanceEntity);
@@ -828,8 +829,9 @@ public class ViewRegistryTest {
     Assert.assertEquals("v2-1", instanceEntity.getProperty("p2").getValue() );
 
     Assert.assertEquals(viewInstanceEntity, viewInstanceDefinitions.iterator().next());
+    Assert.assertEquals(resourceTypeEntity, viewInstanceEntity.getResource().getResourceType());
 
-    verify(viewDAO, viewInstanceDAO, securityHelper, handlerList);
+    verify(viewDAO, viewInstanceDAO, resourceTypeDAO, securityHelper, handlerList);
   }
 
   @Test
@@ -876,8 +878,7 @@ public class ViewRegistryTest {
 
     ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, config.getInstances().get(0));
 
-    expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(null);
-    expect(viewInstanceDAO.findByName("MY_VIEW{1.0.0}", viewInstanceEntity.getInstanceName())).andReturn(viewInstanceEntity);
+    expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(viewInstanceEntity);
 
     handlerList.addViewInstance(viewInstanceEntity);
 
@@ -1099,8 +1100,7 @@ public class ViewRegistryTest {
     ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, config.getInstances().get(0));
     ViewInstanceEntity updateInstance = getViewInstanceEntity(viewEntity, invalidConfig.getInstances().get(0));
 
-    expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(null);
-    expect(viewInstanceDAO.findByName("MY_VIEW{1.0.0}", viewInstanceEntity.getInstanceName())).andReturn(viewInstanceEntity).anyTimes();
+    expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(viewInstanceEntity);
 
     replay(viewDAO, viewInstanceDAO, securityHelper);
 


Mime
View raw message