|
23 | 23 | import org.labkey.api.action.ConfirmAction; |
24 | 24 | import org.labkey.api.action.SimpleRedirectAction; |
25 | 25 | import org.labkey.api.action.SpringActionController; |
| 26 | +import org.labkey.api.collections.CaseInsensitiveHashMap; |
26 | 27 | import org.labkey.api.data.DbSchema; |
27 | 28 | import org.labkey.api.data.DbSchemaType; |
28 | 29 | import org.labkey.api.data.Table; |
@@ -352,6 +353,104 @@ public boolean handlePost(JobIdsForm form, BindException errors) throws Exceptio |
352 | 353 | } |
353 | 354 | } |
354 | 355 |
|
| 356 | + @RequiresPermission(AdminPermission.class) |
| 357 | + public static class ReplaceJobStoreAction extends ConfirmAction<JobIdsForm> |
| 358 | + { |
| 359 | + @Override |
| 360 | + public void validateCommand(JobIdsForm form, Errors errors) |
| 361 | + { |
| 362 | + |
| 363 | + } |
| 364 | + |
| 365 | + @Override |
| 366 | + public URLHelper getSuccessURL(JobIdsForm form) |
| 367 | + { |
| 368 | + return PageFlowUtil.urlProvider(PipelineStatusUrls.class).urlBegin(getContainer()); |
| 369 | + } |
| 370 | + |
| 371 | + @Override |
| 372 | + public ModelAndView getConfirmView(JobIdsForm form, BindException errors) throws Exception |
| 373 | + { |
| 374 | + return new HtmlView(HtmlString.unsafe("This will read the serialized job JSON and replace the database JobStore it." + |
| 375 | + "To continue, enter a comma-delimited list of Job IDs and hit submit:<br><br>" + |
| 376 | + "<label>Enter Job ID(s): </label><input name=\"jobIds\" value=\"" + HtmlString.of(form.getJobIds()) + "\"><br>")); |
| 377 | + } |
| 378 | + |
| 379 | + @Override |
| 380 | + public boolean handlePost(JobIdsForm form, BindException errors) throws Exception |
| 381 | + { |
| 382 | + String jobIDs = StringUtils.trimToNull(form.getJobIds()); |
| 383 | + if (jobIDs == null) |
| 384 | + { |
| 385 | + errors.reject(ERROR_MSG, "No JobIds provided"); |
| 386 | + return false; |
| 387 | + } |
| 388 | + |
| 389 | + Set<String> jobs = new HashSet<>(Arrays.asList(jobIDs.split(","))); |
| 390 | + List<PipelineStatusFile> sfs = new ArrayList<>(); |
| 391 | + for (String id : jobs) |
| 392 | + { |
| 393 | + int jobId = Integer.parseInt(StringUtils.trimToNull(id)); |
| 394 | + PipelineStatusFile sf = PipelineService.get().getStatusFile(jobId); |
| 395 | + if (sf == null) |
| 396 | + { |
| 397 | + errors.reject(ERROR_MSG, "Unable to find job: " + id); |
| 398 | + return false; |
| 399 | + } |
| 400 | + |
| 401 | + if (PipelineJob.TaskStatus.running.name().equalsIgnoreCase(sf.getStatus())) |
| 402 | + { |
| 403 | + errors.reject(ERROR_MSG, "This cannot be used on actively running jobs. Status was: " + sf.getStatus()); |
| 404 | + return false; |
| 405 | + } |
| 406 | + |
| 407 | + sfs.add(sf); |
| 408 | + } |
| 409 | + |
| 410 | + TableInfo ti = DbSchema.get("pipeline", DbSchemaType.Module).getTable("StatusFiles"); |
| 411 | + for (PipelineStatusFile sf : sfs) |
| 412 | + { |
| 413 | + File log = new File(sf.getFilePath()); |
| 414 | + File json = AbstractClusterExecutionEngine.getSerializedJobFile(log); |
| 415 | + if (!json.exists()) |
| 416 | + { |
| 417 | + errors.reject(ERROR_MSG, "Unable to find pipeline JSON, expected: " + json.getPath()); |
| 418 | + return false; |
| 419 | + } |
| 420 | + |
| 421 | + PipelineJob job = null; |
| 422 | + try |
| 423 | + { |
| 424 | + job = PipelineJob.readFromFile(json); |
| 425 | + job.getLogger().info("Replacing DB JobStore from JSON: " + job.getJobGUID() + ": " + job.getActiveTaskStatus()); |
| 426 | + |
| 427 | + Map<String, Object> row = new CaseInsensitiveHashMap<>(); |
| 428 | + row.put("rowid", sf.getRowId()); |
| 429 | + row.put("jobStore", PipelineJob.serializeJob(job, false)); |
| 430 | + row.put("activeTaskId", job.getActiveTaskId().toString()); |
| 431 | + |
| 432 | + Table.update(getUser(), ti, row, sf.getRowId()); |
| 433 | + } |
| 434 | + catch (Exception e) |
| 435 | + { |
| 436 | + if (job != null) |
| 437 | + { |
| 438 | + job.getLogger().error("Unable to update JobStore", e); |
| 439 | + } |
| 440 | + else |
| 441 | + { |
| 442 | + _log.error("Unable to update JobStore", e); |
| 443 | + } |
| 444 | + |
| 445 | + errors.reject(ERROR_MSG, "Unable to update JobStore: " + e.getMessage()); |
| 446 | + return false; |
| 447 | + } |
| 448 | + } |
| 449 | + |
| 450 | + return true; |
| 451 | + } |
| 452 | + } |
| 453 | + |
355 | 454 | @RequiresPermission(ReadPermission.class) |
356 | 455 | public static class ViewJavaLogAction extends SimpleRedirectAction<ViewJavaLogForm> |
357 | 456 | { |
|
0 commit comments