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.command.wf; 020import java.util.ArrayList; 021import java.util.List; 022import org.apache.hadoop.conf.Configuration; 023import org.apache.oozie.client.XOozieClient; 024import org.apache.oozie.command.CommandException; 025import org.apache.oozie.action.hadoop.MapReduceMain; 026import org.jdom.Namespace; 027import org.jdom.Element; 028 029public class SubmitSqoopXCommand extends SubmitHttpXCommand { 030 public SubmitSqoopXCommand(Configuration conf) { 031 super("submitSqoop", "submitSqoop", conf); 032 } 033 034 protected String getOptions(){ 035 return XOozieClient.SQOOP_OPTIONS; 036 } 037 038 @Override 039 protected Namespace getSectionNamespace(){ 040 return Namespace.getNamespace("uri:oozie:sqoop-action:0.4"); 041 } 042 043 @Override 044 protected String getWorkflowName(){ 045 return "sqoop"; 046 } 047 048 @Override 049 protected Element generateSection(Configuration conf, Namespace ns) { 050 String name = "sqoop"; 051 Element ele = new Element(name, ns); 052 Element jt = new Element("job-tracker", ns); 053 jt.addContent(conf.get(XOozieClient.JT)); 054 ele.addContent(jt); 055 Element nn = new Element("name-node", ns); 056 nn.addContent(conf.get(XOozieClient.NN)); 057 ele.addContent(nn); 058 059 List<String> Dargs = new ArrayList<String>(); 060 String[] args = MapReduceMain.getStrings(conf, getOptions()); 061 for (String arg : args) { 062 if (arg.startsWith("-D")) { 063 Dargs.add(arg); 064 } 065 } 066 067 // configuration section 068 if (Dargs.size() > 0) { 069 Element configuration = generateConfigurationSection(Dargs, ns); 070 ele.addContent(configuration); 071 } 072 073 String[] sqoopArgs = conf.get(XOozieClient.SQOOP_COMMAND).split("\n"); 074 for (String arg : sqoopArgs) { 075 Element eArg = new Element("arg", ns); 076 eArg.addContent(arg); 077 ele.addContent(eArg); 078 } 079 080 // file section 081 addFileSection(ele, conf, ns); 082 083 // archive section 084 addArchiveSection(ele, conf, ns); 085 086 return ele; 087 } 088 089 @Override 090 protected void verifyPrecondition() throws CommandException { 091 } 092 093 @Override 094 protected boolean isLockRequired() { 095 return false; 096 } 097 098 @Override 099 protected void loadState() { 100 } 101 102 @Override 103 public String getEntityKey() { 104 return null; 105 } 106}