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

fs rename command for modifying template values #2743

Merged
merged 34 commits into from Jul 15, 2014

Conversation

joshmoore
Copy link
Member

When the FS template is changed (for example to make use of the new features in #2701), sysadmins may want to rearrange their old data to match the new template. The bin/omero fs rename Fileset:ID command now does that.

Testing as a regular user:

  • bin/omero import something
  • bin/omero fs sets # should list the latest fileset
  • bin/omero fs rename FILESET_ID # should rename it
  • you will be asked to move the files (e.g. as inplace_user) outside of OMERO.

Testing as admin:

  • as above, but the bin/omero fs rename step should use the user's name and not root's.
  • If --move is passed, then the files should be moved "server-side" with no user interaction.

In order for an admin user to be able to move files server-side,
RawAccessRequest needed to add a `mv` operation. In addition,
CheckedPath objects need to expose renameTo and moveToDir
methods.
In order to produce a lambda which takes just an ID,
a default can now be passed to proxy_to_instance which
will then be used if the proxy string does not contain
the "Class:" prefix as otherwise required.
Now `rename Fileset:ID` will rename the OriginalFile.path
fields of a Fileset to match the current template. This
is restricted to the owner of the Fileset for the moment.
 * print out all paths to be moved
 * save fileset change in the same transaction
In order to write the integration tests, we need
to have context objects passed everywhere. This
will also be of use when an admin wants to rename
a fileset for a user.
@ximenesuk
Copy link
Contributor

A few comments from a brief run through:

  • Everything works as expected for both a user and an admin.
  • If I don't do the mv following the rename then bin/omero fs sets --check fails expectedly but isn't very useful.
  • I can rename the same id multiple times in a row without moving after each rename.
  • I noticed that the logfile stays put using the original name. I assume this is expected but it does break the expected naming scheme.

A couple of these are clearly idiot-cases but are perhaps easily possible if using shell history laxly. Is there any way to recover other than trawling through history to work out what happened?

@ximenesuk
Copy link
Contributor

Incidentally, also tested with a change to config:

jrs-macbookpro-25031:ome cblackburn$ dist/bin/omero config set omero.fs.repo.path "%user%_%userId%//%year%-%month%-%day%/%time%"
...
jrs-macbookpro-25031:ome cblackburn$ dist/bin/omero fs rename 53 --move
...
Renaming Fileset:53 to user-0_2/2014-07-09/15-39-22.023/
Moving user-0_2/2014-07/09/15-37-09.186/Cats.png to user-0_2/2014-07-09/15-39-22.023/

where the dislocation of the logfile is more immediately apparent

@joshmoore
Copy link
Member Author

NB: I'll add in a move of the log file as well, but I do start to fear what's going to happen when we allow adding random data into these directories!

@joshmoore
Copy link
Member Author

If I don't do the mv following the rename then bin/omero fs sets --check fails expectedly but isn't very useful.

What would you expect to happen?

I can rename the same id multiple times in a row without moving after each rename.

Ditto.

@ximenesuk
Copy link
Contributor

  1. I think in the case of --check getting some results back. I.e. I get an exception rather than a table telling me I have a screwed up fileset.
  2. I don't know. I just wondered if I could move what is effectively and empty fileset.

@ximenesuk
Copy link
Contributor

What is the rationale for a non-admin user to use this command? What is the rationale for not enforcing the move by default?

@joshmoore
Copy link
Member Author

What is the rationale for a non-admin user to use this command? What is the rationale for not enforcing the move by default?

For a user with in-place access, it could be useful; for anyone else, it's mostly dangerous. Having it admin-only would certainly be an option.

The reason for not doing the move by default was mostly not really trusting the code. Error conditions like "move fails in the middle" aren't handled (nor are they easily testable!), whereas a sysadmin would know how to handle move errors on the command-line. Happy to swap the defaults; just trying to be careful at the last minute. /cc @kennethgillen

`fs rename` followed by `fs sets --check` (without
a move inbetween) was leading to a `CmdError` being
printed before this change.
@kennethgillen
Copy link
Member

👍 for @joshmoore's admin-only restriction and safer default.

@joshmoore
Copy link
Member Author

@ximenesuk : urgh. Looking at the log files makes this all quite unseemly. Perhaps a chat tomorrow?

@ximenesuk
Copy link
Contributor

@joshmoore Yes, for a chat.

In preparation for also specifying a tomove for the
log file, we need to specify where the file should
be moved *to*, since the log file is a directory up
from the actual fileset.
@joshmoore
Copy link
Member Author

Log file move pushed. Looking at one example:

.../ManagedRepository/tmpl_9734/2014-07/10$ find 09-26-58*
09-26-58.656
.../ManagedRepository/tmpl_9734/2014-07/10$ find 09-28-26.796*
09-28-26.796
09-28-26.796/mods.fake
09-28-26.796.log

@ximenesuk
Copy link
Contributor

Looks good. Moves logfiles or asks for them to be moved. Fileset check works okay:

jrs-macbookpro-25031:ome cblackburn$ dist/bin/omero fs sets --check --offset 30 --limit 12
Using session 502dd3d0-c9b1-48b2-a3b4-54d1dd179597 (root@localhost:4064). Idle timeout: 10.0 min. Current group: system
 #  | Id  | Prefix                                                           | Images | Files | Transfer | Check  
----+-----+------------------------------------------------------------------+--------+-------+----------+--------
 0  | 116 | user-0_2/2014-07-09/16-09-24.615/                                | 1      | 3     |          | OK     
 1  | 115 | user-0_2/2014-07-09/16-09-22.739/                                | 1      | 4     |          | OK     
 2  | 114 | user-0_2/2014-07-09/16-07-41.539/                                | 4      | 203   |          | OK     
 3  | 113 | user-0_2/2014-07/10/10-51-47.014/                                | 73     | 175   |          | ERROR! 
 4  | 112 | user-0_2/2014-07/10/10-51-33.353/                                | 56     | 141   |          | OK     
 5  | 110 | root_0/2014-07-09/16-00-46.289/                                  | 1      | 2     |          | OK     
 6  | 108 | root_0/2014-07-09/16-00-34.585/                                  | 1      | 2     |          | OK     
 7  | 106 | bbe13664-d770-4007-8d58-30e045a745bf_60/2014-07-09/16-00-23.247/ | 1      | 2     |          | ERROR! 
 8  | 104 | 52b513d2-9f4b-47b2-b535-b66b13b495ee_56/2014-07-09/16-00-07.017/ | 1      | 2     |          | OK     
 9  | 102 | 727a8d68-f096-43d2-9a80-b9c8c3d7f730_53/2014-07-09/15-59-23.508/ | 1      | 2     |          | ERROR! 
 10 | 57  | user-0_2/2014-07/09/14-45-33.692/                                | 1      | 1     |          | OK     
 11 | 56  | user-0_2/2014-07/09/14-44-30.624/                                | 1      | 1     |          | OK     
(12 rows, starting at 30 of approx. 53)

The first error here was a lei fileset not moved when renamed. A later move-by-hand fixed that fine.

And non-admin users get a senible reply to admin options:

jrs-macbookpro-25031:ome cblackburn$ dist/bin/omero -C fs sets --check
Server: [localhost]
Username: [root]user-0
Password:
Created session e392af17-1d8b-4c8a-acdb-3b18ced914b9 (user-0@localhost:4064). Idle timeout: 10.0 min. Current group: pg-0
SecurityViolation: Admins only!

Any further commits to come or aspects that need reviewing?

@joshmoore
Copy link
Member Author

Probably just a decision about who is permitted and what are the defaults a la #2743 (comment) Post-lunch chat?

@joshmoore
Copy link
Member Author

Thoughts on talking to @ximenesuk:

  • attach a history annotation to each fileset that's moved
  • printing out 100s to 1000s lines of "move" statements in the console is bad both for collecting the move commands and for long-running server actions so, move the directory rather than individual files which leads to only 2 mv commands being printed
  • possibly print a warning that the move may not be atomic and remove the --move action.
  • probably a "bulk rename" will be requested early on (could conceivably be tested on octopus /cc @sbesson @pwalczysko) though perhaps anyone who wants something more sophisticated should use OMERO.scripts.

In order to move the top level directory, first
it was necessary to check that the empty directory
would be removed from disk.
There are a number of error conditions where
neither the handle nor the callback object
from client.submit() will be returned to the
user. Since the exceptions do not include the
objects and it was not a part of the "API" to
require a `close()` we will make a best effort
at cleaning up resources when an exception
occurs.
Previous changes to waitOnCmd and submit in BaseClient
broke backwards-compatibility since the handle which was
returned could possibly be closed. Now, close is called
on the handle instance by default only if the invoker
is `client.submit()` since in that case, the consumer has
never held a reference to the handle proxy.
The addition of a new annotation with a different
namespace was causing filesets to no longer be
shown by `bin/omero fs sets`
@joshmoore
Copy link
Member Author

Ready for re-review. (Move is now by default)

@@ -652,8 +652,8 @@ def testCmdDeleteCantDeleteDirectories(self):
gateway = BlitzGateway(client_obj=self.client)
handle = gateway.deleteObjects("/OriginalFile", [id])
try:
pytest.raises(Exception,
gateway._waitOnCmd, handle, failonerror=True)
with pytest.raises(CmdError):
Copy link
Member

Choose a reason for hiding this comment

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

Missing from omero import CmdError.
I will try to flake8 the remaining integration tests in between RCs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed

@ximenesuk
Copy link
Contributor

It all functions as expected with these revisions. With the final commit merged in all the modified and added tests pass.

@joshmoore
Copy link
Member Author

Waiting on travis to be green and then will merge.

joshmoore added a commit that referenced this pull request Jul 15, 2014
`fs rename` command for modifying template values
@joshmoore joshmoore merged commit f1aea4c into ome:dev_5_0 Jul 15, 2014
@joshmoore joshmoore deleted the template-mods branch July 15, 2014 13:10
@joshmoore
Copy link
Member Author

--rebased-to #2805

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

4 participants