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