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