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 static org.apache.oozie.action.hadoop.LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS; 021 022 import java.util.List; 023 024 import org.apache.hadoop.conf.Configuration; 025 import org.apache.hadoop.fs.Path; 026 import org.apache.oozie.action.ActionExecutorException; 027 import org.apache.oozie.client.WorkflowAction; 028 import org.jdom.Element; 029 import org.jdom.JDOMException; 030 import org.jdom.Namespace; 031 032 public class HiveActionExecutor extends JavaActionExecutor { 033 034 public HiveActionExecutor() { 035 super("hive"); 036 } 037 038 @Override 039 protected List<Class> getLauncherClasses() { 040 List<Class> classes = super.getLauncherClasses(); 041 classes.add(LauncherMain.class); 042 classes.add(MapReduceMain.class); 043 classes.add(HiveMain.class); 044 return classes; 045 } 046 047 @Override 048 protected String getLauncherMain(Configuration launcherConf, Element actionXml) { 049 return launcherConf.get(CONF_OOZIE_ACTION_MAIN_CLASS, HiveMain.class.getName()); 050 } 051 052 @Override 053 protected Configuration setupLauncherConf(Configuration conf, Element actionXml, Path appPath, Context context) 054 throws ActionExecutorException { 055 try { 056 super.setupLauncherConf(conf, actionXml, appPath, context); 057 Namespace ns = actionXml.getNamespace(); 058 059 String script = actionXml.getChild("script", ns).getTextTrim(); 060 String scriptName = new Path(script).getName(); 061 addToCache(conf, appPath, script + "#" + scriptName, false); 062 return conf; 063 } 064 catch (Exception ex) { 065 throw convertException(ex); 066 } 067 } 068 069 @Override 070 @SuppressWarnings("unchecked") 071 Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, 072 Path appPath) throws ActionExecutorException { 073 Configuration conf = super.setupActionConf(actionConf, context, actionXml, appPath); 074 075 Namespace ns = actionXml.getNamespace(); 076 String script = actionXml.getChild("script", ns).getTextTrim(); 077 String scriptName = new Path(script).getName(); 078 addToCache(conf, appPath, script + "#" + scriptName, false); 079 080 List<Element> params = (List<Element>) actionXml.getChildren("param", ns); 081 String[] strParams = new String[params.size()]; 082 for (int i = 0; i < params.size(); i++) { 083 strParams[i] = params.get(i).getTextTrim(); 084 } 085 086 HiveMain.setHiveScript(conf, scriptName, strParams); 087 return conf; 088 } 089 090 @Override 091 protected boolean getCaptureOutput(WorkflowAction action) throws JDOMException { 092 return true; 093 } 094 095 /** 096 * Return the sharelib name for the action. 097 * 098 * @return returns <code>hive</code>. 099 * @param actionXml 100 */ 101 @Override 102 protected String getDefaultShareLibName(Element actionXml) { 103 return "hive"; 104 } 105 106 }