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