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.coord;
016    
017    import org.apache.oozie.CoordinatorJobBean;
018    import org.apache.oozie.command.CommandException;
019    import org.apache.oozie.store.CoordinatorStore;
020    import org.apache.oozie.store.StoreException;
021    import org.apache.oozie.util.ParamChecker;
022    import org.apache.oozie.util.XLog;
023    
024    /**
025     * Command for loading a coordinator job information
026     */
027    public class CoordJobCommand extends CoordinatorCommand<CoordinatorJobBean> {
028        private String id;
029        private boolean getActionInfo;
030        private int start = 1;
031        private int len = Integer.MAX_VALUE;
032    
033        /**
034         * @param id coord jobId
035         */
036        public CoordJobCommand(String id) {
037            this(id, 1, Integer.MAX_VALUE);
038        }
039    
040        /**
041         * @param id coord jobId
042         * @param start starting index in the list of actions belonging to the job
043         * @param length number of actions to be returned
044         */
045        public CoordJobCommand(String id, int start, int length) {
046            super("job.info", "job.info", 1, XLog.OPS);
047            this.id = ParamChecker.notEmpty(id, "id");
048            this.getActionInfo = true;
049            this.start = start;
050            this.len = length;
051        }
052    
053        /**
054         * @param id coord jobId
055         * @param getActionInfo false to ignore loading actions for the job
056         */
057        public CoordJobCommand(String id, boolean getActionInfo) {
058            super("job.info", "job.info", 1, XLog.OPS);
059            this.id = ParamChecker.notEmpty(id, "id");
060            this.getActionInfo = getActionInfo;
061        }
062    
063        @Override
064        protected CoordinatorJobBean call(CoordinatorStore store) throws StoreException, CommandException {
065            CoordinatorJobBean coord = store.getCoordinatorJob(id, false);
066            if (this.getActionInfo == true) {
067                coord.setActions(store.getActionsSubsetForCoordinatorJob(id, start, len));
068            }
069            else {
070                coord.setActions(null);
071            }
072            return coord;
073        }
074    
075    }