Skip to content

Commit 947337a

Browse files
committed
Add action to replace PipelineJob JobStore using serialized JSON
1 parent 2a69db9 commit 947337a

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

cluster/src/org/labkey/cluster/ClusterController.java

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.labkey.api.action.ConfirmAction;
2424
import org.labkey.api.action.SimpleRedirectAction;
2525
import org.labkey.api.action.SpringActionController;
26+
import org.labkey.api.collections.CaseInsensitiveHashMap;
2627
import org.labkey.api.data.DbSchema;
2728
import org.labkey.api.data.DbSchemaType;
2829
import org.labkey.api.data.Table;
@@ -352,6 +353,104 @@ public boolean handlePost(JobIdsForm form, BindException errors) throws Exceptio
352353
}
353354
}
354355

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+
355454
@RequiresPermission(ReadPermission.class)
356455
public static class ViewJavaLogAction extends SimpleRedirectAction<ViewJavaLogForm>
357456
{

0 commit comments

Comments
 (0)