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.workflow.lite;
019    
020    
021    import org.apache.oozie.workflow.WorkflowApp;
022    import org.apache.oozie.workflow.WorkflowException;
023    import org.apache.oozie.workflow.WorkflowInstance;
024    import org.apache.oozie.workflow.WorkflowLib;
025    import org.apache.oozie.service.Services;
026    import org.apache.oozie.service.UUIDService;
027    import org.apache.oozie.service.UUIDService.ApplicationType;
028    import org.apache.oozie.util.ParamChecker;
029    import org.apache.hadoop.conf.Configuration;
030    
031    import javax.xml.validation.Schema;
032    import java.io.StringReader;
033    import java.util.Date;
034    import java.util.Map;
035    
036    //TODO javadoc
037    public abstract class LiteWorkflowLib implements WorkflowLib {
038        private Schema schema;
039        private Class<? extends ControlNodeHandler> controlHandlerClass;
040        private Class<? extends DecisionNodeHandler> decisionHandlerClass;
041        private Class<? extends ActionNodeHandler> actionHandlerClass;
042    
043        public LiteWorkflowLib(Schema schema,
044                               Class<? extends ControlNodeHandler> controlNodeHandler,
045                               Class<? extends DecisionNodeHandler> decisionHandlerClass,
046                               Class<? extends ActionNodeHandler> actionHandlerClass) {
047            this.schema = schema;
048            this.controlHandlerClass = controlNodeHandler;
049            this.decisionHandlerClass = decisionHandlerClass;
050            this.actionHandlerClass = actionHandlerClass;
051        }
052    
053        @Override
054        public WorkflowApp parseDef(String appXml, Configuration jobConf, Configuration configDefault) throws WorkflowException {
055            ParamChecker.notEmpty(appXml, "appXml");
056            return new LiteWorkflowAppParser(schema, controlHandlerClass, decisionHandlerClass, actionHandlerClass)
057                    .validateAndParse(new StringReader(appXml), jobConf, configDefault);
058        }
059    
060        @Override
061        public WorkflowInstance createInstance(WorkflowApp app, Configuration conf) throws WorkflowException {
062            ParamChecker.notNull(app, "app");
063            String jobId = Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW);
064            return new LiteWorkflowInstance((LiteWorkflowApp) app, conf, jobId);
065        }
066    
067        @Override
068        public WorkflowInstance createInstance(WorkflowApp app, Configuration conf, String wfId, Map<String, Date> actionEndTimes)
069                throws WorkflowException {
070            ParamChecker.notNull(app, "app");
071            ParamChecker.notNull(wfId, "wfId");
072            return new LiteWorkflowInstance((LiteWorkflowApp) app, conf, wfId, actionEndTimes);
073        }
074    }