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.executor.jpa; 020 021import java.util.List; 022 023import javax.persistence.EntityManager; 024 025import org.apache.oozie.ErrorCode; 026import org.apache.oozie.WorkflowActionBean; 027import org.apache.oozie.WorkflowJobBean; 028import org.apache.oozie.command.CommandException; 029import org.apache.oozie.service.JPAService; 030import org.apache.oozie.service.Services; 031import org.apache.oozie.util.ParamChecker; 032 033/** 034 * This JPA Executor is responsible for getting the Workflow job with actions in certain range. 035 */ 036public class WorkflowInfoWithActionsSubsetGetJPAExecutor implements JPAExecutor<WorkflowJobBean> { 037 038 private String wfJobId = null; 039 private WorkflowJobBean workflow; 040 private final int start; 041 private final int len; 042 043 /** 044 * This will create the WorkflowInfoWithActionsSubsetGetJPAExecutor object. which is responsible for getting the 045 * Workflow job with actions in certain range. 046 * 047 * @param wfJobId 048 * @param start 049 * @param len 050 */ 051 public WorkflowInfoWithActionsSubsetGetJPAExecutor(String wfJobId, int start, int len) { 052 ParamChecker.notNull(wfJobId, "wfJobId"); 053 this.wfJobId = wfJobId; 054 this.start = start; 055 this.len = len; 056 } 057 058 /* (non-Javadoc) 059 * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager) 060 */ 061 @Override 062 public WorkflowJobBean execute(EntityManager em) throws JPAExecutorException { 063 try { 064 JPAService jpaService = Services.get().get(JPAService.class); 065 if (jpaService != null) { 066 this.workflow = jpaService.execute(new WorkflowJobGetJPAExecutor(this.wfJobId)); 067 } 068 else { 069 throw new JPAExecutorException(ErrorCode.E0610, this.wfJobId); 070 } 071 } 072 catch (Exception ex) { 073 if (ex instanceof JPAExecutorException) { 074 throw (JPAExecutorException) ex; 075 } 076 else { 077 throw new JPAExecutorException(ErrorCode.E0603, ex.getMessage(), ex); 078 } 079 } 080 081 if (this.workflow != null) { 082 JPAService jpaService = Services.get().get(JPAService.class); 083 List<WorkflowActionBean> actionList; 084 if (jpaService != null) { 085 actionList = jpaService.execute(new WorkflowActionSubsetGetJPAExecutor(this.wfJobId, start, len)); 086 } 087 else { 088 throw new JPAExecutorException(ErrorCode.E0610, this.wfJobId); 089 } 090 this.workflow.setActions(actionList); 091 } 092 else { 093 throw new JPAExecutorException(ErrorCode.E0604, wfJobId); 094 } 095 096 return this.workflow; 097 } 098 099 /* (non-Javadoc) 100 * @see org.apache.oozie.executor.jpa.JPAExecutor#getName() 101 */ 102 @Override 103 public String getName() { 104 return "WorkflowInfoWithActionsSubsetGetJPAExecutor"; 105 } 106}