001 /** 002 * Copyright (c) 2010 Yahoo! Inc. All rights reserved. 003 * Licensed under the Apache License, Version 2.0 (the "License"); 004 * you may not use this file except in compliance with the License. 005 * You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, 011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 * See the License for the specific language governing permissions and 013 * limitations under the License. See accompanying LICENSE file. 014 */ 015 016 package org.apache.oozie.action.hadoop; 017 018 import org.apache.hadoop.conf.Configuration; 019 import org.apache.oozie.service.Services; 020 import org.apache.oozie.util.XLog; 021 import org.jdom.Element; 022 023 024 public class DistcpActionExecutor extends JavaActionExecutor{ 025 public static final String CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS = "org.apache.hadoop.tools.DistCp"; 026 public static final String CLASS_NAMES = "oozie.actions.main.classnames"; 027 private static final XLog LOG = XLog.getLog(DistcpActionExecutor.class); 028 public static final String DISTCP_TYPE = "distcp"; 029 030 public DistcpActionExecutor() { 031 super("distcp"); 032 } 033 034 /* (non-Javadoc) 035 * @see org.apache.oozie.action.hadoop.JavaActionExecutor#getLauncherMain(org.apache.hadoop.conf.Configuration, org.jdom.Element) 036 */ 037 @Override 038 protected String getLauncherMain(Configuration launcherConf, Element actionXml) { 039 String classNameDistcp = CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS; 040 String name = getClassNamebyType(DISTCP_TYPE); 041 if(name != null){ 042 classNameDistcp = name; 043 } 044 return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, classNameDistcp); 045 } 046 047 /** 048 * This function returns the Action classes names from the configuration 049 * 050 * @param type This is type of the action classes 051 * @return Name of the class from the configuration 052 */ 053 public static String getClassNamebyType(String type){ 054 Configuration conf = Services.get().getConf(); 055 String classname = null; 056 if (conf.get(CLASS_NAMES, "").trim().length() > 0) { 057 for (String function : conf.getStrings(CLASS_NAMES)) { 058 function = DistcpActionExecutor.Trim(function); 059 LOG.debug("class for Distcp Action: " + function); 060 String[] str = function.split("="); 061 if (str.length > 0) { 062 if(type.equalsIgnoreCase(str[0])){ 063 classname = new String(str[1]); 064 } 065 } 066 } 067 } 068 return classname; 069 } 070 071 /** 072 * To trim string 073 * 074 * @param str 075 * @return trim string 076 */ 077 public static String Trim(String str) { 078 if (str != null) { 079 str = str.replaceAll("\\n", ""); 080 str = str.replaceAll("\\t", ""); 081 str = str.trim(); 082 } 083 return str; 084 } 085 }