Browse Source

AMBARI-14514. Hive View: Config changes(Local <--> Custom) are not reflected unless ambari-server is restarted. (Gaurav Nagar via yusaku)

Yusaku Sako 10 years ago
parent
commit
16b75fdea5

+ 50 - 0
contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HiveViewImpl.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.hive;
+
+import org.apache.ambari.view.View;
+import org.apache.ambari.view.ViewDefinition;
+import org.apache.ambari.view.ViewInstanceDefinition;
+import org.apache.ambari.view.hive.utils.SharedObjectsFactory;
+import org.apache.ambari.view.utils.UserLocal;
+
+
+public class HiveViewImpl 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) {
+    //drop all cached connection for instance
+    UserLocal.dropInstanceConnection(definition.getInstanceName());
+    SharedObjectsFactory.dropInstanceConnection(definition.getInstanceName());
+  }
+}

+ 27 - 9
contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java

@@ -37,8 +37,9 @@ import org.apache.ambari.view.utils.hdfs.HdfsUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Generates shared connections. Clients with same tag will get the same connection.
@@ -54,7 +55,7 @@ public class SharedObjectsFactory implements IStorageFactory {
   private final ATSParserFactory atsParserFactory;
   private final RMParserFactory rmParserFactory;
 
-  private static final Map<Class, Map<String, Object>> localObjects = new HashMap<Class, Map<String, Object>>();
+  private static final Map<Class, Map<String, Object>> localObjects = new ConcurrentHashMap<Class, Map<String, Object>>();
 
   public SharedObjectsFactory(ViewContext context) {
     this.context = context;
@@ -64,13 +65,13 @@ public class SharedObjectsFactory implements IStorageFactory {
 
     synchronized (localObjects) {
       if (localObjects.size() == 0) {
-        localObjects.put(OperationHandleControllerFactory.class, new HashMap<String, Object>());
-        localObjects.put(Storage.class, new HashMap<String, Object>());
-        localObjects.put(IJobControllerFactory.class, new HashMap<String, Object>());
-        localObjects.put(ATSParser.class, new HashMap<String, Object>());
-        localObjects.put(SavedQueryResourceManager.class, new HashMap<String, Object>());
-        localObjects.put(HdfsApi.class, new HashMap<String, Object>());
-        localObjects.put(RMParser.class, new HashMap<String, Object>());
+        localObjects.put(OperationHandleControllerFactory.class, new ConcurrentHashMap<String, Object>());
+        localObjects.put(Storage.class, new ConcurrentHashMap<String, Object>());
+        localObjects.put(IJobControllerFactory.class, new ConcurrentHashMap<String, Object>());
+        localObjects.put(ATSParser.class, new ConcurrentHashMap<String, Object>());
+        localObjects.put(SavedQueryResourceManager.class, new ConcurrentHashMap<String, Object>());
+        localObjects.put(HdfsApi.class, new ConcurrentHashMap<String, Object>());
+        localObjects.put(RMParser.class, new ConcurrentHashMap<String, Object>());
       }
     }
   }
@@ -166,4 +167,21 @@ public class SharedObjectsFactory implements IStorageFactory {
       map.clear();
     }
   }
+
+  /**
+   *
+   * Drops all objects for give instance name.
+   *
+   * @param instanceName
+   */
+  public static void dropInstanceConnection(String instanceName){
+    for(Map<String,Object> cache : localObjects.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();
+        }
+      }
+    }
+  }
 }

+ 1 - 1
contrib/views/hive/src/main/resources/view.xml

@@ -23,7 +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>
+    <view-class>org.apache.ambari.view.hive.HiveViewImpl</view-class>
 
     <!-- Hive Configs -->
     <parameter>

+ 4 - 4
contrib/views/utils/src/main/java/org/apache/ambari/view/utils/UserLocal.java

@@ -20,9 +20,9 @@ package org.apache.ambari.view.utils;
 
 import org.apache.ambari.view.ViewContext;
 
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Manages end user specific objects.
@@ -31,7 +31,7 @@ import java.util.Map;
  * @param <T> user-local class
  */
 public class UserLocal<T> {
-  private static Map<Class, Map<String, Object>> viewSingletonObjects = new HashMap<Class, Map<String, Object>>();
+  private static Map<Class, Map<String, Object>> viewSingletonObjects = new ConcurrentHashMap<Class, Map<String, Object>>();
   private final Class<? extends T> tClass;
 
   public UserLocal(Class<? extends T> tClass) {
@@ -57,7 +57,7 @@ public class UserLocal<T> {
    */
   public T get(ViewContext context) {
     if (!viewSingletonObjects.containsKey(tClass)) {
-      viewSingletonObjects.put(tClass, new HashMap<String, Object>());
+      viewSingletonObjects.put(tClass, new ConcurrentHashMap<String, Object>());
     }
 
     Map<String, Object> instances = viewSingletonObjects.get(tClass);
@@ -75,7 +75,7 @@ public class UserLocal<T> {
    */
   public void set(T obj, ViewContext context) {
     if (!viewSingletonObjects.containsKey(tClass)) {
-      viewSingletonObjects.put(tClass, new HashMap<String, Object>());
+      viewSingletonObjects.put(tClass, new ConcurrentHashMap<String, Object>());
     }
 
     Map<String, Object> instances = viewSingletonObjects.get(tClass);