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    package org.apache.oozie.service;
019    
020    import org.apache.hadoop.conf.Configuration;
021    import org.apache.oozie.client.OozieClient;
022    import org.apache.oozie.workflow.WorkflowApp;
023    import org.apache.oozie.workflow.WorkflowException;
024    import org.apache.oozie.workflow.WorkflowLib;
025    import org.apache.oozie.service.Services;
026    import org.apache.oozie.util.ParamChecker;
027    
028    /**
029     * Service that provides workflow application definition reading, parsing and creating proto configuration.
030     */
031    public 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, String authToken) throws WorkflowException {
040            String appPath = ParamChecker.notEmpty(jobConf.get(OozieClient.APP_PATH), OozieClient.APP_PATH);
041            String user = ParamChecker.notEmpty(jobConf.get(OozieClient.USER_NAME), OozieClient.USER_NAME);
042            String group = ParamChecker.notEmpty(jobConf.get(OozieClient.GROUP_NAME), OozieClient.GROUP_NAME);
043            String workflowXml = readDefinition(appPath, user, group, authToken);
044            return parseDef(workflowXml);
045        }
046    
047        public WorkflowApp parseDef(String workflowXml) throws WorkflowException {
048            WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
049            return workflowLib.parseDef(workflowXml);
050        }
051    }