0

Edit: Problem solved, I mistyped "producution" in the configuration. Stupid mistake...

I created a small skeleton Grails application using MongoDB which works on my local computer. I can successfully deploy the application on CloudBees using bees app:deploy target/proj-0.1.war -appid user/proj and it works (except for the DB of course).

Then I created a MongoDB using MongoHQ and received the address mongodb://cloudbees:123@paulo.mongohq.com:10044/456. Based on that, I edited my "DataSource.groovy" as follows:

environments {
    development {
        grails {
            mongo {
                host = 'localhost'
                port = 27017
                databaseName = 'db'
            }
        }
    }
    test {
        grails {
            mongo {
                host = 'localhost'
                port = 27017
                databaseName = 'db'
            }
        }
    }
    producution {
        grails {
           mongo {
               // based on: cloudbees:123@paulo.mongohq.com:10044/456
               host = 'paulo.mongohq.com'
               port = 10044
               username = 'cloudbees'
               password = '123'
               databaseName = '456'
           }
       }
    }
}

However, when I deploy the app with the following commands

bees config:set -a proj -P grails.env=production
grails war
bees app:deploy target/proj-0.1.war -appid user/proj
bees app:tail user/proj

and then open the URL in the browser, I get the following errors as soon as the first request to the DB is made:

Sep 11, 2013 8:24:49 AM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on /127.0.0.1:27017
java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.mongodb.DBPort._open(DBPort.java:223)
    at com.mongodb.DBPort.go(DBPort.java:125)
    at com.mongodb.DBPort.go(DBPort.java:106)
    at com.mongodb.DBPort.findOne(DBPort.java:162)
    at com.mongodb.DBPort.runCommand(DBPort.java:170)
    at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:533)
    at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:334)
    at com.mongodb.Mongo.isMongosConnection(Mongo.java:618)
    at com.mongodb.DB.wrapCommand(DB.java:281)
    at com.mongodb.DB.command(DB.java:259)
    at com.mongodb.DB.command(DB.java:243)
    at com.mongodb.DBCollection.getCount(DBCollection.java:985)
    at com.mongodb.DBCursor.size(DBCursor.java:602)
    [...]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

Sep 11, 2013 8:24:49 AM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on /127.0.0.1:27017
java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.mongodb.DBPort._open(DBPort.java:223)
    [...]
    at java.lang.Thread.run(Unknown Source)

Sep 11, 2013 8:24:49 AM com.mongodb.DBPortPool gotError
WARNING: emptying DBPortPool to /127.0.0.1:27017 b/c of error
java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.mongodb.DBPort._open(DBPort.java:223)
    at com.mongodb.DBPort.go(DBPort.java:125)
    at com.mongodb.DBPort.call(DBPort.java:92)
    at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:244)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
    at com.mongodb.DB.command(DB.java:261)
    at com.mongodb.DB.command(DB.java:243)
    at com.mongodb.DBCollection.getCount(DBCollection.java:985)
    at com.mongodb.DBCursor.size(DBCursor.java:602)
    [...]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

2013-09-11 08:24:49,677 [http-8422-1] ERROR errors.GrailsExceptionResolver  - ConnectException occurred when processing request: [GET] /project/list
Connection refused. Stacktrace follows:
java.net.ConnectException: Connection refused
    at com.mongodb.DBPort._open(DBPort.java:223)
    at com.mongodb.DBPort.go(DBPort.java:125)
    at com.mongodb.DBPort.call(DBPort.java:92)
    at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:244)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
    at com.mongodb.DB.command(DB.java:261)
    at com.mongodb.DB.command(DB.java:243)
    at com.mongodb.DBCollection.getCount(DBCollection.java:985)
    [...]
    at net.stax.appserver.webapp.RequestSetupValve.invoke(RequestSetupValve.java:31)

On http://wiki.cloudbees.com/bin/view/RUN/MongoHQ it says that I also could use bindings as follows:

bees app:bind -a proj -r mongohq:db -as DB

However, I am not sure how that would help at this problem. Any ideas? Are my entries in "DataSource.groovy" wrong? Thanks for your help.

4

1 回答 1

1

您在配置“生产”与“生产”中打错了字

对于绑定资源,您可以使用:

def url = System.getProperty('MONGOHQ_URL_DB') 

在 grails 配置文件中,但 CloudBees 只注入完整的 URL,而不是主机、端口等,因此可以使用新的 java.net.URI(url).host

于 2013-09-11T14:01:38.700 回答