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.sql.SQLException; 021 import java.util.ArrayList; 022 import java.util.List; 023 024 import javax.persistence.EntityManager; 025 import javax.persistence.Query; 026 027 import org.apache.oozie.ErrorCode; 028 import org.apache.oozie.WorkflowActionBean; 029 import org.apache.oozie.util.ParamChecker; 030 031 /** 032 * Load workflow actions for a workflow job. 033 */ 034 public class WorkflowJobGetActionsJPAExecutor implements JPAExecutor<List<WorkflowActionBean>> { 035 036 private String wfJobId = null; 037 038 public WorkflowJobGetActionsJPAExecutor(String wfJobId) { 039 ParamChecker.notNull(wfJobId, "wfJobId"); 040 this.wfJobId = wfJobId; 041 } 042 043 @Override 044 public String getName() { 045 return "WorkflowJobGetActionsJPAExecutor"; 046 } 047 048 @Override 049 @SuppressWarnings("unchecked") 050 public List<WorkflowActionBean> execute(EntityManager em) throws JPAExecutorException { 051 List<WorkflowActionBean> actions; 052 List<WorkflowActionBean> actionList = new ArrayList<WorkflowActionBean>(); 053 try { 054 Query q = em.createNamedQuery("GET_ACTIONS_FOR_WORKFLOW"); 055 q.setParameter("wfId", wfJobId); 056 actions = q.getResultList(); 057 for (WorkflowActionBean a : actions) { 058 WorkflowActionBean aa = getBeanForRunningAction(a); 059 actionList.add(aa); 060 } 061 } 062 catch (SQLException e) { 063 throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e); 064 } 065 return actionList; 066 } 067 068 private WorkflowActionBean getBeanForRunningAction(WorkflowActionBean a) throws SQLException { 069 if (a != null) { 070 WorkflowActionBean action = new WorkflowActionBean(); 071 action.setId(a.getId()); 072 action.setConf(a.getConf()); 073 action.setConsoleUrl(a.getConsoleUrl()); 074 action.setData(a.getData()); 075 action.setErrorInfo(a.getErrorCode(), a.getErrorMessage()); 076 action.setExternalId(a.getExternalId()); 077 action.setExternalStatus(a.getExternalStatus()); 078 action.setName(a.getName()); 079 action.setCred(a.getCred()); 080 action.setRetries(a.getRetries()); 081 action.setTrackerUri(a.getTrackerUri()); 082 action.setTransition(a.getTransition()); 083 action.setType(a.getType()); 084 action.setEndTime(a.getEndTime()); 085 action.setExecutionPath(a.getExecutionPath()); 086 action.setLastCheckTime(a.getLastCheckTime()); 087 action.setLogToken(a.getLogToken()); 088 if (a.getPending() == true) { 089 action.setPending(); 090 } 091 action.setPendingAge(a.getPendingAge()); 092 action.setSignalValue(a.getSignalValue()); 093 action.setSlaXml(a.getSlaXml()); 094 action.setStartTime(a.getStartTime()); 095 action.setStatus(a.getStatus()); 096 action.setJobId(a.getWfId()); 097 action.setUserRetryCount(a.getUserRetryCount()); 098 action.setUserRetryInterval(a.getUserRetryInterval()); 099 action.setUserRetryMax(a.getUserRetryMax()); 100 return action; 101 } 102 return null; 103 } 104 105 }