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