ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject git commit: AMBARI-7644 - After view deploy, GET call returning 400, not possible to create view instances w/o restart
Date Sat, 04 Oct 2014 21:36:00 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk e069b3076 -> 0e959b0ed


AMBARI-7644 - After view deploy, GET call returning 400, not possible to create view instances
w/o restart


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

Branch: refs/heads/trunk
Commit: 0e959b0ed80fc1a170cc10b1c75050c88a7b2d06
Parents: e069b30
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Sat Oct 4 08:58:21 2014 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Sat Oct 4 17:35:33 2014 -0400

----------------------------------------------------------------------
 .../ViewInstanceResourceDefinition.java         |  5 ++-
 .../apache/ambari/server/view/ViewRegistry.java | 35 +++++++++-----------
 .../ambari/server/view/ViewRegistryTest.java    | 28 ++++++++++------
 3 files changed, 36 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0e959b0e/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinition.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinition.java
index 632a6bc..7b1008c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinition.java
@@ -41,7 +41,10 @@ public class ViewInstanceResourceDefinition extends BaseResourceDefinition
{
    */
   public ViewInstanceResourceDefinition(Set<SubResourceDefinition> subResourceDefinitions)
{
     super(Resource.Type.ViewInstance);
-    this.subResourceDefinitions = new HashSet<SubResourceDefinition>(subResourceDefinitions);
+
+    this.subResourceDefinitions = subResourceDefinitions == null ? new HashSet<SubResourceDefinition>()
:
+        new HashSet<SubResourceDefinition>(subResourceDefinitions);
+
     this.subResourceDefinitions.add(new SubResourceDefinition(Resource.Type.ViewPrivilege));
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e959b0e/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 e48c88e..c1139a3 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
@@ -124,7 +124,7 @@ public class ViewRegistry {
    * Mapping of view names to sub-resources.
    */
   private final Map<String, Set<SubResourceDefinition>> subResourceDefinitionsMap
=
-      new HashMap<String, Set<SubResourceDefinition>>();
+      new ConcurrentHashMap<String, Set<SubResourceDefinition>>();
 
   /**
    * Mapping of view types to resource providers.
@@ -403,27 +403,13 @@ public class ViewRegistry {
    *
    * @return the set of sub-resource definitions
    */
-  public synchronized Set<SubResourceDefinition> getSubResourceDefinitions(
+  public Set<SubResourceDefinition> getSubResourceDefinitions(
       String viewName, String version) {
 
     viewName = ViewEntity.getViewName(viewName, version);
 
-    Set<SubResourceDefinition> subResourceDefinitions =
-        subResourceDefinitionsMap.get(viewName);
-
-    if (subResourceDefinitions == null) {
-      subResourceDefinitions = new HashSet<SubResourceDefinition>();
-      ViewEntity definition = getDefinition(viewName);
-      if (definition != null) {
-        for (Resource.Type type : definition.getViewResourceTypes()) {
-          subResourceDefinitions.add(new SubResourceDefinition(type));
-        }
-      }
-      subResourceDefinitionsMap.put(viewName, subResourceDefinitions);
-    }
-    return subResourceDefinitions;
+    return subResourceDefinitionsMap.get(viewName);
   }
-
   /**
    * Read all view archives.
    */
@@ -773,10 +759,13 @@ public class ViewRegistry {
     List<ParameterConfig> parameterConfigurations = viewConfig.getParameters();
 
     Collection<ViewParameterEntity> parameters = new HashSet<ViewParameterEntity>();
+
+    String viewName = viewDefinition.getName();
+
     for (ParameterConfig parameterConfiguration : parameterConfigurations) {
       ViewParameterEntity viewParameterEntity =  new ViewParameterEntity();
 
-      viewParameterEntity.setViewName(viewDefinition.getName());
+      viewParameterEntity.setViewName(viewName);
       viewParameterEntity.setName(parameterConfiguration.getName());
       viewParameterEntity.setDescription(parameterConfiguration.getDescription());
       viewParameterEntity.setRequired(parameterConfiguration.isRequired());
@@ -803,7 +792,7 @@ public class ViewRegistry {
     for (ResourceConfig resourceConfiguration : resourceConfigurations) {
       ViewResourceEntity viewResourceEntity = new ViewResourceEntity();
 
-      viewResourceEntity.setViewName(viewDefinition.getName());
+      viewResourceEntity.setViewName(viewName);
       viewResourceEntity.setName(resourceConfiguration.getName());
       viewResourceEntity.setPluralName(resourceConfiguration.getPluralName());
       viewResourceEntity.setIdProperty(resourceConfiguration.getIdProperty());
@@ -837,7 +826,7 @@ public class ViewRegistry {
     }
 
     ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity();
-    resourceTypeEntity.setName(viewDefinition.getName());
+    resourceTypeEntity.setName(viewName);
 
     viewDefinition.setResourceType(resourceTypeEntity);
 
@@ -860,6 +849,12 @@ public class ViewRegistry {
     viewDefinition.setView(view);
     viewDefinition.setMask(viewConfig.getMasker());
 
+    Set<SubResourceDefinition> subResourceDefinitions = new HashSet<SubResourceDefinition>();
+    for (Resource.Type type : viewDefinition.getViewResourceTypes()) {
+      subResourceDefinitions.add(new SubResourceDefinition(type));
+    }
+    subResourceDefinitionsMap.put(viewName, subResourceDefinitions);
+
     return viewDefinition;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e959b0e/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 47bf5c3..e6a20b3 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
@@ -40,6 +40,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -74,8 +75,6 @@ import org.apache.ambari.server.security.authorization.AmbariGrantedAuthority;
 import org.apache.ambari.server.view.configuration.InstanceConfig;
 import org.apache.ambari.server.view.configuration.InstanceConfigTest;
 import org.apache.ambari.server.view.configuration.PropertyConfig;
-import org.apache.ambari.server.view.configuration.ResourceConfig;
-import org.apache.ambari.server.view.configuration.ResourceConfigTest;
 import org.apache.ambari.server.view.configuration.ViewConfig;
 import org.apache.ambari.server.view.configuration.ViewConfigTest;
 import org.apache.ambari.server.view.events.EventImpl;
@@ -600,21 +599,28 @@ public class ViewRegistryTest {
 
   @Test
   public void testGetSubResourceDefinitions() throws Exception {
+    ViewConfig config = ViewConfigTest.getConfig();
+
     ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
+
     ViewRegistry registry = ViewRegistry.getInstance();
 
-    ResourceConfig config = ResourceConfigTest.getResourceConfigs().get(0);
-    Resource.Type type1 = new Resource.Type("myType");
+    registry.setupViewDefinition(viewDefinition, config, getClass().getClassLoader());
+
+    Set<SubResourceDefinition> subResourceDefinitions =
+        registry.getSubResourceDefinitions(viewDefinition.getCommonName(), viewDefinition.getVersion());
 
-    ResourceProvider provider1 = createNiceMock(ResourceProvider.class);
-    viewDefinition.addResourceProvider(type1, provider1);
 
-    viewDefinition.addResourceConfiguration(type1, config);
-    registry.addDefinition(viewDefinition);
-    Set<SubResourceDefinition> subResourceDefinitions = registry.getSubResourceDefinitions("MY_VIEW",
"1.0.0");
+    Assert.assertEquals(3, subResourceDefinitions.size());
+
+    Set<String> names = new HashSet<String>();
+    for (SubResourceDefinition definition : subResourceDefinitions) {
+      names.add(definition.getType().name());
+    }
 
-    Assert.assertEquals(1, subResourceDefinitions.size());
-    Assert.assertEquals("myType", subResourceDefinitions.iterator().next().getType().name());
+    Assert.assertTrue(names.contains("MY_VIEW{1.0.0}/resources"));
+    Assert.assertTrue(names.contains("MY_VIEW{1.0.0}/resource"));
+    Assert.assertTrue(names.contains("MY_VIEW{1.0.0}/subresource"));
   }
 
   @Test


Mime
View raw message