Bookmark this page

Guided Exercise: Configuring a Data Source

Create, configure, and test a MariaDB data source.

Resources
Files: /home/student/AD248/labs/datasources-defining
Application URL: N/A

Outcomes

You should be able to create and test a data source based on the MariaDB driver.

Before beginning the guided exercise, run the following command to prepare the environment:

[student@workstation ~]$ lab start datasources-defining

Instructions

  1. Start the standalone instance of JBoss EAP by running the following command, which uses /home/student/AD248/labs/datasources-defining/standalone as the base directory:

    [student@workstation ~]$ cd /opt/jboss-eap-7.4/bin
    [student@workstation bin]$ ./standalone.sh \
    -Djboss.server.base.dir=/home/student/AD248/labs/datasources-defining/standalone
  2. Configure and test the data source.

    1. On the workstation machine, open the management console by navigating to http://localhost:9990. Use admin as the username, and redhat123 as the password.

    2. Go to the Configuration page.

    3. Navigate to the datasources subsystem by clicking Subsystems and then Datasources & Drivers.

    4. Click Datasources, and then open the Datasource menu by clicking the + sign. Select the Add Datasource option.

    5. On the first window, select MariaDB and click Next.

    6. Enter the following data and click Next:

      • Name: test-ds

      • JNDI Name: java:jboss/datasources/test-ds

    7. Click Next to accept the following values in the JDBC Driver step.

      • Driver Name: mariadb

      • Driver Module Name: org.mariadb

      • Driver Class Name: org.mariadb.jdbc.Driver

    8. Complete the Connection step with the following data and click Next.

      • Connection URL: jdbc:mariadb://localhost:3306/lab_db

      • User Name: developer

      • Password: redhat123

    9. Click Test Connection to verify that the datasource has access to the database.

    10. Click Next to go to the Review step and then click Finish and Close to complete the process.

  3. Verify the data source configuration.

    1. In the terminal window where the server is running, look for the following log event:

      03:19:56,646 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Bound data source [java:jboss/datasources/test-ds]
    2. Start the management CLI in a new terminal window:

      [student@workstation ~]$ cd /opt/jboss-eap-7.4/bin
      [student@workstation bin]$ ./jboss-cli.sh
    3. Use the following command to see the newly added data source as well as the other fields that can be modified:

      [disconnected /] connect
      [standalone@localhost:9990] /subsystem=datasources/data-source=\
      test-ds:read-resource

      The output should look like the following:

      ...output omitted...
              "datasource-class" => undefined,
              "driver-class" => "org.mariadb.jdbc.Driver",
              "driver-name" => "mariadb",
              "elytron-enabled" => false,
              "enabled" => true,
              "enlistment-trace" => false,
              "exception-sorter-class-name" => "org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter",
              "exception-sorter-properties" => undefined,
              "flush-strategy" => undefined,
              "idle-timeout-minutes" => undefined,
              "initial-pool-size" => undefined,
              "jndi-name" => "java:jboss/datasources/test-ds",
              "jta" => true,
              "max-pool-size" => undefined,
              "mcp" => "org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool",
              "min-pool-size" => undefined,
              "new-connection-sql" => undefined,
      ...output omitted...
  4. Modify the data source.

    Configure some connection pool settings by using the management CLI and the management console to improve the database performance.

    1. Enter the following commands to view the current settings of the test-ds data source:

      [standalone@localhost:9990] cd /subsystem=datasources/data-source=test-ds
      [standalone@localhost:9990 data-source=test-ds] :read-resource(recursive=true)
      ...output omitted...
              "max-pool-size" => undefined,
              "mcp" => "org.jboss.jca.core...,
              "min-pool-size" => undefined
      ...output omitted...

      Notice that several of the attributes of the test-ds data source are undefined.

    2. Enter the following command to set the minimum pool size of the test-ds data source to 5:

      [standalone@localhost:9990 data-source=test-ds] :write-attribute\
      (name=min-pool-size,value=5)
      {
          "outcome" => "success",
          "response-headers" => {
              "operation-requires-reload" => true,
              "process-state" => "reload-required"
          }
      }
    3. Verify the previous change:

      [standalone@localhost:9990 data-source=test-ds] :read-resource(recursive=true)
      ...output omitted...
      "min-pool-size" => 5,
      ...output omitted...
    4. Return to the Configuration page of the management console.

    5. Click View next to test-ds.

    6. Click the Pool tab. Verify that Min Pool Size is 5.

    7. Click Edit and set the Max Pool Size to 20.

    8. Click Save to save your changes.

    9. Click Reload Required at the top of the page and then click Yes to reload the server.

  5. Open a terminal to verify that the changes you made using the CLI and the management console appear in the /home/student/AD248/labs/datasources-defining/standalone/configuration/standalone.xml configuration file.

    [student@workstation ~]$ grep -A 18 test-ds /home/student/\
    AD248/labs/datasources-defining/standalone/configuration/standalone.xml
        <datasource jndi-name="java:jboss/datasources/test-ds" pool-name="test-ds">
            <connection-url>jdbc:mariadb://localhost:3306/lab_db</connection-url>
            <driver-class>org.mariadb.jdbc.Driver</driver-class>
            <driver>mariadb</driver>
            <pool>
                <min-pool-size>5</min-pool-size>
                <max-pool-size>20</max-pool-size>
            </pool>
            <security>
                <user-name>developer</user-name>
                <password>redhat123</password>
            </security>
    ...output omitted...
        </datasource>
  6. Clean up.

    1. Exit the management CLI:

      [standalone@localhost:9990 data-source=test-ds] exit
    2. Stop the instance of JBoss EAP by pressing Ctrl+C in the terminal window that is running JBoss EAP.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish datasources-defining

Revision: ad248-7.4-18a9db2