|
21 | 21 | import org.apache.logging.log4j.Logger; |
22 | 22 | import org.labkey.api.action.ConfirmAction; |
23 | 23 | import org.labkey.api.action.SpringActionController; |
| 24 | +import org.labkey.api.data.DbSchema; |
| 25 | +import org.labkey.api.data.DbSchemaType; |
| 26 | +import org.labkey.api.data.Table; |
| 27 | +import org.labkey.api.data.TableInfo; |
24 | 28 | import org.labkey.api.pipeline.PipelineJob; |
25 | 29 | import org.labkey.api.pipeline.PipelineJobException; |
26 | 30 | import org.labkey.api.pipeline.PipelineJobService; |
|
43 | 47 | import java.io.File; |
44 | 48 | import java.io.IOException; |
45 | 49 | import java.util.ArrayList; |
| 50 | +import java.util.HashMap; |
46 | 51 | import java.util.List; |
| 52 | +import java.util.Map; |
47 | 53 |
|
48 | 54 | public class ClusterController extends SpringActionController |
49 | 55 | { |
@@ -162,6 +168,95 @@ public void setJobIds(String jobIds) |
162 | 168 | } |
163 | 169 | } |
164 | 170 |
|
| 171 | + |
| 172 | + public static class ResetPipelineJobLogFileForm |
| 173 | + { |
| 174 | + private int _jobId; |
| 175 | + private String _filePath; |
| 176 | + |
| 177 | + public int getJobId() |
| 178 | + { |
| 179 | + return _jobId; |
| 180 | + } |
| 181 | + |
| 182 | + public void setJobId(int jobId) |
| 183 | + { |
| 184 | + _jobId = jobId; |
| 185 | + } |
| 186 | + |
| 187 | + public String getFilePath() |
| 188 | + { |
| 189 | + return _filePath; |
| 190 | + } |
| 191 | + |
| 192 | + public void setFilePath(String filePath) |
| 193 | + { |
| 194 | + _filePath = filePath; |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + @RequiresSiteAdmin |
| 199 | + public class ResetPipelineJobLogFileAction extends ConfirmAction<ResetPipelineJobLogFileForm> |
| 200 | + { |
| 201 | + public void validateCommand(ResetPipelineJobLogFileForm form, Errors errors) |
| 202 | + { |
| 203 | + |
| 204 | + } |
| 205 | + |
| 206 | + public URLHelper getSuccessURL(ResetPipelineJobLogFileForm form) |
| 207 | + { |
| 208 | + return PageFlowUtil.urlProvider(PipelineStatusUrls.class).urlBegin(getContainer()); |
| 209 | + } |
| 210 | + |
| 211 | + public ModelAndView getConfirmView(ResetPipelineJobLogFileForm form, BindException errors) throws Exception |
| 212 | + { |
| 213 | + return new HtmlView(HtmlString.unsafe("This will change the PipelineJob log file path for the selected job to the path below." + |
| 214 | + "<br><br>" + |
| 215 | + "<label>Enter Job ID(s): </label><input name=\"jobId\"><br>" + |
| 216 | + "<label>New Filepath: </label><input name=\"filePath\"><br>")); |
| 217 | + } |
| 218 | + |
| 219 | + @Override |
| 220 | + public boolean handlePost(ResetPipelineJobLogFileForm form, BindException errors) throws Exception |
| 221 | + { |
| 222 | + if (form.getJobId() == 0) |
| 223 | + { |
| 224 | + errors.reject(ERROR_MSG, "No JobId provided"); |
| 225 | + return false; |
| 226 | + } |
| 227 | + |
| 228 | + PipelineStatusFile sf = PipelineService.get().getStatusFile(form.getJobId()); |
| 229 | + if (sf == null) |
| 230 | + { |
| 231 | + errors.reject(ERROR_MSG, "Unable to find job: " + form.getJobId()); |
| 232 | + return false; |
| 233 | + } |
| 234 | + |
| 235 | + String path = StringUtils.trimToNull(form.getFilePath()); |
| 236 | + if (path == null) |
| 237 | + { |
| 238 | + errors.reject(ERROR_MSG, "Missing filepath: " + form.getFilePath()); |
| 239 | + return false; |
| 240 | + } |
| 241 | + |
| 242 | + File logFile = new File(path); |
| 243 | + if (!logFile.exists()) |
| 244 | + { |
| 245 | + errors.reject(ERROR_MSG, "File doesnt exist: " + form.getFilePath()); |
| 246 | + return false; |
| 247 | + } |
| 248 | + |
| 249 | + Map<String, Object> toUpdate = new HashMap<>(); |
| 250 | + toUpdate.put("RowId", form.getJobId()); |
| 251 | + toUpdate.put("FilePath", path); |
| 252 | + |
| 253 | + TableInfo ti = DbSchema.get("pipeline", DbSchemaType.Module).getTable("StatusFiles"); |
| 254 | + Table.update(getUser(), ti, toUpdate, form.getJobId()); |
| 255 | + |
| 256 | + return false; |
| 257 | + } |
| 258 | + } |
| 259 | + |
165 | 260 | @RequiresSiteAdmin |
166 | 261 | public class RecoverCompletedJobsAction extends ConfirmAction<JobIdsForm> |
167 | 262 | { |
@@ -212,7 +307,6 @@ public boolean handlePost(JobIdsForm form, BindException errors) throws Exceptio |
212 | 307 | } |
213 | 308 |
|
214 | 309 | sfs.forEach(sf -> { |
215 | | - |
216 | 310 | File log = new File(sf.getFilePath()); |
217 | 311 | File json = AbstractClusterExecutionEngine.getSerializedJobFile(log); |
218 | 312 | if (!json.exists()) |
|
0 commit comments