OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.16k stars 597 forks source link

GA BLOG - Testing database connections in Open Liberty apps using Admin Center #24124

Open aknguyen7 opened 1 year ago

aknguyen7 commented 1 year ago

The information you provide here will be included in the Open Liberty GA release blog post (example), which will be published on openliberty.io/blog/, and potentially elsewhere, to promote this newly released feature/function of Open Liberty. For this post to be included in the GA issue please make sure that this is completed by the end of Friday following the GM (Wednesday). The beta and release blogs are created using automation and rely on you following the template's structure. DO NOT REMOVE/ALTER THE <GHA> TAGS THROUGHOUT THIS TEMPLATE.

Please provide the following information:

  1. If this was previously published in a beta blog post, then provide a link to it on the next line between the <GHA-BLOG-BETA-LINK> tags. If nothing has changed since the beta, you're done and can ommit the remaining steps. If you need to make updates/alterations to the beta content, then do all the steps.

    https://github.com/OpenLiberty/open-liberty/issues/23629
  2. Which Liberty feature(s) does your update relate to?

    Human-readable name (eg WebSockets feature):

          Admin Center feature
          Admin REST Connector feature
          MicroProfile OpenAPI feature
          JDBC feature

    Short feature name (eg websockets-1.0):

              <feature>adminCenter-1.0</feature>
              <feature>restConnector-2.0</feature>
              <feature>mpOpenApi-3.0</feature>
              <feature>jdbc-4.3</feature>

  3. Who is the target persona? Who do you expect to use the update? eg application developer, operations.

    operations and potentially application developer

  4. Provide a summary of the update, including the following points:

    • Looking for a simple way to test your database connections? In [Open Liberty 23.0.0.2], validate your connections using the Liberty Admin Center feature. The test connection will exercise the same code paths as your applications, giving you confidence in your server configuration. The Admin Center connection validation feature is enabled by REST APIs featured in this blog: https://openliberty.io/blog/2019/09/13/testing-database-connections-REST-APIs.html

    • For this example, we'll start by testing the server resource "DefaultDataSource" which is configured to connect to a Derby database using container authentication via an auth alias."

    Sample server.xml:

<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>adminCenter-1.0</feature>
        <feature>restConnector-2.0</feature>
        <feature>jdbc-4.3</feature>
        <feature>mpOpenApi-3.0</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint" httpPort="9080" httpsPort="9443"/>

    <library id="derby">
      <file name="${server.config.dir}/derby/derby.jar"/>
    </library>

    <dataSource id="DefaultDataSource">
      <jdbcDriver libraryRef="derby"/>
      <!-- Example properties referencing an in-memory Derby Embedded database -->
      <properties.derby.embedded databaseName="memory:defaultdb" createDatabase="create"/>
    </dataSource>

    <authData id="myAuth" user="dbuser" password="dbpass"/>

    <!-- Default SSL configuration enables trust for default certificates from the Java runtime --> 
    <ssl id="defaultSSLConfig" trustDefaultCerts="true"/>

    <remoteFileAccess>
       <writeDir>${server.config.dir}</writeDir>
    </remoteFileAccess>

    <basicRegistry id="basic">
       <user name="admin" password="adminpwd"/>
    </basicRegistry>

    <!-- Assign 'admin' to Administrator -->
    <administrator-role>
        <user>admin</user>
    </administrator-role>

</server>

In this server.xml example, you will need to add the derby jar to the server configuration or use your own database configuration.

At minimum you need:

        <feature>adminCenter-1.0</feature>
        <feature>restConnector-2.0</feature>
        <feature>mpOpenApi-3.0</feature>

In addition to JDBC you can also test connections to JCA, JMS and Cloudant resources.

       <feature>connectors-2.0</feature>
       <feature>cloudant-1.0</feature>
       <feature>messaging-3.0</feature>

Configure a Liberty server using the above server.xml for guidance and then start the server. Once started, you can check the logs to find the URL to navigate to the Admin Center. In the above example, you would navigate to the Admin Center using https://localhost:9443/adminCenter/.

Select Server Config tool. image

Select Server.xml to edit. image

Navigate to the resource you would like to test and click the Test button. image

Choose which type of authentication your application uses:

For applications that use container authentication: For this example, the config doesn't have default authentication specified on the datasource element nor are there any login modules configured, therefore you will need to specify an authentication alias by using the dropdown.

image

For applications that use application authentication, choose the 'Application authentication' tab and fill in a valid user name and password for the database resource.

image

If your application does not use a resource reference and you have not enableContainerAuthForDirectLookups="true" in the config element, then choose 'No resource reference' tab and fill in a valid user name and password for the database resource.

image

Click the 'Connection Test' button and results will be displayed at the bottom. A successful Connection Test will look like this:

image

A failed Connection Test will look like this:

image

What happens next?

lauracowen commented 1 year ago

Please use the relevant new issue template for these issues so that they are assigned to the correct people. Also to ensure that the relevant info is in there for the automation to work /cc @mbroz2