summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-12-15 10:35:00 +0000
committerGerrit Code Review <review@openstack.org>2014-12-15 10:35:00 +0000
commit13658d970bef848427e2440a9a3fecc5d53fa74d (patch)
tree9795411f7a78dea6a7761e7c3f14e3e3cd7cd5ca
parent32a61dcdde68c33c7b61d82cdc163d78522d43e1 (diff)
parent6f063eda988b7166de49891ce2c334e25ddaf01b (diff)
Merge "Add main function wrapper for edp.java.adapt_for_oozie config"2015.1.0b1
-rw-r--r--README.rst1
-rw-r--r--edp-adapt-for-oozie/README.rst24
-rw-r--r--edp-adapt-for-oozie/pom.xml55
-rw-r--r--edp-adapt-for-oozie/src/main/java/org/openstack/sahara/edp/MainWrapper.java91
4 files changed, 171 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index a7df4ec..838ff85 100644
--- a/README.rst
+++ b/README.rst
@@ -6,4 +6,5 @@ Sahara-extra is place for Sahara components not included into the main `Sahara r
6Here is the list of components: 6Here is the list of components:
7 7
8* Sources for Swift filesystem implementation for Hadoop: https://github.com/openstack/sahara-extra/blob/master/hadoop-swiftfs/README.rst 8* Sources for Swift filesystem implementation for Hadoop: https://github.com/openstack/sahara-extra/blob/master/hadoop-swiftfs/README.rst
9* Sources for main function wrapper that adapt for oozie: https://github.com/openstack/sahara-extra/blob/master/edp-adapt-for-oozie/README.rst
9* `Diskimage-builder <https://github.com/openstack/diskimage-builder>`_ elements moved to the new repo: https://github.com/openstack/sahara-image-elements 10* `Diskimage-builder <https://github.com/openstack/diskimage-builder>`_ elements moved to the new repo: https://github.com/openstack/sahara-image-elements
diff --git a/edp-adapt-for-oozie/README.rst b/edp-adapt-for-oozie/README.rst
new file mode 100644
index 0000000..7540240
--- /dev/null
+++ b/edp-adapt-for-oozie/README.rst
@@ -0,0 +1,24 @@
1=======================
2Sources for main function wrapper that adapt for oozie
3=======================
4
5In order to pass configurations to MapReduce Application through oozie,
6it is necessary to add the following code.
7(https://github.com/openstack/sahara/blob/master/etc/edp-examples/edp-java/README.rst)
8
9 // This will add properties from the <configuration> tag specified
10 // in the Oozie workflow. For java actions, Oozie writes the
11 // configuration values to a file pointed to by ooze.action.conf.xml
12 conf.addResource(new Path("file:///",
13 System.getProperty("oozie.action.conf.xml")));
14
15This wrapper adds a above configuration file to a default resources and
16invoke actual main function.
17
18And this wrapper provides workaround for oozie's System.exit problem.
19(https://oozie.apache.org/docs/4.0.0/WorkflowFunctionalSpec.html#a3.2.7_Java_Action)
20In caller of oozie, System.exit is converted to exception.
21The application can call System.exit multiple times.
22
23This wrapper stores the argument of System.exit called in first.
24And return stored value if System.exit is called multiple times.
diff --git a/edp-adapt-for-oozie/pom.xml b/edp-adapt-for-oozie/pom.xml
new file mode 100644
index 0000000..c5a9150
--- /dev/null
+++ b/edp-adapt-for-oozie/pom.xml
@@ -0,0 +1,55 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. See accompanying LICENSE file.
14-->
15<project xmlns="http://maven.apache.org/POM/4.0.0"
16 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
18 <modelVersion>4.0.0</modelVersion>
19
20 <groupId>org.openstack.sahara.edp</groupId>
21 <artifactId>edp-main-wrapper</artifactId>
22 <version>1.0.0-SNAPSHOT</version>
23 <name>EDP Java Action Main Wrapper for oozie</name>
24 <packaging>jar</packaging>
25
26 <properties>
27 <file.encoding>UTF-8</file.encoding>
28 <downloadSources>true</downloadSources>
29 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30 </properties>
31
32 <build>
33 <plugins>
34 <plugin>
35 <groupId>org.apache.maven.plugins</groupId>
36 <artifactId>maven-compiler-plugin</artifactId>
37 <configuration>
38 <source>1.6</source>
39 <target>1.6</target>
40 </configuration>
41 </plugin>
42 <plugin>
43 <groupId>org.apache.maven.plugins</groupId>
44 <artifactId>maven-checkstyle-plugin</artifactId>
45 <configuration>
46 <configLocation>file://${basedir}/../hadoop-swiftfs/checkstyle.xml</configLocation>
47 <failOnViolation>false</failOnViolation>
48 <format>xml</format>
49 <format>html</format>
50 </configuration>
51 </plugin>
52 </plugins>
53 </build>
54
55</project>
diff --git a/edp-adapt-for-oozie/src/main/java/org/openstack/sahara/edp/MainWrapper.java b/edp-adapt-for-oozie/src/main/java/org/openstack/sahara/edp/MainWrapper.java
new file mode 100644
index 0000000..e96d287
--- /dev/null
+++ b/edp-adapt-for-oozie/src/main/java/org/openstack/sahara/edp/MainWrapper.java
@@ -0,0 +1,91 @@
1package org.openstack.sahara.edp;
2
3import java.lang.reflect.InvocationTargetException;
4import java.lang.reflect.Method;
5import java.security.Permission;
6import java.util.Arrays;
7
8public class MainWrapper {
9
10 public static void main(String[] args) throws Throwable {
11
12 // Load oozie configuration file
13 String actionConf = System.getProperty("oozie.action.conf.xml");
14 if (actionConf != null) {
15 Class<?> configClass
16 = Class.forName("org.apache.hadoop.conf.Configuration");
17 Method method = configClass.getMethod("addDefaultResource", String.class);
18 method.invoke(null, "action.xml");
19 }
20
21 SecurityManager originalSecurityManager = System.getSecurityManager();
22 WrapperSecurityManager newSecurityManager
23 = new WrapperSecurityManager(originalSecurityManager);
24 System.setSecurityManager(newSecurityManager);
25
26 Class<?> mainClass = Class.forName(args[0]);
27 Method mainMethod = mainClass.getMethod("main", String[].class);
28 String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
29 Throwable exception = null;
30 try {
31 mainMethod.invoke(null, (Object) newArgs);
32 } catch (InvocationTargetException e) {
33 if (!newSecurityManager.getExitInvoked()) {
34 exception = e.getTargetException();
35 }
36 }
37
38 System.setSecurityManager(originalSecurityManager);
39
40 if (exception != null) {
41 throw exception;
42 }
43 if (newSecurityManager.getExitInvoked()) {
44 System.exit(newSecurityManager.getExitCode());
45 }
46 }
47
48 static class WrapperSecurityManager extends SecurityManager {
49 private static boolean exitInvoked = false;
50 private static int firstExitCode;
51 private SecurityManager securityManager;
52
53 public WrapperSecurityManager(SecurityManager securityManager) {
54 this.securityManager = securityManager;
55 }
56
57 @Override
58 public void checkPermission(Permission perm, Object context) {
59 if (securityManager != null) {
60 // check everything with the original SecurityManager
61 securityManager.checkPermission(perm, context);
62 }
63 }
64
65 @Override
66 public void checkPermission(Permission perm) {
67 if (securityManager != null) {
68 // check everything with the original SecurityManager
69 securityManager.checkPermission(perm);
70 }
71 }
72
73 @Override
74 public void checkExit(int status) throws SecurityException {
75 if (!exitInvoked) {
76 // save first System.exit status code
77 exitInvoked = true;
78 firstExitCode = status;
79 }
80 throw new SecurityException("Intercepted System.exit(" + status + ")");
81 }
82
83 public static boolean getExitInvoked() {
84 return exitInvoked;
85 }
86
87 public static int getExitCode() {
88 return firstExitCode;
89 }
90 }
91}