Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1E696200C7F for ; Wed, 24 May 2017 11:00:20 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1D224160BB4; Wed, 24 May 2017 09:00:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 63962160B9C for ; Wed, 24 May 2017 11:00:19 +0200 (CEST) Received: (qmail 94845 invoked by uid 500); 24 May 2017 09:00:18 -0000 Mailing-List: contact commits-help@ranger.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ranger.apache.org Delivered-To: mailing list commits@ranger.apache.org Received: (qmail 94836 invoked by uid 99); 24 May 2017 09:00:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 May 2017 09:00:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1ED5FDFAEB; Wed, 24 May 2017 09:00:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@ranger.apache.org Message-Id: <5c4adaa9e2f546c8a008cd6c3f59d42e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ranger git commit: RANGER-1593 - Avoid Classloading default AtlasResourceMappers Date: Wed, 24 May 2017 09:00:18 +0000 (UTC) archived-at: Wed, 24 May 2017 09:00:20 -0000 Repository: ranger Updated Branches: refs/heads/master 615a70ddb -> 0c7a2d853 RANGER-1593 - Avoid Classloading default AtlasResourceMappers Signed-off-by: Colm O hEigeartaigh 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 Authored: Mon May 22 10:45:48 2017 +0100 Committer: Colm O hEigeartaigh 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 atlasResourceMappers = new HashMap(); + 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 mapperNames = new ArrayList(); - 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); + } } + }