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; 016 017 import java.io.IOException; 018 import java.io.Writer; 019 import java.util.ArrayList; 020 import java.util.HashMap; 021 import java.util.HashSet; 022 import java.util.List; 023 import java.util.Map; 024 import java.util.Properties; 025 import java.util.Set; 026 import java.util.StringTokenizer; 027 028 import org.apache.hadoop.conf.Configuration; 029 import org.apache.oozie.client.CoordinatorJob; 030 import org.apache.oozie.client.OozieClient; 031 import org.apache.oozie.client.WorkflowJob; 032 import org.apache.oozie.command.CommandException; 033 import org.apache.oozie.command.wf.CompletedActionCommand; 034 import org.apache.oozie.command.wf.DefinitionCommand; 035 import org.apache.oozie.command.wf.ExternalIdCommand; 036 import org.apache.oozie.command.wf.JobCommand; 037 import org.apache.oozie.command.wf.JobsCommand; 038 import org.apache.oozie.command.wf.KillCommand; 039 import org.apache.oozie.command.wf.ReRunCommand; 040 import org.apache.oozie.command.wf.ResumeCommand; 041 import org.apache.oozie.command.wf.StartCommand; 042 import org.apache.oozie.command.wf.SubmitCommand; 043 import org.apache.oozie.command.wf.SuspendCommand; 044 import org.apache.oozie.service.DagXLogInfoService; 045 import org.apache.oozie.service.Service; 046 import org.apache.oozie.service.Services; 047 import org.apache.oozie.service.XLogService; 048 import org.apache.oozie.util.ParamChecker; 049 import org.apache.oozie.util.XLog; 050 import org.apache.oozie.util.XLogStreamer; 051 052 public abstract class BaseEngine { 053 public static final String USE_XCOMMAND = "oozie.useXCommand"; 054 055 protected String user; 056 protected String authToken; 057 058 /** 059 * Return the user name. 060 * 061 * @return the user name. 062 */ 063 public String getUser() { 064 return user; 065 } 066 067 /** 068 * Return the authentication token. 069 * 070 * @return the authentication token. 071 */ 072 protected String getAuthToken() { 073 return authToken; 074 } 075 076 /** 077 * Submit a job. <p/> It validates configuration properties. 078 * 079 * @param conf job configuration. 080 * @param startJob indicates if the job should be started or not. 081 * @return the job Id. 082 * @throws BaseEngineException thrown if the job could not be created. 083 */ 084 public abstract String submitJob(Configuration conf, boolean startJob) throws BaseEngineException; 085 086 /** 087 * Start a job. 088 * 089 * @param jobId job Id. 090 * @throws BaseEngineException thrown if the job could not be started. 091 */ 092 public abstract void start(String jobId) throws BaseEngineException; 093 094 /** 095 * Resume a job. 096 * 097 * @param jobId job Id. 098 * @throws BaseEngineException thrown if the job could not be resumed. 099 */ 100 public abstract void resume(String jobId) throws BaseEngineException; 101 102 /** 103 * Suspend a job. 104 * 105 * @param jobId job Id. 106 * @throws BaseEngineException thrown if the job could not be suspended. 107 */ 108 public abstract void suspend(String jobId) throws BaseEngineException; 109 110 /** 111 * Kill a job. 112 * 113 * @param jobId job Id. 114 * @throws BaseEngineException thrown if the job could not be killed. 115 */ 116 public abstract void kill(String jobId) throws BaseEngineException; 117 118 /** 119 * Change a coordinator job. 120 * 121 * @param jobId job Id. 122 * @param changeValue change value. 123 * @throws BaseEngineException thrown if the job could not be changed. 124 */ 125 public abstract void change(String jobId, String changeValue) throws BaseEngineException; 126 127 /** 128 * Rerun a job. 129 * 130 * @param jobId job Id to rerun. 131 * @param conf configuration information for the rerun. 132 * @throws BaseEngineException thrown if the job could not be rerun. 133 */ 134 public abstract void reRun(String jobId, Configuration conf) throws BaseEngineException; 135 136 137 /** 138 * Return the info about a wf job. 139 * 140 * @param jobId job Id. 141 * @return the workflow job info. 142 * @throws DagEngineException thrown if the job info could not be obtained. 143 */ 144 public abstract WorkflowJob getJob(String jobId) throws BaseEngineException; 145 146 /** 147 * Return the info about a wf job with actions subset. 148 * 149 * @param jobId job Id 150 * @param start starting from this index in the list of actions belonging to the job 151 * @param length number of actions to be returned 152 * @return the workflow job info. 153 * @throws DagEngineException thrown if the job info could not be obtained. 154 */ 155 public abstract WorkflowJob getJob(String jobId, int start, int length) throws BaseEngineException; 156 157 /** 158 * Return the info about a coord job. 159 * 160 * @param jobId job Id. 161 * @return the coord job info. 162 * @throws BaseEngineException thrown if the job info could not be obtained. 163 */ 164 public abstract CoordinatorJob getCoordJob(String jobId) throws BaseEngineException; 165 166 /** 167 * Return the info about a coord job with actions subset. 168 * 169 * @param jobId job Id. 170 * @param start starting from this index in the list of actions belonging to the job 171 * @param length number of actions to be returned 172 * @return the coord job info. 173 * @throws BaseEngineException thrown if the job info could not be obtained. 174 */ 175 public abstract CoordinatorJob getCoordJob(String jobId, int start, int length) throws BaseEngineException; 176 177 /** 178 * Return the a job definition. 179 * 180 * @param jobId job Id. 181 * @return the job definition. 182 * @throws BaseEngineException thrown if the job definition could no be obtained. 183 */ 184 public abstract String getDefinition(String jobId) throws BaseEngineException; 185 186 /** 187 * Stream the log of a job. 188 * 189 * @param jobId job Id. 190 * @param writer writer to stream the log to. 191 * @throws IOException thrown if the log cannot be streamed. 192 * @throws BaseEngineException thrown if there is error in getting the Workflow/Coordinator Job Information for 193 * jobId. 194 */ 195 public abstract void streamLog(String jobId, Writer writer) throws IOException, BaseEngineException; 196 197 /** 198 * Return the workflow Job ID for an external ID. <p/> This is reverse lookup for recovery purposes. 199 * 200 * @param externalId external ID provided at job submission time. 201 * @return the associated workflow job ID if any, <code>null</code> if none. 202 * @throws BaseEngineException thrown if the lookup could not be done. 203 */ 204 public abstract String getJobIdForExternalId(String externalId) throws BaseEngineException; 205 206 public abstract String dryrunSubmit(Configuration conf, boolean startJob) 207 throws BaseEngineException; 208 209 }