Page 2 of 2

Re: trigger my own python app whenever a dataset is updated

PostPosted: Wed Nov 30, 2011 3:30 pm
by bhcho
for admin session (before merging it with a general user session).
FYI, 'bhcho' is an admin account.
Code: Select all
In [19]: client = omero.client('ourhost')
In [20]: session = client.createSession(ID, PW)
In [21]: principal = omero.sys.Principal()
In [22]: session.getAdminService().getEventContext()
Out[22]:
object #0 (::omero::sys::EventContext)
{
    shareId = -1
    sessionId = 67434
    sessionUuid = 48e2c655-fcfe-43f7-8c6a-b8f0a6a8d8aa
    userId = 2
    userName = bhcho
    groupId = 3
    groupName = Researchers
    isAdmin = True
    eventId = -1
    eventType = User
    memberOfGroups =
    {
        [0] = 1
        [1] = 3
        [2] = 0
    }
    leaderOfGroups =
    {
    }
    groupPermissions = object #1 (::omero::model::Permissions)
    {
        _perm1 = -39
    }
}
In [23]: gateway=session.createGateway()
In [24]: image=gateway.getImage(long(551))
In [25]: image.getDetails().getGroup().getName()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/OMERO_DIST/<ipython console> in <module>()
AttributeError: 'NoneType' object has no attribute 'getDetails'

it seems like even the admin account cannot retrieve an image (which is owned by a general account 'demo_ome')

After I merge,
Code: Select all
In [21]: principal = omero.sys.Principal()
In [22]: principal.name = 'demo_ome'
In [23]: principal.group = 'Researchers'
In [24]: principal.eventType = "User"
In [25]: timeout = 600000  # 60*2 seconds (milliseconds)
In [26]: user_session = session.getSessionService().createSessionWithTimeout(principal, timeout)
In [27]: client.closeSession()
In [28]: session = client.joinSession(user_session.uuid.val)
In [29]: session.getAdminService().getEventContext()
Out[29]:
object #0 (::omero::sys::EventContext)
{
    shareId = -1
    sessionId = 67436
    sessionUuid = a37f8c07-9490-440a-998c-9930abbd0ab4
    userId = 352
    userName = demo_ome
    groupId = 3
    groupName = Researchers
    isAdmin = False
    eventId = -1
    eventType = User
    memberOfGroups =
    {
        [0] = 3
        [1] = 1
    }
    leaderOfGroups =
    {
    }
    groupPermissions = object #1 (::omero::model::Permissions)
    {
        _perm1 = -39
    }
}
In [30]:
In [31]: gateway=session.createGateway()
In [32]: image=gateway.getImage(long(551))
In [33]: image.getDetails().getGroup().getName()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/OMERO_DIST/<ipython console> in <module>()
AttributeError: 'NoneType' object has no attribute 'getDetails'


I still have the same error

BK

Re: trigger my own python app whenever a dataset is updated

PostPosted: Mon Dec 05, 2011 2:49 pm
by jmoore
Hi BK,

can you show me the whole row for image 551 in the db using the "-x" flag?

Code: Select all
psql omero -x -c "select * from image where id = 551"


Cheers,
~Josh.

Re: trigger my own python app whenever a dataset is updated

PostPosted: Mon Dec 05, 2011 5:00 pm
by bhcho
hi Josh,

this is the output
-[ RECORD 1 ]------+---------------------------------------
id | 551
acquisitiondate | 2011-11-29 14:11:34
archived | f
description |
permissions | -7
name | GQ1H9_image00001_1channel_8bit.ome.tif
partial |
version |
creation_id | 1772
external_id |
group_id | 3
owner_id | 52
update_id | 1772
experiment |
format | 107
imagingenvironment |
instrument | 551
objectivesettings |
stagelabel |

Re: trigger my own python app whenever a dataset is updated

PostPosted: Tue Dec 06, 2011 1:38 pm
by jmoore
Hi BK,

image 551 certainly looks to be in the correct group (3), etc. and the group is group-readable, so something is certainly odd?

Can we maybe cut down on some of the moving pieces? Can you login to webclient or insight as demo_ome and view the image?

At the same time, are you seeing in the server logs for this image when you ask for it?

Thanks,
~Josh

Re: trigger my own python app whenever a dataset is updated

PostPosted: Tue Dec 06, 2011 3:01 pm
by bhcho
Oops. I'm sorry I made a big mistake.
After I migrated to 4.3.3 server, I was still connecting to 4.2.1 version (which is running on the same machine).
I should've used the following code.
Code: Select all
client = omero.client('localhost', new_port)


Now, I'm fine with the code.

Sorry and thanks.
BK

Re: trigger my own python app whenever a dataset is updated

PostPosted: Tue Dec 06, 2011 3:19 pm
by atarkowska
Hi Bkcho

Referring to the source code you pasted in that post. I would strongly recommend you to use omero python gateway (known as BlitzGateway) instead of gateway service which basically is deprecated.

The omero.gateway is a Python library built on top of the OMERO API to facilitate many aspects of working with the API, such as handling connections, creating services, loading objects and traversing object graphs. It consists of a 'connection wrapper' as well as various object wrappers around the omero.model objects. E.g. ImageWrapper wraps omero.model.ImageI.

- http://trac.openmicroscopy.org.uk/ome/wiki/OmeroPy/Gateway - this page is a 'quick-start' guide to the Blitz gateway.
- http://trac.openmicroscopy.org.uk/ome/wiki/OmeroPy/GatewayInfo - here you can find more info.
- http://trac.openmicroscopy.org.uk/ome/wiki/OmeroPy - training examples

Ola

Re: trigger my own python app whenever a dataset is updated

PostPosted: Tue Dec 06, 2011 7:38 pm
by bhcho
Thanks Ola,

What I'm doing from the code above is...
I first create connection to the server using ADMIN account, then I create a general account session by client.joinSession()

To tell you why I'm doing this, I should say from the beginning.

I have a custom Bridge, which will be called when importing an image by a general account 'A'.
This Bridge then calls a python function, which uses many OMERO APIs.
However, there is no way to pass the connection object (Blitzgateway, connection, or session) or the password of account 'A' from the Bridge to the python function.
Thus we save an Admin account information on the server (in config.xml) to firstly create an ADMIN connection. Then using the user id and group name of the account 'A' (without password), I created the session for the account 'A' by joinSession() function.

So, for the Blitzgateway,
I should firstly create an ADMIN conn by
Code: Select all
conn = BlitzGateway(ID, PW, host='localhost', port=int(PORT))

Then is there any way to create another 'conn2' that is for the account 'A', using the ADMIN's 'conn'?
(remember I have only the account 'A's user ID and group name.)

FYI, I could generate a session for the account 'A' by using conn.c.joinSession(), but most of the API functions are used through the 'conn' object, instead of session. For example, conn.getObject

Best,
BK

Re: trigger my own python app whenever a dataset is updated

PostPosted: Wed Dec 07, 2011 10:18 am
by atarkowska
Hi

That functionality is already available in webgateway http://github.com/openmicroscopy/openmi ... s.py#L2192:

Code: Select all
#create connection as root
conn = BlitzGateway(root, rootpasswd, host=host, port=4064)
conn.connect()

# check if user has admin privileges
if not conn.canBeAdmin():
    raise Exception('Not an admin')

# change active group for admin session
conn.setGroupNameForSession('system')

# create new connection as user
conn2 = conn.suConn(user_name, ttl=conn.getSessionService().getSession(conn._sessionUuid).getTimeToIdle().val)

# revert active group for admin session
conn.revertGroupForSession()
# close admin session
conn.seppuku()

# get image using user connection...
img = conn2.getObject('Image', imageId)


Ola

Re: trigger my own python app whenever a dataset is updated

PostPosted: Wed Dec 07, 2011 2:47 pm
by bhcho
Thank you so much!

by the way, does the 'conn2' have a timeout? If so, can I extend it?

BK

Re: trigger my own python app whenever a dataset is updated

PostPosted: Tue Dec 13, 2011 1:54 pm
by atarkowska
Hi BK,

Is the ttl parameter not enough for you?
Code: Select all
# create new connection as user
conn2 = conn.suConn(user_name, ttl=conn.getSessionService().getSession(conn._sessionUuid).getTimeToIdle().val)


alternatively you can look in the documentation http://hudson.openmicroscopy.org.uk/job ... tml#suConn

Thanks
Ola