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;
020
021import org.apache.hadoop.conf.Configuration;
022import org.apache.oozie.action.hadoop.MapReduceMain;
023import org.apache.oozie.client.XOozieClient;
024import org.apache.oozie.command.CommandException;
025import org.jdom.Element;
026import org.jdom.Namespace;
027
028import java.util.ArrayList;
029import java.util.List;
030
031public abstract class SubmitScriptLanguageXCommand extends SubmitHttpXCommand {
032    public SubmitScriptLanguageXCommand(String name, String type, Configuration conf) {
033        super(name, type, conf);
034    }
035
036    @Override
037    protected abstract String getWorkflowName();
038
039    protected abstract String getOptions();
040
041    protected abstract String getScriptParamters();
042
043    @Override
044    protected Namespace getSectionNamespace() {
045        return Namespace.getNamespace("uri:oozie:workflow:0.2");
046    }
047
048    @Override
049    protected Element generateSection(Configuration conf, Namespace ns) {
050        String name = getWorkflowName();
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        List<String> otherArgs = new ArrayList<String>();
061        String[] args = MapReduceMain.getStrings(conf, getOptions());
062        for (String arg : args) {
063            if (arg.startsWith("-D")) {
064                Dargs.add(arg);
065            }
066            else {
067                otherArgs.add(arg);
068            }
069        }
070        String [] params = MapReduceMain.getStrings(conf, getScriptParamters());
071
072        // configuration section
073        if (Dargs.size() > 0) {
074            Element configuration = generateConfigurationSection(Dargs, ns);
075            ele.addContent(configuration);
076        }
077
078        Element script = new Element("script", ns);
079        script.addContent("dummy." + name);
080        ele.addContent(script);
081
082        // parameter section
083        for (String param : params) {
084            Element parameter = new Element("param", ns);
085            parameter.addContent(param);
086            ele.addContent(parameter);
087        }
088
089        // argument section
090        for (String arg : otherArgs) {
091            Element argument = new Element("argument", ns);
092            argument.addContent(arg);
093            ele.addContent(argument);
094        }
095
096        // file section
097        addFileSection(ele, conf, ns);
098
099        // archive section
100        addArchiveSection(ele, conf, ns);
101
102        return ele;
103    }
104
105    @Override
106    public String getEntityKey() {
107        return null;
108    }
109
110    @Override
111    protected boolean isLockRequired() {
112        return false;
113    }
114
115    @Override
116    protected void loadState() {
117
118    }
119
120    @Override
121    protected void verifyPrecondition() throws CommandException {
122
123    }
124}