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; 020 021import org.apache.oozie.client.OozieClientException; 022import org.apache.oozie.client.WorkflowAction; 023import org.apache.oozie.client.WorkflowJob; 024 025import java.util.List; 026 027/** 028 * Client API to submit and manage Oozie workflow jobs against an Oozie instance. <p> This class is thread safe. <p> 029 * Syntax for filter for the {@link #getJobsInfo(String)} {@link #getJobsInfo(String, int, int)} methods: 030 * <code>[NAME=VALUE][;NAME=VALUE]*</code>. <p> Valid filter names are: <ul> <li>name: the workflow application 031 * name from the workflow definition.</li> <li>user: the user that submitted the job.</li> <li>group: the group for the 032 * job.</li> <li>status: the status of the job.</li> </ul> <p> The query will do an AND among all the filter names. The 033 * query will do an OR among all the filter values for the same name. Multiple values must be specified as different 034 * name value pairs. 035 */ 036public class LocalOozieClient extends BaseLocalOozieClient { 037 038 private DagEngine dagEngine; 039 040 /** 041 * Create a workflow client for Oozie local use. 042 * 043 * @param dagEngine the dag engine instance to use. 044 */ 045 public LocalOozieClient(DagEngine dagEngine) { 046 super(dagEngine); 047 this.dagEngine = dagEngine; 048 } 049 050 /** 051 * Get the info of a workflow job. 052 * 053 * @param jobId job Id. 054 * @return the job info. 055 * @throws org.apache.oozie.client.OozieClientException thrown if the job info could not be retrieved. 056 */ 057 @Override 058 public WorkflowJob getJobInfo(String jobId) throws OozieClientException { 059 try { 060 return dagEngine.getJob(jobId); 061 } 062 catch (DagEngineException ex) { 063 throw new OozieClientException(ex.getErrorCode().toString(), ex); 064 } 065 } 066 067 /** 068 * Return the info of the workflow jobs that match the filter. 069 * 070 * @param filter job filter. Refer to the {@link LocalOozieClient} for the filter syntax. 071 * @param start jobs offset, base 1. 072 * @param len number of jobs to return. 073 * @return a list with the workflow jobs info, without node details. 074 * @throws org.apache.oozie.client.OozieClientException thrown if the jobs info could not be retrieved. 075 */ 076 @Override 077 public List<WorkflowJob> getJobsInfo(String filter, int start, int len) throws OozieClientException { 078 try { 079 return (List) dagEngine.getJobs(filter, start, len).getWorkflows(); 080 } 081 catch (DagEngineException ex) { 082 throw new OozieClientException(ex.getErrorCode().toString(), ex); 083 } 084 } 085 086 /** 087 * Return the info of the workflow jobs that match the filter. <p> It returns the first 100 jobs that match the 088 * filter. 089 * 090 * @param filter job filter. Refer to the {@link LocalOozieClient} for the filter syntax. 091 * @return a list with the workflow jobs info, without node details. 092 * @throws org.apache.oozie.client.OozieClientException thrown if the jobs info could not be retrieved. 093 */ 094 @Override 095 public List<WorkflowJob> getJobsInfo(String filter) throws OozieClientException { 096 return getJobsInfo(filter, 1, 100); 097 } 098 099 @Override 100 public WorkflowJob getJobInfo(String jobId, int start, int len) throws OozieClientException { 101 try { 102 return dagEngine.getJob(jobId, start, len); 103 } catch (DagEngineException e) { 104 throw new OozieClientException(e.getErrorCode().toString(), e); 105 } 106 } 107 108 @Override 109 public WorkflowAction getWorkflowActionInfo(String actionId) throws OozieClientException { 110 try { 111 return dagEngine.getWorkflowAction(actionId); 112 } catch (BaseEngineException e) { 113 throw new OozieClientException(e.getErrorCode().toString(), e); 114 } 115 } 116 117 /** 118 * Returns if Oozie is in safe mode or not. 119 * 120 * @return true if safe mode is ON<br> false if safe mode is OFF 121 * @throws org.apache.oozie.client.OozieClientException throw if it could not obtain the safe mode status. 122 */ 123 /*public SYSTEM_MODE isInSafeMode() throws OozieClientException { 124 //return Services.get().isSafeMode(); 125 return Services.get().getSystemMode() ; 126 }*/ 127 128}