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.metacat.workflow;
|
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
|
public class WorkflowJob implements InterruptableJob {
|
43
|
|
44
|
private static Logger logMetacat = Logger.getLogger(WorkflowJob.class);
|
45
|
|
46
|
/**
|
47
|
* Required method that is called when the job is run by the scheduler.
|
48
|
*
|
49
|
* @param executionContext
|
50
|
* the context information for this job
|
51
|
*/
|
52
|
public void execute(JobExecutionContext executionContext) throws JobExecutionException {
|
53
|
try {
|
54
|
// have to be able to get the job detail
|
55
|
JobDetail jobDetail = executionContext.getJobDetail();
|
56
|
if (jobDetail == null) {
|
57
|
throw new JobExecutionException("WorkflowJob.execute - Could not get job detail from execution context");
|
58
|
}
|
59
|
|
60
|
// have to be able to get the job data map from the job detail
|
61
|
JobDataMap jobDataMap = jobDetail.getJobDataMap();
|
62
|
if (jobDataMap == null) {
|
63
|
throw new JobExecutionException("WorkflowJob.execute - Could not get job data map from job detail");
|
64
|
}
|
65
|
|
66
|
// the kar lsid must be part of the job data map
|
67
|
String karLSID = jobDataMap.getString("karid");
|
68
|
if (karLSID == null) {
|
69
|
throw new JobExecutionException("WorkflowJob.execute - Could not get kar LSID from job data map");
|
70
|
}
|
71
|
|
72
|
// Locate service
|
73
|
logMetacat.debug("WorkflowJob.execute - Getting serviceLocator");
|
74
|
KeplerWebServiceLocator serviceLocator = new KeplerWebServiceLocator();
|
75
|
|
76
|
// get endpoint service
|
77
|
logMetacat.debug("WorkflowJob.execute - Getting service");
|
78
|
KeplerWebServicePortType serviceEndpoint = serviceLocator.getKeplerWebServiceHttpSoap11Endpoint();
|
79
|
|
80
|
// call execute against remote endpoint
|
81
|
logMetacat.debug("WorkflowJob.execute - Executing with kar lsid:" + karLSID);
|
82
|
String status = serviceEndpoint.execute(karLSID);
|
83
|
//String status = serviceEndpoint.getStatus(karLSID);
|
84
|
logMetacat.debug("WorkflowJob.execute - Status: " + status);
|
85
|
|
86
|
} catch (RemoteException re) {
|
87
|
String errorStr = "WorkflowJob.execute - Remote problem when trying to execute task: " + re.getMessage();
|
88
|
logMetacat.error(errorStr);
|
89
|
throw new JobExecutionException(errorStr);
|
90
|
} catch (ServiceException se) {
|
91
|
String errorStr = "WorkflowJob.execute - Service problem when trying to execute task: " + se.getMessage();
|
92
|
logMetacat.error(errorStr);
|
93
|
throw new JobExecutionException(errorStr);
|
94
|
} catch (Exception e) {
|
95
|
String errorStr = "WorkflowJob.execute - General problem when trying to execute task: " + e.getMessage();
|
96
|
logMetacat.error(errorStr);
|
97
|
throw new JobExecutionException(errorStr);
|
98
|
}
|
99
|
}
|
100
|
|
101
|
public void interrupt() {
|
102
|
}
|
103
|
}
|