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