Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inplace Import via SymlinkFileTransfer (See #11573) #1989

Merged
merged 19 commits into from Jan 23, 2014

Conversation

joshmoore
Copy link
Member

https://trac.openmicroscopy.org.uk/ome/ticket/11573

This PR implements the same logic as the InPlaceImporter.py script from gh-1929 but in Java. The only thing that is currently not possible is the remote invocation that a script provides. But considering there are security issues when using the script, this is the safer intermediate solution.

To test:
As with gh-1929, the goal is that it's possible to import all files that were previously importable, but the files of the fileset under /OMERO/ManagedRepository should be symlinks not the original files. You will need to shell into the machine running OMERO, and import via the CLI:

bin/omero login
bin/omero import --transfer=ln TESTFILEHERE
bin/omero import --transfer=ln_s TESTFILEHERE
bin/omero import --transfer=ln_rm TESTFILEHERE # Be careful with this!

The key lines to look for in the output:

2014-01-16 16:27:54,836 0          [      main] INFO          ome.formats.importer.ImportConfig  - OMERO Version: 5.0.0-rc1-DEV-ice35
...
## V The following
2014-01-16 16:27:58,414 3578       [      main] INFO   s.importer.transfers.SymlinkFileTransfer  - Transferring /opt/ome3/dist/a.fake...
...
2014-01-16 16:28:00,267 5431       [l.Client-0] INFO   ormats.importer.cli.LoggingImportMonitor  - IMPORT_DONE 

To do:

  • Fill out all Javadoc comments before code review.
  • Rebase onto latest dev_5_0 once RawFileStore.getFileId #1987 is merged. (No commit comments until then, please)

Once this is merged, the GUI importer can be updated to also symlink. /cc @jburel

@ximenesuk
Copy link
Contributor

I've tested this using symlink option as well as upload both implicitly and explicitly. Everything seems to work fine. Although you're not asking for commit comments yet it was noticeable that 1e75402 contained code changes beyond just javadoc improvements.

@joshmoore
Copy link
Member Author

Ack. You're right, @ximenesuk . My git rebase went haywire. I'll piece that back apart when I do the rebasing. Just merging get-fild-id now.

The uploadFile method has a number of responsibilities
that were not easily modifiable. Rather than insert
further `if (symlink) {} then {}` complications, its
been extracted behind the new `FileTransfer` interface
to permit others to inject their own logic.
The number of parameters passed to the `transfer` method
was daunting at best. Further, much of the uploadFile method
was doing logging so that moving the execution into the state
class, the FileTransfer implementors can be ignorant of most
of the arguments.
The rest of the reusable logic from uploadFile has now been
moved to AbstractFileTransfar and re-used by the new
SymlinkFileTransfer class.

Several remote-access methods were needed in the ImportLibrary
itself, though these could perhaps live in a more general
gateway-style utility.
The following options are now all available
for choosing which transfer method to use:

```
 bin/omero import -t upload
 bin/omero import --transfer upload

 bin/omero import -t symlink
 bin/omero import -- -t symlink

 bin/omero import -t your.class.name.Here
```
@joshmoore
Copy link
Member Author

Commit split and rebased onto dev_5_0

@ximenesuk
Copy link
Contributor

I've given this rebased PR a quick run through, importing in both transfer modes for both single and multi-file formats. I've not come across any problems, imports run okay, images are viewable, etc. Is there anything deeper needs doing?

@joshmoore
Copy link
Member Author

I don't think so, @ximenesuk. At this point, we probably need more differentiated testing (screens, etc) a la @pwalczysko and usability questions like "is it clear to users doing this that they have no data guarantees?" (/cc @gusferguson )

Considering this requires: 1) Shelling into the server and 2) manually adding the flag at the moment, I'd say it's fairly safe.

@jburel, thoughts?

@joshmoore joshmoore mentioned this pull request Jan 17, 2014
7 tasks
@ximenesuk
Copy link
Contributor

@joshmoore might it also be worth considering whether to add symlink as a documented option to DropBox imports?

Is there any plan to have a move option? This could be particularly useful for DropBox.

@joshmoore
Copy link
Member Author

The implementation would be quite straight-forward but less safe for the end user. Maybe we require: --transfer=yes-really-move-it. In the case of DropBox, completely ideal, though.

@joshmoore
Copy link
Member Author

My plan is to push a minimal refactoring to this branch to make it easy to implement RsyncFT, MoveFT, etc., but not necessarily try to implement each of them. If there's anything else that needs to go into this PR, let me know.

A simple `mv` command is not possible since 1) the file
must be present for subsequent readds and 2) it's not
safe to remove the file until the import has completed
successfully.

Now, users of the `FileTransfer` API have the responsibility
of calling `afterSuccess` once the `ImportLibrary` has done
its work. An exception may be thrown if cleanup is not
possible.
@joshmoore
Copy link
Member Author

Mentioned refactoring has been pushed. Note: the commands for each transfer have slightly changed:

  • --transfer ln -- hard-link
  • --transfer ln_s -- sym-link
  • --transfer ln_rm -- hard-link followed by a File.delete()

PR description updated.

@joshmoore
Copy link
Member Author

Also updated the CLI help:

$ bin/omero import --javahelp
...
Advanced arguments:
  --transfer=ARG    File transfer method
      Examples:
       -t upload           # Default
       -t ln               # Use hard-link. Locally only!
       -t ln_rm            # Caution! Hard-link followed by rm. Locally only!
       -t ln_s             # Use symlnk. Locally only!
       -t some.class.Name  # Use a class on the CLASSPATH

ex. importer-cli -s localhost -u bart -w simpson -d 50 foo.tiff

Report bugs to <ome-users@lists.openmicroscopy.org.uk>

@ximenesuk
Copy link
Contributor

Thanks @joshmoore I'll review this if there are no further changes expected imminently.

protected File getLocalLocation(OriginalFile root, OriginalFile ofile) {
StringBuilder sb = new StringBuilder();
sb.append(root.getPath().getValue());
sb.append("/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File.separatorChar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to use in the constructor: if (windows) { throw ... }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(-: Less to fix when we get this working for Windows. Might want to wait for Java 7, but this should be doable on NTFS?

@ximenesuk
Copy link
Contributor

Using ln_rm I noticed that only the target file was deleted, though only tested so far with simple dv+log sets.

mt1_R3D_D3D.dv       mt1_R3D_D3D_log.txt  
jrs-macbookpro-25031:ome cblackburn$ dist/bin/omero import -t ln_rm dv-link-rm/mt1_R3D_D3D.dv 
...
2014-01-22 11:07:00,516 2714       [      main] INFO   ormats.importer.cli.LoggingImportMonitor  - FILESET_UPLOAD_START
2014-01-22 11:07:00,528 2726       [      main] INFO   mats.importer.transfers.MoveFileTransfer  - Transferring /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D.dv...
2014-01-22 11:07:00,574 2772       [      main] INFO   ormats.importer.cli.LoggingImportMonitor  - FILE_UPLOAD_STARTED: /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D.dv
2014-01-22 11:07:00,779 2977       [      main] INFO   ormats.importer.cli.LoggingImportMonitor  - FILE_UPLOAD_COMPLETE: /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D.dv
2014-01-22 11:07:00,786 2984       [      main] INFO   mats.importer.transfers.MoveFileTransfer  - Transferring /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D_log.txt...
2014-01-22 11:07:00,821 3019       [      main] INFO   ormats.importer.cli.LoggingImportMonitor  - FILE_UPLOAD_STARTED: /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D_log.txt
2014-01-22 11:07:00,861 3059       [      main] INFO   ormats.importer.cli.LoggingImportMonitor  - FILE_UPLOAD_COMPLETE: /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D_log.txt
2014-01-22 11:07:00,938 3136       [      main] INFO   ormats.importer.cli.LoggingImportMonitor  - FILESET_UPLOAD_END
2014-01-22 11:07:01,408 3606       [l.Client-0] INFO   ormats.importer.cli.LoggingImportMonitor  - METADATA_IMPORTED Step: 1 of 5  Logfile: 357
2014-01-22 11:07:01,730 3928       [l.Client-1] INFO   ormats.importer.cli.LoggingImportMonitor  - PIXELDATA_PROCESSED Step: 2 of 5  Logfile: 357
2014-01-22 11:07:01,921 4119       [l.Client-0] INFO   ormats.importer.cli.LoggingImportMonitor  - THUMBNAILS_GENERATED Step: 3 of 5  Logfile: 357
2014-01-22 11:07:01,937 4135       [l.Client-1] INFO   ormats.importer.cli.LoggingImportMonitor  - METADATA_PROCESSED Step: 4 of 5  Logfile: 357
2014-01-22 11:07:01,950 4148       [l.Client-0] INFO   ormats.importer.cli.LoggingImportMonitor  - OBJECTS_RETURNED Step: 5 of 5  Logfile: 357
2014-01-22 11:07:02,085 4283       [l.Client-1] INFO   ormats.importer.cli.LoggingImportMonitor  - IMPORT_DONE Imported file: /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D.dv
Imported pixels:
86
Other imported objects:
Fileset:16
Image:87
2014-01-22 11:07:02,086 4284       [l.Client-1] INFO      ome.formats.importer.cli.ErrorHandler  - Number of errors: 0
2014-01-22 11:07:02,087 4285       [      main] INFO   mats.importer.transfers.MoveFileTransfer  - Deleting source file /Users/cblackburn/Work/repos/ome/dv-link-rm/mt1_R3D_D3D.dv...
jrs-macbookpro-25031:ome cblackburn$ ls dv-link-rm/mt*
dv-link-rm/mt1_R3D_D3D_log.txt

Importing an entire lei folder containing several sets of files the only files that are deleted are the .lei files. The .tif and other files are still there.

@ximenesuk
Copy link
Contributor

I ran through the various options with the dv files, all upload methods look to work okay, and confirmed the delete issue with lei files but I'll leave any wider review for now.

```
$ bin/omero import -- --transfer-help
...
Advanced arguments:
  --transfer=ARG    File transfer method
      Examples:
       -t upload           # Default
       -t ln               # Use hard-link. Locally only!
       -t ln_rm            # Caution! Hard-link followed by rm. Locally only!
       -t ln_s             # Use symlnk. Locally only!
       -t some.class.Name  # Use a class on the CLASSPATH

ex. importer-cli --tranasfer=ln_s foo.tiff

Report bugs to <ome-users@lists.openmicroscopy.org.uk>

```
@joshmoore
Copy link
Member Author

Fix for MIF and hiding of advanced usage pushed.

@ximenesuk
Copy link
Contributor

The delete now works okay. Is it now worth merging this (once the typo is fixed) even if we readdress what is exposed and how later?

With this change, an annotation is added to the `Fileset` object
on import describing which `FileTransfer` implementation was used.

Use of the default `UploadFileTransfer` is ignored; otherwise, the
FQN is stored as the content of the annotation. If we decided to
move to subclasses of `Fileset` these values should suffice.

Representative output after an import includes:

```
ome2=> \x
ome2=> select discriminator, id, ns, textValue from annotation order by id desc limit 2;
-[ RECORD 1 ]-+---------------------------------------------------
discriminator | /type/OriginalFile/
id            | 3102
ns            | openmicroscopy.org/omero/import/logFile
textvalue     |
-[ RECORD 2 ]-+---------------------------------------------------
discriminator | /basic/text/comment/
id            | 3101
ns            | openmicroscopy.org/omero/import/fileTransfer
textvalue     | ome.formats.importer.transfers.SymlinkFileTransfer
```
@joshmoore
Copy link
Member Author

Typo fixed and an annotation added for the file transfer typo.

@ximenesuk
Copy link
Contributor

This all looks good.

@joshmoore
Copy link
Member Author

Thanks for all the back and forth, @ximenesuk. Merging, though there may be some other small requests before 5.0.0.

joshmoore added a commit that referenced this pull request Jan 23, 2014
Inplace Import via SymlinkFileTransfer (See #11573)
@joshmoore joshmoore merged commit 867818e into ome:dev_5_0 Jan 23, 2014
@joshmoore
Copy link
Member Author

--rebased-to #2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants