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

[BUG] ezomero for importing error by using omero-user-token for omero connection #100

Closed
tymiao1220 opened this issue Feb 28, 2024 · 21 comments

Comments

@tymiao1220
Copy link

Dear ezomero support,

I am using omero-user-token omero-user-token 2 for generating a long term session, the reason is the analysis will need a long time to process and send back to omero server.
ezomero for importing result images back to the Omero server. Here is an example code:

import ezomero

import numpy
from PIL import Image

from omero_user_token import setter, login
from omero.gateway import BlitzGateway


TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1000

token = setter('my-remote-server', 4064, 'user', 'pass', TWENTY_FOUR_HOURS_MS)

client = login(token)
conn = BlitzGateway(client_obj=client)
user = conn.getUser()

ezomero.print_groups(conn)

def createAnImage():

    path = './ivg_omero_upload.jpg'
    a = numpy.random.rand(30,30,3) * 255
    im_out = Image.fromarray(a.astype('uint8')).convert('RGB')
    im_out.save(path)

imagePath = createAnImage()

image_ids = ezomero.ezimport(conn, path)

I can get user info and groups(by ezomero) successfully, but an exception raised for the last line

omero.RemovedSessionException: exception ::omero::RemovedSessionException
{
serverStackTrace = ome.conditions.RemovedSessionException: No context for
at ome.services.sessions.state.SessionCache.getDataNullOrThrowOnTimeout(SessionCache.java:432)
at ome.services.sessions.state.SessionCache.getSessionContext(SessionCache.java:368)
at ome.services.sessions.state.SessionCache.getSessionContext(SessionCache.java:353)
at ome.services.sessions.SessionManagerImpl.find(SessionManagerImpl.java:567)
at ome.services.sessions.SessionBean.getSession(SessionBean.java:201)
at jdk.internal.reflect.GeneratedMethodAccessor476.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at ome.services.util.ServiceHandler.invoke(ServiceHandler.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy95.getSession(Unknown Source)
at jdk.internal.reflect.GeneratedMethodAccessor476.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at ome.security.basic.BasicSecurityWiring.invoke(BasicSecurityWiring.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at ome.services.blitz.fire.AopContextInitializer.invoke(AopContextInitializer.java:43)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy95.getSession(Unknown Source)
at jdk.internal.reflect.GeneratedMethodAccessor478.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at ome.services.blitz.util.IceMethodInvoker.invoke(IceMethodInvoker.java:172)
at ome.services.throttling.Callback.run(Callback.java:56)
at ome.services.throttling.InThreadThrottlingStrategy.callInvokerOnRawArgs(InThreadThrottlingStrategy.java:56)
at ome.services.blitz.impl.AbstractAmdServant.callInvokerOnRawArgs(AbstractAmdServant.java:140)
at ome.services.blitz.impl.SessionI.getSession_async(SessionI.java:123)
at jdk.internal.reflect.GeneratedMethodAccessor477.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at omero.cmd.CallContext.invoke(CallContext.java:85)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy96.getSession_async(Unknown Source)
at omero.api._ISessionTie.getSession_async(_ISessionTie.java:160)
at omero.api._ISessionDisp.___getSession(_ISessionDisp.java:454)
at omero.api._ISessionDisp.__dispatch(_ISessionDisp.java:873)
at IceInternal.Incoming.invoke(Incoming.java:221)
at Ice.ConnectionI.invokeAll(ConnectionI.java:2536)
at Ice.ConnectionI.dispatch(ConnectionI.java:1145)
at Ice.ConnectionI.message(ConnectionI.java:1056)
at IceInternal.ThreadPool.run(ThreadPool.java:395)
at IceInternal.ThreadPool.access$300(ThreadPool.java:12)
at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:832)
at java.base/java.lang.Thread.run(Thread.java:829)
serverExceptionClass = ome.conditions.RemovedSessionException
message = No context for
}

I will appreciated of any suggestion.

@jburel
Copy link

jburel commented Feb 28, 2024

Problem is coming from conn.getSession()
Import is the only place in ezomero when the session needs to be used again

@jburel
Copy link

jburel commented Feb 28, 2024

Using the code snippet above
The following works

client = login(token)
conn = BlitzGateway(client_obj=client)
user = conn.getUser()
print(client.getSessionId())

A possibility could be to replaced
https://github.com/TheJacksonLaboratory/ezomero/blob/main/ezomero/_importer.py#L468C27-L468C63
by accessing the session Id from the client itself

@tymiao1220
Copy link
Author

Thank you for the response, client.getSessionId() works, do you mean to replace conn with client? If so ezomero.ezimport(client, path) still not work also ezomero.print_groups(client) will not work.

@jburel
Copy link

jburel commented Feb 28, 2024

@tymiao1220 of course it won't work since both methods are expected a BlitzGateway object as parameter.
The suggestion was for @erickmartins but some adjustments might be required in the gateway to achieve what is required

@jburel
Copy link

jburel commented Feb 28, 2024

okay I managed to import an image but I used a "private" method so not the strategy to use

@erickmartins
Copy link
Collaborator

What I'm curious about is why a BlitzGateway created in this way is in any way different from one created using a generator directly (or ezomero.connect) - and why that object only seems to be an issue with ezimport but not print_groups, for example. Any ideas @jburel ? It would definitely make it easier to change the ezomero side of things in a defensive way to avoid issues.

@jburel
Copy link

jburel commented Feb 29, 2024

@erickmartins I believe that I have found the source of the problem in the BlitzGateway

@jburel
Copy link

jburel commented Feb 29, 2024

See ome/omero-py#400

@erickmartins
Copy link
Collaborator

Awesome! I'll keep the issue open until I can test it against the merged PR, but I think that's the perfect solution. Thanks a lot!

@jburel
Copy link

jburel commented Feb 29, 2024

Running a test script importing an image using ezomero and omero-user-token and the change implemented in omero-py

ezomero % python test.py
258f82fc-72f6-496f-8029-4838af447a69
258f82fc-72f6-496f-8029-4838af447a69
258f82fc-72f6-496f-8029-4838af447a69
Using OMERO.java-5.6.8-ice36
Server: [workshop.openmicroscopy.org:None]outreach.openmicroscopy.org
Joined session for [email protected]:4064. Idle timeout: 1440 min. Current group: Lab1
2024-02-29 15:26:43,188 508        [      main] INFO          ome.formats.importer.ImportConfig - OMERO.blitz Version: 5.6.3
2024-02-29 15:26:43,217 537        [      main] INFO          ome.formats.importer.ImportConfig - Bioformats version: 6.14.0 revision: fca72bf84a29aee75ab69d9499f723e64ab424ef date: 5 July 2023
2024-02-29 15:26:43,332 652        [      main] INFO   formats.importer.cli.CommandLineImporter - Log levels -- Bio-Formats: ERROR OMERO.importer: INFO
2024-02-29 15:26:43,896 1216       [      main] INFO      ome.formats.importer.ImportCandidates - Depth: 4 Metadata Level: MINIMUM
2024-02-29 15:26:43,957 1277       [      main] INFO      ome.formats.importer.ImportCandidates - 1 file(s) parsed into 1 group(s) with 1 call(s) to setId in 59ms. (62ms total) [0 unknowns]
2024-02-29 15:26:44,013 1333       [      main] INFO       ome.formats.OMEROMetadataStoreClient - Attempting initial SSL connection to outreach.openmicroscopy.org:4064
2024-02-29 15:26:44,956 2276       [      main] INFO       ome.formats.OMEROMetadataStoreClient - Insecure connection requested, falling back
2024-02-29 15:26:46,254 3574       [      main] INFO       ome.formats.OMEROMetadataStoreClient - Pinging session every 300s.
2024-02-29 15:26:46,357 3677       [      main] INFO       ome.formats.OMEROMetadataStoreClient - Server: 5.6.8
2024-02-29 15:26:46,357 3677       [      main] INFO       ome.formats.OMEROMetadataStoreClient - Client: 5.6.3
2024-02-29 15:26:46,357 3677       [      main] INFO       ome.formats.OMEROMetadataStoreClient - Java Version: 11.0.9.1
2024-02-29 15:26:46,357 3677       [      main] INFO       ome.formats.OMEROMetadataStoreClient - OS Name: Mac OS X
2024-02-29 15:26:46,357 3677       [      main] INFO       ome.formats.OMEROMetadataStoreClient - OS Arch: x86_64
2024-02-29 15:26:46,357 3677       [      main] INFO       ome.formats.OMEROMetadataStoreClient - OS Version: 10.16
2024-02-29 15:26:47,097 4417       [2-thread-1] INFO   ormats.importer.cli.LoggingImportMonitor - FILESET_UPLOAD_PREPARATION
2024-02-29 15:26:49,560 6880       [2-thread-1] INFO   ormats.importer.cli.LoggingImportMonitor - FILESET_UPLOAD_START
2024-02-29 15:26:49,641 6961       [3-thread-1] INFO   ts.importer.transfers.UploadFileTransfer - Transferring /Users/jmarie/Documents/git-repo/ezomero/bridge_1.png...
2024-02-29 15:26:49,689 7009       [3-thread-1] INFO   ormats.importer.cli.LoggingImportMonitor - FILE_UPLOAD_STARTED: /Users/jmarie/Documents/git-repo/ezomero/bridge_1.png
2024-02-29 15:26:49,984 7304       [3-thread-1] INFO   ormats.importer.cli.LoggingImportMonitor - FILE_UPLOAD_COMPLETE: /Users/jmarie/Documents/git-repo/ezomero/bridge_1.png
2024-02-29 15:26:50,149 7469       [2-thread-1] INFO   ormats.importer.cli.LoggingImportMonitor - FILESET_UPLOAD_END
2024-02-29 15:26:50,488 7808       [2-thread-1] INFO   ormats.importer.cli.LoggingImportMonitor - IMPORT_STARTED Logfile: 404509
2024-02-29 15:26:50,879 8199       [l.Client-1] INFO   ormats.importer.cli.LoggingImportMonitor - METADATA_IMPORTED Step: 1 of 5  Logfile: 404509
2024-02-29 15:26:51,030 8350       [l.Client-0] INFO   ormats.importer.cli.LoggingImportMonitor - PIXELDATA_PROCESSED Step: 2 of 5  Logfile: 404509
2024-02-29 15:26:51,362 8682       [l.Client-1] INFO   ormats.importer.cli.LoggingImportMonitor - THUMBNAILS_GENERATED Step: 3 of 5  Logfile: 404509
2024-02-29 15:26:51,371 8691       [l.Client-0] INFO   ormats.importer.cli.LoggingImportMonitor - METADATA_PROCESSED Step: 4 of 5  Logfile: 404509
2024-02-29 15:26:51,382 8702       [l.Client-1] INFO   ormats.importer.cli.LoggingImportMonitor - OBJECTS_RETURNED Step: 5 of 5  Logfile: 404509
2024-02-29 15:26:51,533 8853       [l.Client-0] INFO   ormats.importer.cli.LoggingImportMonitor - IMPORT_DONE Imported file: /Users/jmarie/Documents/git-repo/ezomero/bridge_1.png
Image:100313
Other imported objects:
Fileset:66526

==> Summary
1 file uploaded, 1 fileset created, 1 image imported, 0 errors in 0:00:04.484
Imported /Users/jmarie/Documents/git-repo/ezomero/bridge_1.png
WARNING:root:Missing annotation or namespace, skipping annotations
Groups:
                     Lab4: 3	member
                     Lab2: 4	member
                     Lab1: 5	member
                     Lab3: 6	member
               private-fm: 53	
           test_new_group: 103	
                   group1: 153	
                   MyData: 203	
        system-monitoring: 253	
                lab-basel: 303	
                      LCI: 353	
                   PUBLIC: 403	member
!! 02/29/24 15:26:52.740 error: communicator not destroyed during global destruction.%

@erickmartins
Copy link
Collaborator

@jburel can you share the test code you used for this? I am using the code from @tymiao1220 and the omero-py from your PR - still having issues. basically, if I do

import ezomero
conn = ezomero.connect('localhost', 6064, 'root', 'omero')
print(type(conn.getSession())

I get <class 'omero.model.SessionI'> (which is correct based on documentation). If I do

from omero_user_token import setter, login
from omero.gateway import BlitzGateway
token = setter('localhost', 6064, 'root', 'omero', LARGE_NUMBER)
client = login(token)
conn = BlitzGateway(client_obj=client)
print(type(conn.getSession())

I get <class 'omero.api.ServiceFactoryPrx'>, which does not have the getUuid() method. Trying to use the code you suggest for testing the PR

client = omero.client('localhost', 6064)
client.createSession('root', 'omero')
sid = client.getSessionId()
with BlitzGateway(client_obj=client) as conn:
    assert sid == conn.getSession().getUuid().val

gives me the same problem - last line fails with 'ServiceFactoryPrx' object has no attribute 'getUuid'.

@jburel
Copy link

jburel commented Mar 25, 2024

@erickmartins I pushed a new commit to my branch that should fix the. issue your notice
Thanks

@erickmartins
Copy link
Collaborator

@jburel Still seeing the same behavior as of commit 704e50f6, unfortunately. If you have specific code you're using to test it, that might help make sure I'm not doing anything different!

@jburel
Copy link

jburel commented Mar 25, 2024

This is the test

client=omero.client(server)
client.createSession(user, password)
print(client.isSecure())
with BlitzGateway(client_obj=client) as conn:
    print(conn.connect())
    print(conn.getSession().getUuid().val)

@jburel
Copy link

jburel commented Mar 25, 2024

client=omero.client(server)
client.createSession(user, password)
with BlitzGateway(client_obj=client) as conn:
    print(conn.getSession().getUuid().val==client.getSessionId())

This works as expected

@jburel
Copy link

jburel commented Mar 25, 2024

I also tried

TIME = 0.1 * 60 * 60 * 1000
token = setter(server, 4064, user, password, TIME)
client = login(token)
sid = client.getSessionId()
with BlitzGateway(client_obj=client) as conn:
    print(sid == conn.getSession().getUuid().val)

and it works fine

@erickmartins
Copy link
Collaborator

Hmm, interesting. That still gives me a 'ServiceFactoryPrx' object has no attribute 'getUuid' error. My env looks like this;

_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
appdirs                   1.4.4                    pypi_0    pypi
bzip2                     1.0.8                hd590300_5    conda-forge
ca-certificates           2024.2.2             hbcca054_0    conda-forge
certifi                   2024.2.2                 pypi_0    pypi
charset-normalizer        3.3.2                    pypi_0    pypi
click                     8.1.7                    pypi_0    pypi
configparser              4.0.2                    pypi_0    pypi
ezomero                   2.1.0                    pypi_0    pypi
future                    0.18.3                   pypi_0    pypi
idna                      3.6                      pypi_0    pypi
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.2.0               h807b86a_5    conda-forge
libgomp                   13.2.0               h807b86a_5    conda-forge
libiconv                  1.17                 hd590300_2    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libsqlite                 3.45.1               h2797004_0    conda-forge
libstdcxx-ng              13.2.0               h7e041cc_5    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libxcrypt                 4.4.36               hd590300_1    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
ncurses                   6.4                  h59595ed_2    conda-forge
numpy                     1.24.4                   pypi_0    pypi
omero-py                  5.19.1.dev0              pypi_0    pypi
omero-user-token          0.3.0                    pypi_0    pypi
openssl                   1.1.1w               hd590300_0    conda-forge
pillow                    10.2.0                   pypi_0    pypi
pip                       24.0               pyhd8ed1ab_0    conda-forge
portalocker               2.8.2                    pypi_0    pypi
python                    3.8.15          h257c98d_0_cpython    conda-forge
python_abi                3.8                      4_cp38    conda-forge
pyyaml                    6.0.1                    pypi_0    pypi
readline                  8.2                  h8228510_1    conda-forge
requests                  2.31.0                   pypi_0    pypi
setuptools                69.0.3             pyhd8ed1ab_0    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
urllib3                   1.26.18                  pypi_0    pypi
wheel                     0.42.0             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zeroc-ice                 3.6.5            py38h965970a_4    conda-forge

@jburel
Copy link

jburel commented Mar 25, 2024

are you sure you are using my branch?
I have using a dev env and it should be something like

-e git+ssh://[email protected]/ome/omero-py.git@704e50f6d170439a1b6976b64bb641b248ec0add#egg=omero_py

for omero-py

@erickmartins
Copy link
Collaborator

I was in the right commit but had missed the python setup.py devtarget - all looking good now!

@erickmartins
Copy link
Collaborator

@tymiao1220 @jburel since the fix is coming upstream and I have now confirmed it works with ezomero as intended, I will go ahead and close this one. Feel free to reopen in the future if issues arise again!

@jburel
Copy link

jburel commented Apr 24, 2024

I released today omero-py version 5.19.2. This included the fix

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

No branches or pull requests

3 participants