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 034 //TODO javadoc 035 public abstract class LiteWorkflowLib implements WorkflowLib { 036 private Schema schema; 037 private Class<? extends DecisionNodeHandler> decisionHandlerClass; 038 private Class<? extends ActionNodeHandler> actionHandlerClass; 039 040 public LiteWorkflowLib(Schema schema, Class<? extends DecisionNodeHandler> decisionHandlerClass, 041 Class<? extends ActionNodeHandler> actionHandlerClass) { 042 this.schema = schema; 043 this.decisionHandlerClass = decisionHandlerClass; 044 this.actionHandlerClass = actionHandlerClass; 045 } 046 047 @Override 048 public WorkflowApp parseDef(String appXml) throws WorkflowException { 049 ParamChecker.notEmpty(appXml, "appXml"); 050 return new LiteWorkflowAppParser(schema, decisionHandlerClass, actionHandlerClass) 051 .validateAndParse(new StringReader(appXml)); 052 } 053 054 @Override 055 public WorkflowInstance createInstance(WorkflowApp app, Configuration conf) throws WorkflowException { 056 ParamChecker.notNull(app, "app"); 057 String jobId = Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW); 058 return new LiteWorkflowInstance((LiteWorkflowApp) app, conf, jobId); 059 } 060 061 @Override 062 public WorkflowInstance createInstance(WorkflowApp app, Configuration conf, String wfId) throws WorkflowException { 063 ParamChecker.notNull(app, "app"); 064 ParamChecker.notNull(wfId, "wfId"); 065 return new LiteWorkflowInstance((LiteWorkflowApp) app, conf, wfId); 066 } 067 }