[ome-users] How to access OMERO config via the API?

Harri Jäälinoja harri.jaalinoja at helsinki.fi
Tue Apr 3 15:45:29 BST 2012


Hi,

> Is it in dist/etc/omero.properties? You can also try adding it as a single property to etc/local.properties. If those fail you may need to update it in etc/omero.properties and then re-run the entire build to update it across the board. It's not really part of the design to have additional properties like this added as part of extensions.jar.
>

yes, I tried both omero.properties and local.properties, and it fails. I 
am lazy to rerun the entire build, anyway the point was to not have to 
build the project when we add a new group.

Instead I just fixed the config file in the bean definition:
     <bean id="hyldapbean" class="hyldap.HyNewUserGroupBean">
         <constructor-arg value="/home/omero/hyldapConfig.xml"/>
     </bean>

This is good enough for the time being. If you add a way to bring in 
additional properties, then we can make this more flexible.

Regards,
Harri

> -Chris
>
> On 3 Apr 2012, at 14:17, Harri Jäälinoja wrote:
>
>>
>> Hi Chris,
>>
>> thanks, I tried this, but something still goes wrong. Here's the bean description:
>>
>> <beans>
>>
>>     <bean id="hyldapbean" class="hyldap.HyNewUserGroupBean">
>>      <constructor-arg value="${hyldap.config}"/>
>>     </bean>
>>
>>     <bean id="hyldapbean_hc" class="hyldap.HyHcNewUserGroupBean"/>
>>
>> </beans>
>>
>> And I've set the property "hyldap.config" in OMERO config:
>> [omero at lmu-omero3 log]$ omero config get |grep hyldap
>> hyldap.config=/home/omero/hyldapConfig.xml
>> omero.ldap.new_user_group=:bean:hyldapbean
>>
>>
>> Then OMERO startup fails with this error:
>> Error creating bean with name 'ome.server' defined in URL [jar:file:/opt/OMERO/joshmoore/openmicroscopy/dist/lib/server/server.jar!/beanRefContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ome.system.OmeroContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'hyldapbean' defined in URL [jar:file:/opt/OMERO/joshmoore/openmicroscopy/dist/lib/server/extensions.jar!/ome/services/service-hyldap.xml]: Could not resolve placeholder 'hyldap.config'
>>         at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:281)
>>         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:984)
>>         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:888)
>>
>>
>> This is a bit strange, because the syntax seems to be ok, for example this is similar:
>> ./components/blitz/resources/ome/services/blitz-servantDefinitions.xml:<constructor-arg value="${omero.data.dir}"/>
>>
>> Is it necessary to do something else to "enable" new properties? I have it also in etc/omero.properties. You can see the complete files here: https://gist.github.com/2172934, maybe you spot something.
>>
>> Cheers,
>> Harri
>>
>>
>> On 03/04/12 11:14, Chris Allan wrote:
>>> In order to access the ServiceFactory when inside the the server the bean has to be instantiated in a particular way in order to receive the correct state. As your HyNewUserGroupBean's calling context is during login you have no ServiceFactory, the user is not yet logged in. Your best bet is to inject the configuration value in as an argument to the constructor of HyNewUserGroupBean:
>>>
>>> ...
>>> <bean id="hyldapbean" class="hyldap.HyNewUserGroupBean"/>
>>> ...
>>>
>>> becomes:
>>>
>>> ...
>>> <bean id="hyldapbean" class="hyldap.HyNewUserGroupBean">
>>> 	<constructor-arg value="${hyldap.configFile}"/>
>>> </bean>
>>> ...
>>>
>>> and...
>>>
>>> ...
>>> public HyNewUserGroupBean() {
>>> }
>>> ...
>>>
>>> becomes:
>>>
>>> ...
>>> public HyNewUserGroupBean(String configFile) {
>>> 	// Do something with the constructor argument
>>> 	...
>>> }
>>> ...
>>>
>>> You may also need to place a default value into etc/omero.properties:
>>>
>>> ...
>>> # Configuration options for hyldap
>>> hyldap.configFile=
>>> ...
>>>
>>> -Chris
>>>
>>> On 2 Apr 2012, at 17:37, Harri Jäälinoja wrote:
>>>
>>>>
>>>> Hi,
>>>>
>>>> I am trying to make it possible to configure my NewUserGroupBean implementation:
>>>> https://gist.github.com/2172934#file_src%2Fhyldap%2Fhy_new_user_group_bean.java
>>>>
>>>> This is what I cut and pasted from elsewhere in the OMERO project:
>>>>         ServiceFactory sf = new ServiceFactory();
>>>>         IConfig c = sf.getConfigService();
>>>>         String hyldapConfig = c.getConfigValue(CONFIGFILE);
>>>>
>>>> But when I try to run it, it goes like this:
>>>> org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [ome.client], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ome.client' is defined
>>>>         at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:409)
>>>>         at ome.system.OmeroContext.getInstance(OmeroContext.java:203)
>>>>         at ome.system.ServiceFactory.<init>(ServiceFactory.java:81)
>>>>         at hyldap.HyNewUserGroupBean.groups(HyNewUserGroupBean.java:59)
>>>>         at ome.logic.LdapImpl.handleGroupSpecBean(LdapImpl.java:476)
>>>>
>>>> What is the proper way to access the configuration? My idea is to give in OMERO configuration a path to a file that will contain a list of allowed group names found in our LDAP and the OMERO group names they should be mapped to.
>>>>
>>>> omero config set "hyldap.configFile" "/home/omero/hyldapconfig.txt"
>>>>
>>>> hyldapconfig.txt:
>>>> "uid=grp-A91900-bi-vart,ou=alma_workgroups,ou=groups,o=hy","BI-Vartiainen"
>>>> "uid=grp-A34520-biu,ou=alma_workgroups,ou=groups,o=hy","BIU"
>>>> etc... might make that xml, just to have a ready-made parser to use. In the first implementation I hard-coded these in the bean, which is not so nice to maintain.
>>>>
>>>> Cheers,
>>>> Harri
>>>>
>>>> --
>>>> __________________________________________________
>>>> Harri Jäälinoja
>>>> Light Microscopy Unit
>>>> Institute of Biotechnology, University of Helsinki
>>>> http://www.biocenter.helsinki.fi/bi/lmu/
>>>> +358 9 191 59370 fax +358 9 191 59366
>>>>
>>>> _______________________________________________
>>>> ome-users mailing list
>>>> ome-users at lists.openmicroscopy.org.uk
>>>> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-users
>>>
>>
>>
>> --
>> __________________________________________________
>> Harri Jäälinoja
>> Light Microscopy Unit
>> Institute of Biotechnology, University of Helsinki
>> http://www.biocenter.helsinki.fi/bi/lmu/
>> +358 9 191 59370 fax +358 9 191 59366
>>
>


-- 
__________________________________________________
Harri Jäälinoja
Light Microscopy Unit
Institute of Biotechnology, University of Helsinki
http://www.biocenter.helsinki.fi/bi/lmu/
+358 9 191 59370 fax +358 9 191 59366




More information about the ome-users mailing list