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 java.util.List;
021    import java.util.Map;
022    
023    import org.apache.oozie.WorkflowJobBean;
024    import org.apache.oozie.WorkflowsInfo;
025    import org.apache.oozie.store.StoreException;
026    import org.apache.oozie.store.WorkflowStore;
027    import org.apache.oozie.util.XLog;
028    
029    /**
030     * Command for loading the Workflows according to the given filter information
031     */
032    public class JobsCommand extends WorkflowCommand<WorkflowsInfo> {
033        private Map<String, List<String>> filter;
034        private int start;
035        private int len;
036    
037        /**
038         * Constructor taking the filter information
039         *
040         * @param filter Can be name, status, user, group and combination of these
041         * @param start starting from this index in the list of workflows matching the filter are returned
042         * @param length number of workflows to be returned from the list of workflows matching the filter and starting from
043         * index "start".
044         */
045        public JobsCommand(Map<String, List<String>> filter, int start, int length) {
046            super("job.info", "job.info", 1, XLog.OPS, true);
047            this.filter = filter;
048            this.start = start;
049            this.len = length;
050        }
051    
052        @Override
053        protected WorkflowsInfo call(WorkflowStore store) throws StoreException {
054            WorkflowsInfo workflowsInfo = store.getWorkflowsInfo(filter, start, len);
055            for (WorkflowJobBean workflow : workflowsInfo.getWorkflows()) {
056                workflow.setConsoleUrl(JobCommand.getJobConsoleUrl(workflow.getId()));
057            }
058            return workflowsInfo;
059        }
060    
061    }