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-12223 - Views: Don't cache URL stream provider in view context (tbeerbower)
Date Tue, 30 Jun 2015 17:56:38 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 a79b4815e -> e01774a09


AMBARI-12223 - Views: Don't cache URL stream provider in view context (tbeerbower)


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

Branch: refs/heads/branch-2.1
Commit: e01774a095f66582b803ffdfe7533746958fe7d9
Parents: a79b481
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Tue Jun 30 13:54:16 2015 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Tue Jun 30 13:56:27 2015 -0400

----------------------------------------------------------------------
 .../controller/internal/URLStreamProvider.java  |  2 +-
 .../ambari/server/view/ViewContextImpl.java     | 30 +++-----------------
 .../ambari/server/view/ViewContextImplTest.java |  4 +++
 3 files changed, 9 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e01774a0/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
index bc11646..4e60b5f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
@@ -185,7 +185,7 @@ public class URLStreamProvider implements StreamProvider {
         headers = new HashMap<String, List<String>>(headers);
 
         List<String> cookieList = headers.get(COOKIE);
-        String       cookies    = cookieList.isEmpty() ? null : cookieList.get(0);
+        String       cookies    = cookieList == null || cookieList.isEmpty() ? null : cookieList.get(0);
 
         headers.put(COOKIE, Collections.singletonList(appendCookie(cookies, appCookie)));
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e01774a0/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
index 8788346..a22c514 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
@@ -87,16 +87,6 @@ public class ViewContextImpl implements ViewContext, ViewController {
   private final ViewRegistry viewRegistry;
 
   /**
-   * The URL stream provider.
-   */
-  private ViewURLStreamProvider streamProvider;
-
-  /**
-   * The Ambari stream provider.
-   */
-  private ViewAmbariStreamProvider ambariStreamProvider;
-
-  /**
    * The data store.
    */
   private DataStore dataStore = null;
@@ -259,22 +249,17 @@ public class ViewContextImpl implements ViewContext, ViewController
{
 
   @Override
   public org.apache.ambari.view.URLStreamProvider getURLStreamProvider() {
-    ensureURLStreamProvider();
-    return streamProvider;
+    return viewRegistry.createURLStreamProvider(this);
   }
 
   @Override
   public URLConnectionProvider getURLConnectionProvider() {
-    ensureURLStreamProvider();
-    return streamProvider;
+    return viewRegistry.createURLStreamProvider(this);
   }
 
   @Override
   public synchronized AmbariStreamProvider getAmbariStreamProvider() {
-    if (ambariStreamProvider == null) {
-      ambariStreamProvider = viewRegistry.createAmbariStreamProvider();
-    }
-    return ambariStreamProvider;
+    return viewRegistry.createAmbariStreamProvider();
   }
 
   @Override
@@ -309,7 +294,6 @@ public class ViewContextImpl implements ViewContext, ViewController {
 
   @Override
   public HttpImpersonatorImpl getHttpImpersonator() {
-    ensureURLStreamProvider();
     return new HttpImpersonatorImpl(this);
   }
 
@@ -355,14 +339,8 @@ public class ViewContextImpl implements ViewContext, ViewController {
     viewRegistry.unregisterListener(listener, viewName, viewVersion);
   }
 
-  // ----- helper methods ----------------------------------------------------
 
-  // ensure that the URL stream provider has been created
-  private synchronized void ensureURLStreamProvider() {
-    if (streamProvider == null) {
-      streamProvider = viewRegistry.createURLStreamProvider(this);
-    }
-  }
+  // ----- helper methods ----------------------------------------------------
 
   // check for an associated instance
   private void checkInstance() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/e01774a0/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
index e111811..7e2d9b5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
@@ -181,6 +181,7 @@ public class ViewContextImplTest {
     ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
     ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);
     ViewURLStreamProvider urlStreamProvider = createNiceMock(ViewURLStreamProvider.class);
+    ViewURLStreamProvider urlStreamProvider2 = createNiceMock(ViewURLStreamProvider.class);
 
     ResourceProvider provider = createNiceMock(ResourceProvider.class);
     Resource.Type type = new Resource.Type("MY_VIEW/myType");
@@ -190,10 +191,13 @@ public class ViewContextImplTest {
     ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition, viewRegistry);
 
     expect(viewRegistry.createURLStreamProvider(viewContext)).andReturn(urlStreamProvider);
+    expect(viewRegistry.createURLStreamProvider(viewContext)).andReturn(urlStreamProvider2);
 
     replay(viewRegistry);
 
     Assert.assertEquals(urlStreamProvider, viewContext.getURLStreamProvider());
+    // make sure the the provider is not cached
+    Assert.assertEquals(urlStreamProvider2, viewContext.getURLStreamProvider());
 
     verify(viewRegistry);
   }


Mime
View raw message