001 /** 002 * Copyright (c) 2010 Yahoo! Inc. All rights reserved. 003 * Licensed under the Apache License, Version 2.0 (the "License"); 004 * you may not use this file except in compliance with the License. 005 * You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, 011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 * See the License for the specific language governing permissions and 013 * limitations under the License. See accompanying LICENSE file. 014 */ 015 package org.apache.oozie.workflow.lite; 016 017 018 import org.apache.oozie.workflow.WorkflowApp; 019 import org.apache.oozie.workflow.WorkflowException; 020 import org.apache.oozie.workflow.WorkflowInstance; 021 import org.apache.oozie.workflow.WorkflowLib; 022 import org.apache.oozie.service.Services; 023 import org.apache.oozie.service.UUIDService; 024 import org.apache.oozie.service.UUIDService.ApplicationType; 025 import org.apache.oozie.util.ParamChecker; 026 import org.apache.hadoop.conf.Configuration; 027 028 import javax.xml.validation.Schema; 029 import java.io.StringReader; 030 031 //TODO javadoc 032 public abstract class LiteWorkflowLib implements WorkflowLib { 033 private Schema schema; 034 private Class<? extends DecisionNodeHandler> decisionHandlerClass; 035 private Class<? extends ActionNodeHandler> actionHandlerClass; 036 037 public LiteWorkflowLib(Schema schema, Class<? extends DecisionNodeHandler> decisionHandlerClass, 038 Class<? extends ActionNodeHandler> actionHandlerClass) { 039 this.schema = schema; 040 this.decisionHandlerClass = decisionHandlerClass; 041 this.actionHandlerClass = actionHandlerClass; 042 } 043 044 @Override 045 public WorkflowApp parseDef(String appXml) throws WorkflowException { 046 ParamChecker.notEmpty(appXml, "appXml"); 047 return new LiteWorkflowAppParser(schema, decisionHandlerClass, actionHandlerClass) 048 .validateAndParse(new StringReader(appXml)); 049 } 050 051 @Override 052 public WorkflowInstance createInstance(WorkflowApp app, Configuration conf) throws WorkflowException { 053 ParamChecker.notNull(app, "app"); 054 String jobId = Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW); 055 return new LiteWorkflowInstance((LiteWorkflowApp) app, conf, jobId); 056 } 057 058 @Override 059 public WorkflowInstance createInstance(WorkflowApp app, Configuration conf, String wfId) throws WorkflowException { 060 ParamChecker.notNull(app, "app"); 061 ParamChecker.notNull(wfId, "wfId"); 062 return new LiteWorkflowInstance((LiteWorkflowApp) app, conf, wfId); 063 } 064 }