2021-03-28

GKE OFBiz pod not connecting to Cloudsql database

Following this tutorial to connect OFBiz to a MySQL database.

I'm trying to create an OFBiz deployment with persistent storage where new pods will store and retrieve data from MySQL.

Dockerfile for OFBiz pods

FROM openjdk:8

RUN apt-get update && \
apt-get install -y gradle unzip wget vim

RUN wget https://downloads.apache.org/ofbiz/apache-ofbiz-17.12.05.zip && \
unzip apache-ofbiz-17.12.05

WORKDIR apache-ofbiz-17.12.05

RUN gradle wrapper && \
./gradlew cleanAll loadAll

# Allowing URL softwareroboteer
RUN sed -i -e 's/host-headers-allowed=/host-headers-allowed=$URL,/g' /apache-ofbiz-17.12.05/framework/security/config/security.properties

COPY entityengine.xml /apache-ofbiz-17.12.05/framework/entity/config/

CMD ["/apache-ofbiz-17.12.05/gradlew", "ofbiz"]

I am hosting everything on GCP with OFBiz inside a pod running on GKE and am using Google Cloud SQL as a managed MySQL service. I have Cloud SQL set up with a public IP at 34.75.32.160.

Preliminary SQL Commands

I ran the following commands on my database before starting OFBiz.

create database ofbiz;  
create database ofbizolap;  
create database ofbiztenant;  
use mysql;  
select database();  
create user ofbiz@localhost;  
create user ofbizolap@localhost;  
create user ofbiztenant@localhost;  
update user set password=PASSWORD("FAKEPASSWORD") where User='ofbiz';  
update user set password=PASSWORD("FAKEPASSWORD") where User='ofbizolap';  
update user set password=PASSWORD("FAKEPASSWORD") where User='ofbiztenant';  
grant all privileges on *.* to 'ofbiz'@localhost identified by 'ofbiz';  
grant all privileges on *.* to 'ofbizolap'@localhost identified by 'ofbizolap';  
grant all privileges on *.* to 'ofbiztenant'@localhost identified by 'ofbiztenant';

OFBiz Configuration with entityengine.xml

The data backend for ofbiz is configured inside a file entityengine.xml which I have configured in the following way:

Data Source Declarations

I declared three different datasources localmysql, localmysqlolap, and localmysqltenant each connecting to my Cloud SQL server with JDBC.

<datasource name="localmysql"
            helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
            field-type-name="mysql"
            check-on-start="true"
            add-missing-on-start="true"
            check-pks-on-start="false"
            use-foreign-keys="true"
            join-style="ansi-no-parenthesis"
            alias-view-columns="false"
            drop-fk-use-foreign-key-keyword="true"
            table-type="InnoDB"
            character-set="utf8"
            collate="utf8_general_ci">
        <read-data reader-name="tenant"/>
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <read-data reader-name="ext-test"/>
        <read-data reader-name="ext-demo"/>
        <inline-jdbc
                jdbc-driver="com.mysql.jdbc.Driver"
                jdbc-uri="jdbc:mysql://34.75.32.160/ofbiz?autoReconnect=true&amp;characterEncoding=UTF-8"
                jdbc-username="ofbiz"
                jdbc-password="<password>"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MySQL
                and had to set it to -1 in order to avoid this issue.
                For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
        <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
    </datasource>
    <datasource name="localmysqlolap"
            helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
            field-type-name="mysql"
            check-on-start="true"
            add-missing-on-start="true"
            check-pks-on-start="false"
            use-foreign-keys="true"
            join-style="ansi-no-parenthesis"
            alias-view-columns="false"
            drop-fk-use-foreign-key-keyword="true"
            table-type="InnoDB"
            character-set="utf8"
            collate="utf8_general_ci">
        <read-data reader-name="tenant"/>
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <read-data reader-name="ext-test"/>
        <read-data reader-name="ext-demo"/>
        <inline-jdbc
                jdbc-driver="com.mysql.jdbc.Driver"
                jdbc-uri="jdbc:mysql://34.75.32.160/ofbizolap?autoReconnect=true&amp;characterEncoding=UTF-8"
                jdbc-username="ofbizolap"
                jdbc-password="<password>"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MySQL
                and had to set it to -1 in order to avoid this issue.
                For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
        <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
    </datasource>
    <datasource name="localmysqltenant"
            helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO"
            field-type-name="mysql"
            check-on-start="true"
            add-missing-on-start="true"
            check-pks-on-start="false"
            use-foreign-keys="true"
            join-style="ansi-no-parenthesis"
            alias-view-columns="false"
            drop-fk-use-foreign-key-keyword="true"
            table-type="InnoDB"
            character-set="utf8"
            collate="utf8_general_ci">
        <read-data reader-name="tenant"/>
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <read-data reader-name="ext-test"/>
        <read-data reader-name="ext-demo"/>
        <inline-jdbc
                jdbc-driver="com.mysql.jdbc.Driver"
                jdbc-uri="jdbc:mysql://34.75.32.160/ofbiztenant?autoReconnect=true&amp;characterEncoding=UTF-8"
                jdbc-username="ofbiztenant"
                jdbc-password="<password>"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MySQL
                and had to set it to -1 in order to avoid this issue.
                For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
        <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
    </datasource>

Delegators

The delegators tell OFBiz which datasource to use for which functions (in this case: the functions are normal, olap, and tenant). There is one entry for the different ways we can run OFBiz: default, default-no-eca, and test.

I have it set up here to use the MySQL data sources I defined above.

    <delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
        <group-map group-name="org.apache.ofbiz" datasource-name="localmysql"/>
        <group-map group-name="org.apache.ofbiz.olap" datasource-name="localmysqlolap"/>
        <group-map group-name="org.apache.ofbiz.tenant" datasource-name="localsqltenant"/>
    </delegator>
    <!-- May be used when you create a service that manages many data for massive imports, this for performance reason or to escape functional cases --> 
    <delegator name="default-no-eca" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" entity-eca-enabled="false" distributed-cache-clear-enabled="false">
        <group-map group-name="org.apache.ofbiz" datasource-name="localmysql"/>
        <group-map group-name="org.apache.ofbiz.olap" datasource-name="localmysqlolap"/>
        <group-map group-name="org.apache.ofbiz.tenant" datasource-name="localmysqltenant"/>
    </delegator>

    <!-- Be sure that your default delegator (or the one you use) uses the same datasource for test. You must run "gradlew loadAll" before running "gradlew testIntegration" -->
    <delegator name="test" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main">
        <group-map group-name="org.apache.ofbiz" datasource-name="localmysql"/>
        <group-map group-name="org.apache.ofbiz.olap" datasource-name="localmysqlolap"/>
        <group-map group-name="org.apache.ofbiz.tenant" datasource-name="localmysqltenant"/>
    </delegator>

Error

When I run OFBiz with this configuration I receive the following HTTP 500 error:

java.lang.IllegalArgumentException: Could not get next sequenced ID for sequence name: Visit
    org.apache.ofbiz.entity.GenericDelegator.getNextSeqId(GenericDelegator.java:2280)
    org.apache.ofbiz.entity.GenericDelegator.getNextSeqId(GenericDelegator.java:2268)
    org.apache.ofbiz.entity.GenericEntity.setNextSeqId(GenericEntity.java:657)
    org.apache.ofbiz.entity.GenericDelegator.createSetNextSeqId(GenericDelegator.java:771)
    org.apache.ofbiz.webapp.stats.VisitHandler.getVisit(VisitHandler.java:187)
    org.apache.ofbiz.webapp.stats.VisitHandler.getVisitId(VisitHandler.java:100)
    org.apache.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:201)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:686)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    org.apache.ofbiz.webapp.control.SameSiteFilter.doFilter(SameSiteFilter.java:44)
    org.apache.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:191)
    org.apache.ofbiz.webapp.control.ControlFilter.doFilter(ControlFilter.java:157)
    org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)

Kubernetes error logs

Using kubectl logs $POD, here is one of the errors that shows up. All of the errors are related to jdbc driver it seems.

2021-03-27 23:33:50,408 |OFBiz-JobPoller      |DBCPConnectionFactory         |E| null
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_282]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_282]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_282]
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_282]
    at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_282]
    at org.apache.ofbiz.entity.connection.DBCPConnectionFactory.getConnection(DBCPConnectionFactory.java:90) [ofbiz.jar:?]
    at org.apache.ofbiz.entity.transaction.GeronimoTransactionFactory.getConnection(GeronimoTransactionFactory.java:79) [ofbiz.jar:?]
    at org.apache.ofbiz.entity.jdbc.SQLProcessor.getConnection(SQLProcessor.java:261) [ofbiz.jar:?]
    at org.apache.ofbiz.entity.jdbc.SQLProcessor.prepareStatement(SQLProcessor.java:367) [ofbiz.jar:?]
    at org.apache.ofbiz.entity.datasource.GenericDAO.selectCountByCondition(GenericDAO.java:1049) [ofbiz.jar:?]
    at org.apache.ofbiz.entity.datasource.GenericHelperDAO.findCountByCondition(GenericHelperDAO.java:157) [ofbiz.jar:?]
    at org.apache.ofbiz.entity.GenericDelegator.findCountByCondition(GenericDelegator.java:1694) [ofbiz.jar:?]
    at org.apache.ofbiz.entity.GenericDelegator.findCountByCondition(GenericDelegator.java:1653) [ofbiz.jar:?]
    at org.apache.ofbiz.service.job.JobManager.isAvailable(JobManager.java:154) [ofbiz.jar:?]
    at org.apache.ofbiz.service.job.JobPoller$JobManagerPoller.run(JobPoller.java:223) [ofbiz.jar:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_282]```


from Recent Questions - Stack Overflow https://ift.tt/2PxsTHi
https://ift.tt/eA8V8J

No comments:

Post a Comment