ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject [3/4] incubator-ranger git commit: Ranger-684: Modified code to incorporate review comments
Date Fri, 30 Oct 2015 22:33:07 GMT
Ranger-684: Modified code to incorporate review comments

Signed-off-by: Velmurugan Periasamy <vel@apache.org>


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

Branch: refs/heads/master
Commit: e83d4a703c533ce1e8b58ac5cf1dd2df83a25240
Parents: 99b97e2
Author: Sailaja Polavarapu <spolavarapu@hortonworks.com>
Authored: Thu Oct 29 11:09:19 2015 -0700
Committer: Velmurugan Periasamy <vel@apache.org>
Committed: Fri Oct 30 18:32:07 2015 -0400

----------------------------------------------------------------------
 .../process/LdapUserGroupBuilder.java           |  5 ++--
 .../config/UserGroupSyncConfig.java             |  2 +-
 .../org/apache/ranger/usergroupsync/RegEx.java  | 30 +++++++++++++-------
 .../apache/ranger/usergroupsync/RegExTest.java  |  8 +++---
 4 files changed, 27 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e83d4a70/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
b/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
index 911c5d5..e13db58 100644
--- a/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
+++ b/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
@@ -42,6 +42,7 @@ import javax.naming.ldap.PagedResultsResponseControl;
 
 import org.apache.log4j.Logger;
 import org.apache.ranger.unixusersync.config.UserGroupSyncConfig;
+import org.apache.ranger.usergroupsync.Mapper;
 import org.apache.ranger.usergroupsync.AbstractMapper;
 import org.apache.ranger.usergroupsync.UserGroupSink;
 import org.apache.ranger.usergroupsync.UserGroupSource;
@@ -93,8 +94,8 @@ public class LdapUserGroupBuilder implements UserGroupSource {
 
   private boolean  groupUserMapSyncEnabled = false;
   
-  AbstractMapper userNameRegExInst = null;
-  AbstractMapper groupNameRegExInst = null;
+  Mapper userNameRegExInst = null;
+  Mapper groupNameRegExInst = null;
 
 	public static void main(String[] args) throws Throwable {
 		LdapUserGroupBuilder  ugBuilder = new LdapUserGroupBuilder();

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e83d4a70/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
index f43e125..792a05a 100644
--- a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
+++ b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
@@ -752,7 +752,7 @@ public class UserGroupSyncConfig  {
 		return referral;
 	}
 	
-	public List<String> getAllRegexPatterns(String baseProperty) {
+	public List<String> getAllRegexPatterns(String baseProperty) throws Throwable {
 		List<String> regexPatterns = new ArrayList<String>();
 		if (prop != null) {
 			String baseRegex = prop.getProperty(baseProperty);

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e83d4a70/ugsync/src/main/java/org/apache/ranger/usergroupsync/RegEx.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/usergroupsync/RegEx.java b/ugsync/src/main/java/org/apache/ranger/usergroupsync/RegEx.java
index 0e9ed99..4bf452a 100644
--- a/ugsync/src/main/java/org/apache/ranger/usergroupsync/RegEx.java
+++ b/ugsync/src/main/java/org/apache/ranger/usergroupsync/RegEx.java
@@ -37,11 +37,15 @@ public class RegEx extends AbstractMapper {
 	@Override
 	public void init (String baseProperty) {
 		logger.info("Initializing for " + baseProperty);
-		List<String> regexPatterns = config.getAllRegexPatterns(baseProperty);
-		populateReplacementPatterns(baseProperty, regexPatterns);
+		try {
+			List<String> regexPatterns = config.getAllRegexPatterns(baseProperty);
+			populateReplacementPatterns(baseProperty, regexPatterns);
+		} catch (Throwable t) {
+			logger.error("Failed to initialize " + baseProperty, t.fillInStackTrace());
+		}
 	}
 
-	protected void populateReplacementPatterns(String baseProperty, List<String> regexPatterns)
{
+	protected void populateReplacementPatterns(String baseProperty, List<String> regexPatterns)
throws Throwable{
 		replacementPattern = new LinkedHashMap<String, String>();
 		Pattern p = Pattern.compile("s/([^/]*)/([^/]*)/(g)?");
 		for (String regexPattern : regexPatterns) {
@@ -66,17 +70,21 @@ public class RegEx extends AbstractMapper {
 	@Override
 	public String transform (String attrValue) {
 		String result = attrValue;
-		if (replacementPattern != null && !replacementPattern.isEmpty()) {
-			for (String matchPattern : replacementPattern.keySet()) {
-				Pattern p = Pattern.compile(matchPattern);
-				Matcher m = p.matcher(result);
-				if (m.find()) {
-					String replacement = replacementPattern.get(matchPattern);
-					if (replacement != null) {
-						result = m.replaceAll(replacement);
+		try {
+			if (replacementPattern != null && !replacementPattern.isEmpty()) {
+				for (String matchPattern : replacementPattern.keySet()) {
+					Pattern p = Pattern.compile(matchPattern);
+					Matcher m = p.matcher(result);
+					if (m.find()) {
+						String replacement = replacementPattern.get(matchPattern);
+						if (replacement != null) {
+							result = m.replaceAll(replacement);
+						}
 					}
 				}
 			}
+		} catch (Throwable t) {
+			logger.error("Failed to transform " + attrValue, t.fillInStackTrace());
 		}
 		return result;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e83d4a70/ugsync/src/test/java/org/apache/ranger/usergroupsync/RegExTest.java
----------------------------------------------------------------------
diff --git a/ugsync/src/test/java/org/apache/ranger/usergroupsync/RegExTest.java b/ugsync/src/test/java/org/apache/ranger/usergroupsync/RegExTest.java
index 2621862..2c1e023 100644
--- a/ugsync/src/test/java/org/apache/ranger/usergroupsync/RegExTest.java
+++ b/ugsync/src/test/java/org/apache/ranger/usergroupsync/RegExTest.java
@@ -46,14 +46,14 @@ public class RegExTest {
 	}
 
 	@Test
-    public void testUserNameTransform() {
+    public void testUserNameTransform() throws Throwable {
             userRegexPatterns.add("s/\\s/_/");
             userNameRegEx.populateReplacementPatterns(userNameBaseProperty, userRegexPatterns);
             assertEquals("test_user", userNameRegEx.transform("test user"));
     }
 
     @Test
-    public void testGroupNameTransform() {
+    public void testGroupNameTransform() throws Throwable {
             groupRegexPatterns.add("s/\\s/_/g");
             groupRegexPatterns.add("s/_/\\$/g");
             groupNameRegEx.populateReplacementPatterns(userNameBaseProperty, groupRegexPatterns);
@@ -67,7 +67,7 @@ public class RegExTest {
     }
 
     @Test
-    public void testTransform() {
+    public void testTransform() throws Throwable {
             userRegexPatterns.add("s/\\s/_/g");
             userNameRegEx.populateReplacementPatterns(userNameBaseProperty, userRegexPatterns);
             assertEquals("test_user", userNameRegEx.transform("test user"));
@@ -75,7 +75,7 @@ public class RegExTest {
     }
 
     @Test
-    public void testTransform1() {
+    public void testTransform1() throws Throwable {
             userRegexPatterns.add("s/\\\\/ /g");
             userRegexPatterns.add("s//_/g");
             userNameRegEx.populateReplacementPatterns(userNameBaseProperty, userRegexPatterns);


Mime
View raw message