|
20 | 20 | import org.labkey.api.exp.api.ExperimentService; |
21 | 21 | import org.labkey.api.module.ModuleContext; |
22 | 22 | import org.labkey.api.query.FieldKey; |
| 23 | +import org.labkey.api.security.User; |
23 | 24 | import org.labkey.api.sequenceanalysis.RefNtSequenceModel; |
| 25 | +import org.labkey.api.util.FileUtil; |
24 | 26 | import org.labkey.api.util.PageFlowUtil; |
25 | 27 |
|
26 | 28 | import java.io.File; |
@@ -234,68 +236,81 @@ public void updateBarcodeRC(final ModuleContext moduleContext) |
234 | 236 | @SuppressWarnings({"UnusedDeclaration"}) |
235 | 237 | @DeferredUpgrade |
236 | 238 | public void migrateSequenceDirs(final ModuleContext moduleContext) |
| 239 | + { |
| 240 | + doSequenceMigration(moduleContext.getUpgradeUser(), _log); |
| 241 | + } |
| 242 | + |
| 243 | + public static void doSequenceMigration(User u, Logger log) |
237 | 244 | { |
238 | 245 | try |
239 | 246 | { |
240 | 247 | TableInfo ti = SequenceAnalysisSchema.getTable(SequenceAnalysisSchema.TABLE_REF_NT_SEQUENCES); |
241 | 248 | TableSelector ts = new TableSelector(ti); |
242 | 249 | List<RefNtSequenceModel> nts = ts.getArrayList(RefNtSequenceModel.class); |
243 | | - _log.info(nts.size() + " total sequences to migrate"); |
| 250 | + log.info(nts.size() + " total sequences to migrate"); |
244 | 251 | int processed = 0; |
245 | 252 | int totalMigrated = 0; |
246 | 253 | for (RefNtSequenceModel nt : nts) |
247 | 254 | { |
248 | 255 | processed++; |
249 | | - |
250 | 256 | if (processed % 1000 == 0) |
251 | 257 | { |
252 | | - _log.info("{} of {} sequence files migrated", processed, nts.size()); |
| 258 | + log.info("{} of {} sequence files migrated", processed, nts.size()); |
253 | 259 | } |
254 | 260 |
|
255 | 261 | ExpData legacyExpData = ExperimentService.get().getExpData(nt.getSequenceFile()); |
256 | 262 | if (legacyExpData == null) |
257 | 263 | { |
258 | | - _log.error("Missing ExpData for NT sequence: {}", nt.getSequenceFile()); |
| 264 | + log.error("Missing ExpData for NT sequence: {}", nt.getSequenceFile()); |
259 | 265 | continue; |
260 | 266 | } |
261 | 267 |
|
262 | 268 | File legacyFile = legacyExpData.getFile(); |
263 | | - if (!legacyFile.exists()) |
| 269 | + if (!RefNtSequenceModel.BASE_DIRNAME.equals(legacyFile.getParentFile().getName())) |
264 | 270 | { |
265 | | - _log.error("Missing file for NT sequence: {}", legacyFile.getPath()); |
| 271 | + // NOTE: this includes sequences imported to custom locations, such as refSequenceImport pipeline jobs |
266 | 272 | continue; |
267 | 273 | } |
268 | 274 |
|
269 | | - if (!RefNtSequenceModel.BASE_DIRNAME.equals(legacyFile.getParentFile().getName())) |
| 275 | + File newLocation = nt.getExpectedSequenceFile(null); |
| 276 | + if (legacyFile.equals(newLocation)) |
270 | 277 | { |
271 | | - // NOTE: this includes sequences imported to custom locations, such as refSequenceImport pipeline jobs |
272 | 278 | continue; |
273 | 279 | } |
274 | 280 |
|
275 | | - File newLocation = nt.getExpectedSequenceFile(null); |
| 281 | + if (!legacyFile.exists()) |
| 282 | + { |
| 283 | + log.error("Missing file for NT sequence: {}", legacyFile.getPath()); |
| 284 | + continue; |
| 285 | + } |
| 286 | + |
276 | 287 | if (!newLocation.getParentFile().exists()) |
277 | 288 | { |
278 | | - newLocation.getParentFile().mkdirs(); |
| 289 | + FileUtil.mkdirs(newLocation.getParentFile()); |
279 | 290 | } |
280 | 291 |
|
281 | 292 | if (newLocation.exists()) |
282 | 293 | { |
283 | | - _log.error("Target location for migrated sequence file exists, this might indicate a retry after a filed move: {}", newLocation.getPath()); |
284 | | - continue; |
| 294 | + if (newLocation.length() == legacyFile.length()) |
| 295 | + { |
| 296 | + continue; |
| 297 | + } |
| 298 | + |
| 299 | + log.error("Target location for migrated sequence file exists, but file size is smaller. this might indicate a retry after a filed move. deleting the target and retrying: {}", newLocation.getPath()); |
| 300 | + FileUtils.delete(newLocation); |
285 | 301 | } |
286 | 302 |
|
287 | | - totalMigrated++; |
288 | | - FileUtils.copyFile(legacyFile, newLocation); |
| 303 | + FileUtils.moveFile(legacyFile, newLocation); |
289 | 304 | legacyExpData.setDataFileURI(newLocation.toURI()); |
290 | | - legacyExpData.save(moduleContext.getUpgradeUser()); |
291 | | - legacyFile.delete(); |
| 305 | + legacyExpData.save(u); |
| 306 | + totalMigrated++; |
292 | 307 | } |
293 | 308 |
|
294 | | - _log.info("Total sequences migrated: {}", totalMigrated); |
| 309 | + log.info("Total sequences migrated: {}", totalMigrated); |
295 | 310 | } |
296 | 311 | catch (Exception e) |
297 | 312 | { |
298 | | - _log.error("Error upgrading sequenceanalysis module", e); |
| 313 | + log.error("Error migrating sequence files", e); |
299 | 314 | } |
300 | 315 | } |
301 | 316 | } |
0 commit comments