List all active Configuration for Config Admin in gogo shell

801 Views Asked by At

I would like to show on screen the Configuration list returned by org.osgi.service.cm.ConfigurationAdmin.listConfigurations method via gogo shell. I tried with the following:

g! _sref = $.context getServiceReference "org.osgi.service.cm.ConfigurationAdmin"
g! _srv = $.context getService $_sref
g! $_srv listConfigurations

but it fails with the following error:

gogo: IllegalArgumentException: Cannot coerce listconfigurations() to any of [(String)]

What is the right syntax here? Is it possible to do that?

Thanks!

2

There are 2 best solutions below

1
Neil Bartlett On BEST ANSWER

The listConfigurations method takes a String parameter, which is a filter. If you just want an unfiltered list, then you can pass null, e.g.:

$_srv listConfigurations null

This returns an array of Configuration objects, which you will probably want to iterate over with the each command.

However this kind of thing quickly gets too complex for Gogo scripting. For example you're not releasing the service reference with ungetService anywhere. It's probably better to build a reusable Gogo command in Java as a Declarative Services component.

0
Marcel Offermans On

It's probably a lot easier to use the following shell commands to achieve that:

https://bitbucket.org/pjtr/net.luminis.cmc

Which has, amongst other things, a command called:

cm list