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