Permalink
Browse files

Fixing ListDomains and CreateDomain bugs

  • Loading branch information...
1 parent db9f26f commit 44f9f193c6d90e0279d10de0da83de5388ce9257 @robtweed committed May 9, 2011
Showing with 57 additions and 36 deletions.
  1. +57 −36 lib/mdb.js
View
93 lib/mdb.js
@@ -46,7 +46,7 @@
var httpPort = 8081;
-var trace = false;
+var trace = true;
var sdbURLPattern = '/';
var mdbURLPattern = '/mdb/request.mgwsi';
@@ -434,7 +434,7 @@ var ListDomains = function(SDB) {
db.clientPool[db.connection()].getJSON('MDB', [accessKeyId, 'domainIndex'],
function(err, json) {
if (!err) {
- //console.log("json=" + JSON.stringify(json));
+ if (trace) console.log("List Domains: json=" + JSON.stringify(json));
var shortName;
var value;
var domainId;
@@ -446,24 +446,29 @@ var ListDomains = function(SDB) {
if (nvps.MaxNumberOfDomains) {
if (nvps.MaxNumberOfDomains < noOfDomains) maxDomains = nvps.MaxNumberOfDomains;
}
- //console.log("fetching " + maxDomains + " domains from database");
+ if (trace) console.log("fetching " + maxDomains + " domains from database");
var domainList = [];
var count = 0;
- for (shortName in json) {
- value = json[shortName];
- for (domainId in value) {
- db.clientPool[db.connection()].getGlobal('MDB', [accessKeyId, 'domains', domainId, 'name'],
- function (error, results) {
- if (error) return;
- var domainName = results.value;
- count++;
- domainList[count-1] = domainName;
- //console.log("count = " + count + ": " + domainName);
- if (count === maxDomains) ListDomainsResponse(domainList, SDB);
- }
- );
- }
- }
+ if (maxDomains === 0) {
+ ListDomainsResponse(domainList, SDB);
+ }
+ else {
+ for (shortName in json) {
+ value = json[shortName];
+ for (domainId in value) {
+ db.clientPool[db.connection()].getGlobal('MDB', [accessKeyId, 'domains', domainId, 'name'],
+ function (error, results) {
+ if (error) return;
+ var domainName = results.value;
+ count++;
+ domainList[count-1] = domainName;
+ if (trace) console.log("count = " + count + ": " + domainName);
+ if (count === maxDomains) ListDomainsResponse(domainList, SDB);
+ }
+ );
+ }
+ }
+ }
}
}
);
@@ -472,11 +477,18 @@ var ListDomains = function(SDB) {
var ListDomainsResponse = function(domainList, SDB) {
var nvps = SDB.nvps;
var action = nvps.Action;
- var xml = responseStart({action: action, version: nvps.Version, hasContent: true});
- for (var i = 0; i < domainList.length; i++) {
- xml = xml + '<DomainName>' + domainList[i] + '</DomainName>';
+ var xml;
+ if (domainList.length === 0) {
+ xml = responseStart({action: action, version: nvps.Version, hasContent: false});
+ xml = xml + responseEnd(action, SDB.startTime, true);
+ }
+ else {
+ xml = responseStart({action: action, version: nvps.Version, hasContent: true});
+ for (var i = 0; i < domainList.length; i++) {
+ xml = xml + '<DomainName>' + domainList[i] + '</DomainName>';
+ }
+ xml = xml + responseEnd(action, SDB.startTime, true);
}
- xml = xml + responseEnd(action, SDB.startTime, true);
writeResponse(200, xml, SDB.response)
};
@@ -503,23 +515,27 @@ var CreateDomain = function(SDB) {
if (nameOk) {
db.clientPool[db.connection()].getGlobal('MDB', [nvps.AWSAccessKeyId], function (error, results) {
var noOfDomains = results.value;
- if ((noOfDomains === '')||(noOfDomains === '0')) checkDomain(SDB);
- db.clientPool[db.connection()].getGlobal('MDBConfig', ['DomainsPerAccount'], function (error, results) {
- var maxDomains = results.value;
- if (trace) console.log("maxDomains = " + maxDomains);
- if (maxDomains === '') {
- checkDomain(SDB);
- }
- else {
- if (noOfDomains === maxDomains) {
- //max no of domains already in database
- errorResponse('NumberDomainsExceeded', SDB)
+ if ((noOfDomains === '')||(noOfDomains === '0')) {
+ checkDomain(SDB);
+ }
+ else {
+ db.clientPool[db.connection()].getGlobal('MDBConfig', ['DomainsPerAccount'], function (error, results) {
+ var maxDomains = results.value;
+ if (trace) console.log("maxDomains = " + maxDomains);
+ if (maxDomains === '') {
+ checkDomain(SDB);
}
else {
- checkDomain(SDB);
+ if (noOfDomains === maxDomains) {
+ //max no of domains already in database
+ errorResponse('NumberDomainsExceeded', SDB)
+ }
+ else {
+ checkDomain(SDB);
+ }
}
- }
- });
+ });
+ }
});
}
else {
@@ -2182,3 +2198,8 @@ if (!silentStart) {
}
}
+setInterval(function() {
+ console.log("Waiting...");;
+},60000);
+
+

0 comments on commit 44f9f19

Please sign in to comment.