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; 016 017 import org.apache.hadoop.conf.Configuration; 018 019 020 /** 021 * The workflow library provides application parsing and storage capabilities for workflow instances. <p/> The 022 * implementation is responsible for doing the store operations in a transactional way, either in autocommit or within 023 * the scope of a transaction. 024 */ 025 public interface WorkflowLib { 026 027 /** 028 * Parse a workflow application definition. 029 * 030 * @param wfXml string containing the workflow definition. 031 * @return the parse workflow application. 032 * @throws WorkflowException thrown if the definition could not be parsed. 033 */ 034 public WorkflowApp parseDef(String wfXml) throws WorkflowException; 035 036 037 /** 038 * Create a workflow instance. 039 * 040 * @param app application to create a workflow instance of. 041 * @param conf job configuration. 042 * @return the newly created workflow instance. 043 * @throws WorkflowException thrown if the instance could not be created. 044 */ 045 public WorkflowInstance createInstance(WorkflowApp app, Configuration conf) throws WorkflowException; 046 047 /** 048 * Create a workflow instance with the given wfId. This will be used for re-running workflows. 049 * 050 * @param app application to create a workflow instance of. 051 * @param conf job configuration. 052 * @param wfId Workflow ID. 053 * @return the newly created workflow instance. 054 * @throws WorkflowException thrown if the instance could not be created. 055 */ 056 public WorkflowInstance createInstance(WorkflowApp app, Configuration conf, String wfId) throws WorkflowException; 057 058 /** 059 * Insert a workflow instance in storage. 060 * 061 * @param instance of the workflow instance to insert. 062 * @throws WorkflowException thrown if the instance could not be inserted. 063 */ 064 public void insert(WorkflowInstance instance) throws WorkflowException; 065 066 /** 067 * Load a workflow instance from storage. 068 * 069 * @param id ID of the workflow instance to load. 070 * @return the loaded workflow instance. 071 * @throws WorkflowException thrown if the instance could not be loaded. 072 */ 073 public WorkflowInstance get(String id) throws WorkflowException; 074 075 /** 076 * Update a workflow instance in storage. 077 * 078 * @param instance workflow instance to update. 079 * @throws WorkflowException thrown if the instance could not be loaded. 080 */ 081 public void update(WorkflowInstance instance) throws WorkflowException; 082 083 /** 084 * Delete a workflow instance from storage. 085 * 086 * @param id ID of the workflow instance to delete. 087 * @throws WorkflowException thrown if the instance could not be deleted. 088 */ 089 public void delete(String id) throws WorkflowException; 090 091 092 /** 093 * Commit changes to store. 094 * 095 * @throws WorkflowException thrown if the commit could not be done. 096 */ 097 public void commit() throws WorkflowException; 098 099 /** 100 * Close store. It rollbacks if there was no commit. 101 * 102 * @throws WorkflowException thrown if the close could not be done. 103 */ 104 public void close() throws WorkflowException; 105 106 }