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
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
Configure and test the data source.
On the workstation machine, open the management console by navigating to http://localhost:9990.
Use admin as the username, and redhat123 as the password.
Go to the page.
Navigate to the datasources subsystem by clicking and then .
Click , and then open the menu by clicking the sign. Select the option.
On the first window, select and click .
Enter the following data and click :
Name: test-ds
JNDI Name: java:jboss/datasources/test-ds
Click to accept the following values in the step.
Driver Name: mariadb
Driver Module Name: org.mariadb
Driver Class Name: org.mariadb.jdbc.Driver
Complete the step with the following data and click .
Connection URL: jdbc:mariadb://localhost:3306/lab_db
User Name: developer
Password: redhat123
Click to verify that the datasource has access to the database.
Click to go to the step and then click and to complete the process.
Verify the data source configuration.
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]
Start the management CLI in a new terminal window:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./jboss-cli.sh
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...
Modify the data source.
Configure some connection pool settings by using the management CLI and the management console to improve the database performance.
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.
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" } }
Verify the previous change:
[standalone@localhost:9990 data-source=test-ds]:read-resource(recursive=true)...output omitted... "min-pool-size" =>5, ...output omitted...
Return to the page of the management console.
Click next to .
Click the tab. Verify that is 5.
Click and set the to 20.
Click to save your changes.
Click at the top of the page and then click to reload the server.
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>
Clean up.
Exit the management CLI:
[standalone@localhost:9990 data-source=test-ds] exitStop the instance of JBoss EAP by pressing Ctrl+C in the terminal window that is running JBoss EAP.