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