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