[Groonga-commit] groonga/gcs [master] Use awssum to describe domains (experimental)

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Oct 15 13:57:11 JST 2012


YUKI Hiroshi	2012-10-15 13:57:11 +0900 (Mon, 15 Oct 2012)

  New Revision: 409ed95c6596c6e966ec0e98b107168d7de1b177
  https://github.com/groonga/gcs/commit/409ed95c6596c6e966ec0e98b107168d7de1b177

  Log:
    Use awssum to describe domains (experimental)

  Modified files:
    bin/gcs-describe-domain
    lib/command-line.js
    package.json

  Modified: bin/gcs-describe-domain (+41 -3)
===================================================================
--- bin/gcs-describe-domain    2012-10-10 15:40:03 +0900 (0ead20a)
+++ bin/gcs-describe-domain    2012-10-15 13:57:11 +0900 (160c176)
@@ -52,6 +52,43 @@ function report(domain) {
   console.log('======================');
 }
 
+function reportDomainStatus(status) {
+  console.log('=== Domain Summary ===');
+  console.log('Domain Name: %s',
+              status.DomainName);
+  console.log('Document Service endpoint: %s',
+              status.DocService.Endpoint);
+  console.log('Search Service endpoint: %s',
+               status.SearchService.Endpoint);
+  console.log('SearchInstanceType: %s',
+              null);
+  console.log('SearchPartitionCount: %s',
+              status.SearchPartitionCount);
+  console.log('SearchInstanceCount: %s',
+              status.SearchInstanceCount);
+  console.log('Searchable Documents: %s',
+              status.NumSearchableDocs);
+  console.log('Current configuration changes require a call to ' +
+                'IndexDocuments: %s',
+              status.RequiresIndexDocuments ? 'Yes' : 'No' );
+
+//  // additional information for the default search field!
+//  var field = status.defaultSearchField;
+//  if (field)
+//    console.log('Default search field: %s', field.name);
+
+  console.log('');
+  console.log('=== Domain Configuration ===');
+
+  console.log('');
+  console.log('Fields:');
+  console.log('=======');
+//  domain.indexFields.forEach(function(field) {
+//    console.log(field.summary);
+//  });
+  console.log('======================');
+}
+
 function outputNotesForHostAndPort() {
   console.log('*Note: the hostname and the port number is detected from ' +
               'the default options. If you run the service with your ' +
@@ -60,9 +97,10 @@ function outputNotesForHostAndPort() {
 }
 
 if (commandLine.options.domainName) {
-  commandLine.assertDomainExists();
-  report(commandLine.domain);
-  outputNotesForHostAndPort();
+  commandLine.getDomainStatus(function(error, domainStatus) {
+    reportDomainStatus(domainStatus);
+    outputNotesForHostAndPort();
+  });
 } else {
   var domains = CLI.Domain.getAll(commandLine.context);
   domains.forEach(function(domain, index) {

  Modified: lib/command-line.js (+48 -0)
===================================================================
--- lib/command-line.js    2012-10-10 15:40:03 +0900 (e0604f6)
+++ lib/command-line.js    2012-10-15 13:57:11 +0900 (c3ea0d0)
@@ -4,6 +4,10 @@ var Domain = require('./database/domain').Domain;
 var version = require('../package').version;
 var path = require('path');
 
+var awssum = require('awssum');
+var amazon = awssum.load('amazon/amazon');
+var CloudSearch = awssum.load('amazon/cloudsearch').CloudSearch;
+
 var defaultDatabasePath =
       exports.defaultDatabasePath =
       CommandLineInterface.defaultDatabasePath = process.env.GCS_DATABASE_PATH || process.env.HOME + '/.gcs/database/gcs';
@@ -23,12 +27,33 @@ var defaultPrivilegedRanges =
       CommandLineInterface.defaultPrivilegedRanges =
         process.env.GCS_PRIVILEGED_RANGES || '127.0.0.0/8';
 
+CloudSearch.prototype.host = function() {
+  return defaultConfigurationHost.split(':')[0];
+};
+
 function CommandLineInterface() {
   this.program = program;
   this.reservedUsage = null;
   this.reservedOptions = [];
 }
 CommandLineInterface.prototype = {
+  get cloudSearch() {
+    if (!this._couldSearch) {
+      this._cloudSearch = new CloudSearch({
+        accessKeyId: 'dummy-access-key-id',
+        secretAccessKey: 'dummy-access-key',
+      });
+      cloudSearch.addExtras = function(options, args) {
+        options.protocol = 'http';
+        options.port =  defaultConfigurationHost.split(':')[1] || defaultPort;
+      };
+    }
+    return this._cloudSearch;
+  },
+  get domainName() {
+    return this.options.domainName;
+  },
+
   get databasePath() {
     return this.options.databasePath || defaultDatabasePath;
   },
@@ -90,6 +115,29 @@ CommandLineInterface.prototype = {
     return this;
   },
 
+  getDomainStatus: function(callback) {
+    var domainName = this.domainName;
+    this.cloudSearch.DescribeDomains(function(error, data) {
+      if (error) {
+        console.log('Unexpected error: ' + error);
+        process.exit(1);
+      }
+      var matchedDomains = DescribeDomainsResponse
+           .DescribeDomainsResult
+           .DomainStatusList
+           .member
+           .filter(function(domainStatus) {
+             return domainStatus.DomainName == domainName;
+           });
+      if (matchedDomains.length) {
+        callback(null, matchedDomains[0]);
+      } else {
+        console.log('You must specify an existing domain name.');
+        process.exit(1);
+      }
+    });
+  },
+
   assertDomainExists: function() {
     if (!this.domain.exists()) {
       console.log('You must specify an existing domain name.');

  Modified: package.json (+1 -0)
===================================================================
--- package.json    2012-10-10 15:40:03 +0900 (c6724cc)
+++ package.json    2012-10-15 13:57:11 +0900 (e5b3b7a)
@@ -18,6 +18,7 @@
     "chai": ""
   },
   "dependencies": {
+    "awssum": "",
     "commander": "",
     "dateformat": "",
     "express": "~ 2.5.10",
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index