You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Andrei Petru Mura <ma...@gmail.com> on 2021/09/09 13:49:37 UTC

Getting spring status of Active bundle via JMX from Karaf 4.0.4

Hello,

In Karaf 4.0.4, I have my own bundles deployed using spring-dm. I would be
interested if there is a possibility to get the status of a bundle via JMX
as it is listed in karaf console.

In karaf, I get this:
karaf@root> list

285 | Active   |  80 | 1.0.0.SNAPSHOT | bundle-name

From my Java routine, I try to get the status via:

BundlesMBean mbeanProxy = JMX.newMBeanProxy(mbeanServer, bundlesObjName,
BundlesMBean.class, true);
TabularData tabularData = mbeanProxy.getBundles();

for (Object k : tabularData.keySet()) {
    // key from tabularData is a java.util.List
    Object[] key = ((List<?>) k).toArray();
    // CompositeData is a java.util.Map that hold properties
    // of a JMX entity
    CompositeData bundle = tabularData.get(key);
    String nameAttr = (String) bundle.get(BUNDLE_NAME_ATTR);
    String versionAttr = (String) bundle.get(BUNDLE_VERSION_ATTR);
    // checks if interested bundle
    if ( (nameAttr != null && nameAttr.equals("bundle-name"))
        && (versionAttr != null && versionAttr.equals("1.0.0.SNAPSHOT"))
    {
        // return bundle status taken as it is as java.lang.String
        // in karaf.
        return (String) bundle.get(BUNDLE_STATE_ATTR);
    }
}

The problem is that I always get null. Why this? and how can I make it so
that I get the Spring status?

Thanks,
Andrei

Re: Getting spring status of Active bundle via JMX from Karaf 4.0.4

Posted by JB Onofré <jb...@nanthrax.net>.
Bundle:diag doesn’t help ?

Anyway sure you can it programmatically by deploying your own bundle. But the problem is not jmx, ssh or code, it’s the fact we don’t provide spring-dm state service. So you would have to implement it yourself. 

Regards 
JB

> Le 10 sept. 2021 à 12:28, Andrei Petru Mura <ma...@gmail.com> a écrit :
> 
> 
> Yes, I intend to switch to blueprint, but not right now. Firstly I would need a solution to my problem. Is there any other way to access karaf remotely other than JMX and SSH console? I'm interested in a programmatic way. 
> 
> Thanks,
> Andrei
> 
>> On Fri, Sep 10, 2021 at 1:23 PM JB Onofré <jb...@nanthrax.net> wrote:
>> Hi
>> 
>> Karaf 4.0 is super old. Anyway we provided state for blueprint and SCR but not spring-dm. And spring-dm is now deprecated (replaced by blueprint). 
>> 
>> Any plan for you to move to blueprint ?
>> 
>> Regards 
>> JB
>> 
>>>> Le 10 sept. 2021 à 12:13, Andrei Petru Mura <ma...@gmail.com> a écrit :
>>>> 
>>> 
>>> Hi there,
>>> 
>>> Did my message reach out to you?
>>> 
>>> Thanks,
>>> Andrei
>>> 
>>>> On Thu, Sep 9, 2021 at 4:49 PM Andrei Petru Mura <ma...@gmail.com> wrote:
>>>> Hello,
>>>> 
>>>> In Karaf 4.0.4, I have my own bundles deployed using spring-dm. I would be interested if there is a possibility to get the status of a bundle via JMX as it is listed in karaf console.
>>>> 
>>>> In karaf, I get this:
>>>> karaf@root> list
>>>> 
>>>> 285 | Active   |  80 | 1.0.0.SNAPSHOT | bundle-name
>>>> 
>>>> From my Java routine, I try to get the status via:
>>>> 
>>>> BundlesMBean mbeanProxy = JMX.newMBeanProxy(mbeanServer, bundlesObjName, BundlesMBean.class, true);
>>>> TabularData tabularData = mbeanProxy.getBundles();
>>>> 
>>>> for (Object k : tabularData.keySet()) {
>>>>     // key from tabularData is a java.util.List
>>>>     Object[] key = ((List<?>) k).toArray();
>>>>     // CompositeData is a java.util.Map that hold properties
>>>>     // of a JMX entity
>>>>     CompositeData bundle = tabularData.get(key);
>>>>     String nameAttr = (String) bundle.get(BUNDLE_NAME_ATTR);
>>>>     String versionAttr = (String) bundle.get(BUNDLE_VERSION_ATTR);
>>>>     // checks if interested bundle
>>>>     if ( (nameAttr != null && nameAttr.equals("bundle-name"))
>>>>         && (versionAttr != null && versionAttr.equals("1.0.0.SNAPSHOT"))
>>>>     {
>>>>         // return bundle status taken as it is as java.lang.String
>>>>         // in karaf.
>>>>         return (String) bundle.get(BUNDLE_STATE_ATTR);
>>>>     }
>>>> }
>>>> 
>>>> The problem is that I always get null. Why this? and how can I make it so that I get the Spring status?
>>>> 
>>>> Thanks,
>>>> Andrei

Re: Getting spring status of Active bundle via JMX from Karaf 4.0.4

Posted by Andrei Petru Mura <ma...@gmail.com>.
Yes, I intend to switch to blueprint, but not right now. Firstly I would
need a solution to my problem. Is there any other way to access karaf
remotely other than JMX and SSH console? I'm interested in a programmatic
way.

Thanks,
Andrei

On Fri, Sep 10, 2021 at 1:23 PM JB Onofré <jb...@nanthrax.net> wrote:

> Hi
>
> Karaf 4.0 is super old. Anyway we provided state for blueprint and SCR but
> not spring-dm. And spring-dm is now deprecated (replaced by blueprint).
>
> Any plan for you to move to blueprint ?
>
> Regards
> JB
>
> Le 10 sept. 2021 à 12:13, Andrei Petru Mura <ma...@gmail.com> a
> écrit :
>
> 
> Hi there,
>
> Did my message reach out to you?
>
> Thanks,
> Andrei
>
> On Thu, Sep 9, 2021 at 4:49 PM Andrei Petru Mura <ma...@gmail.com>
> wrote:
>
>> Hello,
>>
>> In Karaf 4.0.4, I have my own bundles deployed using spring-dm. I would
>> be interested if there is a possibility to get the status of a bundle via
>> JMX as it is listed in karaf console.
>>
>> In karaf, I get this:
>> karaf@root> list
>>
>> 285 | Active   |  80 | 1.0.0.SNAPSHOT | bundle-name
>>
>> From my Java routine, I try to get the status via:
>>
>> BundlesMBean mbeanProxy = JMX.newMBeanProxy(mbeanServer, bundlesObjName,
>> BundlesMBean.class, true);
>> TabularData tabularData = mbeanProxy.getBundles();
>>
>> for (Object k : tabularData.keySet()) {
>>     // key from tabularData is a java.util.List
>>     Object[] key = ((List<?>) k).toArray();
>>     // CompositeData is a java.util.Map that hold properties
>>     // of a JMX entity
>>     CompositeData bundle = tabularData.get(key);
>>     String nameAttr = (String) bundle.get(BUNDLE_NAME_ATTR);
>>     String versionAttr = (String) bundle.get(BUNDLE_VERSION_ATTR);
>>     // checks if interested bundle
>>     if ( (nameAttr != null && nameAttr.equals("bundle-name"))
>>         && (versionAttr != null && versionAttr.equals("1.0.0.SNAPSHOT"))
>>     {
>>         // return bundle status taken as it is as java.lang.String
>>         // in karaf.
>>         return (String) bundle.get(BUNDLE_STATE_ATTR);
>>     }
>> }
>>
>> The problem is that I always get null. Why this? and how can I make it so
>> that I get the Spring status?
>>
>> Thanks,
>> Andrei
>>
>

Re: Getting spring status of Active bundle via JMX from Karaf 4.0.4

Posted by JB Onofré <jb...@nanthrax.net>.
Hi

Karaf 4.0 is super old. Anyway we provided state for blueprint and SCR but not spring-dm. And spring-dm is now deprecated (replaced by blueprint). 

Any plan for you to move to blueprint ?

Regards 
JB

> Le 10 sept. 2021 à 12:13, Andrei Petru Mura <ma...@gmail.com> a écrit :
> 
> 
> Hi there,
> 
> Did my message reach out to you?
> 
> Thanks,
> Andrei
> 
>> On Thu, Sep 9, 2021 at 4:49 PM Andrei Petru Mura <ma...@gmail.com> wrote:
>> Hello,
>> 
>> In Karaf 4.0.4, I have my own bundles deployed using spring-dm. I would be interested if there is a possibility to get the status of a bundle via JMX as it is listed in karaf console.
>> 
>> In karaf, I get this:
>> karaf@root> list
>> 
>> 285 | Active   |  80 | 1.0.0.SNAPSHOT | bundle-name
>> 
>> From my Java routine, I try to get the status via:
>> 
>> BundlesMBean mbeanProxy = JMX.newMBeanProxy(mbeanServer, bundlesObjName, BundlesMBean.class, true);
>> TabularData tabularData = mbeanProxy.getBundles();
>> 
>> for (Object k : tabularData.keySet()) {
>>     // key from tabularData is a java.util.List
>>     Object[] key = ((List<?>) k).toArray();
>>     // CompositeData is a java.util.Map that hold properties
>>     // of a JMX entity
>>     CompositeData bundle = tabularData.get(key);
>>     String nameAttr = (String) bundle.get(BUNDLE_NAME_ATTR);
>>     String versionAttr = (String) bundle.get(BUNDLE_VERSION_ATTR);
>>     // checks if interested bundle
>>     if ( (nameAttr != null && nameAttr.equals("bundle-name"))
>>         && (versionAttr != null && versionAttr.equals("1.0.0.SNAPSHOT"))
>>     {
>>         // return bundle status taken as it is as java.lang.String
>>         // in karaf.
>>         return (String) bundle.get(BUNDLE_STATE_ATTR);
>>     }
>> }
>> 
>> The problem is that I always get null. Why this? and how can I make it so that I get the Spring status?
>> 
>> Thanks,
>> Andrei

Re: Getting spring status of Active bundle via JMX from Karaf 4.0.4

Posted by Andrei Petru Mura <ma...@gmail.com>.
Hi there,

Did my message reach out to you?

Thanks,
Andrei

On Thu, Sep 9, 2021 at 4:49 PM Andrei Petru Mura <ma...@gmail.com>
wrote:

> Hello,
>
> In Karaf 4.0.4, I have my own bundles deployed using spring-dm. I would be
> interested if there is a possibility to get the status of a bundle via JMX
> as it is listed in karaf console.
>
> In karaf, I get this:
> karaf@root> list
>
> 285 | Active   |  80 | 1.0.0.SNAPSHOT | bundle-name
>
> From my Java routine, I try to get the status via:
>
> BundlesMBean mbeanProxy = JMX.newMBeanProxy(mbeanServer, bundlesObjName,
> BundlesMBean.class, true);
> TabularData tabularData = mbeanProxy.getBundles();
>
> for (Object k : tabularData.keySet()) {
>     // key from tabularData is a java.util.List
>     Object[] key = ((List<?>) k).toArray();
>     // CompositeData is a java.util.Map that hold properties
>     // of a JMX entity
>     CompositeData bundle = tabularData.get(key);
>     String nameAttr = (String) bundle.get(BUNDLE_NAME_ATTR);
>     String versionAttr = (String) bundle.get(BUNDLE_VERSION_ATTR);
>     // checks if interested bundle
>     if ( (nameAttr != null && nameAttr.equals("bundle-name"))
>         && (versionAttr != null && versionAttr.equals("1.0.0.SNAPSHOT"))
>     {
>         // return bundle status taken as it is as java.lang.String
>         // in karaf.
>         return (String) bundle.get(BUNDLE_STATE_ATTR);
>     }
> }
>
> The problem is that I always get null. Why this? and how can I make it so
> that I get the Spring status?
>
> Thanks,
> Andrei
>