We're Hiring!

Shutdown handler in an OMERO.script

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Re: Shutdown handler in an OMERO.script

Postby PaulVanSchayck » Tue Jul 01, 2014 7:19 am

Hey Josh,

Thanks for the suggestion of storing something in the session directly. That's something I hadn't thought about yet. I think much effort is made in rejoining an existing session for an user when one exists, right? So, even though this is not persistent, it would still be retrievable when say, launching a script from Insight and then logging into to the webclient?

Also, I ran into this problem when running "updateService.saveObject(jobObj)" as non admin user:
Code: Select all
serverExceptionClass = ome.conditions.SecurityViolation
message = Updating ome.model.jobs.ScriptJob:Id_10192 not allowed.

Is this a bug? The job is assigned to the user performing the update.

Thank you,

Paul
PaulVanSchayck
 
Posts: 41
Joined: Tue May 20, 2014 7:04 am

Re: Shutdown handler in an OMERO.script

Postby jmoore » Tue Jul 01, 2014 7:23 am

Morning, Paul

PaulVanSchayck wrote:I think much effort is made in rejoining an existing session for an user when one exists, right? So, even though this is not persistent, it would still be retrievable when say, launching a script from Insight and then logging into to the webclient?


I don't think this would be the case. Each client (insight, web, script) will be in its own session. One session can access the contents of another session, but there's nothing in the clients to just know which session to grab.


Also, I ran into this problem when running "updateService.saveObject(jobObj)" as non admin user:
Code: Select all
serverExceptionClass = ome.conditions.SecurityViolation
message = Updating ome.model.jobs.ScriptJob:Id_10192 not allowed.

Is this a bug? The job is assigned to the user performing the update.


Did this fail in one case but not another? If so, perhaps the group for the session was changed? Otherwise, could you send me the full exception as well as where it occurred?

Thanks,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Shutdown handler in an OMERO.script

Postby PaulVanSchayck » Tue Jul 01, 2014 7:43 am

Morning Josh,

I don't think this would be the case. Each client (insight, web, script) will be in its own session. One session can access the contents of another session, but there's nothing in the clients to just know which session to grab.

Hmm.. that would cause too much hacking around to make this workable for our purposes.

Did this fail in one case but not another? If so, perhaps the group for the session was changed? Otherwise, could you send me the full exception as well as where it occurred?

Hmm.. no so far I had only been testing this with my own user (admin), and not a normal user. Changing a normal user to admin fixes the problem consistently. The full exception is:
Code: Select all
WARNING:omero.gateway:SecurityViolation on <class 'omero.gateway.OmeroGatewaySafeCallWrapper'> to <e451b544-0b37-4524-b2e8-06dee47d9c64omero.api.IUpdate> saveObject((object #0 (::omero::model::ScriptJob)
{
    _id = object #1 (::omero::RLong)
    {
        _val = 10195
    }
    _details = object #2 (::omero::model::Details)
    {
        _owner = object #3 (::omero::model::Experimenter)
        {
            _id = object #4 (::omero::RLong)
            {
                _val = 152
            }
            _details = <nil>
            _loaded = False
            _version = <nil>
            _groupExperimenterMapSeq =
            {
            }
            _groupExperimenterMapLoaded = False
            _omeName = <nil>
            _firstName = <nil>
            _middleName = <nil>
            _lastName = <nil>
            _institution = <nil>
            _email = <nil>
            _annotationLinksSeq =
            {
            }
            _annotationLinksLoaded = False
            _annotationLinksCountPerOwner =
            {
            }
        }
        _group = object #5 (::omero::model::ExperimenterGroup)
        {
            _id = object #6 (::omero::RLong)
            {
                _val = 53
            }
            _details = object #7 (::omero::model::Details)
            {
                _owner = <nil>
                _group = <nil>
                _creationEvent = <nil>
                _updateEvent = <nil>
                _permissions = object #8 (::omero::model::Permissions)
                {
                    _restrictions =
                    {
                        [0] = False
                        [1] = True
                        [2] = True
                        [3] = True
                    }
                    _perm1 = -40
                }
                _externalInfo = <nil>
                _call =
                {
                    key = omero.session.uuid
                    value = ec05a3fa-356c-432e-be7e-9305d019c4b6
                   
                    key = omero.client.uuid
                    value = e451b544-0b37-4524-b2e8-06dee47d9c64
                }
                _event = object #9 (::omero::sys::EventContext)
                {
                    shareId = -1
                    sessionId = 8219
                    sessionUuid = *********
                    userId = 152
                    userName = testing
                    groupId = 53
                    groupName = testing
                    isAdmin = False
                    eventId = -1
                    eventType = User
                    memberOfGroups =
                    {
                        [0] = 53
                        [1] = 1
                    }
                    leaderOfGroups =
                    {
                        [0] = 53
                    }
                    groupPermissions = object #10 (::omero::model::Permissions)
                    {
                        _restrictions =
                        {
                        }
                        _perm1 = -40
                    }
                }
            }
            _loaded = True
            _version = object #11 (::omero::RInt)
            {
                _val = 0
            }
            _name = object #12 (::omero::RString)
            {
                _val = testing
            }
            _groupExperimenterMapSeq =
            {
            }
            _groupExperimenterMapLoaded = False
            _annotationLinksSeq =
            {
            }
            _annotationLinksLoaded = False
            _annotationLinksCountPerOwner =
            {
            }
            _description = object #13 (::omero::RString)
            {
                _val = A group containing all testing users and data
            }
        }
        _creationEvent = object #14 (::omero::model::Event)
        {
            _id = object #15 (::omero::RLong)
            {
                _val = 125429
            }
            _details = <nil>
            _loaded = False
            _status = <nil>
            _time = <nil>
            _experimenter = <nil>
            _experimenterGroup = <nil>
            _type = <nil>
            _containingEvent = <nil>
            _logsSeq =
            {
            }
            _logsLoaded = False
            _session = <nil>
        }
        _updateEvent = object #16 (::omero::model::Event)
        {
            _id = object #17 (::omero::RLong)
            {
                _val = 125433
            }
            _details = <nil>
            _loaded = False
            _status = <nil>
            _time = <nil>
            _experimenter = <nil>
            _experimenterGroup = <nil>
            _type = <nil>
            _containingEvent = <nil>
            _logsSeq =
            {
            }
            _logsLoaded = False
            _session = <nil>
        }
        _permissions = object #18 (::omero::model::Permissions)
        {
            _restrictions =
            {
                [0] = True
                [1] = True
                [2] = True
                [3] = True
            }
            _perm1 = -40
        }
        _externalInfo = <nil>
        _call =
        {
            key = omero.session.uuid
            value = ec05a3fa-356c-432e-be7e-9305d019c4b6
           
            key = omero.client.uuid
            value = e451b544-0b37-4524-b2e8-06dee47d9c64
        }
        _event = object #19 (::omero::sys::EventContext)
        {
            shareId = -1
            sessionId = 8219
            sessionUuid = *********
            userId = 152
            userName = testing
            groupId = 53
            groupName = testing
            isAdmin = False
            eventId = -1
            eventType = User
            memberOfGroups =
            {
                [0] = 53
                [1] = 1
            }
            leaderOfGroups =
            {
                [0] = 53
            }
            groupPermissions = object #20 (::omero::model::Permissions)
            {
                _restrictions =
                {
                }
                _perm1 = -40
            }
        }
    }
    _loaded = True
    _version = <nil>
    _username = object #21 (::omero::RString)
    {
        _val = testing
    }
    _groupname = object #22 (::omero::RString)
    {
        _val = testing
    }
    _type = object #23 (::omero::RString)
    {
        _val = User
    }
    _message = object #24 (::omero::RString)
    {
        _val = |PID:18263 |Progress:0.00 |Message:Initializing...
    }
    _status = object #25 (::omero::model::JobStatus)
    {
        _id = object #26 (::omero::RLong)
        {
            _val = 5
        }
        _details = object #27 (::omero::model::Details)
        {
            _owner = <nil>
            _group = <nil>
            _creationEvent = <nil>
            _updateEvent = <nil>
            _permissions = object #28 (::omero::model::Permissions)
            {
                _restrictions =
                {
                    [0] = True
                    [1] = True
                    [2] = True
                    [3] = True
                }
                _perm1 = -40
            }
            _externalInfo = <nil>
            _call =
            {
                key = omero.session.uuid
                value = ec05a3fa-356c-432e-be7e-9305d019c4b6
               
                key = omero.client.uuid
                value = e451b544-0b37-4524-b2e8-06dee47d9c64
            }
            _event = object #29 (::omero::sys::EventContext)
            {
                shareId = -1
                sessionId = 8219
                sessionUuid = *********
                userId = 152
                userName = testing
                groupId = 53
                groupName = testing
                isAdmin = False
                eventId = -1
                eventType = User
                memberOfGroups =
                {
                    [0] = 53
                    [1] = 1
                }
                leaderOfGroups =
                {
                    [0] = 53
                }
                groupPermissions = object #30 (::omero::model::Permissions)
                {
                    _restrictions =
                    {
                    }
                    _perm1 = -40
                }
            }
        }
        _loaded = True
        _value = object #31 (::omero::RString)
        {
            _val = Running
        }
    }
    _submitted = object #32 (::omero::RTime)
    {
        _val = 1404199963829
    }
    _scheduledFor = object #33 (::omero::RTime)
    {
        _val = 1404199963829
    }
    _started = object #34 (::omero::RTime)
    {
        _val = 1404199963982
    }
    _finished = <nil>
    _originalFileLinksSeq =
    {
    }
    _originalFileLinksLoaded = False
    _originalFileLinksCountPerOwner =
    {
    }
    _description = <nil>
},), {})
Traceback (most recent call last):
  File "/home/service-unix-img/OMERO.server/lib/python/omero/gateway/__init__.py", line 3533, in __call__
    return self.f(*args, **kwargs)
  File "/home/service-unix-img/OMERO.server/lib/python/omero_api_IUpdate_ice.py", line 107, in saveObject
    return _M_omero.api.IUpdate._op_saveObject.invoke(self, ((obj, ), _ctx))
SecurityViolation: exception ::omero::SecurityViolation
{
    serverStackTrace = ome.conditions.SecurityViolation: Updating ome.model.jobs.ScriptJob:Id_10195 not allowed.
   at ome.security.basic.BasicACLVoter.throwUpdateViolation(BasicACLVoter.java:228)
   at ome.security.CompositeACLVoter.throwUpdateViolation(CompositeACLVoter.java:96)
   at ome.security.ACLEventListener.onPreUpdate(ACLEventListener.java:129)
   at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:236)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:87)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:259)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1208)
   at ome.logic.UpdateImpl.afterUpdate(UpdateImpl.java:294)
   at ome.logic.UpdateImpl.doAction(UpdateImpl.java:312)
   at ome.logic.UpdateImpl.doAction(UpdateImpl.java:302)
   at ome.logic.UpdateImpl.saveObject(UpdateImpl.java:108)
   at sun.reflect.GeneratedMethodAccessor829.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at ome.security.basic.EventHandler.invoke(EventHandler.java:154)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:111)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at ome.tools.hibernate.ProxyCleanupFilter$Interceptor.invoke(ProxyCleanupFilter.java:241)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at ome.services.util.ServiceHandler.invoke(ServiceHandler.java:116)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at com.sun.proxy.$Proxy98.saveObject(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor829.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at ome.security.basic.BasicSecurityWiring.invoke(BasicSecurityWiring.java:98)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at ome.services.blitz.fire.AopContextInitializer.invoke(AopContextInitializer.java:43)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at com.sun.proxy.$Proxy98.saveObject(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor848.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at ome.services.blitz.util.IceMethodInvoker.invoke(IceMethodInvoker.java:179)
   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:149)
   at ome.services.blitz.impl.UpdateI.saveObject_async(UpdateI.java:81)
   at sun.reflect.GeneratedMethodAccessor847.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at omero.cmd.CallContext.invoke(CallContext.java:78)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at com.sun.proxy.$Proxy99.saveObject_async(Unknown Source)
   at omero.api._IUpdateTie.saveObject_async(_IUpdateTie.java:108)
   at omero.api._IUpdateDisp.___saveObject(_IUpdateDisp.java:136)
   at omero.api._IUpdateDisp.__dispatch(_IUpdateDisp.java:357)
   at IceInternal.Incoming.invoke(Incoming.java:222)
   at Ice.ConnectionI.invokeAll(ConnectionI.java:2482)
   at Ice.ConnectionI.dispatch(ConnectionI.java:1258)
   at Ice.ConnectionI.message(ConnectionI.java:1213)
   at IceInternal.ThreadPool.run(ThreadPool.java:321)
   at IceInternal.ThreadPool.access$300(ThreadPool.java:12)
   at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:693)
   at java.lang.Thread.run(Thread.java:745)

    serverExceptionClass = ome.conditions.SecurityViolation
    message = Updating ome.model.jobs.ScriptJob:Id_10195 not allowed.
}


Thanks,

Paul
PaulVanSchayck
 
Posts: 41
Joined: Tue May 20, 2014 7:04 am

Re: Shutdown handler in an OMERO.script

Postby jmoore » Tue Jul 01, 2014 9:37 am

Ah, I think I see. Did you try to move to `iUpdate.saveObject()` on the job as opposed to the job service? If so, that won't work, since those objects are protected from tampering. That method would only work with the annotation strategy I mentioned.

Cheers,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Shutdown handler in an OMERO.script

Postby PaulVanSchayck » Tue Jul 01, 2014 10:24 am

Hmm.. that's unfortunate. Yes, I'm was always using updateService.saveObject(jobObj).

So moving to the job service. This also doesn't seem to actually set the message (regardless of being admin or not)
Code: Select all
handle = conn.c.sf.createJobHandle()
handle.attach(long(jobid))
handle.setMessage(msg)

Am I missing something here?

Thanks,

Paul
PaulVanSchayck
 
Posts: 41
Joined: Tue May 20, 2014 7:04 am

Re: Shutdown handler in an OMERO.script

Postby jmoore » Tue Jul 01, 2014 10:49 am

That `setMesage()` doesn't work, certainly surprises me. But now I'm a bit confused. I read your previous forum posts as if this were already working for you. But that's not the case? ~J.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Shutdown handler in an OMERO.script

Postby PaulVanSchayck » Tue Jul 01, 2014 11:40 am

Oh! I'm sorry for the confusion. I was using this before:
Code: Select all
jobid = conn.getProperty("omero.job")
jobObj = queryService.findByQuery("from Job where id = :jobid", p)
jobObj.setMessage(rstring(msg))
updateService.saveObject(jobObj)

Which doesn't work as non-admin

Now I was trying to use:
Code: Select all
jobid = c.getProperty("omero.job")
handle = c.sf.createJobHandle()
handle.attach(long(jobid))
status = handle.jobStatus()
handle.setMessage("Foo")

Now, ignore my previous message. There was an unrelated mistake in my code causing the setMessage() call not to be executed. However, this fixing this it gives the following error:
Code: Select all
File "/home/service-unix-img/OMERO.server/lib/python/omero_api_JobHandle_ice.py", line 236, in setMessage
   return _M_omero.api.JobHandle._op_setMessage.invoke(self, ((message, ), _ctx))
serverStackTrace = ome.conditions.ApiUsageException: An ome.model.jobs.JobStatus enum does not exist with the value: null
at ome.logic.TypesImpl.getEnumeration(TypesImpl.java:128)
at ome.services.JobBean.setStatusAndMessage(JobBean.java:304)
at ome.services.JobBean.setMessage(JobBean.java:297)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Changing to
Code: Select all
handle.setMessage(rstring("foobar"))

Gives:
Code: Select all
return _M_omero.api.JobHandle._op_setMessage.invoke(self, ((message, ), _ctx))
ValueError: invalid value for argument 1 in operation `setMessage'


Changing to:
Code: Select all
handle.setStatusAndMessage("Running",rstring("foobar"))

Does work! And also as normal user! Solving the problem. However the API usage from here is bit unclear in all this.

[edit]I see now, that the API docs do explain the rstring() usage. And I suspect that first calling handle.setStatus() before handle.setMessage() will fix the rather. Only this is not documented.[/edit]

Thanks,

Paul
PaulVanSchayck
 
Posts: 41
Joined: Tue May 20, 2014 7:04 am

Re: Shutdown handler in an OMERO.script

Postby jmoore » Wed Jul 02, 2014 7:02 am

Glad it's all worked out, Paul! I'll make a note to either fix the status/message logic, or make a note of the ordering requirement in the docs.

Thanks for the feedback.
~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Previous

Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests