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