Page 1 of 1

Having Apache call OMERO CLI's HQL command

PostPosted: Fri Sep 05, 2014 10:58 am
by dasesan
Hi there,

I have a web application which calls OMERO CLI to import/export data from/to OMERO. This works Ok as long as the web server user is not apache (www-data), but does not work when www-data is the web server user and therefore also the user executing OMERO CLI. Presumably this happens because www-data cannot write to its own home /var/www which is usually owned by root.

In theory that problem can be fixed by using OMERO CLI's --session-dir option
$path/bin/omero login -u <user> -w <password> --session-dir=/tmp

which successfully logs the user on to OMERO and returns the session key.

The problem comes when executing HQL commands, to which I can pass the session key, as follows:

$path/bin/omero hql -q --limit -1 "SELECT i.id FROM Experimenter i WHERE i.omeName='<user>'" -k <key> -u <user> -w <password>

which returns: Could not access session dir: /var/www/omero

It seems that the HQL command tries to find the session key in the default user home /var/www
I thought of passing the session-dir to the HQL command as well, but this is not supported.

Could somebody explain if I've missed something or how to overcome this issue?

Thanks a lot in advance,
Daniel

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Mon Sep 08, 2014 7:56 am
by jmoore
Hi Daniel,

thanks for pointing out this discrepancy; a fix is in the works! Most likely we'll introduce an environment variable like "OMERO_SESSION_DIR" so that it's unnecessary to pass an explicit argument (and equally, not possible to forget to pass the argument).

Until then, the easiest solution is likely that we help you convert your use of the CLI to a simple Python script. Perhaps something like:
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import omero
import omero.cli

HOST = "yourhost"
USER = "youruser"
PASS = "yourpassword"

client = omero.client(HOST)
client.createSession(USER, PASS)

try:
    cli = omero.cli.CLI()
    cli.loadplugins()
    cli._client = client

    for x in sys.argv[1:]:
        cli.invoke(
            ["hql", "-q", "--limit", "-1",
            ("SELECT i.id FROM Experimenter i "
            "WHERE i.omeName='%s'") % x])

finally:
    client.__del__()



which produces

Code: Select all
$ PYTHONPATH=dist/lib/python python hql_script.py root
# | Col1
---+------
0 | 0   
(1 row)


Cheers,
~Josh

P.S. when using "-k" it's unnecessary to use "-u" or "-w" on the CLI.

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Tue Sep 09, 2014 9:22 am
by dasesan
Hi Josh,

Thanks a lot for your explanation.
An environment variable like "OMERO_SESSION_DIR" would help indeed. It'd be great if that change could make it into the next Omero release.

Cheers,
Daniel

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Fri Feb 20, 2015 9:21 am
by ehrenfeu
Hi Josh,

I'm just writing to ask about the status of this - if I got it right, the commits below introduced the required functionality, but they haven't made it to the 5.0.x branch, right?

Code: Select all
d154e285f0333b02aa13fdc5bc3f371d98cafb41
22fe2171503e4b5ee040fb85da95d5bf95a424ee

Cheers
~Niko

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Fri Feb 20, 2015 9:31 am
by jmoore
Hi Niko,

yup, that's Sebastien's https://github.com/openmicroscopy/openm ... /pull/3032 which is currently marked as "no-rebase" (i.e for 5.1 only). There's no current timescale for a 5.0.9, but I'll certainly put that on the list of things to consider.

Cheers,
~Josh.

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Fri Feb 20, 2015 10:00 am
by ehrenfeu
Hi Josh,

I'm fine with having this in 5.1 only, given the release roadmap for it is only a couple of weeks from now.

So no need for additional merging and testing efforts on this in a 5.0.9 from my side!

Thanks for the update, though!
~Niko

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Wed Apr 08, 2015 12:28 pm
by ehrenfeu
The merge has made it into the 5.1 release, right?

~Niko

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Wed Apr 08, 2015 12:40 pm
by sbesson
Hi Niko,

the OMERO_SESSION_DIR support should definitely be included in 5.1.0.

Code: Select all
$ bin/omero version
5.1.0-ice34-b35
$ OMERO_SESSION_DIR=/tmp/sessions bin/omero login root@localhost:14064
Password:
Created session 8378d2f3-967c-4d95-b3d7-97c340fb558c (root@localhost:14064). Idle timeout: 10.0 min. Current group: system
$ OMERO_SESSION_DIR=/tmp/sessions bin/omero sessions file
/tmp/sessions/omero/sessions/localhost/root/8378d2f3-967c-4d95-b3d7-97c340fb558c


See also http://www.openmicroscopy.org/site/supp ... -directory. Let us know if you encounter any issue or if usage needs to be clarified.

Best,
Sebastien

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Wed Apr 08, 2015 1:09 pm
by ehrenfeu
Hi Sebastian,

thanks for the details. We'll explicitly test this once we have our OMERO upgraded!

Cheers
~Niko

Re: Having Apache call OMERO CLI's HQL command

PostPosted: Fri Apr 24, 2015 3:42 pm
by sbesson
Hi,

as a follow-up on this thread, we merged another Pull Request into the development line which will be included in the upcoming 5.1.1 release. This Pull Request fixes a minor issue by deprecating the OMERO_SESSION_DIR environment variable and recommending the usage of the OMERO_SESSIONDIR environment variable instead as a way to specify a custom sessions directory.

The corresponding documentation page will be updated when 5.1.1 is released to reflect the way existing custom sessions directory should be upgraded between 5.1.0 and 5.1.x.

Sebastien