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 019package org.apache.oozie.action.hadoop; 020 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.fs.Path; 023import org.apache.oozie.action.ActionExecutorException; 024import org.apache.oozie.service.ConfigurationService; 025import org.apache.oozie.util.XLog; 026import org.jdom.Element; 027 028import java.util.ArrayList; 029import java.util.List; 030 031public class DistcpActionExecutor extends JavaActionExecutor{ 032 public static final String CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS = "org.apache.oozie.action.hadoop.DistcpMain"; 033 private static final String DISTCP_MAIN_CLASS_NAME = "org.apache.hadoop.tools.DistCp"; 034 public static final String CLASS_NAMES = "oozie.actions.main.classnames"; 035 private static final XLog LOG = XLog.getLog(DistcpActionExecutor.class); 036 public static final String DISTCP_TYPE = "distcp"; 037 038 public DistcpActionExecutor() { 039 super("distcp"); 040 } 041 042 @Override 043 Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) 044 throws ActionExecutorException { 045 actionConf = super.setupActionConf(actionConf, context, actionXml, appPath); 046 String classNameDistcp = CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS; 047 String name = getClassNamebyType(DISTCP_TYPE); 048 if(name != null){ 049 classNameDistcp = name; 050 } 051 actionConf.set(JavaMain.JAVA_MAIN_CLASS, DISTCP_MAIN_CLASS_NAME); 052 return actionConf; 053 } 054 055 @Override 056 public List<Class> getLauncherClasses() { 057 List<Class> classes = new ArrayList<Class>(); 058 try { 059 classes.add(Class.forName(CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS)); 060 } 061 catch (ClassNotFoundException e) { 062 throw new RuntimeException("Class not found", e); 063 } 064 return classes; 065 } 066 067 /** 068 * This function returns the Action classes names from the configuration 069 * 070 * @param type This is type of the action classes 071 * @return Name of the class from the configuration 072 */ 073 public static String getClassNamebyType(String type){ 074 String classname = null; 075 for (String function : ConfigurationService.getStrings(CLASS_NAMES)) { 076 function = DistcpActionExecutor.Trim(function); 077 LOG.debug("class for Distcp Action: " + function); 078 String[] str = function.split("="); 079 if (str.length > 0) { 080 if(type.equalsIgnoreCase(str[0])){ 081 classname = new String(str[1]); 082 } 083 } 084 } 085 return classname; 086 } 087 088 /** 089 * To trim string 090 * 091 * @param str 092 * @return trim string 093 */ 094 public static String Trim(String str) { 095 if (str != null) { 096 str = str.replaceAll("\\n", ""); 097 str = str.replaceAll("\\t", ""); 098 str = str.trim(); 099 } 100 return str; 101 } 102 103 /** 104 * Return the sharelib name for the action. 105 * 106 * @return returns <code>distcp</code>. 107 * @param actionXml 108 */ 109 @Override 110 protected String getDefaultShareLibName(Element actionXml) { 111 return "distcp"; 112 } 113 114 @Override 115 protected String getLauncherMain(Configuration launcherConf, Element actionXml) { 116 return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS); 117 } 118}