You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by sreeraaman <sr...@gmail.com> on 2015/08/26 17:29:20 UTC

Karaf Feature autoupdate

Dear All,

We have a requirement, wherein, all updates should happen automatically.
Our application is packaged as a custom karaf distro and run as a service in
the end-user environment. All the application specific bundles / features
are hosted in our nexus repo and the same is added to the
org.ops4j.pax.url.mvn.cfg file under the property
org.ops4j.pax.url.mvn.repositories. Hence, all bundle / feature resolution
will pickup our nexus repository.

Now, to enable an auto update for our application, we were thinking of the
following possibility.

Have a quartz scheduler that will run everyday at a pre-determined time and
trigger our AutoUpdater Service which is a SCR Component.

The component looks like this.

@Component(name="AppUpdater",provide=IAutoUpdater.class,immediate=true)
public class AutoUpdater implements IAutoUpdater{

//we inject the FeaturesService & MavenResolver (pax url aether)

FeaturesService featureService;
MavenResolver mavenResolver;

@Reference(service=MavenResolver.class,optional=false)
public void setMavenResolver(..){
..
}

@Reference(service=FeaturesService.class,optional=false)
public void setFeatureService(...){
..
}

The IAutoUpdater interface has a method with the following signature.

public void update(String[] featuresToUpdate);

In the implementation of the update method, we do the following:

public void update(String[] featuresToUpdate){
for (String feature:featuresToUpdate){
//Try to retrieve the feature by name
Feature f = featureService.getFeature(feature);
if (f != null) { // feature is already installed
  //we build the feature url. for eg.
mvn:mygroupid/feature/LATEST/features/xml //feature name &
  //artifact ids are the same.
 String featureUrl = buildFeatureUrl(feature);
  //This resolves and downloads the feature xml file
  File file = mavenResolver.resolve(featureUrl);
  //parse the xml to obtain the latest feature version.
  String latestVersion = parseFeatureFile(file);
  //compare the latestversion with the installed feature version.
  if (!f.getVersion().equals(latestVersion)){
    //feature requires an update.
    //remove the current feature
    featureService.uninstallFeature(feature);
   //remove the repository as well
  
featureService.removeRepository(featureService.getRepositoryUriFor(feature,
f.getVersion()), true);
   featureService.addRepository(file.toURI()); 
   featureService.installFeature(feature);
 else{
   //you are already running the latest version of the feature. leave it as
it is.
 }

} 

}

}


}


Just wanted to understand if this is the right way of doing it or is there
any other approach that can be
adopted.

Note: MavenResolver is available only as of pax-url-aether 2.4.1.

This solution would work only on karaf 3.0.4 +.

best regards
Sriraman.



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Feature-autoupdate-tp4042069.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Karaf Feature autoupdate

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

bundle:watch can use filtering to decide which bundle you update. It 
also triggers a refresh when required (and it's the case for the 
features resolver).

On Karaf 4 you can update feature as well but it's up to you to trigger it.

Regards
JB

On 08/27/2015 12:42 PM, sreeraaman wrote:
> hi JB,
>
> Thanks for the quick update. Just to elaborate,
>
> Our application is packaged as a set of features .
>
> For third party dependencies, there is a separate feature.
> For utility bundles, there is a separate feature.
> For the application, there is a separate feature.
>
> A change in any of these features should trigger an auto update.
>
> bundle:watch would be painful to do for all the bundles inside the above
> three features. Also, if a new bundle gets added to the above feature, then
> again, we will have to track it by entering the bundle:watch command from
> the karaf console.
>
> We want to avoid the end users from logging in via the karaf console and do
> something.
>
> Hope this clarifies.
>
> best regards
> Sriraman.
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Feature-autoupdate-tp4042069p4042092.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf Feature autoupdate

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Sriraman,

sorry to say but the features can't be "auto"-updated.

A feature.xml is more like a repository and is kind of static, therefore
you would need to register a new version of the feature.xml again
with a feature:repo-add

What can be done, though is to make sure you connect Karaf to an OBR (Karaf
Cave for example).
Now when you install or update a certain bundle it automatically can pull
in new requirements, updated external bundles etc.

Usually you want to have a stable enviroment for your application and not a
continous "re-deployment" unless you are talking of a CI/CD server.
In that case it usually is best to trigger the bundle update from the
outside.
Either from a "shell-script" with bundle:update or via JMX.
JMX can be "proxied" through to a REST call via Jolokia.


regards, Achim


2015-08-27 12:42 GMT+02:00 sreeraaman <sr...@gmail.com>:

> hi JB,
>
> Thanks for the quick update. Just to elaborate,
>
> Our application is packaged as a set of features .
>
> For third party dependencies, there is a separate feature.
> For utility bundles, there is a separate feature.
> For the application, there is a separate feature.
>
> A change in any of these features should trigger an auto update.
>
> bundle:watch would be painful to do for all the bundles inside the above
> three features. Also, if a new bundle gets added to the above feature, then
> again, we will have to track it by entering the bundle:watch command from
> the karaf console.
>
> We want to avoid the end users from logging in via the karaf console and do
> something.
>
> Hope this clarifies.
>
> best regards
> Sriraman.
>
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Karaf-Feature-autoupdate-tp4042069p4042092.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>



-- 

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>

Software Architect / Project Manager / Scrum Master

Re: Karaf Feature autoupdate

Posted by sreeraaman <sr...@gmail.com>.
hi JB,

Thanks for the quick update. Just to elaborate,

Our application is packaged as a set of features .

For third party dependencies, there is a separate feature.
For utility bundles, there is a separate feature.
For the application, there is a separate feature.

A change in any of these features should trigger an auto update. 

bundle:watch would be painful to do for all the bundles inside the above
three features. Also, if a new bundle gets added to the above feature, then
again, we will have to track it by entering the bundle:watch command from
the karaf console. 

We want to avoid the end users from logging in via the karaf console and do
something.

Hope this clarifies.

best regards
Sriraman.




--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Feature-autoupdate-tp4042069p4042092.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Karaf Feature autoupdate

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Why not using bundle:watch ?

Regards
JB

On 08/26/2015 05:29 PM, sreeraaman wrote:
> Dear All,
>
> We have a requirement, wherein, all updates should happen automatically.
> Our application is packaged as a custom karaf distro and run as a service in
> the end-user environment. All the application specific bundles / features
> are hosted in our nexus repo and the same is added to the
> org.ops4j.pax.url.mvn.cfg file under the property
> org.ops4j.pax.url.mvn.repositories. Hence, all bundle / feature resolution
> will pickup our nexus repository.
>
> Now, to enable an auto update for our application, we were thinking of the
> following possibility.
>
> Have a quartz scheduler that will run everyday at a pre-determined time and
> trigger our AutoUpdater Service which is a SCR Component.
>
> The component looks like this.
>
> @Component(name="AppUpdater",provide=IAutoUpdater.class,immediate=true)
> public class AutoUpdater implements IAutoUpdater{
>
> //we inject the FeaturesService & MavenResolver (pax url aether)
>
> FeaturesService featureService;
> MavenResolver mavenResolver;
>
> @Reference(service=MavenResolver.class,optional=false)
> public void setMavenResolver(..){
> ..
> }
>
> @Reference(service=FeaturesService.class,optional=false)
> public void setFeatureService(...){
> ..
> }
>
> The IAutoUpdater interface has a method with the following signature.
>
> public void update(String[] featuresToUpdate);
>
> In the implementation of the update method, we do the following:
>
> public void update(String[] featuresToUpdate){
> for (String feature:featuresToUpdate){
> //Try to retrieve the feature by name
> Feature f = featureService.getFeature(feature);
> if (f != null) { // feature is already installed
>    //we build the feature url. for eg.
> mvn:mygroupid/feature/LATEST/features/xml //feature name &
>    //artifact ids are the same.
>   String featureUrl = buildFeatureUrl(feature);
>    //This resolves and downloads the feature xml file
>    File file = mavenResolver.resolve(featureUrl);
>    //parse the xml to obtain the latest feature version.
>    String latestVersion = parseFeatureFile(file);
>    //compare the latestversion with the installed feature version.
>    if (!f.getVersion().equals(latestVersion)){
>      //feature requires an update.
>      //remove the current feature
>      featureService.uninstallFeature(feature);
>     //remove the repository as well
>
> featureService.removeRepository(featureService.getRepositoryUriFor(feature,
> f.getVersion()), true);
>     featureService.addRepository(file.toURI());
>     featureService.installFeature(feature);
>   else{
>     //you are already running the latest version of the feature. leave it as
> it is.
>   }
>
> }
>
> }
>
> }
>
>
> }
>
>
> Just wanted to understand if this is the right way of doing it or is there
> any other approach that can be
> adopted.
>
> Note: MavenResolver is available only as of pax-url-aether 2.4.1.
>
> This solution would work only on karaf 3.0.4 +.
>
> best regards
> Sriraman.
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Feature-autoupdate-tp4042069.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com