Deploy thorntail while database is down

28 views
Skip to first unread message

usta

unread,
May 25, 2020, 9:59:26 AM5/25/20
to Thorntail
Hey foks

So i am trying to make my application robust to database failures and errors. To this end i am trying to start my application without a running database, but the deployment errors out with:

WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 14) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
WARN  [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (ServerService Thread Pool -- 14) HHH000342: Could not obtain connection to query metadata : javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources...
ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 14) MSC000001: Failed to start service jboss.persistenceunit..... org.jboss.msc.service.StartException in service jboss.persistenceunit....: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

I can start the application when the database is running.

I am trying to follow The twelve-factor app methodology as a guideline to the application I am building, and in this instance i need to be able to start my application regardless of the status of the database. Furthermore should the database become unavailable the application should keep running and if the database becomes available again then the application should function without intervention needed.

Of course this requires error handling in the application code, but how do i configure thorntail to allow this behavior? and avoid the deployment crashing in the first place?

myds is defined via enviroment variables:

THORNTAIL_DATASOURCES_DATA_DASH_SOURCES_MYDS_DRIVER_DASH_NAME: postgresql
THORNTAIL_DATASOURCES_DATA_DASH_SOURCES_
MYDS_CONNECTION_DASH_URL: jdbc:postgresql://database:5432/postgres
THORNTAIL_DATASOURCES_DATA_DASH_SOURCES_
MYDS_USER_DASH_NAME: postgres
THORNTAIL_DATASOURCES_DATA_DASH_SOURCES_
MYDS_PASSWORD: postgres

The persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="myPU">
    <jta-data-source>java:jboss/datasources/myds</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>

    <properties>
      <property name="javax.persistence.jdbc.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <!-- DB Dialect -->
      <property name="hibernate.show_sql" value="true" /> <!-- Show SQL in console -->
      <property name="hibernate.format_sql" value="true" /> <!-- Show SQL formatted -->
    </properties>
  </persistence-unit>
</persistence>

The way i am currently accessing the database from code looks like this:

    import javax.persistence.PersistenceContext;
    import javax.persistence.EntityManager;

    @PersistenceContext(unitName = "myPU")
    EntityManager em;


Also i'm using Thorntail 2.6.0.FINAL

Thanks

Ladislav Thon

unread,
May 25, 2020, 10:29:15 AM5/25/20
to thor...@googlegroups.com

Hi,

I don't think Thorntail can affect this, this is a common behavior in WildFly.

I'm not sure what Hibernate does during deployment that requires connecting to the database -- perhaps it's trying to update the schema or something like that? There might be some configuration options to tune this.

If you can get this working with WildFly, then it should be easy to translate to Thorntail.

LT

--
You received this message because you are subscribed to the Google Groups "Thorntail" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thorntail+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thorntail/ba39a17d-a25c-4c07-adab-4b1f0b5c7908%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages