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 - backport to 1.7.0
Date Fri, 31 Oct 2014 21:32:56 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.7.0 240c9f69c -> 605ee38b8


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


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

Branch: refs/heads/branch-1.7.0
Commit: 605ee38b88f11f2332d431f0c144f99fee04f117
Parents: 240c9f6
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Fri Oct 31 17:32:18 2014 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Fri Oct 31 17:32:47 2014 -0400

----------------------------------------------------------------------
 .../ViewInstanceResourceDefinition.java         |  5 ++-
 .../apache/ambari/server/view/ViewRegistry.java | 36 ++++++++------------
 .../ambari/server/view/ViewRegistryTest.java    | 33 ++++++++----------
 3 files changed, 34 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/605ee38b/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/605ee38b/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 6581dfe..07b237f 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
@@ -123,7 +123,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.
@@ -402,27 +402,12 @@ 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) {
-        if (definition.isDeployed()) {
-          for (Resource.Type type : definition.getViewResourceTypes()) {
-            subResourceDefinitions.add(new SubResourceDefinition(type));
-          }
-          subResourceDefinitionsMap.put(viewName, subResourceDefinitions);
-        }
-      }
-    }
-    return subResourceDefinitions;
+    return subResourceDefinitionsMap.get(viewName);
   }
 
   /**
@@ -820,10 +805,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());
@@ -850,7 +838,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());
@@ -884,7 +872,7 @@ public class ViewRegistry {
     }
 
     ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity();
-    resourceTypeEntity.setName(viewDefinition.getName());
+    resourceTypeEntity.setName(viewName);
 
     viewDefinition.setResourceType(resourceTypeEntity);
 
@@ -907,6 +895,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/605ee38b/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 bcbcfad..7c0cade 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;
@@ -75,8 +76,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;
@@ -611,30 +610,28 @@ public class ViewRegistryTest {
 
   @Test
   public void testGetSubResourceDefinitions() throws Exception {
-    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
-    ViewRegistry registry = ViewRegistry.getInstance();
-
-    viewDefinition.setStatus(ViewDefinition.ViewStatus.DEPLOYING);
+    ViewConfig config = ViewConfigTest.getConfig();
 
-    registry.addDefinition(viewDefinition);
-    Set<SubResourceDefinition> subResourceDefinitions = registry.getSubResourceDefinitions("MY_VIEW",
"1.0.0");
+    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
 
-    Assert.assertTrue(subResourceDefinitions.isEmpty());
+    ViewRegistry registry = ViewRegistry.getInstance();
 
-    ResourceConfig config = ResourceConfigTest.getResourceConfigs().get(0);
-    Resource.Type type1 = new Resource.Type("myType");
+    registry.setupViewDefinition(viewDefinition, config, getClass().getClassLoader());
 
-    ResourceProvider provider1 = createNiceMock(ResourceProvider.class);
-    viewDefinition.addResourceProvider(type1, provider1);
+    Set<SubResourceDefinition> subResourceDefinitions =
+        registry.getSubResourceDefinitions(viewDefinition.getCommonName(), viewDefinition.getVersion());
 
-    viewDefinition.addResourceConfiguration(type1, config);
 
-    viewDefinition.setStatus(ViewDefinition.ViewStatus.DEPLOYED);
+    Assert.assertEquals(3, subResourceDefinitions.size());
 
-    subResourceDefinitions = registry.getSubResourceDefinitions("MY_VIEW", "1.0.0");
+    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