ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject ambari git commit: AMBARI-14212. Changes in Instance Definition does not get reflects in pig and hive view due to caching in UserLocal.java (Gaurav Nagar via yusaku)
Date Fri, 04 Dec 2015 17:17:28 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 5c5e670f3 -> 2c51d1b7c


AMBARI-14212. Changes in Instance Definition does not get reflects in pig and hive view due
to caching in UserLocal.java (Gaurav Nagar via yusaku)


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

Branch: refs/heads/branch-2.2
Commit: 2c51d1b7c61add947e3ca5e5f4d2dfb63b56429b
Parents: 5c5e670
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Fri Dec 4 09:15:44 2015 -0800
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Fri Dec 4 09:17:17 2015 -0800

----------------------------------------------------------------------
 .../internal/ViewInstanceResourceProvider.java  |   1 +
 .../apache/ambari/server/view/ViewRegistry.java |  12 ++
 .../main/java/org/apache/ambari/view/View.java  |   7 ++
 contrib/views/hive/src/main/resources/view.xml  |   1 +
 .../ambari/view/pig/utils/UserLocalObjects.java |  10 +-
 contrib/views/pig/src/main/resources/view.xml   |   1 +
 .../apache/ambari/view/pig/test/FileTest.java   |   4 +-
 .../apache/ambari/view/pig/test/HelpTest.java   |   4 +-
 .../ambari/view/pig/test/IntegrationalTest.java |  10 +-
 .../apache/ambari/view/pig/test/JobTest.java    |   6 +-
 .../apache/ambari/view/pig/test/ScriptTest.java |   4 +-
 .../view/pig/test/ScriptTestHDFSUnmanaged.java  |   6 +-
 .../view/pig/test/ScriptTestUnmanaged.java      |   4 +-
 .../org/apache/ambari/view/utils/UserLocal.java |  20 +++-
 .../org/apache/ambari/view/utils/ViewImpl.java  |  50 ++++++++
 .../apache/ambari/view/utils/ViewUserLocal.java | 116 -------------------
 16 files changed, 115 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
index 7cecedc..71d0826 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
@@ -414,6 +414,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider
{
         if (includeInstance(view.getCommonName(), view.getVersion(), instance.getInstanceName(),
false)) {
           try {
             ViewRegistry.getInstance().updateViewInstance(instance);
+            ViewRegistry.getInstance().updateView(instance);
           } catch (org.apache.ambari.view.SystemException e) {
             throw new AmbariException("Caught exception trying to update view instance.",
e);
           } catch (ValidationException e) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/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 ddfd4e3..3385395 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
@@ -569,6 +569,18 @@ public class ViewRegistry {
   }
 
   /**
+   * Calls onUpdate hook on View class
+   *
+   * @param instanceEntity
+   */
+  public void updateView(ViewInstanceEntity instanceEntity){
+    ViewEntity viewEntity = getDefinition(instanceEntity.getViewName());
+    if(null != viewEntity && null != viewEntity.getView()){
+      viewEntity.getView().onUpdate(instanceEntity);
+    }
+  }
+
+  /**
    * Get a view instance entity for the given view name and instance name.
    *
    * @param viewName      the view name

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/ambari-views/src/main/java/org/apache/ambari/view/View.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/View.java b/ambari-views/src/main/java/org/apache/ambari/view/View.java
index 4de1746..60d02bc 100644
--- a/ambari-views/src/main/java/org/apache/ambari/view/View.java
+++ b/ambari-views/src/main/java/org/apache/ambari/view/View.java
@@ -43,4 +43,11 @@ public interface View {
    * @param definition  the view instance definition
    */
   public void onDestroy(ViewInstanceDefinition definition);
+
+  /**
+   * Called by the view framework when the given instance is being updated
+   *
+   * @param definition
+   */
+  public void onUpdate(ViewInstanceDefinition definition);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/hive/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/view.xml b/contrib/views/hive/src/main/resources/view.xml
index 23f901b..e04ed4b 100644
--- a/contrib/views/hive/src/main/resources/view.xml
+++ b/contrib/views/hive/src/main/resources/view.xml
@@ -23,6 +23,7 @@
     <min-ambari-version>2.0.*</min-ambari-version>
 
     <validator-class>org.apache.ambari.view.hive.PropertyValidator</validator-class>
+    <view-class>org.apache.ambari.view.utils.ViewImpl</view-class>
 
     <!-- Hive Configs -->
     <parameter>

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/UserLocalObjects.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/UserLocalObjects.java
b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/UserLocalObjects.java
index 1b22a45..8293899 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/UserLocalObjects.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/UserLocalObjects.java
@@ -21,7 +21,7 @@ package org.apache.ambari.view.pig.utils;
 import org.apache.ambari.view.ViewContext;
 import org.apache.ambari.view.pig.templeton.client.TempletonApi;
 import org.apache.ambari.view.pig.templeton.client.TempletonApiFactory;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.ambari.view.utils.hdfs.HdfsApiException;
 import org.apache.ambari.view.utils.hdfs.HdfsUtil;
@@ -35,15 +35,15 @@ public class UserLocalObjects {
   /**
    * HdfsApi user-local instance
    */
-  private static ViewUserLocal<HdfsApi> hdfsApi;
+  private static UserLocal<HdfsApi> hdfsApi;
 
   /**
    * TempletonApi user-local instance
    */
-  private static ViewUserLocal<TempletonApi> templetonApi;
+  private static UserLocal<TempletonApi> templetonApi;
 
   static {
-    templetonApi = new ViewUserLocal<TempletonApi>(TempletonApi.class) {
+    templetonApi = new UserLocal<TempletonApi>(TempletonApi.class) {
       @Override
       protected synchronized TempletonApi initialValue(ViewContext context) {
         TempletonApiFactory templetonApiFactory = new TempletonApiFactory(context);
@@ -51,7 +51,7 @@ public class UserLocalObjects {
       }
     };
 
-    hdfsApi = new ViewUserLocal<HdfsApi>(HdfsApi.class) {
+    hdfsApi = new UserLocal<HdfsApi>(HdfsApi.class) {
       @Override
       protected synchronized HdfsApi initialValue(ViewContext context) {
         try {

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/resources/view.xml b/contrib/views/pig/src/main/resources/view.xml
index 636e26e..30efae8 100644
--- a/contrib/views/pig/src/main/resources/view.xml
+++ b/contrib/views/pig/src/main/resources/view.xml
@@ -23,6 +23,7 @@
     <min-ambari-version>2.0.*</min-ambari-version>
 
     <validator-class>org.apache.ambari.view.pig.PropertyValidator</validator-class>
+    <view-class>org.apache.ambari.view.utils.ViewImpl</view-class>
 
     <!-- HDFS Configs -->
     <parameter>

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
index 7f0db4a..8c9f70e 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
@@ -22,7 +22,7 @@ import org.apache.ambari.view.pig.HDFSTest;
 import org.apache.ambari.view.pig.resources.files.FileResource;
 import org.apache.ambari.view.pig.resources.files.FileService;
 import org.apache.ambari.view.pig.utils.*;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.json.simple.JSONObject;
 import org.junit.*;
@@ -60,7 +60,7 @@ public class FileTest extends HDFSTest {
   @AfterClass
   public static void shutDown() throws Exception {
     HDFSTest.shutDown(); // super
-    ViewUserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
+    UserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
   }
 
   private Response doCreateFile() throws IOException, InterruptedException {

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
index 5e41aed..6e2810e 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
@@ -20,7 +20,7 @@ package org.apache.ambari.view.pig.test;
 
 import org.apache.ambari.view.pig.HDFSTest;
 import org.apache.ambari.view.pig.services.HelpService;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.json.simple.JSONObject;
 import org.junit.*;
@@ -45,7 +45,7 @@ public class HelpTest extends HDFSTest {
   @AfterClass
   public static void shutDown() throws Exception {
     HDFSTest.shutDown(); // super
-    ViewUserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
+    UserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/IntegrationalTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/IntegrationalTest.java
b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/IntegrationalTest.java
index 9813fea..92476c6 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/IntegrationalTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/IntegrationalTest.java
@@ -26,7 +26,7 @@ import org.apache.ambari.view.pig.resources.jobs.JobService;
 import org.apache.ambari.view.pig.resources.scripts.ScriptService;
 import org.apache.ambari.view.pig.templeton.client.TempletonApi;
 import org.apache.ambari.view.pig.utils.UserLocalObjects;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.junit.*;
 
@@ -48,7 +48,7 @@ public class IntegrationalTest extends HDFSTest {
   @AfterClass
   public static void shutDown() throws Exception {
     HDFSTest.shutDown(); // super
-    ViewUserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
+    UserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
   }
 
   @Override
@@ -63,13 +63,13 @@ public class IntegrationalTest extends HDFSTest {
   @After
   public void tearDown() throws Exception {
     super.tearDown();
-    ViewUserLocal.dropAllConnections(TempletonApi.class);
-    ViewUserLocal.dropAllConnections(HdfsApi.class);
+    UserLocal.dropAllConnections(TempletonApi.class);
+    UserLocal.dropAllConnections(HdfsApi.class);
   }
 
   @Test
   public void testHdfsApiDependsOnInstance() throws Exception {
-    ViewUserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
+    UserLocal.dropAllConnections(HdfsApi.class); //cleanup API connection
 
     ViewContext context1 = createNiceMock(ViewContext.class);
     ViewContext context2 = createNiceMock(ViewContext.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
index 71c8828..f619848 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
@@ -27,7 +27,7 @@ import org.apache.ambari.view.pig.utils.BadRequestFormattedException;
 import org.apache.ambari.view.pig.utils.NotFoundFormattedException;
 import org.apache.ambari.view.pig.utils.ServiceFormattedException;
 import org.apache.ambari.view.pig.utils.UserLocalObjects;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.ambari.view.utils.hdfs.HdfsApiException;
 import org.apache.hadoop.fs.FSDataOutputStream;
@@ -72,8 +72,8 @@ public class JobTest extends BasePigTest {
   @After
   public void tearDown() throws Exception {
     super.tearDown();
-    ViewUserLocal.dropAllConnections(TempletonApi.class);
-    ViewUserLocal.dropAllConnections(HdfsApi.class);
+    UserLocal.dropAllConnections(TempletonApi.class);
+    UserLocal.dropAllConnections(HdfsApi.class);
   }
 
   public static Response doCreateJob(String title, String pigScript, String templetonArguments,
JobService jobService) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTest.java
b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTest.java
index d00b414..6b2f602 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTest.java
@@ -22,7 +22,7 @@ import org.apache.ambari.view.pig.HDFSTest;
 import org.apache.ambari.view.pig.resources.scripts.ScriptService;
 import org.apache.ambari.view.pig.resources.scripts.models.PigScript;
 import org.apache.ambari.view.pig.utils.NotFoundFormattedException;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.json.simple.JSONObject;
 import org.junit.*;
@@ -51,7 +51,7 @@ public class ScriptTest extends HDFSTest {
   @AfterClass
   public static void shutDown() throws Exception {
     HDFSTest.shutDown(); // super
-    ViewUserLocal.dropAllConnections(HdfsApi.class);
+    UserLocal.dropAllConnections(HdfsApi.class);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
index d33fd2f..9da715c 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
@@ -28,7 +28,7 @@ import org.apache.ambari.view.pig.resources.scripts.ScriptService;
 import org.apache.ambari.view.pig.persistence.utils.StorageUtil;
 import org.apache.ambari.view.pig.resources.scripts.models.PigScript;
 import org.apache.ambari.view.pig.utils.MisconfigurationFormattedException;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.ambari.view.utils.hdfs.HdfsUtil;
 import org.json.simple.JSONObject;
@@ -56,7 +56,7 @@ public class ScriptTestHDFSUnmanaged extends HDFSTest {
   @AfterClass
   public static void shutDown() throws Exception {
     HDFSTest.shutDown(); // super
-    ViewUserLocal.dropAllConnections(HdfsApi.class);
+    UserLocal.dropAllConnections(HdfsApi.class);
   }
 
   @Override
@@ -65,7 +65,7 @@ public class ScriptTestHDFSUnmanaged extends HDFSTest {
     super.setUp();
     handler = createNiceMock(ViewResourceHandler.class);
     context = createNiceMock(ViewContext.class);
-    ViewUserLocal.dropAllConnections(HdfsApi.class);
+    UserLocal.dropAllConnections(HdfsApi.class);
     StorageUtil.dropAllConnections();
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
index 8322d2c..23f9fba 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
@@ -22,7 +22,7 @@ import org.apache.ambari.view.ViewContext;
 import org.apache.ambari.view.ViewResourceHandler;
 import org.apache.ambari.view.pig.BasePigTest;
 import org.apache.ambari.view.pig.resources.scripts.ScriptService;
-import org.apache.ambari.view.utils.ViewUserLocal;
+import org.apache.ambari.view.utils.UserLocal;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.ambari.view.utils.hdfs.HdfsApiException;
 import org.junit.*;
@@ -46,7 +46,7 @@ public class ScriptTestUnmanaged extends BasePigTest {
 
   @AfterClass
   public static void shutDown() throws Exception {
-    ViewUserLocal.dropAllConnections(HdfsApi.class);
+    UserLocal.dropAllConnections(HdfsApi.class);
   }
 
   @Before

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/UserLocal.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/UserLocal.java
b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/UserLocal.java
index 4d36de0..605e0d3 100644
--- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/UserLocal.java
+++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/UserLocal.java
@@ -21,6 +21,7 @@ package org.apache.ambari.view.utils;
 import org.apache.ambari.view.ViewContext;
 
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 /**
@@ -124,6 +125,23 @@ public class UserLocal<T> {
    * Method should not normally be called from production code.
    */
   public static void dropAllConnections() {
-    viewSingletonObjects.clear();
+      viewSingletonObjects.clear();
+  }
+
+  /**
+   *
+   * Drops all objects for give instance name.
+   *
+   * @param instanceName
+   */
+  public static void dropInstanceConnection(String instanceName){
+    for(Map<String,Object> cache : viewSingletonObjects.values()){
+      for(Iterator<Map.Entry<String, Object>> it = cache.entrySet().iterator();it.hasNext();){
+        Map.Entry<String, Object> entry = it.next();
+        if(entry.getKey().startsWith(instanceName+":")){
+          it.remove();
+        }
+      }
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewImpl.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewImpl.java
b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewImpl.java
new file mode 100644
index 0000000..170e775
--- /dev/null
+++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewImpl.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.view.utils;
+
+import org.apache.ambari.view.View;
+import org.apache.ambari.view.ViewDefinition;
+import org.apache.ambari.view.ViewInstanceDefinition;
+
+/**
+ * Default implementation that drop cached objects onUpdate
+ *
+ */
+public class ViewImpl implements View {
+  @Override
+  public void onDeploy(ViewDefinition definition) {
+
+  }
+
+  @Override
+  public void onCreate(ViewInstanceDefinition definition) {
+
+  }
+
+  @Override
+  public void onDestroy(ViewInstanceDefinition definition) {
+
+  }
+
+  @Override
+  public void onUpdate(ViewInstanceDefinition definition) {
+    //refresh all cached connection
+    UserLocal.dropInstanceConnection(definition.getInstanceName());
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c51d1b7/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewUserLocal.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewUserLocal.java
b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewUserLocal.java
deleted file mode 100644
index b9d80b1..0000000
--- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ViewUserLocal.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.utils;
-
-import org.apache.ambari.view.ViewContext;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Manages end user specific objects.
- * Ensures that the instance of specific class is exists only in one instance for
- * specific user of specific instance.
- * @param <T> user-local class
- */
-public class ViewUserLocal<T> {
-  private static Map<Class, Map<String, Object>> viewSingletonObjects = new HashMap<Class,
Map<String, Object>>();
-  private final Class<T> tClass;
-
-  public ViewUserLocal(Class<T> tClass) {
-    this.tClass = tClass;
-  }
-
-  /**
-   * Initial value of user-local class. Value can be set either by initialValue() on first
get() call,
-   * or directly by calling set() method. Default initial value is null, it can be changed
by overriding
-   * this method.
-   * @param context initial value usually based on user properties provided by View Context
-   * @return initial value of user-local variable
-   */
-  protected synchronized T initialValue(ViewContext context) {
-    return null;
-  }
-
-  /**
-   * Returns user-local instance.
-   * If instance of class is not present yet for user, calls initialValue to create it.
-   * @param context View context that provides instance and user names.
-   * @return instance
-   */
-  public T get(ViewContext context) {
-    if (!viewSingletonObjects.containsKey(tClass)) {
-      viewSingletonObjects.put(tClass, new HashMap<String, Object>());
-    }
-
-    Map<String, Object> instances = viewSingletonObjects.get(tClass);
-
-    if (!instances.containsKey(getTagName(context))) {
-      instances.put(getTagName(context), initialValue(context));
-    }
-    return (T) instances.get(getTagName(context));
-  }
-
-  /**
-   * Method for directly setting user-local singleton instances.
-   * @param obj new variable value for current user
-   * @param context ViewContext that provides username and instance name
-   */
-  public void set(T obj, ViewContext context) {
-    if (!viewSingletonObjects.containsKey(tClass)) {
-      viewSingletonObjects.put(tClass, new HashMap<String, Object>());
-    }
-
-    Map<String, Object> instances = viewSingletonObjects.get(tClass);
-    instances.put(getTagName(context), obj);
-  }
-
-  /**
-   * Returns unique key for Map to store a user-local variable.
-   * @param context ViewContext
-   * @return Unique identifier of pair instance-user.
-   */
-  private String getTagName(ViewContext context) {
-    if (context == null) {
-      return "<null>";
-    }
-    return String.format("%s:%s", context.getInstanceName(), context.getUsername());
-  }
-
-  /**
-   * Method for testing purposes, intended to clear the cached user-local instances.
-   * Method should not normally be called from production code.
-   * @param tClass classname instances of which should be dropped
-   */
-  public static void dropAllConnections(Class tClass) {
-    Map<String, Object> instances = viewSingletonObjects.get(tClass);
-    if (instances != null) {
-      viewSingletonObjects.get(tClass).clear();
-    }
-  }
-
-  /**
-   * Method for testing purposes, intended to clear the cached user-local instances.
-   * Drops all classes of user-local variables.
-   * Method should not normally be called from production code.
-   */
-  public static void dropAllConnections() {
-    viewSingletonObjects.clear();
-  }
-}


Mime
View raw message