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