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