I have a products db configured on docker:
productsdb:
container_name: productsdb
volumes:
- productsdb_data1:/var/lib/mysql
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: "admin"
MYSQL_PASSWORD: "admin"
networks:
- commerce_net
ports:
- "3309:3306"
When I try to connect to this db from my spring boot project, the following exception is shown during server startup:
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: 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.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
... 33 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:609) ~[na:na]
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
... 36 common frames omitted
The application.properties are set to connect to host 'productsdb' as:
spring.datasource.url=jdbc:mysql://productsdb:3309/products?createDatabaseIfNotExist=true&useSSL=false
The server start was tried using docker compose as well as using the command:
docker run --network=commerce_net -p 8085:8085 producttest -d
Any possible reason why this exception could occur?
If you want to start your application in the same container as your database, you must use the container port instead of using the host port of your database. So the database address you use in the application should be:
spring.datasource.url=jdbc:mysql://productsdb:3306/products?createDatabaseIfNotExist=true&useSSL=false
The port definition in docker-compose.yml is made in the form of HOST:CONTAINER. That is why your first port refers to your host port, and the second one refers to your container port. You can access detailed information from the Docker documentation.
If springboot is also in same docker compose file then use MySQL port as 3306
If its in different docker compose file then please update your network to --network={db_compose_file_directory_name}_commerce_net and spring.datasource.url=jdbc:mysql://localhost:3309/products?createDatabaseIfNotExist=true&useSSL=false
Try to provide docker-compose file and complete docker run command for service
Related
I am trying to index Maven Repositories in IntelliJ so I can search for classes, but I get an error every time. I am using the latest version of IntelliJ. Why am I unable to update them?
This is what appears in the logs
2021-07-08 09:43:48,949 [70347579] WARN - #org.jetbrains.idea.maven - Failed to update Maven indices for: [central] https://repo.maven.apache.org/maven2
org.jetbrains.idea.maven.server.CannotStartServerException: Cannot connect to the Maven process. Try again later. If the problem persists, check the Maven Importing JDK settings and restart IntelliJ IDEA
at org.jetbrains.idea.maven.server.RemoteObjectWrapper.perform(RemoteObjectWrapper.java:84)
at org.jetbrains.idea.maven.server.MavenIndexerWrapper.createIndex(MavenIndexerWrapper.java:61)
at org.jetbrains.idea.maven.indices.MavenIndex.createContext(MavenIndex.java:382)
at org.jetbrains.idea.maven.indices.MavenIndex.updateOrRepair(MavenIndex.java:335)
at org.jetbrains.idea.maven.indices.MavenIndices.updateOrRepair(MavenIndices.java:128)
at org.jetbrains.idea.maven.indices.MavenIndicesManager.doUpdateIndices(MavenIndicesManager.java:324)
at org.jetbrains.idea.maven.indices.MavenIndicesManager$3.run(MavenIndicesManager.java:288)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:998)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsync$5(CoreProgressManager.java:497)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:228)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:178)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:688)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:634)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:64)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:165)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:228)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused (Connection refused)
at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:623)
at java.rmi/sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:209)
at java.rmi/sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:196)
at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:132)
at java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:217)
at java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:162)
at com.sun.proxy.$Proxy169.createIndexer(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.intellij.execution.rmi.RemoteUtil.invokeRemote(RemoteUtil.java:150)
at com.intellij.execution.rmi.RemoteUtil.access$400(RemoteUtil.java:21)
at com.intellij.execution.rmi.RemoteUtil$1.lambda$invoke$0(RemoteUtil.java:134)
at com.intellij.openapi.util.ClassLoaderUtil.computeWithClassLoader(ClassLoaderUtil.java:31)
at com.intellij.execution.rmi.RemoteUtil.executeWithClassLoader(RemoteUtil.java:202)
at com.intellij.execution.rmi.RemoteUtil$1.invoke(RemoteUtil.java:134)
at com.sun.proxy.$Proxy169.createIndexer(Unknown Source)
at org.jetbrains.idea.maven.server.MavenServerConnector.createIndexer(MavenServerConnector.java:61)
at org.jetbrains.idea.maven.server.MavenServerManager$6.create(MavenServerManager.java:474)
at org.jetbrains.idea.maven.server.MavenServerManager$6.create(MavenServerManager.java:461)
at org.jetbrains.idea.maven.server.RemoteObjectWrapper.getOrCreateWrappee(RemoteObjectWrapper.java:43)
at org.jetbrains.idea.maven.server.MavenIndexerWrapper.getRemoteId(MavenIndexerWrapper.java:154)
at org.jetbrains.idea.maven.server.MavenIndexerWrapper.lambda$createIndex$0(MavenIndexerWrapper.java:61)
at org.jetbrains.idea.maven.server.RemoteObjectWrapper.perform(RemoteObjectWrapper.java:78)
... 23 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.base/java.net.Socket.connect(Socket.java:609)
at java.base/java.net.Socket.connect(Socket.java:558)
at java.base/java.net.Socket.(Socket.java:454)
at java.base/java.net.Socket.(Socket.java:231)
at com.intellij.execution.rmi.RemoteServer$1.createSocket(RemoteServer.java:174)
at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:617)
... 47 more
Here is a screenshot of my Maven config:
I tried to migrate from the embedded derby database to PostgreSQL without success. I managed to get the connections settings on the system.yaml config but now it is failing on initialization with the following error: org.postgresql.util.PSQLException: ERROR: relation "artifactory_servers" does not exist
This is on artifactory version 7.6.3 running on Windows Server 2019, connecting to an Azure PosrgreSQL db instance
If I check on the Postgres server I see that a bunch of tables were created.
Full stack:
`021-03-07T17:53:22.467Z [1;32m[jfrt ][0;39m [1;31m[ERROR][0;39m [860e6cabc013fca9] [tifactoryHomeConfigListener:62] [ocalhost-startStop-2] - Failed initializing Home. Caught exception:
org.artifactory.storage.StorageException: Failed to get Artifactory server [artifactory]
at org.artifactory.storage.db.servers.service.ArtifactoryServersServiceImpl.getArtifactoryServer(ArtifactoryServersServiceImpl.java:68)
at org.artifactory.lifecycle.storage.db.servers.service.ArtifactoryServersCommonServiceImpl.getArtifactoryServer(ArtifactoryServersCommonServiceImpl.java:142)
at org.artifactory.state.ArtifactoryStateManagerUtil.createOrUpdateArtifactoryServerState(ArtifactoryStateManagerUtil.java:32)
at org.artifactory.lifecycle.storage.db.init.PostDbSchemaInitializationManager.createInitialServerState(PostDbSchemaInitializationManager.java:72)
at org.artifactory.lifecycle.storage.db.init.PostDbSchemaInitializationManager.convertAndInit(PostDbSchemaInitializationManager.java:63)
at org.artifactory.lifecycle.storage.db.init.HaInitLock.runInsideInitLockIfNeeded(HaInitLock.java:81)
at org.artifactory.lifecycle.storage.db.init.PostDbSchemaInitializationManager.init(PostDbSchemaInitializationManager.java:50)
at org.artifactory.lifecycle.webapp.servlet.BasicConfigurationManager.initArtifactoryInstallation(BasicConfigurationManager.java:141)
at org.artifactory.lifecycle.webapp.servlet.BasicConfigurationManager.initialize(BasicConfigurationManager.java:125)
at org.artifactory.lifecycle.webapp.servlet.ArtifactoryHomeConfigListener.contextInitialized(ArtifactoryHomeConfigListener.java:57)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4697)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5163)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:614)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1822)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "artifactory_servers" does not exist
Position: 15
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
at com.sun.proxy.$Proxy32.executeQuery(Unknown Source)
at org.jfrog.storage.JdbcHelper.executeSelect(JdbcHelper.java:120)
at org.jfrog.storage.JdbcHelper.executeSelect(JdbcHelper.java:92)
at org.artifactory.storage.db.servers.dao.ArtifactoryServersDao.getArtifactoryServer(ArtifactoryServersDao.java:74)
at org.artifactory.storage.db.servers.service.ArtifactoryServersServiceImpl.getArtifactoryServer(ArtifactoryServersServiceImpl.java:66)
... 22 common frames omitted`
This question already has answers here:
Docker Compose wait for container X before starting Y
(20 answers)
Closed 2 years ago.
I am new to Docker and I'm trying to dockerize my application. I'm using MySQL and Spring Boot.
When I use docker-compose up, a few exception occurs:
todoapp-container_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
todoapp-container_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_111]
todoapp-container_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_111]
todoapp-container_1 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_111]
and a little bit down:
todoapp-container_1 | Caused by: java.net.ConnectException: Connection refused (Connection refused)
todoapp-container_1 | at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_111]
todoapp-container_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_111]
todoapp-container_1 | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_111]
Here is my docker-compose:
version: '3'
services:
mysql-container:
image: mysql:8
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=todo
- MYSQL_PASSWORD=todo
- MYSQL_USER=todo
todoapp-container:
image: todoapp-service
ports:
- 8080:8080
build:
context: .
dockerfile: Dockerfile
depends_on:
- mysql-container
and my application.properties:
#SERVER
server.port=8080
#MYSQL
spring.datasource.url=jdbc:mysql://mysql-container:3306/todo?createDatabaseIfNotExist=true
spring.datasource.username=todo
spring.datasource.password=todo
spring.jpa.generate-ddl=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
#JACKSON SERIALIZATION FOR NULL FIELDS
spring.jackson.default-property-inclusion=non_null
The thing is, if I run docker-compose up for the second time, it works flawless without any exceptions and can use the postman for requests. I assume there is a problem at the moment when the containers are starting, I think I have to make the todoapp-container to wait until the mysql-container starts but I am not really sure about it.
You can control the order of service startup and shutdown with the depends_on option.
However, for startup Compose does not wait until a container is “ready” (whatever that means for your particular application) - only until it’s running.
To handle this, design your application to attempt to re-establish a connection to the database after a failure. If the application retries the connection, it can eventually connect to the database.
There are other suggestions in the official documentation that are worth to look at :)
I want to read a csv file that is available to Sftp server by using a cdap source plugin.
I came across FTP Batch Source plugin that does the same. But when running this i am getting below exception.
Caused by: java.io.IOException: No FileSystem for scheme: sftp
at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2798) ~[org.apache.hadoop.hadoop-common-2.8.0.jar:na]
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2809) ~[org.apache.hadoop.hadoop-common-2.8.0.jar:na]
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:100) ~[org.apache.hadoop.hadoop-common-2.8.0.jar:na]
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2848) ~[org.apache.hadoop.hadoop-common-2.8.0.jar:na]
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2830) ~[org.apache.hadoop.hadoop-common-2.8.0.jar:na]
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:389) ~[org.apache.hadoop.hadoop-common-2.8.0.jar:na]
at co.cask.hydrator.format.plugin.AbstractFileSource.prepareRun(AbstractFileSource.java:129) ~[na:na]
at co.cask.hydrator.format.plugin.AbstractFileSource.prepareRun(AbstractFileSource.java:63) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource$1.call(WrappedBatchSource.java:53) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource$1.call(WrappedBatchSource.java:50) ~[na:na]
at co.cask.cdap.etl.common.plugin.Caller$1.call(Caller.java:30) ~[na:na]
at co.cask.cdap.etl.common.plugin.StageLoggingCaller.call(StageLoggingCaller.java:40) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource.prepareRun(WrappedBatchSource.java:50) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource.prepareRun(WrappedBatchSource.java:36) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource$1.call(WrappedBatchSource.java:53) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource$1.call(WrappedBatchSource.java:50) ~[na:na]
at co.cask.cdap.etl.common.plugin.Caller$1.call(Caller.java:30) ~[na:na]
at co.cask.cdap.etl.common.plugin.StageLoggingCaller.call(StageLoggingCaller.java:40) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource.prepareRun(WrappedBatchSource.java:50) ~[na:na]
at co.cask.cdap.etl.common.plugin.WrappedBatchSource.prepareRun(WrappedBatchSource.java:36) ~[na:na]
at co.cask.cdap.etl.common.submit.SubmitterPlugin$3.run(SubmitterPlugin.java:83) ~[na:na]
at co.cask.cdap.internal.app.runtime.AbstractContext$2.run(AbstractContext.java:534) ~[na:na]
at co.cask.cdap.data2.transaction.Transactions$CacheBasedTransactional.finishExecute(Transactions.java:224) ~[na:na]
... 18 common frames omitted
I am using below version of libraries which is also a ristriction.
Hadoop - 2.7.3
Spark - 2.3.0
I also came across this question which suggest using this and setting proeprty fs.sftp.impl to org.apache.hadoop.fs.sftp.SFTPFileSystem will solve the issue but not sure how use above code and set this proeprty.
You need to set a file system properties under the Advanced section when using SFTP as the protocol:
{
"fs.sftp.impl": "org.apache.hadoop.fs.sftp.SFTPFileSystem"
}
The FTP plugin is deprecated to my understanding. Use the SFTP Action plugin instead and build a pipeline like so :
The idea is to first copy the file to the local file system of the runtime environment and then sink the file where you wish (GCS in my case).
I'm not sure what else I'm missing here, but my application is failing on start with:
Message : The connection attempt failed.
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:60) ~[flyway-core-5.2.4.jar!/:na]
at org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(DatabaseFactory.java:72) ~[flyway-core-5.2.4.jar!/:na]
at org.flywaydb.core.Flyway.execute(Flyway.java:1670) ~[flyway-core-5.2.4.jar!/:na]
at org.flywaydb.core.Flyway.migrate(Flyway.java:1356) ~[flyway-core-5.2.4.jar!/:na]
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar!/:2.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
... 26 common frames omitted
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.Driver.makeConnection(Driver.java:458) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.Driver.connect(Driver.java:260) ~[postgresql-42.2.6.jar!/:42.2.6]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar!/:na]
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56) ~[flyway-core-5.2.4.jar!/:na]
... 32 common frames omitted
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
at org.postgresql.core.PGStream.<init>(PGStream.java:75) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192) ~[postgresql-42.2.6.jar!/:42.2.6]
... 44 common frames omitted
My app.yaml is
runtime: java11
manual_scaling:
instances: 1
beta_settings:
cloud_sql_instances: recruiters-wtf:europe-west2:recruiters-wtf=tcp:5432
while my application.properties contains:
spring.datasource.url=jdbc:postgresql://172.17.0.1:5432/${DB_NAME:recruiters_wtf}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASS}
What else am I missing? The database is being successfully used by a Kubernetes deployment of the same application.
Following kurtisvg's answer, I change the connection string to:
spring.datasource.url=jdbc:postgresql://google/recruiters_wtf?cloudSqlInstance=recruiters-wtf:europe-west2:recruiters-wtf=tcp:5432&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=${DB_USER}&password=${DB_PASS}
I already had postgres-socket-factory installed. That change the error to:
Message : The connection attempt failed.
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:60) ~[flyway-core-5.2.4.jar!/:na]
at org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(DatabaseFactory.java:72) ~[flyway-core-5.2.4.jar!/:na]
at org.flywaydb.core.Flyway.execute(Flyway.java:1670) ~[flyway-core-5.2.4.jar!/:na]
at org.flywaydb.core.Flyway.migrate(Flyway.java:1356) ~[flyway-core-5.2.4.jar!/:na]
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar!/:2.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
... 26 common frames omitted
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.Driver.makeConnection(Driver.java:458) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.Driver.connect(Driver.java:260) ~[postgresql-42.2.6.jar!/:42.2.6]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar!/:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar!/:na]
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56) ~[flyway-core-5.2.4.jar!/:na]
... 32 common frames omitted
Caused by: java.io.IOException: No such file or directory
at jnr.unixsocket.UnixSocketChannel.doConnect(UnixSocketChannel.java:127) ~[jnr-unixsocket-0.23.jar!/:na]
at jnr.unixsocket.UnixSocketChannel.connect(UnixSocketChannel.java:136) ~[jnr-unixsocket-0.23.jar!/:na]
at jnr.unixsocket.UnixSocketChannel.open(UnixSocketChannel.java:68) ~[jnr-unixsocket-0.23.jar!/:na]
at com.google.cloud.sql.core.CoreSocketFactory.connect(CoreSocketFactory.java:180) ~[jdbc-socket-factory-core-1.0.15.jar!/:na]
at com.google.cloud.sql.postgres.SocketFactory.createSocket(SocketFactory.java:71) ~[postgres-socket-factory-1.0.15.jar!/:na]
at org.postgresql.core.PGStream.<init>(PGStream.java:67) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91) ~[postgresql-42.2.6.jar!/:42.2.6]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192) ~[postgresql-42.2.6.jar!/:42.2.6]
... 44 common frames omitted
As documented here:
App Engine standard enviroments do not support connecting to the Cloud
SQL instance using TCP. Your code should not try to access the
instance using an IP address (such as 127.0.0.1 or 172.17.0.1) unless
you have configured Serverless VPC Access.
First, you'll need to remove the beta_settings entry in your app.yaml file since:
it is intended for App Engine Flexible (and actually instruct the platform to spin up a sidecar container running the CloudSQL proxy, which you don't need with Socket Factory for JDBC)
the syntax you used with =tcp:5432 would actually instructs the CloudSQL proxy to connect via TCP port.
So your Base JDBC url should look like jdbc:postgresql://google/recruiters_wtf
Your full datasource url would be (note the removed =tcp:5432 part):
jdbc:postgresql://google/recruiters_wtf?cloudSqlInstance=recruiters-wtf:europe-west2:recruiters-wtf&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=${DB_USER}&password=${DB_PASS}
Finally, note that, as mentioned in the link I provided above:
The PostgreSQL standard requires the Unix socket to have a
.s.PGSQL.5432 suffix in the socket path. Some libraries apply this
suffix automatically, but others require you to specify the socket
path as follows: /cloudsql/INSTANCE_CONNECTION_NAME/.s.PGSQL.5432.
I'm seeing that you are using DB_NAME:recruiters_wtf, shoudn't that be DB_NAME?
Attempt to use: spring.cloud.gcp.sql.database-name if not.
Also please make sure to deploy with beta
Let me know.
It's likely that one of two things is occurring that allow your k8s cluster to connect:
1. You are using a Private IP
2. You are using a Public IP, and added your k8s cluster to the whitelist
If you are using a private IP to connect, you'll have to configure Serverless VPC Access to allow App Engine to connect.
If you are using a Public IP, you won't be able to add App Engine to your whitelist because there is no guarantee what IP it connects from. Instead, I suggest using the Cloud SQL JDBC Socket Factory to authenticate your connections instead.
Ensure that the service account for your service has one of the following IAM roles:
Cloud SQL Client (preferred)
Cloud SQL Editor
Cloud SQL Admin
Or, you can manually assign the following IAM permissions:
cloudsql.instances.connect
cloudsql.instances.get