Glassfish JDBC Connection Pool to Mysql DB mounted on openshift - jdbc

First of all, English is not my native language, so I apologize in advance for any errors in my grammar.
What I'm trying to do is connect from a local hosted Glassfish Server, to a Mysql Database mounted in Openshift.
The server has already been mounted in Openshift, and I have been able to connect to it using MySQL Workbench over TCP/IP with SSH.
The problem comes with connecting from glassfish, when I try to ping the JDBC Connection Pool it gives me the following error:
Ping Connection Pool failed for jdbc/studygroup-pool. The connection could not be allocated: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Please check the server.log for more details.
What I have in domain.xml
<jdbc-connection-pool driver-classname="com.mysql.jdbc.Driver" name="jdbc/studygroup-pool" res-type="java.sql.Driver">
<property name="password" value="MysqlPassword"></property>
<property name="user" value="MysqlAdmin"></property>
<property name="URL" value="jdbc:mysql://127.13.73.130:3306/servicesstudygroup"></property>
</jdbc-connection-pool>
Is there anyway to give the ssh key to glassfish to connect that way?
I'm lost in what I have to change to connect to it. If there is any information missing, please tell me what I am missing and I will provide it.
This is what i get with rhc about portforwarding
Service Local
OpenShift
------- --------------- ---- -------------------
httpd 127.0.0.1:8080 => 127.13.73.131:8080
httpd 127.0.0.1:8081 => 127.13.73.133:8080
java 127.0.0.1:7600 => 127.13.73.129:7600
java 127.0.0.1:8082 => 127.13.73.129:8080
mongodb 127.0.0.1:27017 => 127.13.73.132:27017
mysql 127.0.0.1:3307 => 127.13.73.130:3306
-----------------------------------------------------------------------------------------------
And this is from env | grep MYSQL
SQL
OPENSHIFT_MYSQL_DIR=/var/lib/openshift/sshuser/mysql/
OPENSHIFT_MYSQL_DB_PORT=3306
OPENSHIFT_MYSQL_DB_HOST=127.13.73.130
OPENSHIFT_MYSQL_DB_PASSWORD=mysqlpassword
OPENSHIFT_MYSQL_IDENT=redhat:mysql:5.5:0.2.20
OPENSHIFT_MYSQL_DB_USERNAME=adminmysql
OPENSHIFT_MYSQL_DB_SOCKET=/var/lib/openshift/sshuser/mysql//socket/mysql.sock
OPENSHIFT_MYSQL_DB_URL=mysql://adminmysql:passwordmysql#127.13.73.130:3306/
OPENSHIFT_MYSQL_VERSION=5.5
OPENSHIFT_MYSQL_DB_LOG_DIR=/var/lib/openshift/sshuser/app-root/logs/
OPENSHIFT_MYSQL_LD_LIBRARY_PATH_ELEMENT=/opt/rh/mysql55/root/usr/lib64
The only thing that i have changed are the sshuser, mysql user and password.

Related

Hibernate/c3pO doesn't work under Tomcat - Windows 10: apparent deadlock

My app uses Hibernate and c3po, and isn't starting under windows 10 + eclipse Oxygen + Tomcat 8, while under Linux works fine with the same configuration.
These are some lines the console shows when starting Tomcat
2017/11/27 18:21:03 WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector#15cc07ce -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
This should a connection problem as reported here .
This seems confirmed by an exception I get:
2017/11/27 18:21:14 WARN com.mchange.v2.resourcepool.BasicResourcePool - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask#1e723184 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
org.postgresql.util.PSQLException: FATALE: the remaining connection slots are reserveed to non replica superusers connections
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:469)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
From postgresql log I see there are many connection until the db says it cannot allocate more. The connections are far above 10, while I have this in my hibernate.cfg.xml
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">3</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
psql -h localhost -U user db works fine
I used Wireshark and RawCap under Windows to capture the connections and it seems the connections are acquired, as the log says, but after seeing Postgres saying "ready for queries", they are closed, if I saw well.
What else can I look at to debug what's happening??
It turned out that I was using the wrong postgresql driver. I have java 8, and using PostgreSQL JDBC 4.2 Driver, 42.1.4 solved the issue.

Wildfly 10 for jms messaging

I tried a simple spring jms example and deployed in tomee worked fine (din't start activemq server). Then I migrated to wildfly 10. But here i need to start activemq server. Is it needed wildfly is already integrated with activemq right? On starting the server (standalone.bat) should start the activemq isn't?
EDIT: Actually some configuration has been changed (I was not aware of the change). I unzipped wildfly 10 again and tried to deploy using "standalone.bat -c standalone-full.xml". Server started successfully but got the below given error.
10:29:26,172 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final) started in 13367ms - Started 401 of 691 services (397 services are lazy, passive or on-demand)
10:29:29,101 INFO [org.springframework.jms.listener.DefaultMessageListenerContainer] (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) JMS message listener invoker needs to establish shared Connection
10:29:30,111 ERROR [org.springframework.jms.listener.DefaultMessageListenerContainer] (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) Could not refresh JMS Connection for destination 'myMessageQueue' - retrying in 5000 ms. Cause: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect
I managed to fix this problem by adding an embedded broker to my springcontext.xml
<amq:broker id="broker" useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:61617" />
</amq:transportConnectors>
</amq:broker>
Refered : http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html

Setting up a database in glassfish server 4.1

As specified in oracle documentation I'm trying to setup a database in glassfish server. my JDK version is 1.8 and the glassfish is 4.1. I'm using the ojdbc7.jar.
I've put the ojdbc into \glassfish\domains\domain1\lib\ext folder and re-started both server and the database. But when I try to ping, an error comes as:
Ping Connection Pool failed for TestPool. Connection could not be allocated because: IO Error: The Network Adapter could not establish the connection
in server.log I found:
2015-04-13T18:35:25.413+0530] [glassfish 4.1] [WARNING] [test.connection.pool.failed] [javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors.service] [tid: _ThreadID=45 _ThreadName=admin-listener(2)] [timeMillis: 1428930325413] [levelValue: 900] [[
RAR8054: Exception while creating an unpooled [test] connection for pool [ TestPool ], Connection could not be allocated because: IO Error: The Network Adapter could not establish the connection]]
But I can ping "Derby Pool" which is in glassfish by default successfully. I've setup all the Connection pool properties and JVM options as mentioned in the documents.
Can someone please help to setup this correctly?
Thanks in Advance.
The driver seems to have problems connecting to the oracle instance.
Make sure you can make the connection from the glassfish to the oracle server. Especially check the hostname / port (the default oracle portnumber is 1521).
Here's a snapshot of my setup:
But while trying to ping, I found these on server log:
RAR8054: Exception while creating an unpooled [test] connection for pool [ TEST ], Connection could not be allocated because: IO Error: The Network Adapter could not establish the connection]]
Is this due to a server error, because I'm using glassfish 4.1.

JDBC pooling Oracle driver Socket read timed out

I run Java EE application on Glassfish server v3 together with Oracle 12 DB on the same machine under Windows Server 2012 64bit. I use latest ojdbc7 driver.
Connection pool config:
<jdbc-connection-pool validation-table-name="DUAL" steady-pool-size="20" statement-cache-size="100" associate-with-thread="true" statement-timeout-in-seconds="30" idle-timeout-in-seconds="60" max-wait-time-in-millis="2000" validate-atmost-once-period-in-seconds="20" datasource-classname="oracle.jdbc.pool.OracleDataSource" pool-resize-quantity="5" max-pool-size="60" res-type="javax.sql.DataSource" name="dbPool" is-connection-validation-required="true">
<property name="driverClass" value="oracle.jdbc.OracleDriver"></property>
<property name="user" value="xxx"></property>
<property name="url" value="jdbc:oracle:thin:#(DESCRIPTION=(ENABLE=BROKEN)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)))"></property>
<property name="password" value="xxx"></property>
<property name="portNumber" value="1521"></property>
<property name="databaseName" value="orcl"></property>
<property name="serverName" value="127.0.0.1"></property>
<property name="oracle.jdbc.ReadTimeout" value="300000"></property>
<property name="oracle.net.CONNECT_TIMEOUT" value="10000"></property>
</jdbc-connection-pool>
After 2 or 3 hours, when there is more than 1 user (3-5) using my application, it stops responding and I get this in glassfish logs
javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator|_ThreadID=152;_ThreadName=Thread-2;|RAR5038:Unexpected exception while creating resource for pool dbPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: IO Error: Socket read timed out
[...]
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: IO Error: Socket read timed out
From the database side it looks like this
Fatal NI connect error 12560, connecting to:
(LOCAL=NO)
VERSION INFORMATION:
TNS for 64-bit Windows: Version 12.1.0.1.0 - Production
Oracle Bequeath NT Protocol Adapter for 64-bit Windows: Version 12.1.0.1.0 - Production
Windows NT TCP/IP NT Protocol Adapter for 64-bit Windows: Version 12.1.0.1.0 - Production
Time: 13-JUN-2014 03:14:49
Tracing not turned on.
Tns error struct:
ns main err code: 12560
TNS-12560: TNS:protocol adapter error
ns secondary err code: 0
nt main err code: 0
nt secondary err code: 0
nt OS err code: 0
opiodr aborting process unknown ospid (3404) as a result of ORA-609
When I just reset db listener everything works ok for next 1-2 hours (depends on application load). So temporary solution is to run bat script from windows scheduler to reset the listener every 1h.
I tried everything I could find - applied these parameters:
- Sqlnet.ora:
SQLNET.INBOUND_CONNECT_TIMEOUT=180
SQLNET.EXPIRE_TIME=5
- Listener.ora:
INBOUND_CONNECT_TIMEOUT_LISTENER_IPC=120
But still without success

not able to connect remote hiveserver2 using ip address

I am runnnig hive service hiveserver2 with following config in hive-site.xml
<property>
<name>hive.server2.thrift.bind.host</name>
<value>ip_address</value>
</property>
<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
</property>
From my local(same machine) jdbc client I am able to connect to hiveserver2
jdbc:hive2://id_address:10000/default
howerver when I run my jdbc client from other machine I am getting connection timeout issue.
Note that I am able to ping to hiveserver host with ip_address.
What could be issue? As I am using ip address still do I need to check entries in /etc/hosts?
Issue resolved
Issue was with firewall, hive configs were correct.
I disabled iptable for time being.
# services iptables stop
Following answer in following link was helpful for generic connection issues.
java.net.ConnectException :connection timed out: connect?

Resources