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.CoordinatorActionBean;
018    import org.apache.oozie.ErrorCode;
019    import org.apache.oozie.command.CommandException;
020    import org.apache.oozie.command.PreconditionException;
021    import org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor;
022    import org.apache.oozie.executor.jpa.JPAExecutorException;
023    import org.apache.oozie.service.JPAService;
024    import org.apache.oozie.service.Services;
025    import org.apache.oozie.util.ParamChecker;
026    
027    public class CoordActionInfoXCommand extends CoordinatorXCommand<CoordinatorActionBean> {
028        /**
029         * This class gets the Coordinator action info based on coordinator action id.
030         */
031        private final String id;
032    
033        public CoordActionInfoXCommand(String id) {
034            super("action.info", "action.info", 1);
035            this.id = ParamChecker.notEmpty(id, "id");
036        }
037    
038        /* (non-Javadoc)
039         * @see org.apache.oozie.command.XCommand#execute()
040         */
041        @Override
042        protected CoordinatorActionBean execute() throws CommandException {
043            JPAService jpaService = Services.get().get(JPAService.class);
044            if (jpaService != null) {
045                CoordinatorActionBean action;
046                try {
047                    action = jpaService.execute(new CoordActionGetJPAExecutor(this.id));
048                }
049                catch (JPAExecutorException e) {
050                    throw new CommandException(e);
051                }
052                return action;
053            }
054            else {
055                LOG.error(ErrorCode.E0610);
056                return null;
057            }
058        }
059    
060        /* (non-Javadoc)
061         * @see org.apache.oozie.command.XCommand#getEntityKey()
062         */
063        @Override
064        protected String getEntityKey() {
065            return null;
066        }
067    
068        /* (non-Javadoc)
069         * @see org.apache.oozie.command.XCommand#loadState()
070         */
071        @Override
072        protected void loadState() throws CommandException {
073        }
074    
075        /* (non-Javadoc)
076         * @see org.apache.oozie.command.XCommand#verifyPrecondition()
077         */
078        @Override
079        protected void verifyPrecondition() throws CommandException, PreconditionException {
080        }
081    
082        /* (non-Javadoc)
083         * @see org.apache.oozie.command.XCommand#isLockRequired()
084         */
085        @Override
086        protected boolean isLockRequired() {
087            return false;
088        }
089    }