YUKI Hiroshi
null+****@clear*****
Wed Nov 5 17:12:22 JST 2014
YUKI Hiroshi 2014-11-05 17:12:22 +0900 (Wed, 05 Nov 2014) New Revision: 6c94fa92660bd6e378522d864999b69dd0661322 https://github.com/droonga/express-droonga/commit/6c94fa92660bd6e378522d864999b69dd0661322 Message: Remove obsolete codes to operate catalog.json Removed files: lib/catalog/index.js lib/catalog/v2.js test/catalog/v2.test.js Modified files: lib/droonga-protocol/connection-pool.js Deleted: lib/catalog/index.js (+0 -12) 100644 =================================================================== --- lib/catalog/index.js 2014-11-05 17:08:38 +0900 (61b6be6) +++ /dev/null @@ -1,12 +0,0 @@ -var CatalogV2 = require('./v2').CatalogV2; - -function Catalog(raw) { - switch (raw.version) { - case 2: - return new CatalogV2(raw); - default: - throw new Error('catalog version ' + raw.version + ' is not supported.'); - } -}; - -exports.Catalog = Catalog; Deleted: lib/catalog/v2.js (+0 -111) 100644 =================================================================== --- lib/catalog/v2.js 2014-11-05 17:08:38 +0900 (b722077) +++ /dev/null @@ -1,111 +0,0 @@ -var util = require('util'); - -function CatalogV2(raw) { - this._raw = raw; -} -CatalogV2.prototype = { - get allHostNames() { - if (this._allHostNames) - return this._allHostNames; - var uniqueHostNames = {}; - this.datasets.forEach(function(dataset) { - dataset.allHostNames.forEach(function(hostName) { - uniqueHostNames[hostName] = true; - }); - }); - return this._allHostNames = Object.keys(uniqueHostNames).sort(); - }, - get datasets() { - if (this._datasets) - return this._datasets; - return this._datasets = Object.keys(this._raw.datasets || {}) - .map((function(datasetName) { - return new Dataset(datasetName, - this._raw.datasets[datasetName]); - }).bind(this)); - } -}; - - -function VolumeCollectionOwner(raw) { - this._raw = raw; -} -VolumeCollectionOwner.prototype = { - get allHostNames() { - if (this._allHostNames) - return this._allHostNames; - - var uniqueHostNames = {}; - - this.replicas.forEach(function(replica) { - replica.allHostNames.forEach(function(hostName) { - uniqueHostNames[hostName] = true; - }); - }); - - this.slices.forEach(function(replica) { - replica.allHostNames.forEach(function(hostName) { - uniqueHostNames[hostName] = true; - }); - }); - - if (this.ownVolume) - uniqueHostNames[this.ownVolume.hostName] = true; - - return this._allHostNames = Object.keys(uniqueHostNames).sort(); - }, - - get replicas() { - if (this._replicas) - return this._replicas; - return this._replicas = (this._raw.replicas || []).map(function(replica) { - return new Replica(replica); - }); - }, - - get slices() { - if (this._slices) - return this._slices; - return this._slices = (this._raw.slices || []).map(function(slice) { - return new Slice(slice); - }); - }, - - ADDRESS_PATTERN: /^([^:]+)(?::(\d+))?\/([^\.]+)\.(.+)$/, // hostName, port, tag, path - get ownVolume() { - if (typeof this._ownVolume !== 'undefined') - return this._ownVolume; - - if (this._raw.volume && this._raw.volume.address) { - var address = this._raw.volume.address; - var match = address.match(this.ADDRESS_PATTERN); - this._ownVolume = { - hostName: match[1] - }; - } - else { - this._ownVolume = null; - } - return this._ownVolume; - } -}; - - -function Dataset(name, raw) { - this.name = name; - this._raw = raw; -} -util.inherits(Dataset, VolumeCollectionOwner); - -function Replica(raw) { - this._raw = raw; -} -util.inherits(Replica, VolumeCollectionOwner); - -function Slice(raw) { - this._raw = raw; -} -util.inherits(Slice, VolumeCollectionOwner); - - -exports.CatalogV2 = CatalogV2; Modified: lib/droonga-protocol/connection-pool.js (+0 -31) =================================================================== --- lib/droonga-protocol/connection-pool.js 2014-11-05 17:08:38 +0900 (106a3ad) +++ lib/droonga-protocol/connection-pool.js 2014-11-05 17:12:22 +0900 (9fe7628) @@ -15,7 +15,6 @@ var exec = require('child_process').exec, var Connection = require('./connection').Connection; var ConsoleLogger = require('../console-logger').ConsoleLogger; -var Catalog = require('../catalog').Catalog; var SerfAgent = require('../serf/agent'); function ConnectionPool(params) { @@ -112,36 +111,6 @@ ConnectionPool.prototype = { return this._hostNames.length; }, - updateHostNamesFromCatalog: function() { - return this.getHostNamesFromCatalog() - .then((function(hostNames) { - this.hostNames = hostNames; - return hostNames; - }).bind(this)); - }, - - getHostNamesFromCatalog: function() { - return this.fetchCatalog() - .then(function(catalog) { - return catalog.allHostNames; - }); - }, - - fetchCatalog: function() { - return this.get().thenableEmitMessage('catalog.fetch') - .then(this._handleFetchedCatalog.bind(this)); - }, - _handleFetchedCatalog: function(result) { - this._logger.debug('ConnectionPool: fetchCatalog: fetched result'); - this._logger.debug(result); - if (result.errorCode) { - this._logger.error(new Error('ConnectionPool: failed to fetch catalog')); - return; - } - var catalog = result.response.body; - return new Catalog(catalog); - }, - getHostNamesFromCluster: function() { return Q.Promise((function(resolve, reject, notify) { // Because node-rpc has no API to disconnect from the RPC host, Deleted: test/catalog/v2.test.js (+0 -235) 100644 =================================================================== --- test/catalog/v2.test.js 2014-11-05 17:08:38 +0900 (e3b9530) +++ /dev/null @@ -1,235 +0,0 @@ -var assert = require('chai').assert; - -var utils = require('../test-utils'); - -var CatalogV2 = require('../../lib/catalog/v2').CatalogV2; - -function singleVolumeWithHostName(hostname, localPath) { - localPath = localPath || '000'; - return { - volume: { - address: hostname + ':10031/droonga.' + localPath - } - }; -} - -suite('CatalogV2', function() { - suite('allHostNames', function() { - test('no dataset', function() { - var catalog = new CatalogV2({ - version: 2 - }); - assert.deepEqual(catalog.allHostNames, []) - }); - - test('blank datasets', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - } - }); - assert.deepEqual(catalog.allHostNames, []) - }); - - test('datasets', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - dataset1: singleVolumeWithHostName('127.0.0.1'), - dataset2: singleVolumeWithHostName('127.0.0.2'), - dataset3: singleVolumeWithHostName('127.0.0.3') - } - }); - var expectedAllHostNames = [ - '127.0.0.1', - '127.0.0.2', - '127.0.0.3' - ].sort(); - assert.deepEqual(catalog.allHostNames, expectedAllHostNames) - }); - - test('replicas', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - datasetWithReplicas: { - replicas: [ - singleVolumeWithHostName('127.0.0.1'), - singleVolumeWithHostName('127.0.0.2') - ] - } - } - }); - var expectedAllHostNames = [ - '127.0.0.1', - '127.0.0.2' - ].sort(); - assert.deepEqual(catalog.allHostNames, expectedAllHostNames) - }); - - test('slices in replicas', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - datasetWithReplicas: { - replicas: [ - { - slices: [ - singleVolumeWithHostName('127.0.0.1'), - singleVolumeWithHostName('127.0.0.2') - ] - }, - { - slices: [ - singleVolumeWithHostName('127.0.0.11'), - singleVolumeWithHostName('127.0.0.12') - ] - } - ] - } - } - }); - var expectedAllHostNames = [ - '127.0.0.1', - '127.0.0.2', - '127.0.0.11', - '127.0.0.12' - ].sort(); - assert.deepEqual(catalog.allHostNames, expectedAllHostNames) - }); - - test('slices', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - datasetWithSlices: { - slices: [ - singleVolumeWithHostName('127.0.0.1'), - singleVolumeWithHostName('127.0.0.2') - ] - } - } - }); - var expectedAllHostNames = [ - '127.0.0.1', - '127.0.0.2' - ].sort(); - assert.deepEqual(catalog.allHostNames, expectedAllHostNames) - }); - - test('replicas in slices', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - datasetWithSlices: { - slices: [ - { - replicas: [ - singleVolumeWithHostName('127.0.0.1'), - singleVolumeWithHostName('127.0.0.2') - ] - }, - { - replicas: [ - singleVolumeWithHostName('127.0.0.11'), - singleVolumeWithHostName('127.0.0.12') - ] - } - ] - } - } - }); - var expectedAllHostNames = [ - '127.0.0.1', - '127.0.0.2', - '127.0.0.11', - '127.0.0.12' - ].sort(); - assert.deepEqual(catalog.allHostNames, expectedAllHostNames) - }); - - test('deeply nested (recomended structure)', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - topLevelDataset: { - replicas: [ - { // main - slices: [ - { - replicas: [ - singleVolumeWithHostName('127.0.0.1'), - singleVolumeWithHostName('127.0.0.2') - ] - }, - { - replicas: [ - singleVolumeWithHostName('127.0.0.11'), - singleVolumeWithHostName('127.0.0.12') - ] - } - ] - }, - { // sub, new slice structure - slices: [ - { - replicas: [ - singleVolumeWithHostName('127.0.0.21'), - singleVolumeWithHostName('127.0.0.22') - ] - }, - { - replicas: [ - singleVolumeWithHostName('127.0.0.31'), - singleVolumeWithHostName('127.0.0.32') - ] - }, - { - replicas: [ - singleVolumeWithHostName('127.0.0.41'), - singleVolumeWithHostName('127.0.0.42') - ] - } - ] - } - ] - } - } - }); - var expectedAllHostNames = [ - '127.0.0.1', - '127.0.0.2', - '127.0.0.11', - '127.0.0.12', - '127.0.0.21', - '127.0.0.22', - '127.0.0.31', - '127.0.0.32', - '127.0.0.41', - '127.0.0.42' - ].sort(); - assert.deepEqual(catalog.allHostNames, expectedAllHostNames) - }); - - test('same host, different local path', function() { - var catalog = new CatalogV2({ - version: 2, - datasets: { - topLevelDataset: { - replicas: [ - singleVolumeWithHostName('127.0.0.1', '000'), - singleVolumeWithHostName('127.0.0.2', '000'), - singleVolumeWithHostName('127.0.0.1', '001'), - singleVolumeWithHostName('127.0.0.2', '001') - ] - } - } - }); - var expectedAllHostNames = [ - '127.0.0.1', - '127.0.0.2' - ].sort(); - assert.deepEqual(catalog.allHostNames, expectedAllHostNames) - }); - }); -}); -------------- next part -------------- HTML����������������������������...Download