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