This project has retired. For details please refer to its
Attic page.
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 package org.apache.oozie.command.wf;
019
020 import org.apache.oozie.ErrorCode;
021 import org.apache.oozie.WorkflowJobBean;
022 import org.apache.oozie.XException;
023 import org.apache.oozie.command.CommandException;
024 import org.apache.oozie.command.PreconditionException;
025 import org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor;
026 import org.apache.oozie.service.JPAService;
027 import org.apache.oozie.service.Services;
028 import org.apache.oozie.util.LogUtils;
029 import org.apache.oozie.util.ParamChecker;
030
031 public class DefinitionXCommand extends WorkflowXCommand<String> {
032 private String jobId;
033 private WorkflowJobBean wfJob;
034
035 public DefinitionXCommand(String jobId) {
036 super("definition", "definition", 1);
037 this.jobId = ParamChecker.notEmpty(jobId, "jobId");
038 }
039
040 @Override
041 protected boolean isLockRequired() {
042 return false;
043 }
044
045 @Override
046 public String getEntityKey() {
047 return this.jobId;
048 }
049
050 @Override
051 protected void loadState() throws CommandException {
052 try {
053 JPAService jpaService = Services.get().get(JPAService.class);
054
055 if (jpaService != null) {
056 this.wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
057 LogUtils.setLogInfo(wfJob, logInfo);
058 }
059 else {
060 LOG.error(ErrorCode.E0610);
061 }
062 }
063 catch (XException ex) {
064 throw new CommandException(ex);
065 }
066 }
067
068 @Override
069 protected void verifyPrecondition() throws CommandException, PreconditionException {
070 }
071
072 @Override
073 protected String execute() throws CommandException {
074 if (wfJob != null) {
075 return wfJob.getWorkflowInstance().getApp().getDefinition();
076 }
077 else {
078 throw new CommandException(ErrorCode.E0604);
079 }
080 }
081
082 }