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