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