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