azkaban-developers

Consolidate common code808 (#809) * Fixed comments for execute.as.user

11/15/2016 3:44:24 PM

Details

diff --git a/azkaban-common/src/main/java/azkaban/jobExecutor/ProcessJob.java b/azkaban-common/src/main/java/azkaban/jobExecutor/ProcessJob.java
index bb1b35f..54854d2 100644
--- a/azkaban-common/src/main/java/azkaban/jobExecutor/ProcessJob.java
+++ b/azkaban-common/src/main/java/azkaban/jobExecutor/ProcessJob.java
@@ -112,7 +112,7 @@ public class ProcessJob extends AbstractProcessJob {
     // by default, run as effectiveUser
     String executeAsUserBinaryPath = null;
     String effectiveUser = null;
-    boolean isExecuteAsUser = determineExecuteAsUser(sysProps, jobProps);
+    boolean isExecuteAsUser = sysProps.getBoolean(EXECUTE_AS_USER, true);
 
     // nativeLibFolder specifies the path for execute-as-user file,
     // which will change user from Azkaban to effectiveUser
@@ -177,10 +177,6 @@ public class ProcessJob extends AbstractProcessJob {
     generateProperties(propFiles[1]);
   }
 
-  private boolean determineExecuteAsUser(Props sysProps, Props jobProps) {
-    return sysProps.getBoolean(EXECUTE_AS_USER, true);
-  }
-
   /**
    * <pre>
    * This method extracts the kerberos ticket cache file name from the jobprops.
diff --git a/azkaban-common/src/test/java/azkaban/jobExecutor/AllJobExecutorTests.java b/azkaban-common/src/test/java/azkaban/jobExecutor/AllJobExecutorTests.java
index c41bbfe..6f4aeeb 100644
--- a/azkaban-common/src/test/java/azkaban/jobExecutor/AllJobExecutorTests.java
+++ b/azkaban-common/src/test/java/azkaban/jobExecutor/AllJobExecutorTests.java
@@ -19,10 +19,28 @@ package azkaban.jobExecutor;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
+import azkaban.flow.CommonJobProperties;
+import azkaban.utils.Props;
 
 @RunWith(Suite.class)
 @SuiteClasses({ JavaProcessJobTest.class, ProcessJobTest.class,
     PythonJobTest.class })
 public class AllJobExecutorTests {
 
+  public static Props setUpCommonProps(){
+
+    Props props = new Props();
+    props.put("fullPath", ".");
+    props.put(CommonJobProperties.PROJECT_NAME, "test_project");
+    props.put(CommonJobProperties.FLOW_ID, "test_flow");
+    props.put(CommonJobProperties.JOB_ID, "test_job");
+    props.put(CommonJobProperties.EXEC_ID, "123");
+    props.put(CommonJobProperties.SUBMIT_USER, "test_user");
+
+    //The execute-as-user binary requires special permission. It's not convenient to

+    //set up in a unit test that is self contained. So EXECUTE_AS_USER is set to false

+    //so that we don't have to rely on the binary file to change user in the test case.
+    props.put(ProcessJob.EXECUTE_AS_USER, "false");
+    return props;
+  }
 }
diff --git a/azkaban-common/src/test/java/azkaban/jobExecutor/JavaProcessJobTest.java b/azkaban-common/src/test/java/azkaban/jobExecutor/JavaProcessJobTest.java
index 21254ec..cc284af 100644
--- a/azkaban-common/src/test/java/azkaban/jobExecutor/JavaProcessJobTest.java
+++ b/azkaban-common/src/test/java/azkaban/jobExecutor/JavaProcessJobTest.java
@@ -104,17 +104,9 @@ public class JavaProcessJobTest {
     File workingDir = temp.newFolder("testJavaProcess");
 
     // Initialize job
-    props = new Props();
+    props = AllJobExecutorTests.setUpCommonProps();
     props.put(AbstractProcessJob.WORKING_DIR, workingDir.getCanonicalPath());
     props.put("type", "java");
-    props.put("fullPath", ".");
-
-    props.put(CommonJobProperties.PROJECT_NAME, "test_project");
-    props.put(CommonJobProperties.FLOW_ID, "test_flow");
-    props.put(CommonJobProperties.JOB_ID, "test_job");
-    props.put(CommonJobProperties.EXEC_ID, "123");
-    props.put(CommonJobProperties.SUBMIT_USER, "test_user");
-    props.put("execute.as.user", "false");
 
     job = new JavaProcessJob("testJavaProcess", props, props, log);
   }
diff --git a/azkaban-common/src/test/java/azkaban/jobExecutor/ProcessJobTest.java b/azkaban-common/src/test/java/azkaban/jobExecutor/ProcessJobTest.java
index 1a6fa3c..44512eb 100644
--- a/azkaban-common/src/test/java/azkaban/jobExecutor/ProcessJobTest.java
+++ b/azkaban-common/src/test/java/azkaban/jobExecutor/ProcessJobTest.java
@@ -42,17 +42,10 @@ public class ProcessJobTest {
   public void setUp() throws IOException {
     File workingDir = temp.newFolder("TestProcess");
 
-    props = new Props();
+    // Initialize job
+    props = AllJobExecutorTests.setUpCommonProps();
     props.put(AbstractProcessJob.WORKING_DIR, workingDir.getCanonicalPath());
     props.put("type", "command");
-    props.put("fullPath", ".");
-
-    props.put(CommonJobProperties.PROJECT_NAME, "test_project");
-    props.put(CommonJobProperties.FLOW_ID, "test_flow");
-    props.put(CommonJobProperties.JOB_ID, "test_job");
-    props.put(CommonJobProperties.EXEC_ID, "123");
-    props.put(CommonJobProperties.SUBMIT_USER, "test_user");
-    props.put("execute.as.user", "false");
 
     job = new ProcessJob("TestProcess", props, props, log);
   }