2017-05-04 62 views
0

目前,我正在使用Bluemix來部署和使用PencilBlue託管網站。我的問題在於連接一個存儲服務「compone-for-mongo」和pencilblue框架。 此連接通過VCAP JSON完成。 VCAP帶有以下結構;Compose-for-mongodb與pencilblue的Bluemix連接

{ 
    "compose-for-mongodb": [ 
     { 
      "credentials": { 
       "db_type": "mongodb", 
       "name": "**************************************", 
       "uri_cli": "**************************************", 
       "ca_certificate_base64": "*********************************************************************", 
       "deployment_id": "*********************************", 
       "uri": "******************************************************" 
      }, 
      "syslog_drain_url": null, 
      "label": "compose-for-mongodb", 
      "provider": null, 
      "plan": "***********", 
      "name": "************************", 
      "tags": [ 
       "big_data", 
       "data_management", 
       "ibm_created" 
      ] 
     } 
    ] 
} 

據我瞭解這一點,「撰寫換MongoDB的」是一個集羣而不是服務器。我們需要通過VCAP JSON在PencilBlue和這個「集羣」之間建立連接。目前,我們正試圖帶領JSO​​N解析在config.js像這樣:

if (typeof process.env.VCAP_SERVICES === 'string') { 
     try { 
      var vcapServices = JSON.parse(process.env.VCAP_SERVICES); 
      var vcapMongo = vcapServices['compose-for-mongodb'][0].credentials; 

      var uri = vcapMongo.uri; 

      mongoConfig.servers = [ 
       uri 
      ]; 

      var userPassword = uri.split('mongodb://')[1].split('@')[0].split(':'); 

      mongoConfig.authentication = { 
       un: userPassword[0], 
       pw: userPassword[1] 
      }; 

      var db = uri.split('?uri=')[0].split('/')[1]; 

      mongoConfig.options.mongos = { 
       ssl: true, 
       sslValidate: true, 
       sslCA: [new Buffer(vcapMongo.ca_certificate_base64, 'base64')], 
       poolSize: 1, 
       reconnectTries: 1 
      }; 

      mongoConfig.name = db; 

我們已經嘗試沒有成功多種方式。

有沒有人遇到過這個問題呢?有沒有關於這個問題的任何文件?

重現步驟:

創建Bluemix節點應用程序,並將它與「撰寫換MongoDB的」存儲服務連接。

PencilBlue版本:0.8.0

環境說明:Node.js的SDK中Bluemix和撰寫換MongoDB的服務連接

回答

1

我已經有經驗和成功與NoSQL的數據源連接pencilblue框架如Compose-for-MongoDB。這裏有一個sample repo,有一些方便的部署到bluemix按鈕,爲你設置一切 - 如果你想要一個交鑰匙方法(注意:需要一些耐心:-)管道腳本包含一些硬編碼延遲(~8分鐘),以適應服務實例化的不確定性)。對於您的特定問題,存儲庫的config.js應該有所幫助。最後,該回購還使用this repo內的使用Bluemix Object Storage服務的媒體提供商插件。

下面是摘錄:

[....] 

try { 
    var services = JSON.parse(process.env.VCAP_SERVICES); 
    // look for a service starting with 'mysql' 
    // MySQL is the only one supported by Ghost right now 
    for (var svcName in services) { 
     if (svcName.match(/^compose-for-mongodb/)) { 
      mongoCreds = services[svcName][0]['credentials']; 
      var uriObject = mongodbUri.parse(mongoCreds.uri) 
      mongoCreds.host = uriObject.hosts[0].host 
      mongoCreds.port = uriObject.hosts[0].port 
      mongoCreds.user = uriObject.username 
      mongoCreds.password = uriObject.password 
      mongoCreds.client = 'mongo'; 
      mongoCreds.userpass = mongoCreds.user + ":" + mongoCreds.password + "@" 
      mongoCreds.db = uriObject.database; 
     } 
    } 
} 

[....] 

"db": { 
     "type": mongoCreds.client, 
     "servers": [ 
      "mongodb://" + mongoCreds.userpass + mongoCreds.host + ":" + mongoCreds.port 
     ], 
     "name": mongoCreds.db, 
     "options": { 
      "server": { 
      "ssl": cloud, 
      "sslValidate": cloud, 
      "sslCert": Buffer.from(mongoCreds.ca_certificate_base64, 'base64').toString('ascii'), 
      "sslCA" : [Buffer.from(mongoCreds.ca_certificate_base64, 'base64').toString('ascii')] 
      } 
     }, 
     "writeConcern": "majority", 
     "query_logging": false, 
     "authentication": { 
      "un": mongoCreds.user, 
      "pw": mongoCreds.password 
     } 
    }, 

[....] 
+0

該文件是一個救星,謝謝 –