1616
1717package org .labkey .cluster ;
1818
19+ import org .apache .commons .lang3 .StringUtils ;
1920import org .labkey .api .action .ConfirmAction ;
2021import org .labkey .api .action .SpringActionController ;
2122import org .labkey .api .pipeline .PipelineJob ;
3435import org .springframework .validation .Errors ;
3536import org .springframework .web .servlet .ModelAndView ;
3637
38+ import java .util .ArrayList ;
39+ import java .util .List ;
40+
3741public class ClusterController extends SpringActionController
3842{
3943 private static final DefaultActionResolver _actionResolver = new DefaultActionResolver (ClusterController .class );
@@ -92,44 +96,60 @@ public URLHelper getSuccessURL(ForcePipelineCancelForm form)
9296 public ModelAndView getConfirmView (ForcePipelineCancelForm form , BindException errors ) throws Exception
9397 {
9498 return new HtmlView ("This will change the status of the pipeline job with the provided ID to Cancelled. It is intended to help the situation when the normal UI leave a job in a perpetual 'Cancelling' state." +
95- "To continue, enter the Job ID and hit submit:<br><br>" +
96- "<label>Enter Job ID: </label><input name=\" jobId \" ><br>" );
99+ "To continue, enter a comma-delimited list of Job IDs and hit submit:<br><br>" +
100+ "<label>Enter Job ID: </label><input name=\" jobIds \" ><br>" );
97101 }
98102
99103 public boolean handlePost (ForcePipelineCancelForm form , BindException errors ) throws Exception
100104 {
101- PipelineStatusFile sf = PipelineService . get (). getStatusFile ( form .getJobId ());
102- if (sf == null )
105+ String jobIDs = StringUtils . trimToNull ( form .getJobIds ());
106+ if (jobIDs == null )
103107 {
104- errors .reject (ERROR_MSG , "Unable to find job: " + form . getJobId () );
108+ errors .reject (ERROR_MSG , "No JobIds provided" );
105109 return false ;
106110 }
107111
108- if (!PipelineJob .TaskStatus .cancelling .name ().equalsIgnoreCase (sf .getStatus ()))
112+ List <PipelineStatusFile > sfs = new ArrayList <>();
113+ for (String id : jobIDs .split ("," ))
109114 {
110- errors .reject (ERROR_MSG , "This should only be used on jobs with status cancelling. Was: " + sf .getStatus ());
111- return false ;
115+ int jobId = Integer .parseInt (StringUtils .trimToNull (id ));
116+ PipelineStatusFile sf = PipelineService .get ().getStatusFile (jobId );
117+ if (sf == null )
118+ {
119+ errors .reject (ERROR_MSG , "Unable to find job: " + id );
120+ return false ;
121+ }
122+
123+ if (!PipelineJob .TaskStatus .cancelling .name ().equalsIgnoreCase (sf .getStatus ()))
124+ {
125+ errors .reject (ERROR_MSG , "This should only be used on jobs with status cancelling. Was: " + sf .getStatus ());
126+ return false ;
127+ }
128+
129+ sfs .add (sf );
112130 }
113131
114- sf .setStatus (PipelineJob .TaskStatus .cancelled .name ().toUpperCase ());
115- sf .save ();
132+ sfs .forEach (sf -> {
133+ sf .setStatus (PipelineJob .TaskStatus .cancelled .name ().toUpperCase ());
134+ sf .save ();
135+ });
116136
117137 return true ;
118138 }
119139 }
120140
121141 public static class ForcePipelineCancelForm
122142 {
123- private int jobId ;
143+ private String jobIds ;
124144
125- public int getJobId ()
145+ public String getJobIds ()
126146 {
127- return jobId ;
147+ return jobIds ;
128148 }
129149
130- public void setJobId (int jobId )
150+ public void setJobId (String jobIds )
131151 {
132- this .jobId = jobId ;
152+ this .jobIds = jobIds ;
133153 }
134154 }
135155}
0 commit comments