vendredi 31 juillet 2015

Ironworker connection to Openshift MySQL database

I just installed the ironworker cartridge from Openshift's marketplace - experimenting with a hello-world nodejs worker that tries to connect to the MySQL DB on Openshift and the attempt is refused. [BTW, I can connect to the DB via MySQL workbench using the very same credentials, via port-forwarding]. I also SSH'd in to grab the environment info with

env | grep OPENSHIFT_MYSQL

and used the host and port.

Tried creating a basic connection in the worker and received the following result (actual config values changed):

my config: {"host":"111.11.nnn.nnn","port":3306,"user":"myapp","pass":"xxxxxxxxxxx","db":"app_db"}
about to make DB connection
We got an error connection to the DB: {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","fatal":true}

I believe the connection is being refused not by the database, but perhaps the firewall/environment itself because I can connect via other means. Suggestions?

FYI - the code:

var mysql = require('mysql');

// variables specific to your ironworker environment
var iron_helper = require('node_helper');
var params = iron_helper.params;
var task_id = iron_helper.task_id;
var config = iron_helper.config;
console.log('my config: ' + JSON.stringify(config));
console.log('about to make DB connection');
var connection = mysql.createConnection('mysql://'+config.user+':'+config.pass+'@'+config.host+':'+config.port+'/'+config.db);


var query = "select count(*) from reservations;";

connection.query( query, function(err, callResults){
if (err) {
   console.log("We got an error connection to the DB: " + JSON.stringify(err));
}
else {
    console.log("We got a result: " + JSON.stringify(callResults));
}
connection.destroy();
});

Aucun commentaire:

Enregistrer un commentaire