Project

General

Profile

« Previous | Next » 

Revision 5013

Added by daigle over 15 years ago

Add the ability to delete a scheduled workflow (move status to deleted in database)

View differences:

lib/style/skins/sanparks/sanparks-scheduled-jobs.css
50 50
.content-subsection {
51 51
	vertical-align: middle;
52 52
	margin: 0px 0px 0px 195px;
53
	width: 800px;
53
	width: 820px;
54 54
}
55 55

  
56 56
.content-subsection-header {
......
174 174
 **********************************************************************/
175 175

  
176 176
.col {
177
	padding-left: 5px;
177
	padding-left: 0px;
178 178
}
179 179

  
180 180
.col1 {
181
	width: 210px;
181
	width: 200px;
182 182
	text-align: left;
183
	padding-left: 5px;
183 184
	font-weight: bold;
184 185
}
185 186

  
......
188 189
}
189 190

  
190 191
.col3 {
191
	width: 170px;
192
	width: 140px;
192 193
}
193 194

  
194 195
.col4 {
195
	width: 60px;
196
	width: 140px;
196 197
}
197 198

  
198 199
.col5 {
199
	width: 70px;
200
	width: 60px;
200 201
}
201 202

  
202 203
.col6 {
203
	width: 110px;
204
	width: 150px;
204 205
	border-right: none;
205 206
}
lib/style/common/scheduledWorkflowResultset.xsl
41 41
			<div class="col col1">Run Name</div>
42 42
			<div class="col col2">Status</div>
43 43
			<div class="col col3">Start Time</div>
44
			<div class="col col4">Interval</div>
45
			<div class="col col5">Run Count</div>
44
			<div class="col col4">End Time</div>
45
			<div class="col col5">Interval</div>
46 46
			<div class="col col6">Action</div>
47 47
		</div>	
48 48
		<!-- div>jobs: <xsl:number value="count(scheduledWorkflowResultset/scheduledJob)" />	</div -->	
......
68 68
						<xsl:value-of select='./startTime' />		
69 69
					</div>
70 70
					<div class="col col4">	
71
						<xsl:value-of select='./intervalValue' /><xsl:value-of select='./intervalUnit' /> 		
71
						<xsl:value-of select='./endTime' />		
72 72
					</div>
73 73
					<div class="col col5">	
74
						1 of 10
74
						<xsl:value-of select='./intervalValue' /><xsl:value-of select='./intervalUnit' /> 		
75 75
					</div>
76 76
					<div class="col col6">	
77 77
						<a>
78 78
							<xsl:choose>
79 79
							<xsl:when test="./status = 'scheduled'">
80 80
								<xsl:attribute name="class">underlined</xsl:attribute>
81
								<xsl:attribute name="href"><xsl:value-of select='$contextURL' />/metacat?action=unscheduleWorkflow&amp;workflowjobid=<xsl:value-of select='./name' />&amp;workflowname=<xsl:value-of select='./jobParam[@name=&apos;workflowname&apos;]/value' />&amp;qformat=<xsl:value-of select='$qformat' />&amp;forwardto=scheduleWorkflowRun.jsp</xsl:attribute>
81
								<xsl:attribute name="href"><xsl:value-of select='$contextURL' />/metacat?action=unscheduleWorkflow&amp;workflowjobid=<xsl:value-of select='./name' />&amp;qformat=<xsl:value-of select='$qformat' />&amp;forwardto=scheduleWorkflowRun.jsp</xsl:attribute>
82 82
								Unschedule
83 83
							</xsl:when>
84 84
							<xsl:otherwise>
85 85
								<xsl:attribute name="class">underlined</xsl:attribute>
86
								<xsl:attribute name="href"><xsl:value-of select='$contextURL' />/metacat?action=rescheduleWorkflow&amp;workflowjobid=<xsl:value-of select='./name' />&amp;workflowname=<xsl:value-of select='./jobParam[@name=&apos;workflowname&apos;]/value' />&amp;qformat=<xsl:value-of select='$qformat' />&amp;forwardto=scheduleWorkflowRun.jsp</xsl:attribute>
86
								<xsl:attribute name="href"><xsl:value-of select='$contextURL' />/metacat?action=rescheduleWorkflow&amp;workflowjobid=<xsl:value-of select='./name' />&amp;qformat=<xsl:value-of select='$qformat' />&amp;forwardto=scheduleWorkflowRun.jsp</xsl:attribute>
87 87
								Reschedule
88 88
							</xsl:otherwise>
89 89
							</xsl:choose>
90
						</a>					 
90
						</a>|						
91
						<xsl:choose>
92
						<xsl:when test="./status = 'unscheduled'">
93
							<a>
94
								<xsl:attribute name="class">underlined</xsl:attribute>
95
								<xsl:attribute name="href"><xsl:value-of select='$contextURL' />/metacat?action=deleteScheduledWorkflow&amp;workflowjobid=<xsl:value-of select='./name' />&amp;qformat=<xsl:value-of select='$qformat' />&amp;forwardto=scheduleWorkflowRun.jsp</xsl:attribute>
96
								Delete	
97
							</a>
98
						</xsl:when>
99
						<xsl:otherwise>
100
							Delete
101
						</xsl:otherwise>
102
						</xsl:choose>		
91 103
					</div>		
92 104
				</div>
93 105
			</xsl:for-each>
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
912 912
						ResponseUtil.sendErrorXML(response, ResponseUtil.GET_SCHEDULED_WORKFLOW_ERROR, be);
913 913
						return;						
914 914
					}
915
				} else if (action.equals("deleteScheduledWorkflow")) {
916
					try {
917
						WorkflowScheduler.getInstance().deleteJob(request, response, params, 
918
								userName, groupNames);				
919
						return;
920
					} catch (BaseException be) {
921
						ResponseUtil.sendErrorXML(response, ResponseUtil.DELETE_SCHEDULED_WORKFLOW_ERROR, be);
922
						return;						
923
					}
915 924
				} else {
916 925
					PrintWriter out = response.getWriter();
917 926
					out.println("<?xml version=\"1.0\"?>");
src/edu/ucsb/nceas/metacat/workflow/WorkflowScheduler.java
194 194
				}
195 195
				
196 196
				String destination = "/style/skins/" + qformat + "/" + forwardto
197
					+ "?workflowid=" + jobParams.get("workflowid") + "&karid=" 
198
					+ jobParams.get("karid");			
197
					+ "?workflowid=" + jobParams.get("workflowid") 
198
					+ "&karid=" + jobParams.get("karid");			
199 199
				RequestUtil.forwardRequest(request, response, destination);
200 200
			} else {
201 201
				ResponseUtil.sendSuccessXML(response, xmlResult);
......
264 264
				ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
265 265
				
266 266
				// we need to include the workflow id in the forward url
267
				String workflowId = null;
268
				ScheduledJobParamDAO jobParamDAO = jobDAO.getJobParam("workflowid");
269
				if (jobParamDAO != null) {
270
					workflowId = jobParamDAO.getValue();
267
				ScheduledJobParamDAO workflowIdJobParamDAO = jobDAO.getJobParam("workflowid");
268
				if (workflowIdJobParamDAO == null) {
269
					throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - could not find workflow " 
270
							+ "id when unscheduling job: " + jobName);
271 271
				}	
272 272
				
273 273
				// we need to include the workflow id in the forward url
274
				String karId = null;
275 274
				ScheduledJobParamDAO karJobParamDAO = jobDAO.getJobParam("karid");
276
				if (karJobParamDAO != null) {
277
					karId = karJobParamDAO.getValue();
275
				if (karJobParamDAO == null) {
276
					throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - could not find kar " 
277
							+ "id when unscheduling job: " + jobName);
278 278
				}
279 279
				
280
				// we need to include the workflow id in the url
281
				ScheduledJobParamDAO workflowNameJobParamDAO = jobDAO.getJobParam("workflowname");
282
				if (workflowNameJobParamDAO == null) {
283
					throw new MetacatSchedulerException("WorkflowScheduler.unScheduleJob - could not find workflow " 
284
							+ "name when unscheduling job: " + jobName);
285
				}
286
				
280 287
				String destination = "/style/skins/" + qformat + "/" + forwardto
281
					+ "?workflowid=" + workflowId + "&karid=" + karId;			
288
					+ "?workflowid=" + workflowIdJobParamDAO.getValue() 
289
					+ "&karid=" + karJobParamDAO.getValue()
290
					+ "&workflowname=" + workflowNameJobParamDAO.getValue();
291
				
282 292
				RequestUtil.forwardRequest(request, response, destination.toString());
283 293
			} else {
284 294
				ResponseUtil.sendSuccessXML(response, xmlResult);
......
344 354
					qformat = qformats[0];
345 355
				}
346 356
				
347
				// we need to include the workflow id in the forward url
348
				String workflowId = null;
349
				ScheduledJobParamDAO jobParamDAO = jobDAO.getAllJobParams().get("workflowid");
350
				if (jobParamDAO != null) {
351
					workflowId = jobParamDAO.getValue();
357
				// we need to include the workflow id in the url
358
				ScheduledJobParamDAO workflowIdJobParamDAO = jobDAO.getAllJobParams().get("workflowid");
359
				if (workflowIdJobParamDAO == null) {
360
					throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - could not find workflow " 
361
							+ "id when deleting job: " + jobName);
362
					
352 363
				}
353 364
				
354
				// we need to include the workflow id in the forward url
355
				String karId = null;
365
				// we need to include the workflow id in the url
356 366
				ScheduledJobParamDAO karJobParamDAO = jobDAO.getJobParam("karid");
357
				if (karJobParamDAO != null) {
358
					karId = karJobParamDAO.getValue();
367
				if (karJobParamDAO == null) {
368
					throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - could not find kar " 
369
							+ "id when deleting job: " + jobName);
359 370
				}
360 371
				
372
				// we need to include the workflow id in the url
373
				ScheduledJobParamDAO workflowNameJobParamDAO = jobDAO.getJobParam("workflowname");
374
				if (workflowNameJobParamDAO == null) {
375
					throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - could not find workflow " 
376
							+ "name when deleting job: " + jobName);
377
				}
378
				
361 379
				String destination = "/style/skins/" + qformat + "/" + forwardto
362
					+ "?workflowid=" + workflowId + "&karid=" + karId;			
363
				RequestUtil.forwardRequest(request, response, destination.toString());
380
					+ "?workflowid=" + workflowIdJobParamDAO.getValue()	
381
					+ "&karid=" + karJobParamDAO.getValue()
382
					+ "&workflowname=" + workflowNameJobParamDAO.getValue();
383
				
384
				RequestUtil.forwardRequest(request, response, destination);
364 385
			} else {
365 386
				ResponseUtil.sendSuccessXML(response, result);
366 387
			}
......
383 404
	 */
384 405
	public void deleteJob(HttpServletRequest request, HttpServletResponse response, 
385 406
			Hashtable<String, String[]> params, String username, String[] groups) throws MetacatSchedulerException {
407
		 try {
408
		// workflow job id must exist
409
		String jobNames[] = params.get("workflowjobid");	
410
		if (jobNames == null || jobNames.length == 0) {
411
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - workflowjobid field must be populated "
412
					+ "in scheduler parameters when deleting job.");
413
		}			
414
		String jobName = jobNames[0];
415

  
416
		ScheduledJobAccess jobAccess = new ScheduledJobAccess();
417
		ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
386 418
		
419
		// delete the job
420
		SchedulerService schedulerService = SchedulerService.getInstance();
421
		String result = schedulerService.deleteJob(jobDAO, username, groups);
422
		
423
		// if there is a forwardto param on the request, then send the user to the page
424
		// referenced in that param, otherwise, just send the xml back.
425
		String forwardtos[] = params.get("forwardto");
426
		String forwardto = null;
427
		if (forwardtos != null && forwardtos.length > 0) {
428
			forwardto = forwardtos[0];
429
		}
430
		
431
		if (forwardto != null) {
432
			String qformats[] = params.get("qformat");
433
			String qformat = null;
434
			if (qformats != null && qformats.length > 0) {
435
				qformat = qformats[0];
436
			}
437
			
438
			// we need to include the workflow id in the url
439
			ScheduledJobParamDAO workflowIdJobParamDAO = jobDAO.getAllJobParams().get("workflowid");
440
			if (workflowIdJobParamDAO == null) {
441
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - could not find workflow " 
442
						+ "id when deleting job: " + jobName);
443
				
444
			}
445
			
446
			// we need to include the workflow id in the url
447
			ScheduledJobParamDAO karJobParamDAO = jobDAO.getJobParam("karid");
448
			if (karJobParamDAO == null) {
449
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - could not find kar " 
450
						+ "id when deleting job: " + jobName);
451
			}
452
			
453
			// we need to include the workflow id in the url
454
			ScheduledJobParamDAO workflowNameJobParamDAO = jobDAO.getJobParam("workflowname");
455
			if (workflowNameJobParamDAO == null) {
456
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - could not find workflow " 
457
						+ "name when deleting job: " + jobName);
458
			}
459
			
460
			String destination = "/style/skins/" + qformat + "/" + forwardto
461
				+ "?workflowid=" + workflowIdJobParamDAO.getValue()	
462
				+ "&karid=" + karJobParamDAO.getValue()
463
				+ "&workflowname=" + workflowNameJobParamDAO.getValue();
464
			
465
			RequestUtil.forwardRequest(request, response, destination);
466
		} else {
467
			ResponseUtil.sendSuccessXML(response, result);
468
		}
469
		
470
		} catch (AccessException ae) {
471
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - DB access issue when deleting job  : ", ae);
472
		} catch (ServiceException se) {
473
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - Service issue deleting job", se);
474
		} catch (IOException ioe) {
475
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - I/O issue deleting job: " + ioe.getMessage());
476
		} catch (ServletException se) {
477
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - Servlet issue deleting job: " + se.getMessage());
478
		} catch (ErrorSendingErrorException esee) {
479
			throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - Issue sending erro when deleting job: " + esee.getMessage());			
480
		}
387 481
	}
388 482
	
389 483
	/**
src/edu/ucsb/nceas/metacat/util/ResponseUtil.java
59 59
	public static Long UNSCHEDULE_WORKFLOW_ERROR = new Long(130002);
60 60
	public static Long RESCHEDULE_WORKFLOW_ERROR = new Long(130003);
61 61
	public static Long GET_SCHEDULED_WORKFLOW_ERROR = new Long(130004);
62
	public static Long DELETE_SCHEDULED_WORKFLOW_ERROR = new Long(130005);
62 63
	
63 64
	
64 65
	// errorCodes is a lookup table for generic messages for each code.  It
......
74 75
		errorCodes.put(UNSCHEDULE_WORKFLOW_ERROR, "Unschedule workflow error");
75 76
		errorCodes.put(RESCHEDULE_WORKFLOW_ERROR, "Reschedule workflow error");
76 77
		errorCodes.put(GET_SCHEDULED_WORKFLOW_ERROR, "Get scheduled workflow error");
78
		errorCodes.put(DELETE_SCHEDULED_WORKFLOW_ERROR, "Delete scheduled workflow error");
77 79
	}
78 80
	
79 81
	private static Logger logMetacat = Logger.getLogger(ResponseUtil.class);
src/edu/ucsb/nceas/metacat/scheduler/SchedulerService.java
198 198
        try {
199 199
			jobClass = (Class<Job>) Class.forName(jobClassName);
200 200

  
201
			String startTimeStr = DateUtil.getHumanReadable(startCal, true);
201
			String startTimeStr = DateUtil.getHumanReadable(startCal);
202 202
			logMetacat.info("SchedulerService.scheduleJob - Scheduling job -- name: "
203 203
					+ jobName + ", class: " + jobClassName + ", start time: "
204 204
					+ startTimeStr + ", interval value: " + intervalValue
......
248 248
	 */
249 249
	public String unScheduleJob(String jobName, String username,
250 250
			String[] groups) throws ServiceException {
251
		
252
		ScheduledJobDAO jobDAO = null;
251 253
		try {
252 254
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
253
			ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
255
			jobDAO = jobAccess.getJobByName(jobName);
254 256
			if (jobDAO == null) {
255 257
				throw new ServiceException("SchedulerService.unscheduleJob - Could " 
256 258
						+ "not find job with name: " + jobName);
......
267 269
							+ "scheduled job because of service issue: " + se.getMessage());
268 270
		} catch (AccessException ae) {
269 271
			throw new ServiceException("SchedulerService.unscheduleJob - Could not create "
270
							+ "scheduled job because of db access issue: ", ae);
272
							+ "scheduled job : " + jobDAO.getName() + " because of db access issue: ", ae);
271 273
		}
272 274
		
273 275
		return "Unscheduled: " + jobName;
......
339 341
	        			+ jobDAO.getClassName() + " : " + cnfe.getMessage());
340 342
	        } 
341 343
	        
342
	        String startTimeStr = DateUtil.getHumanReadable(startCal, true);
344
	        String startTimeStr = DateUtil.getHumanReadable(startCal);
343 345
	        logMetacat.info("SchedulerService.rescheduleJob - name: " + jobDAO.getName() + ", class: " + jobClassName 
344 346
	        		+ ", start time: " + startTimeStr + ", interval value: " + jobDAO.getIntervalValue() 
345 347
	        		+ ", interval unit: " + jobDAO.getIntervalUnit());  
......
353 355
			
354 356
		} catch (AccessException ae) {
355 357
			throw new ServiceException("SchedulerService.reScheduleJob - Could not reschedule "
356
					+ "job because of db access issue: ", ae);
358
					+ "job : " + jobDAO.getName() + " because of db access issue: ", ae);
357 359
		} catch (UtilException ue) {
358 360
			throw new ServiceException("SchedulerService.reScheduleJob - Could not reschedule "
359
					+ "job due to a utility issue: " + ue.getMessage());
361
					+ "job : " + jobDAO.getName() + " due to a utility issue: " + ue.getMessage());
360 362
		}
361 363
        		
362 364
		return "Resheduled: " + jobDAO.getName();
363 365
	}
366

  
367
	/**
368
	 * Remove the job from the scheduler and set the job status to deleted in the database
369
	 * @param jobName
370
	 *            the string holding the name of the job to delete
371
	 * @param username
372
	 *            the user name
373
	 * @param groups
374
	 *            the user's group name
375
	 * @return a message saying that the job was deleted
376
	 */
377
	public String deleteJob(String jobName, String username,
378
			String[] groups) throws ServiceException {
379
		
380
		ScheduledJobDAO jobDAO = null;
381
		try {	
382
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
383
			jobDAO = jobAccess.getJobByName(jobName);
384
		} catch (AccessException ae) {
385
			throw new ServiceException("SchedulerService.deleteJob - Could not delete "
386
					+ "scheduled job : " + jobDAO.getName() + " because of db access issue: ", ae);
387
		}
388
		
389
		return deleteJob(jobDAO, username, groups);
390
	}
364 391
	
365 392
	/**
366 393
	 * Remove the job from the scheduler and set the job status to deleted in the database
367 394
	 * @param jobDAO
368
	 *            the job data object holding the information about the job to
369
	 *            delete
395
	 *            the job data object holding the information about the job to delete
370 396
	 * @param username
371 397
	 *            the user name
372 398
	 * @param groups
373 399
	 *            the user's group name
374 400
	 * @return a message saying that the job was deleted
375 401
	 */
376
	public String deleteJob(String jobName, String username,
402
	public String deleteJob(ScheduledJobDAO jobDAO, String username,
377 403
			String[] groups) throws ServiceException {
378 404

  
379 405
		String groupName = "";
380 406
		try {
381
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
382
			ScheduledJobDAO jobDAO = jobAccess.getJobByName(jobName);
383
			groupName = jobDAO.getGroupName();
384 407

  
385
			sched.deleteJob(jobName, groupName);
408
			sched.deleteJob(jobDAO.getName(), groupName);
386 409
			
387 410
			jobDAO.setStatus(StatusUtil.DELETED);
411
			ScheduledJobAccess jobAccess = new ScheduledJobAccess();
388 412
			jobAccess.updateJobStatus(jobDAO);
389 413
		} catch (SchedulerException se) {
390
			throw new ServiceException("SchedulerService.deleteJob - Could not delete job: " + jobName
414
			throw new ServiceException("SchedulerService.deleteJob - Could not delete job: " + jobDAO.getName()
391 415
							+ " for group: " + groupName + " : " + se.getMessage());
392 416
		} catch (AccessException ae) {
393 417
			throw new ServiceException("SchedulerService.deleteJob - Could not delete "
394
					+ "scheduled job because of db access issue: ", ae);
418
					+ "scheduled job: " + jobDAO.getName() + " because of db access issue: ", ae);
395 419
		}
396 420
		
397
		return "Deleted: " + jobName;
421
		return "Deleted: " + jobDAO.getName();
398 422
	}
399 423
	
400 424
	/**
......
484 508
			String startTimeString = null;
485 509
			try {
486 510
				startTimeString = 
487
					DateUtil.getHumanReadable(scheduledJobDAO.getStartTime(), true);
511
					DateUtil.getHumanReadable(scheduledJobDAO.getStartTime());
488 512
			} catch (UtilException ue) {
489 513
				throw new ServiceException("SchedulerService.jobToXML - error getting human readable date for job: " 
490 514
						+ scheduledJobDAO.getId() + " ; " + ue.getMessage());
491 515
			}
492
			jobXML += "<startTime>" + startTimeString
493
					+ "</startTime>";
494
			jobXML += "<intervalValue>" + scheduledJobDAO.getIntervalValue()
495
					+ "</intervalValue>";
496
			jobXML += "<intervalUnit>" + scheduledJobDAO.getIntervalUnit()
497
					+ "</intervalUnit>";
516
			jobXML += "<startTime>" + startTimeString + "</startTime>";
517
			
518
			String endTimeString = null;
519
			try {
520
				if (scheduledJobDAO.getEndTime() != null) {
521
					endTimeString = DateUtil.getHumanReadable(scheduledJobDAO.getEndTime());
522
				}
523
			} catch (UtilException ue) {
524
				throw new ServiceException("SchedulerService.jobToXML - error getting human readable date for job: " 
525
						+ scheduledJobDAO.getId() + " ; " + ue.getMessage());
526
			}
527
			jobXML += "<endTime>" + endTimeString + "</endTime>";
528
			jobXML += "<intervalValue>" + scheduledJobDAO.getIntervalValue() + "</intervalValue>";
529
			jobXML += "<intervalUnit>" + scheduledJobDAO.getIntervalUnit() + "</intervalUnit>";
498 530

  
499 531
			HashMap<String, ScheduledJobParamDAO> jobParams = scheduledJobDAO
500 532
					.getAllJobParams();

Also available in: Unified diff