I have this command, not touched since 2017 (because I stopped needing
it).

Is it possible to inject/access the BundleContext of the current bundle
in this class?

 @Command(scope="ukelonn", name="release-liquibase-lock", description = 
"Forcibly release the Liquibase changelog lock")
 @Service
 public class KarafReleaseLiquibaseLockCommand implements Action {
     @Reference
     UkelonnService ukelonn;

     @Override
     public Object execute() throws Exception {
         DataSource datasource = ukelonn.getDataSource();
         UkelonnLiquibase liquibase = new UkelonnLiquibase();
         try (Connection connection = datasource.getConnection()) {
             liquibase.forceReleaseLocks(connection);
         }
         System.out.println("Forcibly unlocked the Liquibase changelog lock"); 
// NOSONAR This is command output and should not go to a logger
         return null;
     }
 }

I need the BundleContext to be able to replace ClassLoaderResourceAccessor[1]
with OSGiResourceAccessor[2] to try fixing the following stack trace[3]
in karaf.log.

The liquibase setup seems to work, in spite of the stack trace, but it
looked like something that should be fixed, and changing to something
called OSGiResourceAccessor seemed like something that should be tried.

Thanks!


- Steinar

PS! For the curious I no longer need this command to clear the liquibase
changelog lock, because I figured out why the lock tended to get stuck:
karaf was occasionally brutally killed and restarted, sometimes in the
middle of the liquibase setup[4].


References:
[1] 
<https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/resource/ClassLoaderResourceAccessor.java#L19>
[2] 
<https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/resource/OSGiResourceAccessor.java#L6>
[3] 
<https://gist.github.com/steinarb/37b891b7e64df386e822b661991f5af0#file-karaf-log-L438>
[4] 
<https://steinar.bang.priv.no/2019/11/28/how-i-learnt-about-linux-oom-killer/>

Reply via email to