You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by ad...@apache.org on 2017/03/06 22:08:34 UTC
incubator-hawq git commit: HAWQ-1374. Use variable service name for
RPS
Repository: incubator-hawq
Updated Branches:
refs/heads/master bacfb0f1c -> 999a749bb
HAWQ-1374. Use variable service name for RPS
(this closes #1160)
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/999a749b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/999a749b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/999a749b
Branch: refs/heads/master
Commit: 999a749bbceabdd177271605c0ed45f90b9854a7
Parents: bacfb0f
Author: Alexander Denissov <ad...@pivotal.io>
Authored: Fri Mar 3 14:56:31 2017 -0800
Committer: Alexander Denissov <ad...@pivotal.io>
Committed: Mon Mar 6 14:07:27 2017 -0800
----------------------------------------------------------------------
ranger-plugin/conf/ranger-hawq-security.xml | 2 +-
.../authorization/RangerHawqAuthorizer.java | 10 ++---
.../apache/hawq/ranger/authorization/Utils.java | 19 +++++-----
.../RangerHawqAuthorizerAppIdTest.java | 39 --------------------
.../RangerHawqAuthorizerServiceNameTest.java | 36 ++++++++++++++++++
.../hawq/ranger/authorization/UtilsTest.java | 16 ++++----
.../src/test/resources/ranger-hawq-security.xml | 2 +-
7 files changed, 61 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/999a749b/ranger-plugin/conf/ranger-hawq-security.xml
----------------------------------------------------------------------
diff --git a/ranger-plugin/conf/ranger-hawq-security.xml b/ranger-plugin/conf/ranger-hawq-security.xml
index 0cdc160..9bcf1b0 100644
--- a/ranger-plugin/conf/ranger-hawq-security.xml
+++ b/ranger-plugin/conf/ranger-hawq-security.xml
@@ -21,7 +21,7 @@
<configuration xmlns:xi="http://www.w3.org/2001/XInclude">
<property>
<name>ranger.plugin.hawq.service.name</name>
- <value>hawq</value>
+ <value>${ranger.hawq.instance}</value>
<description>
Name of the Ranger service containing policies for this HAWQ instance
</description>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/999a749b/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizer.java
----------------------------------------------------------------------
diff --git a/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizer.java b/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizer.java
index 0458bae..6fa67ab 100644
--- a/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizer.java
+++ b/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizer.java
@@ -30,7 +30,6 @@ import org.apache.hawq.ranger.authorization.model.HawqPrivilege;
import org.apache.hawq.ranger.authorization.model.HawqResource;
import org.apache.hawq.ranger.authorization.model.ResourceAccess;
import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
import org.apache.ranger.plugin.policyengine.RangerAccessResource;
import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
@@ -39,6 +38,7 @@ import org.apache.ranger.plugin.service.RangerBasePlugin;
import java.util.*;
+import static org.apache.hawq.ranger.authorization.Utils.APPID;
import static org.apache.hawq.ranger.authorization.Utils.HAWQ;
/**
@@ -67,13 +67,13 @@ public class RangerHawqAuthorizer implements HawqAuthorizer {
LOG.info("********** Initializing RangerHawqAuthorizer **********");
- String appId = Utils.getAppId();
+ String instance = Utils.getInstanceName();
- LOG.info(String.format("Initializing RangerBasePlugin for service %s:%s", HAWQ, appId));
- rangerPlugin = new RangerBasePlugin(HAWQ, appId);
+ LOG.info(String.format("Initializing RangerBasePlugin for service %s:%s:%s", HAWQ, instance, APPID));
+ rangerPlugin = new RangerBasePlugin(HAWQ, APPID);
rangerPlugin.setResultProcessor(new RangerDefaultAuditHandler());
rangerPlugin.init();
- LOG.info(String.format("********** Initialized RangerBasePlugin for service %s:%s **********", HAWQ, appId));
+ LOG.info(String.format("********** Initialized RangerBasePlugin for service %s:%s:%s **********", HAWQ, instance, APPID));
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/999a749b/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/Utils.java
----------------------------------------------------------------------
diff --git a/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/Utils.java b/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/Utils.java
index 5f99b9d..a3579a9 100644
--- a/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/Utils.java
+++ b/ranger-plugin/service/src/main/java/org/apache/hawq/ranger/authorization/Utils.java
@@ -32,26 +32,27 @@ import java.util.Properties;
public abstract class Utils {
public static final String HAWQ = "hawq";
+ public static final String APPID = "rps";
public static final String UNKNOWN = "unknown";
- public static final String APP_ID_PROPERTY_ENV = "ranger.hawq.instance";
- public static final String APP_ID_PROPERTY_FILE = "RANGER_HAWQ_INSTANCE";
- public static final String VERSION_PROPERTY_ENV = "version";
- public static final String VERSION_PROPERTY_FILE = "RPS_VERSION";
+ public static final String INSTANCE_PROPERTY_KEY_ENV = "ranger.hawq.instance";
+ public static final String INSTANCE_PROPERTY_KEY_FILE = "RANGER_HAWQ_INSTANCE";
+ public static final String VERSION_PROPERTY_KEY_ENV = "version";
+ public static final String VERSION_PROPERTY_KEY_FILE = "RPS_VERSION";
public static final String RANGER_SERVICE_PROPERTY_FILE = "rps.properties";
private static final Log LOG = LogFactory.getLog(Utils.class);
private static final Properties properties = readPropertiesFromFile();
/**
- * Retrieves the app id from the environment variable with the key ranger.hawq.instance
+ * Retrieves the instance name from the environment variable with the key ranger.hawq.instance
* or from the rps.properties file with the key RANGER_HAWQ_INSTANCE
*
* If none exist, hawq is used as the default
*
- * @return String id of the app
+ * @return instance name
*/
- public static String getAppId() {
- return System.getProperty(APP_ID_PROPERTY_ENV, properties.getProperty(APP_ID_PROPERTY_FILE, HAWQ));
+ public static String getInstanceName() {
+ return System.getProperty(INSTANCE_PROPERTY_KEY_ENV, properties.getProperty(INSTANCE_PROPERTY_KEY_FILE, HAWQ));
}
/**
@@ -63,7 +64,7 @@ public abstract class Utils {
* @return version of the service
*/
public static String getVersion() {
- return System.getProperty(VERSION_PROPERTY_ENV, properties.getProperty(VERSION_PROPERTY_FILE, UNKNOWN));
+ return System.getProperty(VERSION_PROPERTY_KEY_ENV, properties.getProperty(VERSION_PROPERTY_KEY_FILE, UNKNOWN));
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/999a749b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerAppIdTest.java
----------------------------------------------------------------------
diff --git a/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerAppIdTest.java b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerAppIdTest.java
deleted file mode 100644
index 461864e..0000000
--- a/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerAppIdTest.java
+++ /dev/null
@@ -1,39 +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.hawq.ranger.authorization;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(Utils.class)
-public class RangerHawqAuthorizerAppIdTest {
-
- @Test
- public void testAppIdIsSet() {
- PowerMockito.mockStatic(Utils.class);
- when(Utils.getAppId()).thenReturn("foo");
- assertEquals("foo", RangerHawqAuthorizer.getInstance().getRangerPlugin().getAppId());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/999a749b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerServiceNameTest.java
----------------------------------------------------------------------
diff --git a/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerServiceNameTest.java b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerServiceNameTest.java
new file mode 100644
index 0000000..4aa5a7a
--- /dev/null
+++ b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/RangerHawqAuthorizerServiceNameTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.hawq.ranger.authorization;
+
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+import org.junit.Test;
+
+import static org.apache.hawq.ranger.authorization.Utils.INSTANCE_PROPERTY_KEY_ENV;
+import static org.junit.Assert.assertEquals;
+public class RangerHawqAuthorizerServiceNameTest {
+
+ @Test
+ public void testServiceNameIsSet() {
+ System.setProperty(INSTANCE_PROPERTY_KEY_ENV, "instance");
+ assertEquals("instance", Utils.getInstanceName());
+ RangerBasePlugin plugin = RangerHawqAuthorizer.getInstance().getRangerPlugin();
+ assertEquals("instance", plugin.getServiceName());
+ assertEquals("hawq", plugin.getServiceType());
+ assertEquals("rps", plugin.getAppId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/999a749b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/UtilsTest.java
----------------------------------------------------------------------
diff --git a/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/UtilsTest.java b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/UtilsTest.java
index 5b94df0..3c99719 100644
--- a/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/UtilsTest.java
+++ b/ranger-plugin/service/src/test/java/org/apache/hawq/ranger/authorization/UtilsTest.java
@@ -21,8 +21,8 @@ package org.apache.hawq.ranger.authorization;
import org.junit.Test;
-import static org.apache.hawq.ranger.authorization.Utils.APP_ID_PROPERTY_ENV;
-import static org.apache.hawq.ranger.authorization.Utils.VERSION_PROPERTY_ENV;
+import static org.apache.hawq.ranger.authorization.Utils.INSTANCE_PROPERTY_KEY_ENV;
+import static org.apache.hawq.ranger.authorization.Utils.VERSION_PROPERTY_KEY_ENV;
import static org.junit.Assert.assertEquals;
/**
@@ -32,21 +32,21 @@ public class UtilsTest {
@Test
public void testAppId_SystemEnv() throws Exception {
- System.setProperty(APP_ID_PROPERTY_ENV, "app-id");
- assertEquals("app-id", Utils.getAppId());
- System.clearProperty(APP_ID_PROPERTY_ENV);
+ System.setProperty(INSTANCE_PROPERTY_KEY_ENV, "instance");
+ assertEquals("instance", Utils.getInstanceName());
+ System.clearProperty(INSTANCE_PROPERTY_KEY_ENV);
}
@Test
public void testAppId_PropertyFile() throws Exception {
- assertEquals("instance-test", Utils.getAppId());
+ assertEquals("instance-test", Utils.getInstanceName());
}
@Test
public void testGetVersion_SystemEnv() throws Exception {
- System.setProperty(VERSION_PROPERTY_ENV, "1.2.3");
+ System.setProperty(VERSION_PROPERTY_KEY_ENV, "1.2.3");
assertEquals("1.2.3", Utils.getVersion());
- System.clearProperty(VERSION_PROPERTY_ENV);
+ System.clearProperty(VERSION_PROPERTY_KEY_ENV);
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/999a749b/ranger-plugin/service/src/test/resources/ranger-hawq-security.xml
----------------------------------------------------------------------
diff --git a/ranger-plugin/service/src/test/resources/ranger-hawq-security.xml b/ranger-plugin/service/src/test/resources/ranger-hawq-security.xml
index 6141df7..110647c 100644
--- a/ranger-plugin/service/src/test/resources/ranger-hawq-security.xml
+++ b/ranger-plugin/service/src/test/resources/ranger-hawq-security.xml
@@ -21,7 +21,7 @@
<configuration xmlns:xi="http://www.w3.org/2001/XInclude">
<property>
<name>ranger.plugin.hawq.service.name</name>
- <value>hawq</value>
+ <value>${ranger.hawq.instance}</value>
<description>
Name of the Ranger service containing policies for this HAWQ instance
</description>