null+****@clear*****
null+****@clear*****
2012年 6月 21日 (木) 15:20:36 JST
SHIMODA Hiroshi 2012-06-21 15:20:36 +0900 (Thu, 21 Jun 2012) New Revision: b9f4ace2ba21fef0e4b1749f2b24c23a981c99b5 https://github.com/groonga/gcs/commit/b9f4ace2ba21fef0e4b1749f2b24c23a981c99b5 Log: Return response body of the condiguration API as an XML, for CreateDomain action Modified files: lib/api/2011-02-01/configuration.js Modified: lib/api/2011-02-01/configuration.js (+60 -1) =================================================================== --- lib/api/2011-02-01/configuration.js 2012-06-21 14:41:53 +0900 (7b46172) +++ lib/api/2011-02-01/configuration.js 2012-06-21 15:20:36 +0900 (923b112) @@ -5,6 +5,8 @@ var Deferred = require('jsdeferred').Deferred; exports.version = path.basename(__dirname); +var XMLNS = 'http://cloudsearch.amazonaws.com/doc/2011-02-01'; +var FAKE_DOMAIN_ID = 'example'; function createCommonErrorResponse(errorCode, message) { return '<?xml version="1.0"?>\n' + @@ -20,6 +22,48 @@ function createCommonErrorResponse(errorCode, message) { var handlers = Object.create(null); + +function getBaseDomain(domain) { + return domain.replace(/^cloudsearch\./, ''); +} + +function createDomainStatus(options) { +return '<DomainStatus>' + + '<SearchPartitionCount>' + (options.searchPartitionCount || 0) + + '</SearchPartitionCount>' + + '<SearchService>' + + '<Endpoint>' + (options.searchEndpoint || '') +'</Endpoint>' + + '</SearchService>' + + '<NumSearchableDocs>' + (options.searchableDocumentsCount || 0) + + '</NumSearchableDocs>' + + '<Created>' + (options.created || 'false') + '</Created>' + + '<DomainId>' + options.domainName + '/' + options.domainName + + '</DomainId>' + + '<SearchInstanceCount>' + (options.searchInstanceCount || 0) + + '</SearchInstanceCount>' + + '<DomainName>' + options.domainName + '</DomainName>' + + '<RequiresIndexDocuments>' + + (options.requiresIndexDocuments || 'false') + + '</RequiresIndexDocuments>' + + '<Deleted>' + (options.deleted || 'false') + '</Deleted>' + + '<DocService>' + + '<Endpoint>' + (options.documentsEndpoint || '') +'</Endpoint>' + + '</DocService>' + + '</DomainStatus>' + +} + +function createCreateDomainResponse(options) { + return '<?xml version="1.0"?>\n' + + '<CreateDomainResponse xmlns="' + XMLNS + '">' + + '<CreateDomainResult>' + + createDomainStatus() + + '</CreateDomainResult>' + + '<ResponseMetadata>' + + '<RequestId>' + (options.requestId || '') + '</RequestId>' + + '</ResponseMetadata>' + + '</CreateDomainResponse>'; +} + handlers.CreateDomain = function(database, request, response) { var domain = new Domain(request); var options = { @@ -38,13 +82,27 @@ handlers.CreateDomain = function(database, request, response) { return database.commandDeferred('table_create', termsOptions); }) .next(function(data) { - response.send('created ' + domain.name); + var host = getBaseDomain(request.headers.host); + response.send(createCreateDomainResponse({ + domainName: domain.name, + domainId: FAKE_DOMAIN_ID, + searchEndpoint: 'http://search-' + domain.name + '-' + FAKE_DOMAIN_ID + + '/' + exports.version + '/search', + documentsEndpoint: 'http://doc-' + domain.name + '-' + FAKE_DOMAIN_ID + + '/' + exports.version + '/documents/batch', + created: true, + searchableDocumentsCount: 0, + searchInstanceCount: 0, + searchPartitionCount: 0, + requiresIndexDocuments: false + })); }) .error(function(error) { return response.send(error.message, 400); }); }; + handlers.DefineIndexField = function(database, request, response) { var domain = new Domain(request); @@ -77,6 +135,7 @@ handlers.DefineIndexField = function(database, request, response) { }); }; + exports.createHandler = function(database) { return function(request, response) { var message, body; -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... Download