You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/01/08 19:16:02 UTC
[45/50] [abbrv] ambari git commit: AMBARI-14514. Hive View: Config
changes(Local <--> Custom) are not reflected unless ambari-server is
restarted. (Gaurav Nagar via yusaku)
AMBARI-14514. Hive View: Config changes(Local <--> Custom) are not reflected unless ambari-server is restarted. (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/33ca59fc
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/33ca59fc
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/33ca59fc
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 33ca59fcaa76c3e94344eba7b1a9eda5aa700f1d
Parents: 74facbd
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Thu Jan 7 21:27:21 2016 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Thu Jan 7 21:27:21 2016 -0800
----------------------------------------------------------------------
.../apache/ambari/view/hive/HiveViewImpl.java | 50 ++++++++++++++++++++
.../view/hive/utils/SharedObjectsFactory.java | 36 ++++++++++----
contrib/views/hive/src/main/resources/view.xml | 2 +-
.../org/apache/ambari/view/utils/UserLocal.java | 8 ++--
4 files changed, 82 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/33ca59fc/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HiveViewImpl.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HiveViewImpl.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HiveViewImpl.java
new file mode 100644
index 0000000..f98e2b0
--- /dev/null
+++ b/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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/33ca59fc/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java
index bb49400..94af2fb 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java
+++ b/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();
+ }
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/33ca59fc/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 e04ed4b..b6f03ad 100644
--- a/contrib/views/hive/src/main/resources/view.xml
+++ b/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>
http://git-wip-us.apache.org/repos/asf/ambari/blob/33ca59fc/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 605e0d3..9d831ee 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
@@ -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);