ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject incubator-ranger git commit: RANGER-274: Enhanced RangerConfiguration for supporting ranger-admin properties. Removed Ranger*ConfigPropertyRepository classes.
Date Wed, 08 Jul 2015 05:37:12 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/tag-policy 4bbf3906b -> 493b8d9c4


RANGER-274: Enhanced RangerConfiguration for supporting ranger-admin properties. Removed Ranger*ConfigPropertyRepository
classes.

Signed-off-by: Madhan Neethiraj <madhan@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/493b8d9c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/493b8d9c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/493b8d9c

Branch: refs/heads/tag-policy
Commit: 493b8d9c48cb2e3b68edb6589e2e32ca7db61944
Parents: 4bbf390
Author: Abhay Kulkarni <akulkarni@hortonworks.com>
Authored: Tue Jul 7 14:26:44 2015 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Wed Jul 8 10:21:04 2015 +0530

----------------------------------------------------------------------
 .../admin/client/RangerAdminRESTClient.java     |  8 ++--
 .../hadoop/config/RangerConfiguration.java      | 40 +++++++++++-----
 .../common/RangerConfigPropertyRepository.java  | 50 --------------------
 .../ranger/plugin/service/RangerBasePlugin.java |  3 --
 .../RangerPluginConfigPropertyRepository.java   | 48 -------------------
 .../plugin/policyengine/TestPolicyEngine.java   |  3 --
 .../org/apache/ranger/biz/ServiceDBStore.java   |  7 ++-
 .../RangerAdminConfigPropertyRepository.java    | 45 ------------------
 8 files changed, 37 insertions(+), 167 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
b/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
index edc0e63..321e4b2 100644
--- a/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
+++ b/agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java
@@ -30,7 +30,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.security.AccessControlException;
 import org.apache.ranger.admin.client.datatype.RESTResponse;
 
-import org.apache.ranger.common.RangerConfigPropertyRepository;
+import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
 import org.apache.ranger.plugin.model.RangerTaggedResource;
 import org.apache.ranger.plugin.model.RangerTaggedResourceKey;
 import org.apache.ranger.plugin.util.*;
@@ -75,8 +75,8 @@ public class RangerAdminRESTClient implements RangerAdminClient {
 		this.serviceName = serviceName;
 		this.pluginId    = restUtils.getPluginId(serviceName, appId);
 
-		String url               = RangerConfigPropertyRepository.getProperty(propertyPrefix +
".policy.rest.url");
-		String sslConfigFileName = RangerConfigPropertyRepository.getProperty(propertyPrefix +
".policy.rest.ssl.config.file");
+		String url               = RangerConfiguration.getInstance().get(propertyPrefix + ".policy.rest.url");
+		String sslConfigFileName = RangerConfiguration.getInstance().get(propertyPrefix + ".policy.rest.ssl.config.file");
 
 		if (url == null) {
 
@@ -84,7 +84,7 @@ public class RangerAdminRESTClient implements RangerAdminClient {
 				LOG.info("RangerAdminRESTClient.init() : no such property " + propertyPrefix + ".policy.rest.url,
using value of ranger.externalurl property instead.");
 			}
 
-			url = RangerConfigPropertyRepository.getProperty("ranger.externalurl");
+			url = RangerConfiguration.getInstance().get("ranger.externalurl");
 		}
 
 		if(LOG.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
index 0a8907c..6cb289f 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
@@ -52,6 +52,28 @@ public class RangerConfiguration extends Configuration {
 		}
 	}
 
+	public boolean addAdminResources() {
+		String defaultCfg = "ranger-admin-default-site.xml";
+		String addlCfg = "ranger-admin-site.xml";
+
+		if(LOG.isDebugEnabled()) {
+			LOG.debug("==> addAdminResources()");
+		}
+		boolean ret = true;
+
+		if (! addResourceIfReadable(defaultCfg)) {
+			ret = false;
+		}
+
+		if (! addResourceIfReadable(addlCfg)) {
+			ret = false;
+		}
+
+		if(LOG.isDebugEnabled()) {
+			LOG.debug("<== addAdminResources(), result=" + ret);
+		}
+		return ret;
+	}
 
 	private boolean addResourceIfReadable(String aResourceName) {
 		
@@ -62,8 +84,8 @@ public class RangerConfiguration extends Configuration {
 
 		String fName = getFileLocation(aResourceName) ;
 		if (fName != null) {
-			if(LOG.isDebugEnabled()) {
-				LOG.debug("<== addResourceIfReadable(" + aResourceName + "): resource file is " +
fName);
+			if(LOG.isInfoEnabled()) {
+				LOG.info("addResourceIfReadable(" + aResourceName + "): resource file is " + fName);
 			}
 
 			File f = new File(fName) ;
@@ -74,23 +96,17 @@ public class RangerConfiguration extends Configuration {
 					addResource(fUrl) ;
 					ret = true;
 				} catch (MalformedURLException e) {
-					if(LOG.isDebugEnabled()) {
-						LOG.debug("Unable to find URL for the resource name [" + aResourceName +"]. Ignoring
the resource:" + aResourceName);
-					}
+					LOG.error("Unable to find URL for the resource name [" + aResourceName + "]. Ignoring
the resource:" + aResourceName);
 				}
 			} else {
-				if(LOG.isDebugEnabled()) {
-					LOG.debug("<== addResourceIfReadable(" + aResourceName + "): resource not readable");
-				}
+				LOG.error("addResourceIfReadable(" + aResourceName + "): resource not readable");
 			}
 		} else {
-			if(LOG.isDebugEnabled()) {
-				LOG.debug("<== addResourceIfReadable(" + aResourceName + "): couldn't find resource
file location");
-			}
+			LOG.error("addResourceIfReadable(" + aResourceName + "): couldn't find resource file location");
 		}
 
 		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== addResourceIfReadable(" + aResourceName + ")");
+			LOG.debug("<== addResourceIfReadable(" + aResourceName + "), result=" + ret);
 		}
 		return ret;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/agents-common/src/main/java/org/apache/ranger/common/RangerConfigPropertyRepository.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/common/RangerConfigPropertyRepository.java
b/agents-common/src/main/java/org/apache/ranger/common/RangerConfigPropertyRepository.java
deleted file mode 100644
index 21c6bb2..0000000
--- a/agents-common/src/main/java/org/apache/ranger/common/RangerConfigPropertyRepository.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.ranger.common;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Interface to get configuration values for Ranger (both security-admin and agents-common)
- */
-
-public abstract class RangerConfigPropertyRepository {
-	private static final Log LOG = LogFactory.getLog(RangerConfigPropertyRepository.class);
-
-
-	protected static volatile RangerConfigPropertyRepository instance = null;
-
-	public static String getProperty(String name) {
-
-		String ret = null;
-
-		if (instance != null) {
-			ret = instance.getPropertyValue(name);
-		} else {
-			LOG.error("RangerConfigPropertyRepository.getPropery() - Object not created correctly.");
-		}
-
-		return ret;
-	}
-
-	abstract protected String getPropertyValue(String name);
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
index bafe634..601dcae 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
@@ -35,7 +35,6 @@ import org.apache.ranger.plugin.policyengine.*;
 import org.apache.ranger.plugin.policyevaluator.RangerPolicyEvaluator;
 import org.apache.ranger.plugin.util.GrantRevokeRequest;
 import org.apache.ranger.plugin.util.PolicyRefresher;
-import org.apache.ranger.plugin.util.RangerPluginConfigPropertyRepository;
 import org.apache.ranger.plugin.util.ServicePolicies;
 
 
@@ -57,8 +56,6 @@ public class RangerBasePlugin {
 	public RangerBasePlugin(String serviceType, String appId) {
 		this.serviceType = serviceType;
 		this.appId       = appId;
-
-		RangerPluginConfigPropertyRepository.init();
 	}
 
 	public String getServiceType() {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerPluginConfigPropertyRepository.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerPluginConfigPropertyRepository.java
b/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerPluginConfigPropertyRepository.java
deleted file mode 100644
index e656f72..0000000
--- a/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerPluginConfigPropertyRepository.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.ranger.plugin.util;
-
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
-import org.apache.ranger.common.RangerConfigPropertyRepository;
-
-public class RangerPluginConfigPropertyRepository extends RangerConfigPropertyRepository
{
-
-	public static RangerConfigPropertyRepository init() {
-		RangerConfigPropertyRepository ret = instance;
-
-		if (ret == null) {
-			synchronized(RangerConfigPropertyRepository.class) {
-				ret = instance;
-				if (ret == null) {
-					ret = instance = new RangerPluginConfigPropertyRepository();
-				}
-			}
-		}
-
-		return ret;
-	}
-
-	@Override
-	protected final String getPropertyValue(String propertyName) {
-		return RangerConfiguration.getInstance().get(propertyName);
-	}
-
-	private RangerPluginConfigPropertyRepository() {}
-}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
----------------------------------------------------------------------
diff --git a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
index e5b2f77..fd39193 100644
--- a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
+++ b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
@@ -34,7 +34,6 @@ import org.apache.ranger.plugin.model.RangerPolicy;
 import org.apache.ranger.plugin.model.RangerTaggedResource;
 import org.apache.ranger.plugin.model.RangerServiceDef;
 import org.apache.ranger.plugin.policyengine.TestPolicyEngine.PolicyEngineTestCase.TestData;
-import org.apache.ranger.plugin.util.RangerPluginConfigPropertyRepository;
 import org.apache.ranger.plugin.util.ServicePolicies;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -124,8 +123,6 @@ public class TestPolicyEngine {
 		RangerConfiguration rangerConfig = RangerConfiguration.getInstance();
 		rangerConfig.addResource(filePath);
 
-		RangerPluginConfigPropertyRepository.init();
-
 	}
 
 	@AfterClass

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
index 3e256a6..3f657be 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
@@ -33,6 +33,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
 import org.apache.ranger.common.AppConstants;
 import org.apache.ranger.common.ContextUtil;
 import org.apache.ranger.common.DateUtil;
@@ -44,7 +45,6 @@ import org.apache.ranger.common.RangerConstants;
 import org.apache.ranger.common.RangerFactory;
 import org.apache.ranger.common.StringUtil;
 import org.apache.ranger.common.UserSessionBase;
-import org.apache.ranger.common.RangerAdminConfigPropertyRepository;
 import org.apache.ranger.db.RangerDaoManager;
 import org.apache.ranger.db.XXAccessTypeDefDao;
 import org.apache.ranger.db.XXAccessTypeDefGrantsDao;
@@ -211,7 +211,10 @@ public class ServiceDBStore extends AbstractServiceStore {
 			synchronized(ServiceDBStore.class) {
 				if(!legacyServiceDefsInitDone) {
 
-					RangerAdminConfigPropertyRepository.init();
+					if (! RangerConfiguration.getInstance().addAdminResources()) {
+						LOG.error("Could not add ranger-admin resources to RangerConfiguration.");
+					}
+
 					TransactionTemplate txTemplate = new TransactionTemplate(txManager);
 
 					final ServiceDBStore dbStore = this;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/493b8d9c/security-admin/src/main/java/org/apache/ranger/common/RangerAdminConfigPropertyRepository.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/common/RangerAdminConfigPropertyRepository.java
b/security-admin/src/main/java/org/apache/ranger/common/RangerAdminConfigPropertyRepository.java
deleted file mode 100644
index 946e719..0000000
--- a/security-admin/src/main/java/org/apache/ranger/common/RangerAdminConfigPropertyRepository.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.ranger.common;
-
-public class RangerAdminConfigPropertyRepository extends RangerConfigPropertyRepository {
-
-	public static RangerConfigPropertyRepository init() {
-		RangerConfigPropertyRepository ret = instance;
-
-		if (ret == null) {
-			synchronized(RangerConfigPropertyRepository.class) {
-				ret = instance;
-				if (ret == null) {
-					ret = instance = new RangerAdminConfigPropertyRepository();
-				}
-			}
-		}
-
-		return ret;
-	}
-
-	@Override
-	protected final String getPropertyValue(String propertyName) {
-		return PropertiesUtil.getProperty(propertyName);
-	}
-
-	private RangerAdminConfigPropertyRepository() {}
-}
\ No newline at end of file


Mime
View raw message