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.service;
020
021import org.apache.hadoop.conf.Configuration;
022import org.apache.oozie.client.OozieClient;
023import org.apache.oozie.workflow.WorkflowApp;
024import org.apache.oozie.workflow.WorkflowException;
025import org.apache.oozie.workflow.WorkflowLib;
026import org.apache.oozie.util.ParamChecker;
027
028/**
029 * Service that provides workflow application definition reading, parsing and creating proto configuration.
030 */
031public class LiteWorkflowAppService extends WorkflowAppService {
032    /**
033     * Parse workflow definition.
034     *
035     * @param jobConf workflow job configuration.
036     * @param authToken authorization token.
037     * @return workflow application.
038     */
039    public WorkflowApp parseDef(Configuration jobConf) throws WorkflowException {
040        return parseDef(jobConf, null);
041    }
042
043    public WorkflowApp parseDef(Configuration jobConf, Configuration configDefault) throws WorkflowException {
044        String appPath = ParamChecker.notEmpty(jobConf.get(OozieClient.APP_PATH), OozieClient.APP_PATH);
045        String user = ParamChecker.notEmpty(jobConf.get(OozieClient.USER_NAME), OozieClient.USER_NAME);
046        String workflowXml = readDefinition(appPath, user, jobConf);
047        return parseDef(workflowXml, jobConf, configDefault);
048    }
049
050    @Override
051    public WorkflowApp parseDef(String wfXml, Configuration jobConf) throws WorkflowException {
052        return parseDef(wfXml, jobConf, null);
053    }
054
055    public WorkflowApp parseDef(String workflowXml, Configuration jobConf, Configuration configDefault)
056            throws WorkflowException {
057        WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
058        return workflowLib.parseDef(workflowXml, jobConf, configDefault);
059    }
060
061}