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.bundle;
019
020import java.util.List;
021
022import org.apache.oozie.BundleJobBean;
023import org.apache.oozie.CoordinatorJobBean;
024import org.apache.oozie.ErrorCode;
025import org.apache.oozie.XException;
026import org.apache.oozie.command.CommandException;
027import org.apache.oozie.command.PreconditionException;
028import org.apache.oozie.command.XCommand;
029import org.apache.oozie.executor.jpa.BundleJobGetCoordinatorsJPAExecutor;
030import org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor;
031import org.apache.oozie.service.JPAService;
032import org.apache.oozie.service.Services;
033import org.apache.oozie.util.ParamChecker;
034
035/**
036 * Command for Getting the Bundle job bean it also gets coordinators information in the Bundle job.
037 */
038public class BundleJobXCommand extends XCommand<BundleJobBean> {
039    private final String id;
040
041    /**
042     * Command for Getting the Bundle job bean it also gets coordinators information in the Bundle job.
043     *
044     * @param id bundle jobId
045     */
046    public BundleJobXCommand(String id) {
047        super("job.info", "job.info", 1);
048        this.id = ParamChecker.notEmpty(id, "id");
049    }
050
051    /* (non-Javadoc)
052     * @see org.apache.oozie.command.XCommand#isLockRequired()
053     */
054    @Override
055    protected boolean isLockRequired() {
056        return false;
057    }
058
059    /* (non-Javadoc)
060     * @see org.apache.oozie.command.XCommand#getEntityKey()
061     */
062    @Override
063    public String getEntityKey() {
064        return this.id;
065    }
066
067    /* (non-Javadoc)
068     * @see org.apache.oozie.command.XCommand#loadState()
069     */
070    @Override
071    protected void loadState() throws CommandException {
072    }
073
074    /* (non-Javadoc)
075     * @see org.apache.oozie.command.XCommand#verifyPrecondition()
076     */
077    @Override
078    protected void verifyPrecondition() throws CommandException, PreconditionException {
079    }
080
081    /* (non-Javadoc)
082     * @see org.apache.oozie.command.XCommand#execute()
083     */
084    @Override
085    protected BundleJobBean execute() throws CommandException {
086        try {
087            JPAService jpaService = Services.get().get(JPAService.class);
088            BundleJobBean bundleJob = null;
089            if (jpaService != null) {
090                bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(id));
091                List<CoordinatorJobBean> coordinators = jpaService.execute(new BundleJobGetCoordinatorsJPAExecutor(id));
092                bundleJob.setCoordJobs(coordinators);
093            }
094            else {
095                LOG.error(ErrorCode.E0610);
096            }
097            return bundleJob;
098        }
099        catch (XException ex) {
100            throw new CommandException(ex);
101        }
102    }
103
104}