Merge "Add main function wrapper for edp.java.adapt_for_oozie config"
This commit is contained in:
commit
13658d970b
|
@ -6,4 +6,5 @@ Sahara-extra is place for Sahara components not included into the main `Sahara r
|
|||
Here is the list of components:
|
||||
|
||||
* Sources for Swift filesystem implementation for Hadoop: https://github.com/openstack/sahara-extra/blob/master/hadoop-swiftfs/README.rst
|
||||
* Sources for main function wrapper that adapt for oozie: https://github.com/openstack/sahara-extra/blob/master/edp-adapt-for-oozie/README.rst
|
||||
* `Diskimage-builder <https://github.com/openstack/diskimage-builder>`_ elements moved to the new repo: https://github.com/openstack/sahara-image-elements
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
=======================
|
||||
Sources for main function wrapper that adapt for oozie
|
||||
=======================
|
||||
|
||||
In order to pass configurations to MapReduce Application through oozie,
|
||||
it is necessary to add the following code.
|
||||
(https://github.com/openstack/sahara/blob/master/etc/edp-examples/edp-java/README.rst)
|
||||
|
||||
// This will add properties from the <configuration> tag specified
|
||||
// in the Oozie workflow. For java actions, Oozie writes the
|
||||
// configuration values to a file pointed to by ooze.action.conf.xml
|
||||
conf.addResource(new Path("file:///",
|
||||
System.getProperty("oozie.action.conf.xml")));
|
||||
|
||||
This wrapper adds a above configuration file to a default resources and
|
||||
invoke actual main function.
|
||||
|
||||
And this wrapper provides workaround for oozie's System.exit problem.
|
||||
(https://oozie.apache.org/docs/4.0.0/WorkflowFunctionalSpec.html#a3.2.7_Java_Action)
|
||||
In caller of oozie, System.exit is converted to exception.
|
||||
The application can call System.exit multiple times.
|
||||
|
||||
This wrapper stores the argument of System.exit called in first.
|
||||
And return stored value if System.exit is called multiple times.
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed 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. See accompanying LICENSE file.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.openstack.sahara.edp</groupId>
|
||||
<artifactId>edp-main-wrapper</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>EDP Java Action Main Wrapper for oozie</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<file.encoding>UTF-8</file.encoding>
|
||||
<downloadSources>true</downloadSources>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<configuration>
|
||||
<configLocation>file://${basedir}/../hadoop-swiftfs/checkstyle.xml</configLocation>
|
||||
<failOnViolation>false</failOnViolation>
|
||||
<format>xml</format>
|
||||
<format>html</format>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,91 @@
|
|||
package org.openstack.sahara.edp;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.Permission;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MainWrapper {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
|
||||
// Load oozie configuration file
|
||||
String actionConf = System.getProperty("oozie.action.conf.xml");
|
||||
if (actionConf != null) {
|
||||
Class<?> configClass
|
||||
= Class.forName("org.apache.hadoop.conf.Configuration");
|
||||
Method method = configClass.getMethod("addDefaultResource", String.class);
|
||||
method.invoke(null, "action.xml");
|
||||
}
|
||||
|
||||
SecurityManager originalSecurityManager = System.getSecurityManager();
|
||||
WrapperSecurityManager newSecurityManager
|
||||
= new WrapperSecurityManager(originalSecurityManager);
|
||||
System.setSecurityManager(newSecurityManager);
|
||||
|
||||
Class<?> mainClass = Class.forName(args[0]);
|
||||
Method mainMethod = mainClass.getMethod("main", String[].class);
|
||||
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
Throwable exception = null;
|
||||
try {
|
||||
mainMethod.invoke(null, (Object) newArgs);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (!newSecurityManager.getExitInvoked()) {
|
||||
exception = e.getTargetException();
|
||||
}
|
||||
}
|
||||
|
||||
System.setSecurityManager(originalSecurityManager);
|
||||
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
if (newSecurityManager.getExitInvoked()) {
|
||||
System.exit(newSecurityManager.getExitCode());
|
||||
}
|
||||
}
|
||||
|
||||
static class WrapperSecurityManager extends SecurityManager {
|
||||
private static boolean exitInvoked = false;
|
||||
private static int firstExitCode;
|
||||
private SecurityManager securityManager;
|
||||
|
||||
public WrapperSecurityManager(SecurityManager securityManager) {
|
||||
this.securityManager = securityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermission(Permission perm, Object context) {
|
||||
if (securityManager != null) {
|
||||
// check everything with the original SecurityManager
|
||||
securityManager.checkPermission(perm, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermission(Permission perm) {
|
||||
if (securityManager != null) {
|
||||
// check everything with the original SecurityManager
|
||||
securityManager.checkPermission(perm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkExit(int status) throws SecurityException {
|
||||
if (!exitInvoked) {
|
||||
// save first System.exit status code
|
||||
exitInvoked = true;
|
||||
firstExitCode = status;
|
||||
}
|
||||
throw new SecurityException("Intercepted System.exit(" + status + ")");
|
||||
}
|
||||
|
||||
public static boolean getExitInvoked() {
|
||||
return exitInvoked;
|
||||
}
|
||||
|
||||
public static int getExitCode() {
|
||||
return firstExitCode;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue