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.command.wf; 016 017 import org.apache.oozie.WorkflowJobBean; 018 import org.apache.oozie.store.StoreException; 019 import org.apache.oozie.store.WorkflowStore; 020 import org.apache.oozie.util.ParamChecker; 021 import org.apache.oozie.util.XLog; 022 import org.apache.oozie.service.Services; 023 024 /** 025 * Command for loading a job information 026 */ 027 public class JobCommand extends WorkflowCommand<WorkflowJobBean> { 028 private String id; 029 private int start = 1; 030 private int len = Integer.MAX_VALUE; 031 032 /** 033 * @param id wf jobId 034 */ 035 public JobCommand(String id) { 036 this(id, 1, Integer.MAX_VALUE); 037 } 038 039 /** 040 * @param id wf jobId 041 * @param start starting index in the list of actions belonging to the job 042 * @param length number of actions to be returned 043 */ 044 public JobCommand(String id, int start, int length) { 045 super("job.info", "job.info", 1, XLog.OPS, true); 046 this.id = ParamChecker.notEmpty(id, "id"); 047 this.start = start; 048 this.len = length; 049 } 050 051 @Override 052 protected WorkflowJobBean call(WorkflowStore store) throws StoreException { 053 WorkflowJobBean workflow = store.getWorkflowInfoWithActionsSubset(id, start, len); 054 workflow.setConsoleUrl(getJobConsoleUrl(id)); 055 return workflow; 056 } 057 058 static String getJobConsoleUrl(String jobId) { 059 String consoleUrl = Services.get().getConf().get("oozie.JobCommand.job.console.url", null); 060 return (consoleUrl != null) ? consoleUrl + jobId : null; 061 } 062 063 }