001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.oozie.action.hadoop; 019 020 import java.io.IOException; 021 import java.io.StringReader; 022 import java.util.ArrayList; 023 import java.util.List; 024 import java.util.StringTokenizer; 025 026 import org.apache.hadoop.conf.Configuration; 027 import org.apache.hadoop.fs.Path; 028 import org.apache.oozie.action.ActionExecutorException; 029 import org.apache.oozie.client.WorkflowAction; 030 import org.apache.oozie.util.XConfiguration; 031 import org.apache.oozie.util.XmlUtils; 032 import org.jdom.Element; 033 import org.jdom.JDOMException; 034 import org.jdom.Namespace; 035 036 public class SqoopActionExecutor extends JavaActionExecutor { 037 038 039 public SqoopActionExecutor() { 040 super("sqoop"); 041 } 042 043 @Override 044 protected List<Class> getLauncherClasses() { 045 List<Class> classes = super.getLauncherClasses(); 046 classes.add(LauncherMain.class); 047 classes.add(MapReduceMain.class); 048 classes.add(HiveMain.class); 049 classes.add(SqoopMain.class); 050 return classes; 051 } 052 053 @Override 054 protected String getLauncherMain(Configuration launcherConf, Element actionXml) { 055 return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, SqoopMain.class.getName()); 056 } 057 058 @Override 059 Configuration setupLauncherConf(Configuration conf, Element actionXml, Path appPath, Context context) 060 throws ActionExecutorException { 061 super.setupLauncherConf(conf, actionXml, appPath, context); 062 063 HiveActionExecutor hiveAE = new HiveActionExecutor(); 064 hiveAE.setupHiveDefault(conf, appPath, actionXml); 065 066 return conf; 067 } 068 069 @Override 070 @SuppressWarnings("unchecked") 071 Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) 072 throws ActionExecutorException { 073 super.setupActionConf(actionConf, context, actionXml, appPath); 074 Namespace ns = actionXml.getNamespace(); 075 076 try { 077 Element e = actionXml.getChild("configuration", ns); 078 if (e != null) { 079 String strConf = XmlUtils.prettyPrint(e).toString(); 080 XConfiguration inlineConf = new XConfiguration(new StringReader(strConf)); 081 checkForDisallowedProps(inlineConf, "inline configuration"); 082 XConfiguration.copy(inlineConf, actionConf); 083 } 084 } catch (IOException ex) { 085 throw convertException(ex); 086 } 087 088 String[] args; 089 if (actionXml.getChild("command", ns) != null) { 090 String command = actionXml.getChild("command", ns).getTextTrim(); 091 StringTokenizer st = new StringTokenizer(command, " "); 092 List<String> l = new ArrayList<String>(); 093 while (st.hasMoreTokens()) { 094 l.add(st.nextToken()); 095 } 096 args = l.toArray(new String[l.size()]); 097 } 098 else { 099 List<Element> eArgs = (List<Element>) actionXml.getChildren("arg", ns); 100 args = new String[eArgs.size()]; 101 for (int i = 0; i < eArgs.size(); i++) { 102 args[i] = eArgs.get(i).getTextTrim(); 103 } 104 } 105 106 SqoopMain.setSqoopCommand(actionConf, args); 107 return actionConf; 108 } 109 110 @Override 111 protected boolean getCaptureOutput(WorkflowAction action) throws JDOMException { 112 return true; 113 } 114 115 116 /** 117 * Return the sharelib postfix for the action. 118 * 119 * @param context executor context. 120 * @param actionXml the action XML. 121 * @return the action sharelib post fix, this implementation returns <code>hive</code>. 122 */ 123 protected String getShareLibPostFix(Context context, Element actionXml) { 124 return "sqoop"; 125 } 126 127 }