[CONTROLLER-623] ManagementFactory.getPlatformMBeanServer() does not work in karaf Created: 13/Jul/14  Updated: 19/Oct/17  Resolved: 17/Mar/16

Status: Resolved
Project: controller
Component/s: config
Affects Version/s: Helium
Fix Version/s: None

Type: Bug
Reporter: Ed Warnicke Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Mac OS
Platform: PC


Attachments: HTML File pastebin    
External issue ID: 1359

 Description   

This bug was discovered in the context of:

https://git.opendaylight.org/gerrit/#/c/8963/

trying to do the Karaf work.

The shell script that starts karaf on line 410 has
-Djavax.management.builder.initial=org.apache.karaf.management.boot.KarafMBeanServerBuilder

This causes the config subsystem to break in karaf due to its many uses of:
ManagementFactory.getPlatformMBeanServer()
(see ConfigManagerActivator [line 32] for one of many examples).

If you
feature:install odl-config-startup from
https://git.opendaylight.org/gerrit/#/c/8963/
in karaf (to launch karaf:
cd controller/opendaylight/distribution/opendaylight-karaf/;mvn clean install;cd target/;unzip -o controller/opendaylight/distribution/opendaylight-karaf/target/distribution.opendaylight-karaf-1.4.2-SNAPSHOT.zip; cd distribution.opendaylight-karaf-1.4.2-SNAPSHOT/bin;./karaf
)

You will get an exception like the one in the attachment. This is rooted in karaf JMX RBAC as enforced by the:
-Djavax.management.builder.initial=org.apache.karaf.management.boot.KarafMBeanServerBuilder

This can be solved in two ways:

1) Remove from the bin/karaf the
-Djavax.management.builder.initial=org.apache.karaf.management.boot.KarafMBeanServerBuilder
Disadvantage: It means that if folks try to install us in a normal karaf container there will still be breakage... this is a non-standard way to customize karaf.

2) Write a ConfigManagementFactory with a getPlatformMBeanServer() that does
the right thing in Karaf and just passes through to ManagementFactory.getPlatformMBeanServer() everywhere else. Replace all of our uses of ManagementFactory.getPlatformMBeanServer() with
ConfigManagementFactory.getPlatformMBeanServer().

Note... the right thing for karaf looks something like:

Map<String,String> h = new HashMap<String,String>();
h.put(Context.SECURITY_PRINCIPAL, “karaf");
h.put(Context.SECURITY_CREDENTIALS, “karaf");

JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
MBeanServerConnection con = connector.getMBeanServerConnection();
Where obviously rather than hardcode the username and password, we read them from properties.
http://karaf.apache.org/manual/latest/users-guide/monitoring.html gives you the URL, though it should also not
be hardcoded but rather obtained using ConfigAdmin service and load the org.apache.karaf.management config PID. Care should be taken to do this in a way that
does not break if run in our old container.
Disadvantage: Its work, but I don't think a lot of work.



 Comments   
Comment by Ed Warnicke [ 13/Jul/14 ]

This is the exception trace that you get if you use
https://git.opendaylight.org/gerrit/#/c/8963/

and in karaf do:

feature:install odl-config-startup

and wait a minute or so.

Comment by Ed Warnicke [ 13/Jul/14 ]

Attachment pastebin has been added with description: Exception trace

Comment by Ed Warnicke [ 13/Jul/14 ]

Side note: What's actually happening here is that Karaf introduced RBAC for JMX in 3.0, and its tweaked down so hard you really can't use ManagementFactory.getPlatformMBeanServer()

(I am honestly unqualified to know if its tweaked down too hard or not)

Comment by Ed Warnicke [ 13/Jul/14 ]

Correction to one liner for building and running karaf:

cd controller/opendaylight/distribution/opendaylight-karaf/;mvn clean install;cd target/;unzip -o distribution.opendaylight-karaf-1.4.2-SNAPSHOT.zip; cd distribution.opendaylight-karaf-1.4.2-SNAPSHOT/bin;./karaf

Comment by Robert Varga [ 18/Jul/14 ]

So I think we need to go for option #2, which I think will need to occur by installing a platform support bundle:

  • one for default JVMs
  • another for Karaf

Note that adding a remote connector may introduce failure modes which we have not accounted for (like, the connection going down).

Comment by Maros Marsalek [ 10/Sep/14 ]

Workaround is present in ODL and its being fixed in karaf 3.0.2 (according to Ed)

Generated at Wed Feb 07 19:53:28 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.