Repository: knox
Updated Branches:
  refs/heads/master 59735a88c -> 1275b0882


KNOX-493 - Data and sub data directory should be made configurable. (Andreina J 
via lmccay)

Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/1275b088
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/1275b088
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/1275b088

Branch: refs/heads/master
Commit: 1275b08820bac477901d3a6e207ea867426c5e6c
Parents: 59735a8
Author: Larry McCay <lmc...@hortonworks.com>
Authored: Thu Feb 5 22:20:39 2015 -0500
Committer: Larry McCay <lmc...@hortonworks.com>
Committed: Thu Feb 5 22:20:39 2015 -0500

----------------------------------------------------------------------
 CHANGES                                         |  1 +
 .../gateway/config/impl/GatewayConfigImpl.java  | 17 ++++-
 .../hadoop/gateway/GatewayGlobalConfigTest.java | 66 +++++++++++++++++++-
 .../conf-demo/conf/gateway-default.xml          | 11 ++++
 .../resources/conf-demo/conf/gateway-site.xml   | 11 ++++
 5 files changed, 102 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/1275b088/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 2588f74..e795281 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ Release Notes - Apache Knox - Version 0.6.0
   * [KNOX-479] - Remove cacheManager configuration from template files
   * [KNOX-480] - KnoxCLI needs to print usage when alias not provided
   * [KNOX-494] - knox-env.sh script should print proper warning message , if 
JAVA is not set. (Andreina J via lmccay)
+  * [KNOX-493] - Data and sub data directory should be made configurable. 
(Andreina J via lmccay)
 
 ------------------------------------------------------------------------------
 Release Notes - Apache Knox - Version 0.5.1

http://git-wip-us.apache.org/repos/asf/knox/blob/1275b088/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
----------------------------------------------------------------------
diff --git 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
index 87691b9..4b2a0ac 100644
--- 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
+++ 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
@@ -98,6 +98,8 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
   public static final String HTTP_PORT = GATEWAY_CONFIG_FILE_PREFIX + ".port";
   public static final String HTTP_PATH = GATEWAY_CONFIG_FILE_PREFIX + ".path";
   public static final String DEPLOYMENT_DIR = GATEWAY_CONFIG_FILE_PREFIX + 
".deployment.dir";
+  public static final String SECURITY_DIR = GATEWAY_CONFIG_FILE_PREFIX + 
".security.dir";
+  public static final String DATA_DIR = GATEWAY_CONFIG_FILE_PREFIX + 
".data.dir";
   public static final String HADOOP_CONF_DIR = GATEWAY_CONFIG_FILE_PREFIX + 
".hadoop.conf.dir";
 //  public static final String SHIRO_CONFIG_FILE = GATEWAY_CONFIG_FILE_PREFIX 
+ ".shiro.config.file";
   public static final String FRONTEND_URL = GATEWAY_CONFIG_FILE_PREFIX + 
".frontend.url";
@@ -105,6 +107,8 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
   public static final String DEFAULT_HTTP_PORT = "8888";
   public static final String DEFAULT_HTTP_PATH = "gateway";
   public static final String DEFAULT_DEPLOYMENT_DIR = "deployments";
+  public static final String DEFAULT_SECURITY_DIR = "security";
+  public static final String DEFAULT_DATA_DIR = "data";
   private static final String SSL_ENABLED = "ssl.enabled";
   private static final String SSL_EXCLUDE_PROTOCOLS = "ssl.exclude.protocols";
 //  public static final String DEFAULT_SHIRO_CONFIG_FILE = "shiro.ini";
@@ -148,8 +152,15 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
 
   @Override
   public String getGatewayDataDir() {
-    String value = getVar( GATEWAY_DATA_HOME_VAR, getGatewayHomeDir() + 
File.separator + "data" );
-    return value;
+    String systemValue =
+        System.getProperty(GATEWAY_DATA_HOME_VAR, 
System.getenv(GATEWAY_DATA_HOME_VAR));
+    String dataDir = null;
+    if (systemValue != null) {
+      dataDir = systemValue;
+    } else {
+      dataDir = get(DATA_DIR, getGatewayHomeDir() + File.separator + 
DEFAULT_DATA_DIR);
+    }
+    return dataDir;
   }
 
   @Override
@@ -280,7 +291,7 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
 
   @Override
   public String getGatewaySecurityDir() {
-    return getGatewayDataDir() + File.separator + "security";
+    return get(SECURITY_DIR, getGatewayDataDir() + File.separator + 
DEFAULT_SECURITY_DIR);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/knox/blob/1275b088/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
----------------------------------------------------------------------
diff --git 
a/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
 
b/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
index 4534165..277703a 100644
--- 
a/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
+++ 
b/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
@@ -102,4 +102,68 @@ public class GatewayGlobalConfigTest {
     GatewayConfig config = new GatewayConfigImpl();
     assertThat(config.getGatewayDeploymentDir(), is(homeDirName + 
File.separator + "deployments"));
   }
-}
+
+  @Test
+  public void testForDefaultSecurityDataDir() {
+    String homeDirName = getHomeDirName("conf-site/conf/gateway-site.xml");
+    System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
+    System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName);
+    GatewayConfig config = new GatewayConfigImpl();
+    assertThat(config.getGatewaySecurityDir(), is(homeDirName + File.separator 
+ "security"));
+  }
+
+  @Test
+  public void testForUpdatedSecurityDataDir() {
+    String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml");
+    System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
+    System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName);
+    GatewayConfig config = new GatewayConfigImpl();
+    assertTrue(("/test").equalsIgnoreCase(config.getGatewaySecurityDir()));
+  }
+
+  @Test
+  public void testForDataDirSetAsSystemProperty() {
+    String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml");
+    System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName + 
File.separator
+        + "DataDirSystemProperty");
+    GatewayConfig config = new GatewayConfigImpl();
+    assertTrue((homeDirName + File.separator + 
"DataDirSystemProperty").equalsIgnoreCase(config
+        .getGatewayDataDir()));
+  }
+
+  @Test
+  public void testForDataDirSetAsConfiguration() {
+    String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml");
+    System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
+    System.clearProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR);
+    GatewayConfig config = new GatewayConfigImpl();
+    assertTrue(("/testDataDir").equalsIgnoreCase(config
+        .getGatewayDataDir()));
+  }
+
+  @Test
+  public void testForDefaultDataDir() {
+    String homeDirName = getHomeDirName("conf-site/conf/gateway-site.xml");
+    System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
+    System.clearProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR);
+    GatewayConfig config = new GatewayConfigImpl();
+    assertTrue((homeDirName + File.separator + 
"data").equalsIgnoreCase(config.getGatewayDataDir()));
+  }
+
+  /**
+   * When data dir is set at both system property and configuration level , 
then system property
+   * value should be considered
+   **/
+  @Test
+  public void testDataDirSetAsBothSystemPropertyAndConfig() {
+    String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml");
+    System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
+    System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName + 
File.separator
+        + "DataDirSystemProperty");
+    GatewayConfig config = new GatewayConfigImpl();
+    assertTrue((homeDirName + File.separator + 
"DataDirSystemProperty").equalsIgnoreCase(config
+        .getGatewayDataDir()));
+  }
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/1275b088/gateway-server/src/test/resources/conf-demo/conf/gateway-default.xml
----------------------------------------------------------------------
diff --git 
a/gateway-server/src/test/resources/conf-demo/conf/gateway-default.xml 
b/gateway-server/src/test/resources/conf-demo/conf/gateway-default.xml
index 0adf47f..747255f 100644
--- a/gateway-server/src/test/resources/conf-demo/conf/gateway-default.xml
+++ b/gateway-server/src/test/resources/conf-demo/conf/gateway-default.xml
@@ -53,4 +53,15 @@ limitations under the License.
         <value>/test</value>
         <description>The path that contains deployments.</description>
     </property>
+    <property>
+        <name>gateway.security.dir</name>
+        <value>/test</value>
+        <description>The path that contains Security.</description>
+    </property>
+     <property>
+        <name>gateway.data.dir</name>
+        <value>/testDataDir</value>
+        <description>The path that contains Gateway Data (Security and 
deployments)</description>
+    </property>
+    
 </configuration>

http://git-wip-us.apache.org/repos/asf/knox/blob/1275b088/gateway-server/src/test/resources/conf-demo/conf/gateway-site.xml
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/resources/conf-demo/conf/gateway-site.xml 
b/gateway-server/src/test/resources/conf-demo/conf/gateway-site.xml
index 0635bde..c9d9cc3 100644
--- a/gateway-server/src/test/resources/conf-demo/conf/gateway-site.xml
+++ b/gateway-server/src/test/resources/conf-demo/conf/gateway-site.xml
@@ -59,5 +59,16 @@ limitations under the License.
         <value>/test</value>
         <description>The path that contains deployments.</description>
     </property>
+    <property>
+        <name>gateway.security.dir</name>
+        <value>/test</value>
+        <description>The path that contains Security.</description>
+    </property>
+     <property>
+        <name>gateway.data.dir</name>
+        <value>/testDataDir</value>
+        <description>The path that contains Gateway Data (Security and 
deployments)</description>
+    </property>
+    
 
 </configuration>

Reply via email to