3 Replies Latest reply on Oct 7, 2019 10:50 AM by Ramesh Reddy

    Teiid 12.2 dockerized unable to connect to mongodb instance on Atlas

    Marco Ardito Master

      Hi,

       

      I'm back on Teiid since a long time, and now trying to deploy a wildfly server on docker with teiid 12.2 and the latest web console.

       

      Everything works quite smoothly:

      • I can configure a mongodb RA connection definition
        • although I struggled a bit with the RemoteServerList which, I learned reading sources, MUST begin with a "mongodb://" string, it seems or it will not be able to load correctly
          see MongoDBManagedConnectionFactory.java
      • I can deploy a mongodb test VDB (xml) which is valid and active

       

      My mongodb source is a "free tier" Atlas instance, which gives me this connection string (replaced sensitive info with XXXX)

       

      mongodb+srv://:@cluster0-XXXXX.mongodb.net/admin?retryWrites=true&w=majority

       

      which works everywhere (replacing user and password of course) in clients like MongoDB Compass

      my RA connection definition is declared as: (replaced sensitive info with XXXX)

       

      /subsystem=resource-adapters/resource-adapter=mongodb/connection-definitions=mongodbDS:add(jndi-name=java:/mongodbDS, class-name=org.teiid.resource.adapter.mongodb.MongoDBManagedConnectionFactory, enabled=true, use-java-context=true)
      /subsystem=resource-adapters/resource-adapter=mongodb/connection-definitions=mongodbDS/config-properties=RemoteServerList:add(value="mongodb://cluster0-XXXXX.mongodb.net")
      /subsystem=resource-adapters/resource-adapter=mongodb/connection-definitions=mongodbDS/config-properties=Database:add(value="XXXXX")
      /subsystem=resource-adapters/resource-adapter=mongodb/connection-definitions=mongodbDS/config-properties=Username:add(value="XXXXX")
      /subsystem=resource-adapters/resource-adapter=mongodb/connection-definitions=mongodbDS/config-properties=Password:add(value="XXXXX")
      /subsystem=resource-adapters/resource-adapter=mongodb/connection-definitions=mongodbDS/config-properties=Ssl:add(value="true")
      /subsystem=resource-adapters/resource-adapter=mongodb:activate

       

      But as soon as I try a query, either from the console's https://developer.jboss.org/  or a SquirrelSQL connection (from my pc, the docker hosting the teiid container)

      • I get no results, or hanging query in SquirrelSQL
      • in the logs I see something like (replaced sensitive info with XXXX)

       

      11:12:18,171 INFO  [org.mongodb.driver.cluster] (cluster-ClusterId{value='XXXXXXXXXXXXXXXXXX', description='null'}-cluster0-XXXXX.mongodb.net:27017) uqfyXAth7Iu5 Exception in monitor thread while connecting to server cluster0-XXXXX.mongodb.net:27017: com.mongodb.MongoSocketException: cluster0-XXXXX.mongodb.net: Name or service not known
          at com.mongodb//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211)
          at com.mongodb//com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75)
          at com.mongodb//com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
          at com.mongodb//com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
          at com.mongodb//com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
          at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: java.net.UnknownHostException: cluster0-XXXXX.mongodb.net: Name or service not known
          at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
          at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
          at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1515)
          at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
          at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
          at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
          at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
          at com.mongodb//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203)
          ... 5 more

       

      and I don't understand why I get a

      Exception in monitor thread while connecting to server cluster0-XXXXX.mongodb.net:27017: com.mongodb.MongoSocketException: cluster0-ef08y.mongodb.net: Name or service not known

       

      could anyone help me to fix this?

        • 1. Re: Teiid 12.2 dockerized unable to connect to mongodb instance on Atlas
          Ramesh Reddy Master

          Did you try those native MongoDB clients from the same machine as where Teiid installed? Teiid is saying it can not reach that server.

          • 2. Re: Teiid 12.2 dockerized unable to connect to mongodb instance on Atlas
            Marco Ardito Master

            I have a very basic teiid docker container, built from jboss/teiid image, and I run it with network = host

            from the host, I can use clients like MongoDb Compass and others to connect to that atlas server

             

            attaching a shell to the teiid container, I can ping www.redhat.com, www.google.com, and others

            so I can't understand why teiid says that it cannot reach that atlas server

             

            I was thinking about that 27017 port  that gets appended to the server

            since I didn't specify that number into my connection definitin, it should be appended by teiid translator, maybe

             

            but the connection address that atlas cloud console gives me has no port,

            and it starts with "mongodb+srv://" instead of "mongodb://" (string that teiid seems to require to be able to load the resource)

             

            example:

            mongodb+srv://<username>:<password>@cluster0-XXXXX.mongodb.net/admin

             

            In fact using such string in MongoDB Compass, the connection needs no port inserted (the ui shows a SRV switch activated)

             

             

            Instead, if I toggle the SRV switch off, I get a textbox to be filled with the port number

             

             

            and if I use the port option, with the connection url I'm given it does not work even in Compass

             

             

            Could it be that the teiid connector should act similarly? I mean

             

            • if the server string starts with "mongodb://" then teiid will add the port 27017 if not provided
            • if the server string starts with "mongodb+srv://" then teiid will not add any port when connecting

             

            tbh I don't know what the added "+srv" string means at all, never seen anything like that

             

            Thanks, Marco

            • 3. Re: Teiid 12.2 dockerized unable to connect to mongodb instance on Atlas
              Ramesh Reddy Master

              The way I see the code currently if the server URL does not start with "mongodb://" then it considers it as null. You can add JIRA to fix this behavior to accept the configuration as provided. Also provide a link for this free tier Mongo that we can test after the change to make sure it works.