WebSphere Application Server & Liberty

 View Only
  • 1.  Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    IBM Champion
    Posted Wed June 22, 2022 03:47 AM
    Hi everyone!
    When writing a feature, I found out that one of my features may NOT have

    <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>

    ... to work properly, while another feature, which is to start between datasources and the application actually needs this to work properly.
    This is the documentation I used:  Liberty feature manifest files - IBM Documentation

    There does not seem to be much of a documentation about the bundle manifest files, however.

    ---

    The second question is about Subsystem-Content.
    When I write some other features into Subsystem-Content and then uninstall that feature again, the features mentioned in subsystem-content are also uninstalled. This is my SUBSYSTEM.MF file snippet:

    Subsystem-Content: my.company.feature;version="[${parsedVersion.osgiVersion},${parsedVersion.osgiVersion}]";start-order:="1";start-phase=CONTAINER_LATE,
    com.ibm.websphere.appserver.servlet-3.1; ibm.tolerates:="3.0, 4.0"; type="osgi.subsystem.feature",
    com.ibm.websphere.appserver.jsp-2.3; type="osgi.subsystem.feature",
    com.ibm.websphere.appserver.jndi-1.0; type="osgi.subsystem.feature",
    com.ibm.wsspi.appserver.webBundle-1.0; type="osgi.subsystem.feature",
    com.ibm.websphere.appserver.spi.kernel.service;version="[1.3,2.0)"
    Now, when I uninstall that feature, the kernel service gets uninstalled. Along with it: all the binaries belonging to it, e.g. featureManager, productInfo scripts etc.
    What did I do wrong here?

    ------------------------------
    ------------------------------
    Benjamin Marwell
    System Engineer // IBM Champion // Apache Shiro PMC
    Finanz Informatik
    ------------------------------
    ------------------------------


  • 2.  RE: Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    Posted Fri July 01, 2022 11:24 AM
    Edited by THOMAS JOHNSON Fri July 01, 2022 11:26 AM

    Hey Benjamin,

    These are great questions, thank you! I wouldn't call myself a bnd tools, or OSGi expert, but I've worked with both these pieces in my years of Liberty development so I thought I'd try lending a hand to get to the bottom of this.

    To your first question, the lazy activation of a bundle. In the bnd tools world, using the lazy bundle activation policy means that a bundle isn't started until after the first request to load a class. According to the bnd tools documentation, the request can come from either normal class loading or from a bundle's loadClass method. You can view that documentation here: Bnd Tools Activation Policy Documentation

    Without knowing more about what's in those two features, I'm going to make some assumptions. I'd bet that the behavior your seeing, where one feature needs eager initialization (the default) while another needs lazy initialization, probably has to do with what the features are providing (i.e. it's bundles startup can't be deferred because another feature depends on what it's providing).

    In regards the Subsystem-Content header, lets use the jsp-2.3 feature as an example.  If your feature is starting,  and has marked the jsp-2.3 feature as Subsystem-Content, the framework will check to see if jsp-2.3 is already loaded by another feature or defined by you via server.xml configuration. If not already loaded, then the framework will start jsp-2.3 for your feature. The same is true for when the feature is stopped, meaning if you don't have jsp-2.3 defined in your server.xml and no other feature needs jsp-2.3, then the framework will stop it along with your feature and any other Subsystem-Content features that are no longer needed.

    If you want a feature to keep running even after the feature that uses it has stopped, all you need to do is add it the list of features in the server.xml. If jsp-2.3 was the feature you wanted to remain up after you stop your feature, then it'd look something like this: 

    <server>
       <featureManager>
           <feature>yourFeature-1.0</feature>
           <feature>jsp-2.3</feature>
       <featureManager>
    <server>

    The caveat here is that only features denoted as public can be defined in the server.xml. See the visibility section of the Liberty feature manifest files link you pointed to for more info on that.  Hopefully that helps clarify, if not let me know and I'll get you some real help!

    Thanks again for reaching out!



    ------------------------------
    THOMAS JOHNSON
    ------------------------------



  • 3.  RE: Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    IBM Champion
    Posted Tue July 05, 2022 02:53 AM
    Hi Thomas!

    Thanks for the clarification! Yes, it is what I thought, too. But it does not add up (for me).

    Here's my first feature, which is public: bmarwell/cowsay-liberty-feature: Cowsay for YOUR Liberty! (github.com)
    I created it as a showcase feature (how to create a feature). BUT. It does not depend on other features. The moment I add "lazy", it will not start -- even though it is defined in the server.xml file. I think this behaviour DOES make sense, because there is no external class loading any of my classes.

    Now, the other feature is a datasource extension. It has a simple UI and thus is using JSP+EL+JNDI. Why JNDI not JPA/JDBC? Because it is all we need: We scan for JNDI names only. It is supposed to find datasources the moment it gets activated.
    If I use eager init, then it will never find datasources. There is no possible start time I could find (CONTAINER_LATE / APP_EARLY) where the datasources *ARE* available. So with lazy initialisation, it seems hacky: The moment the web applications are started, including the datasource extension's UI, it gets loaded. At that time, datasources ARE available, so it finds them.
    From what I have read: There should (maybe) be a point where datasources are initialized, so I can use eager initialization and a better and more specific bundle load time?

    Oh and another hint. I removed the other features as a dependency from "Subsystem-Content". If I do specify them and uninstall my feature, the other features get uninstalled along with it making liberty unusable (even no FeatureManager left to reinstall them, no JSP, etc.). That is probably a bug or at least not intended?

    Thanks,
    Ben

    ------------------------------
    ------------------------------
    Benjamin Marwell
    System Engineer // IBM Champion // Apache Shiro PMC
    Finanz Informatik
    ------------------------------
    ------------------------------



  • 4.  RE: Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    User Group Leader
    Posted Mon July 11, 2022 09:25 AM
    About the "Subsystem-Content".  Feature manager is part of the kernel and should not be able to be uninstalled when your feature gets removed.  What features are you including?  It seems you are observing that if you enable your feature (by including it in the feature.xml), then disable it while Liberty is running then your feature gets uninstalled along with the feature manager.  Then if you try to enable your feature again (or any other feature) the newly enabled features are not installed again and Liberty is left in a non-functional state.  If that is true then please open an issue with steps to reproduce.

    For the lazy activation.  Generally we recommend the use of Declarative Service components instead of a bundle activator.  With DS the service components can have dependencies that will delay their activation until all their dependencies are satisfied.  It is unclear what code in your bundle is trying to access a data source.  I assume you are trying to access it with JNDI from your description.  Perhaps you could wait until a DataSource OSGi service is available before trying to look for it?

    ------------------------------
    Tom Watson
    ------------------------------



  • 5.  RE: Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    IBM Champion
    Posted Tue July 12, 2022 02:50 AM
    > then disable it while Liberty is running

    ... no. When I UNINSTALL a feature by using the featureManager or similar utilities, then afterwards the tools from the bin/ directory are also gone.
    I had added this:

    Subsystem-Content: my.util.feature;version="[${parsedVersion.osgiVersion},${parsedVersion.osgiVersion}]";start-order:="1";start-phase=CONTAINER_LATE,com.ibm.websphere.appserver.servlet-3.1; ibm.tolerates:="3.0, 4.0"; type="osgi.subsystem.feature",com.ibm.websphere.appserver.jsp-2.3; type="osgi.subsystem.feature",com.ibm.websphere.appserver.jndi-1.0; type="osgi.subsystem.feature",com.ibm.wsspi.appserver.webBundle-1.0; type="osgi.subsystem.feature"

    > Generally we recommend the use of Declarative Service components instead of a bundle activator.

    I read all the IBM pages a dozen of times but somehow only came across the Activator. Will look into it: Composing advanced features by using OSGi Declarative Services - IBM Documentation. But from that I still cannot see how to wait for any DataSource to be available. I'd be happy for a hint.




    ------------------------------
    ------------------------------
    Benjamin Marwell
    System Engineer // IBM Champion // Apache Shiro PMC
    Finanz Informatik
    ------------------------------
    ------------------------------



  • 6.  RE: Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    User Group Leader
    Posted Tue July 12, 2022 09:28 AM
    The behavior of featureManager sounds wrong to me.  An issue likely needs to be opened for that.  Are you using Open Liberty or Websphere Liberty?

    See https://github.ibm.com/websphere/xwiki-washome-websphere-most/wiki/LibertyCookbook_Using_Declarative_Services_to_get_a_DataSource that describes how components can use declarative services to require a data source.


    ------------------------------
    Tom Watson
    ------------------------------



  • 7.  RE: Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    IBM Champion
    Posted Tue July 12, 2022 09:38 AM
    Hey Tom,

    I am not an IBMer. I do not have access to that site!

    ------------------------------
    ------------------------------
    Benjamin Marwell
    System Engineer // IBM Champion // Apache Shiro PMC
    Finanz Informatik
    ------------------------------
    ------------------------------



  • 8.  RE: Liberty Features: Bundle-ActivationPolicy: lazy and Subsystem-Content

    User Group Leader
    Posted Tue July 12, 2022 09:59 AM
      |   view attached
    Sorry about that, I didn't check that the page was publicly available.  I just uploaded a PDF of the content of that page.  It should be migrated to open liberty wiki in my opinion.

    ------------------------------
    Tom Watson
    ------------------------------