1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: a single workflow job that is schedulable
|
4
|
* Copyright: 2009 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Michael Daigle
|
7
|
*
|
8
|
* '$Author: daigle $'
|
9
|
* '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
|
10
|
* '$Revision: 4080 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
package edu.ucsb.nceas.workflowscheduler;
|
27
|
|
28
|
import java.rmi.RemoteException;
|
29
|
import javax.xml.rpc.ServiceException;
|
30
|
|
31
|
import org.apache.log4j.Logger;
|
32
|
|
33
|
import org.quartz.InterruptableJob;
|
34
|
import org.quartz.JobDetail;
|
35
|
import org.quartz.JobDataMap;
|
36
|
import org.quartz.JobExecutionContext;
|
37
|
import org.quartz.JobExecutionException;
|
38
|
|
39
|
import org.kepler.executionWS.KeplerWebServiceLocator;
|
40
|
import org.kepler.executionWS.KeplerWebServicePortType;
|
41
|
|
42
|
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobAccess;
|
43
|
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobDAO;
|
44
|
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobParamDAO;
|
45
|
|
46
|
public class WorkflowJob implements InterruptableJob {
|
47
|
|
48
|
private static Logger logMetacat = Logger.getLogger(WorkflowJob.class);
|
49
|
|
50
|
/**
|
51
|
* Required method that is called when the job is run by the scheduler.
|
52
|
*
|
53
|
* @param executionContext
|
54
|
* the context information for this job
|
55
|
*/
|
56
|
public void execute(JobExecutionContext executionContext) throws JobExecutionException {
|
57
|
try {
|
58
|
// have to be able to get the job detail
|
59
|
JobDetail jobDetail = executionContext.getJobDetail();
|
60
|
if (jobDetail == null) {
|
61
|
throw new JobExecutionException("WorkflowJob.execute - Could not get job detail from execution context");
|
62
|
}
|
63
|
|
64
|
// have to be able to get the job data map from the job detail
|
65
|
JobDataMap jobDataMap = jobDetail.getJobDataMap();
|
66
|
if (jobDataMap == null) {
|
67
|
throw new JobExecutionException("WorkflowJob.execute - Could not get job data map from job detail");
|
68
|
}
|
69
|
|
70
|
String jobName = jobDetail.getName();
|
71
|
|
72
|
ScheduledJobAccess jobAccess = new ScheduledJobAccess();
|
73
|
ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
|
74
|
|
75
|
if(jobDAO == null) {
|
76
|
String errorMessage = "WorkflowJob.execute - Could not retrieve job info from "
|
77
|
+ "database for job: " + jobName;
|
78
|
logMetacat.error(errorMessage);
|
79
|
throw new JobExecutionException(errorMessage);
|
80
|
}
|
81
|
|
82
|
// the kar lsid must be part of the job data map
|
83
|
ScheduledJobParamDAO jobParamDAO = jobDAO.getAllJobParams().get("karid");
|
84
|
if (jobParamDAO == null) {
|
85
|
throw new JobExecutionException("WorkflowJob.execute - Could not get job param named karid from "
|
86
|
+ "job data map for job: " + jobName);
|
87
|
}
|
88
|
String karLSID = jobParamDAO.getValue();
|
89
|
if (karLSID == null) {
|
90
|
throw new JobExecutionException("WorkflowJob.execute - Could not get kar LSID for job: " + jobName);
|
91
|
}
|
92
|
|
93
|
// Locate service
|
94
|
logMetacat.debug("WorkflowJob.execute - Getting kepler webservice Locator");
|
95
|
KeplerWebServiceLocator serviceLocator = new KeplerWebServiceLocator();
|
96
|
|
97
|
// get endpoint service
|
98
|
logMetacat.debug("WorkflowJob.execute - Getting kepler webservice");
|
99
|
KeplerWebServicePortType serviceEndpoint = serviceLocator.getKeplerWebServiceHttpSoap11Endpoint();
|
100
|
|
101
|
// call execute against remote endpoint
|
102
|
logMetacat.debug("WorkflowJob.execute - Executing with kar lsid:" + karLSID);
|
103
|
String status = serviceEndpoint.execute(karLSID);
|
104
|
logMetacat.debug("WorkflowJob.execute - Status: " + status);
|
105
|
|
106
|
} catch (RemoteException re) {
|
107
|
String errorStr = "WorkflowJob.execute - Remote problem when trying to execute task: " + re.getMessage();
|
108
|
logMetacat.error(errorStr);
|
109
|
throw new JobExecutionException(errorStr);
|
110
|
} catch (ServiceException se) {
|
111
|
String errorStr = "WorkflowJob.execute - Service problem when trying to execute task: " + se.getMessage();
|
112
|
logMetacat.error(errorStr);
|
113
|
throw new JobExecutionException(errorStr);
|
114
|
} catch (Exception e) {
|
115
|
String errorStr = "WorkflowJob.execute - General problem when trying to execute task: " + e.getMessage();
|
116
|
logMetacat.error(errorStr);
|
117
|
throw new JobExecutionException(errorStr);
|
118
|
}
|
119
|
}
|
120
|
|
121
|
public void interrupt() {
|
122
|
}
|
123
|
}
|