ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject ranger git commit: RANGER-1593 - Avoid Classloading default AtlasResourceMappers
Date Wed, 24 May 2017 09:00:18 GMT
Repository: ranger
Updated Branches:
  refs/heads/master 615a70ddb -> 0c7a2d853


RANGER-1593 - Avoid Classloading default AtlasResourceMappers

Signed-off-by: Colm O hEigeartaigh <coheigea@apache.org>


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

Branch: refs/heads/master
Commit: 0c7a2d853251b64de019884f5f8aa1cc1acb29e7
Parents: 615a70d
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Mon May 22 10:45:48 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed May 24 09:51:47 2017 +0100

----------------------------------------------------------------------
 .../source/atlas/AtlasResourceMapperUtil.java   | 57 ++++++++++----------
 1 file changed, 27 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/0c7a2d85/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasResourceMapperUtil.java
----------------------------------------------------------------------
diff --git a/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasResourceMapperUtil.java
b/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasResourceMapperUtil.java
index 5227d8c..40a639b 100644
--- a/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasResourceMapperUtil.java
+++ b/tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasResourceMapperUtil.java
@@ -34,6 +34,8 @@ public class AtlasResourceMapperUtil {
 
 	private static Map<String, AtlasResourceMapper> atlasResourceMappers = new HashMap<String,
AtlasResourceMapper>();
 
+	private static final String MAPPER_NAME_DELIMITER = ",";
+
 	public static boolean isEntityTypeHandled(String entityTypeName) {
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> isEntityTypeHandled(entityTypeName=" + entityTypeName + ")");
@@ -75,52 +77,47 @@ public class AtlasResourceMapperUtil {
 	}
 
 	static public boolean initializeAtlasResourceMappers(Properties properties) {
-		final String MAPPER_NAME_DELIMITER = ",";
-
 		String customMapperNames = TagSyncConfig.getCustomAtlasResourceMappers(properties);
 
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> initializeAtlasResourceMappers.initializeAtlasResourceMappers(" + customMapperNames
+ ")");
 		}
-		boolean ret = true;
 
-		List<String> mapperNames = new ArrayList<String>();
-		mapperNames.add("org.apache.ranger.tagsync.source.atlas.AtlasHiveResourceMapper");
-		mapperNames.add("org.apache.ranger.tagsync.source.atlas.AtlasHdfsResourceMapper");
-		mapperNames.add("org.apache.ranger.tagsync.source.atlas.AtlasHbaseResourceMapper");
-		mapperNames.add("org.apache.ranger.tagsync.source.atlas.AtlasKafkaResourceMapper");
-		mapperNames.add("org.apache.ranger.tagsync.source.atlas.AtlasStormResourceMapper");
+		// Initialize the default mappers
+		initializeAtlasResourceMapper(new AtlasHiveResourceMapper(), properties);
+		initializeAtlasResourceMapper(new AtlasHdfsResourceMapper(), properties);
+		initializeAtlasResourceMapper(new AtlasHbaseResourceMapper(), properties);
+		initializeAtlasResourceMapper(new AtlasKafkaResourceMapper(), properties);
+		initializeAtlasResourceMapper(new AtlasStormResourceMapper(), properties);
 
+		// Initialize the custom mappers
+		boolean ret = true;
 		if (StringUtils.isNotBlank(customMapperNames)) {
 			for (String customMapperName : customMapperNames.split(MAPPER_NAME_DELIMITER)) {
-				mapperNames.add(customMapperName.trim());
-			}
-		}
-
-		for (String mapperName : mapperNames) {
-			try {
-				Class<?> clazz = Class.forName(mapperName);
-				AtlasResourceMapper resourceMapper = (AtlasResourceMapper) clazz.newInstance();
-
-				resourceMapper.initialize(properties);
-
-				for (String entityTypeName : resourceMapper.getSupportedEntityTypes()) {
-					add(entityTypeName, resourceMapper);
-				}
-
-			} catch (Exception exception) {
-				LOG.error("Failed to create AtlasResourceMapper:" + mapperName + ": ", exception);
-				ret = false;
+			    try {
+			        Class<?> clazz = Class.forName(customMapperName);
+			        AtlasResourceMapper resourceMapper = (AtlasResourceMapper) clazz.newInstance();
+
+			        initializeAtlasResourceMapper(resourceMapper, properties);
+			    } catch (Exception exception) {
+			        LOG.error("Failed to create AtlasResourceMapper:" + customMapperName + ": ", exception);
+			        ret = false;
+			    }
 			}
 		}
 
 		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== initializeAtlasResourceMappers.initializeAtlasResourceMappers(" + mapperNames
+ "): " + ret);
+			LOG.debug("<== initializeAtlasResourceMappers.initializeAtlasResourceMappers(" + customMapperNames
+ "): " + ret);
 		}
 		return ret;
 	}
 
-	private static void add(String entityType, AtlasResourceMapper mapper) {
-		atlasResourceMappers.put(entityType, mapper);
+	private static void initializeAtlasResourceMapper(AtlasResourceMapper resourceMapper, Properties
properties) {
+	    resourceMapper.initialize(properties);
+
+        for (String entityTypeName : resourceMapper.getSupportedEntityTypes()) {
+            atlasResourceMappers.put(entityTypeName, resourceMapper);
+        }
 	}
+
 }


Mime
View raw message