What's the current model for console commands?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What's the current model for console commands?

Steinar Bang
I need to create a very simple console command to provide a way to
forcibly unlock a liquibase changelog lock (can be left in place as
locked if the liquibase update code crashes during a changelog update).

However I have a hard time figuring out how to do this.

The descriptions that google digs up are very much out of date.
  https://karaf.apache.org/manual/latest-2.x/developers-guide/extending-console.html
  http://icodebythesea.blogspot.no/2011/11/creating-your-own-apache-karaf-console.html

The classes these documents refer to have changed their package names,
have been deprecated for the last 3 years, as a fix for this issue:
  https://issues.apache.org/jira/browse/KARAF-2805

What I would have liked to do, was to register an OSGi service and have
karaf pick it up.  But that sounds like the whiteboarding pattern and
that ended up as a won't fix:
  https://issues.apache.org/jira/browse/KARAF-2762

Is the current way, the following?
 1. Create a class that implements the interface
    org.apache.karaf.shell.api.action.Action
 2. Add a @Service annotation to the class
 3. Karaf will find an instantiate this class

(If so, then that's not ideal, because then that action class will need
to use some kind of singleton to get to the OSGi services it needs...)

Thanks!


- Steinar

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the current model for console commands?

jbonofre
Hi Steinar,

you can take a look on the documentation:

http://karaf.apache.org/manual/latest/#_console_3

Especially the "By hand" section which is up to date.

You will see the annotations from the new Shell API, including the @Service
"new" one.

As a complete example, you can take a look on any Karaf internal commands.

Regards
JB

On 07/18/2017 05:24 PM, Steinar Bang wrote:

> I need to create a very simple console command to provide a way to
> forcibly unlock a liquibase changelog lock (can be left in place as
> locked if the liquibase update code crashes during a changelog update).
>
> However I have a hard time figuring out how to do this.
>
> The descriptions that google digs up are very much out of date.
>    https://karaf.apache.org/manual/latest-2.x/developers-guide/extending-console.html
>    http://icodebythesea.blogspot.no/2011/11/creating-your-own-apache-karaf-console.html
>
> The classes these documents refer to have changed their package names,
> have been deprecated for the last 3 years, as a fix for this issue:
>    https://issues.apache.org/jira/browse/KARAF-2805
>
> What I would have liked to do, was to register an OSGi service and have
> karaf pick it up.  But that sounds like the whiteboarding pattern and
> that ended up as a won't fix:
>    https://issues.apache.org/jira/browse/KARAF-2762
>
> Is the current way, the following?
>   1. Create a class that implements the interface
>      org.apache.karaf.shell.api.action.Action
>   2. Add a @Service annotation to the class
>   3. Karaf will find an instantiate this class
>
> (If so, then that's not ideal, because then that action class will need
> to use some kind of singleton to get to the OSGi services it needs...)
>
> Thanks!
>
>
> - Steinar
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the current model for console commands?

jbonofre
In reply to this post by Steinar Bang
By the way, extended and new samples are coming with the "new" dev guide (that
will be available pretty soon).

Regards
JB

On 07/18/2017 05:24 PM, Steinar Bang wrote:

> I need to create a very simple console command to provide a way to
> forcibly unlock a liquibase changelog lock (can be left in place as
> locked if the liquibase update code crashes during a changelog update).
>
> However I have a hard time figuring out how to do this.
>
> The descriptions that google digs up are very much out of date.
>    https://karaf.apache.org/manual/latest-2.x/developers-guide/extending-console.html
>    http://icodebythesea.blogspot.no/2011/11/creating-your-own-apache-karaf-console.html
>
> The classes these documents refer to have changed their package names,
> have been deprecated for the last 3 years, as a fix for this issue:
>    https://issues.apache.org/jira/browse/KARAF-2805
>
> What I would have liked to do, was to register an OSGi service and have
> karaf pick it up.  But that sounds like the whiteboarding pattern and
> that ended up as a won't fix:
>    https://issues.apache.org/jira/browse/KARAF-2762
>
> Is the current way, the following?
>   1. Create a class that implements the interface
>      org.apache.karaf.shell.api.action.Action
>   2. Add a @Service annotation to the class
>   3. Karaf will find an instantiate this class
>
> (If so, then that's not ideal, because then that action class will need
> to use some kind of singleton to get to the OSGi services it needs...)
>
> Thanks!
>
>
> - Steinar
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the current model for console commands?

Steinar Bang
In reply to this post by jbonofre
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> Hi Steinar,
> you can take a look on the documentation:

> http://karaf.apache.org/manual/latest/#_console_3

Thanks!

The HelloShellCommand sample seems easy to follow.

I've now also read the javadoc here:
 https://github.com/apache/karaf/blob/master/shell/core/src/main/java/org/apache/karaf/shell/api/action/Action.java#L21

In short:
 1. Implement the Action interface in a class with a no-argument constructor
 2. Annotate the implementation with @Command
 3. Annotate the implementation with @Service
 4. Create fields for the OSGi services needed and annotate these fields
    with @Reference

Karaf will then instantiate the class as needed and provide the OSGi
services (so there is no need to mess around with singletons).

> Especially the "By hand" section which is up to date.


> You will see the annotations from the new Shell API, including the
> @Service "new" one.

> As a complete example, you can take a look on any Karaf internal commands.

Ok, thanks.  I will try just the simple approach first. :-)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the current model for console commands?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:
>>>>> Jean-Baptiste Onofré <[hidden email]>:

>> Hi Steinar,
>> you can take a look on the documentation:

>> http://karaf.apache.org/manual/latest/#_console_3

> Thanks!

> The HelloShellCommand sample seems easy to follow.

> I've now also read the javadoc here:
>  https://github.com/apache/karaf/blob/master/shell/core/src/main/java/org/apache/karaf/shell/api/action/Action.java#L21

> In short:
>  1. Implement the Action interface in a class with a no-argument constructor
>  2. Annotate the implementation with @Command
>  3. Annotate the implementation with @Service
>  4. Create fields for the OSGi services needed and annotate these fields
>     with @Reference

> Karaf will then instantiate the class as needed and provide the OSGi
> services (so there is no need to mess around with singletons).

Forgot one thing:
 5. Add a Karaf-Commands manifest header:
     http://karaf.apache.org/manual/latest/#_manifest

But after that it worked like a charm.
  https://github.com/steinarb/ukelonn/blob/work/use-liquibase/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/KarafReleaseLiquibaseLockCommand.java

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the current model for console commands?

jbonofre
By the way, the karaf service maven plugin can update the MANIFEST for you, no
need to do it by hand.

Regards
JB

On 07/18/2017 11:33 PM, Steinar Bang wrote:

>>>>>> Steinar Bang <[hidden email]>:
>>>>>> Jean-Baptiste Onofré <[hidden email]>:
>
>>> Hi Steinar,
>>> you can take a look on the documentation:
>
>>> http://karaf.apache.org/manual/latest/#_console_3
>
>> Thanks!
>
>> The HelloShellCommand sample seems easy to follow.
>
>> I've now also read the javadoc here:
>>   https://github.com/apache/karaf/blob/master/shell/core/src/main/java/org/apache/karaf/shell/api/action/Action.java#L21
>
>> In short:
>>   1. Implement the Action interface in a class with a no-argument constructor
>>   2. Annotate the implementation with @Command
>>   3. Annotate the implementation with @Service
>>   4. Create fields for the OSGi services needed and annotate these fields
>>      with @Reference
>
>> Karaf will then instantiate the class as needed and provide the OSGi
>> services (so there is no need to mess around with singletons).
>
> Forgot one thing:
>   5. Add a Karaf-Commands manifest header:
>       http://karaf.apache.org/manual/latest/#_manifest
>
> But after that it worked like a charm.
>    https://github.com/steinarb/ukelonn/blob/work/use-liquibase/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/KarafReleaseLiquibaseLockCommand.java
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Loading...