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 org.apache.hadoop.conf.Configuration; 021 import org.apache.oozie.service.Services; 022 import org.apache.oozie.util.XLog; 023 import org.jdom.Element; 024 025 026 public class DistcpActionExecutor extends JavaActionExecutor{ 027 public static final String CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS = "org.apache.hadoop.tools.DistCp"; 028 public static final String CLASS_NAMES = "oozie.actions.main.classnames"; 029 private static final XLog LOG = XLog.getLog(DistcpActionExecutor.class); 030 public static final String DISTCP_TYPE = "distcp"; 031 032 public DistcpActionExecutor() { 033 super("distcp"); 034 } 035 036 /* (non-Javadoc) 037 * @see org.apache.oozie.action.hadoop.JavaActionExecutor#getLauncherMain(org.apache.hadoop.conf.Configuration, org.jdom.Element) 038 */ 039 @Override 040 protected String getLauncherMain(Configuration launcherConf, Element actionXml) { 041 String classNameDistcp = CONF_OOZIE_DISTCP_ACTION_MAIN_CLASS; 042 String name = getClassNamebyType(DISTCP_TYPE); 043 if(name != null){ 044 classNameDistcp = name; 045 } 046 return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, classNameDistcp); 047 } 048 049 /** 050 * This function returns the Action classes names from the configuration 051 * 052 * @param type This is type of the action classes 053 * @return Name of the class from the configuration 054 */ 055 public static String getClassNamebyType(String type){ 056 Configuration conf = Services.get().getConf(); 057 String classname = null; 058 if (conf.get(CLASS_NAMES, "").trim().length() > 0) { 059 for (String function : conf.getStrings(CLASS_NAMES)) { 060 function = DistcpActionExecutor.Trim(function); 061 LOG.debug("class for Distcp Action: " + function); 062 String[] str = function.split("="); 063 if (str.length > 0) { 064 if(type.equalsIgnoreCase(str[0])){ 065 classname = new String(str[1]); 066 } 067 } 068 } 069 } 070 return classname; 071 } 072 073 /** 074 * To trim string 075 * 076 * @param str 077 * @return trim string 078 */ 079 public static String Trim(String str) { 080 if (str != null) { 081 str = str.replaceAll("\\n", ""); 082 str = str.replaceAll("\\t", ""); 083 str = str.trim(); 084 } 085 return str; 086 } 087 }