Permalink
Browse files

Adding global classpath and proxy.

  • Loading branch information...
1 parent d35f6e9 commit 1d0890f745383b6370785e2df5bc151fb713b545 @rbpark committed Jun 6, 2012
View
@@ -34,12 +34,12 @@
<classpathentry kind="lib" path="lib/jdom-1.1.jar"/>
<classpathentry kind="lib" path="lib/commons-pool-1.4.jar"/>
<classpathentry kind="lib" path="lib/avro-1.3.3.jar"/>
- <classpathentry kind="lib" path="lib/jackson-core-asl-1.5.5.jar"/>
- <classpathentry kind="lib" path="lib/jackson-mapper-asl-1.5.5.jar"/>
<classpathentry kind="lib" path="lib/json_simple-1.1.jar"/>
<classpathentry kind="lib" path="lib/pig-0.9.1-withouthadoop.jar"/>
<classpathentry kind="lib" path="lib/commons-configuration-1.8.jar"/>
- <classpathentry kind="lib" path="lib/hadoop-core-1.0.0-p8.jar"/>
<classpathentry kind="lib" path="lib/ehcache-core-2.5.1.jar"/>
+ <classpathentry kind="lib" path="lib/hadoop-core-1.0.2-p1.jar"/>
+ <classpathentry kind="lib" path="lib/jackson-core-asl-1.8.8.jar"/>
+ <classpathentry kind="lib" path="lib/jackson-mapper-asl-1.8.8.jar"/>
<classpathentry kind="output" path="dist/classes"/>
</classpath>
@@ -21,6 +21,7 @@
import java.util.StringTokenizer;
import azkaban.app.JobDescriptor;
+
public class JavaJob extends JavaProcessJob {
public static final String RUN_METHOD_PARAM = "method.run";
@@ -37,7 +38,6 @@
private String _progressMethod;
private Object _javaObject = null;
- private JobDescriptor _descriptor;
public JavaJob(JobDescriptor descriptor) {
super(descriptor);
@@ -92,8 +92,13 @@ public void run() {
}
_logger.info("Class name " + className);
- // Create the object.
- _javaObject = getObject(_jobName, className, prop);
+ // Create the object using proxy
+ if (SecurityUtils.shouldProxy(prop)) {
+ _javaObject = getObjectAsProxyUser(prop, _logger, _jobName, className);
+ }
+ else {
+ _javaObject = getObject(_jobName, className, prop);
+ }
if(_javaObject == null) {
_logger.info("Could not create java object to run job: " + className);
throw new Exception("Could not create running object");
@@ -223,6 +228,17 @@ public void cancelJob() {
}
}
+ private static Object getObjectAsProxyUser(final Properties prop, Logger logger, final String jobName, final String className) throws Exception{
+ Object obj = SecurityUtils.getProxiedUser(prop, logger, new Configuration()).doAs(new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ return getObject(jobName, className, prop);
+ }
+ });
+
+ return obj;
+ }
+
private static Object getObject(String jobName, String className, Properties properties)
throws Exception {
Class<?> runningClass = JavaJobRunnerMain.class.getClassLoader().loadClass(className);
@@ -20,10 +20,16 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.log4j.Logger;
+
import azkaban.app.JobDescriptor;
public class JavaProcessJob extends ProcessJob {
+ private static final Logger log = Logger
+ .getLogger(JavaProcessJob.class);
+
public static final String CLASSPATH = "classpath";
+ public static final String GLOBAL_CLASSPATH = "global.classpath";
public static final String JAVA_CLASS = "java.class";
public static final String INITIAL_MEMORY_SIZE = "Xms";
public static final String MAX_MEMORY_SIZE = "Xmx";
@@ -73,22 +79,34 @@ protected String getClassPathParam() {
protected List<String> getClassPaths() {
List<String> classPaths = getProps().getStringList(CLASSPATH, null, ",");
+
+ ArrayList<String> classpathList = new ArrayList<String>(classPaths);
+
+ // Adding global properties used system wide.
+ if (getProps().containsKey(GLOBAL_CLASSPATH)) {
+ List<String> globalClasspath = getProps().getStringList(GLOBAL_CLASSPATH);
+ for (String global: globalClasspath) {
+ log.info("Adding to global classpath:" + global);
+ classpathList.add(global);
+ }
+ }
if (classPaths == null) {
File path = new File(getPath());
File parent = path.getParentFile();
- classPaths = new ArrayList<String>();
+
for (File file : parent.listFiles()) {
if (file.getName().endsWith(".jar")) {
- classPaths.add(file.getName());
+ log.info("Adding to classpath:" + file.getName());
+ classpathList.add(file.getName());
}
}
-
- return classPaths;
+ }
+ else {
+ classpathList.addAll(classPaths);
}
- // inserting class path in a non-immutable list.
- return new ArrayList<String>(classPaths);
+ return classpathList;
}
protected String getInitialMemorySize() {

0 comments on commit 1d0890f

Please sign in to comment.