diff --git a/examples/basic_sg_accel_config.json b/examples/basic_sg_accel_config.json deleted file mode 100644 index 06d7b81a39..0000000000 --- a/examples/basic_sg_accel_config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "log": ["HTTP+"], - "adminInterface": "127.0.0.1:4985", - "interface": "0.0.0.0:4984", - "databases": { - "default": { - "server": "http://localhost:8091", - "bucket": "default", - "channel_index": { - "server":"http://localhost:8091", - "bucket":"channel_bucket" - } - } - } -} diff --git a/rest/config.go b/rest/config.go index abff835d67..e36d776ed0 100644 --- a/rest/config.go +++ b/rest/config.go @@ -86,6 +86,7 @@ type ServerConfig struct { ClusterConfig *ClusterConfig `json:"cluster_config,omitempty"` // Bucket and other config related to CBGT SkipRunmodeValidation bool `json:"skip_runmode_validation,omitempty"` // If this is true, skips any config validation regarding accel vs normal mode Unsupported *UnsupportedServerConfig `json:"unsupported,omitempty"` // Config for unsupported features + RunMode SyncGatewayRunMode `json:"runmode,omitempty"` // Whether this is an SG reader or an SG Accelerator } // Bucket configuration elements - used by db, shadow, index @@ -299,6 +300,43 @@ func (dbConfig DbConfig) validate() error { } +func (dbConfig *DbConfig) validateSgDbConfig() error { + + if err := dbConfig.validate(); err != nil { + return err + } + + if dbConfig.ChannelIndex != nil && dbConfig.ChannelIndex.IndexWriter == true { + return fmt.Errorf("Invalid configuration for Sync Gw. Must not be configured as an IndexWriter") + } + + return nil + +} + +func (dbConfig *DbConfig) validateSgAccelDbConfig() error { + + if err := dbConfig.validate(); err != nil { + return err + } + + if dbConfig.ChannelIndex == nil { + return fmt.Errorf("Invalid configuration for Sync Gw Accel. Must have a ChannelIndex defined") + } + + if dbConfig.ChannelIndex.IndexWriter == false { + return fmt.Errorf("Invalid configuration for Sync Gw Accel. Must be configured as an IndexWriter") + } + + if strings.ToLower(dbConfig.FeedType) != strings.ToLower(base.DcpShardFeedType) { + return fmt.Errorf("Invalid configuration for Sync Gw Accel. Must be configured for DCPSHARD feedtype") + + } + + return nil + +} + func (dbConfig *DbConfig) modifyConfig() { if dbConfig.ChannelIndex != nil { // if there is NO feed type, set to DCPSHARD, since that's the only @@ -325,7 +363,7 @@ func (channelIndexConfig *ChannelIndexConfig) GetCredentials() (string, string, } // Reads a ServerConfig from raw data -func ReadServerConfigFromData(data []byte) (*ServerConfig, error) { +func ReadServerConfigFromData(runMode SyncGatewayRunMode, data []byte) (*ServerConfig, error) { data = base.ConvertBackQuotedStrings(data) var config *ServerConfig @@ -333,6 +371,8 @@ func ReadServerConfigFromData(data []byte) (*ServerConfig, error) { return nil, err } + config.RunMode = runMode + // Validation: if err := config.setupAndValidateDatabases(); err != nil { return nil, err @@ -342,7 +382,7 @@ func ReadServerConfigFromData(data []byte) (*ServerConfig, error) { } // Reads a ServerConfig from a URL. -func ReadServerConfigFromUrl(url string) (*ServerConfig, error) { +func ReadServerConfigFromUrl(runMode SyncGatewayRunMode, url string) (*ServerConfig, error) { resp, err := http.Get(url) if err != nil { @@ -353,21 +393,21 @@ func ReadServerConfigFromUrl(url string) (*ServerConfig, error) { if err != nil { return nil, err } - return ReadServerConfigFromData(responseBody) + return ReadServerConfigFromData(runMode, responseBody) } // Reads a ServerConfig from either a JSON file or from a URL. -func ReadServerConfig(path string) (*ServerConfig, error) { +func ReadServerConfig(runMode SyncGatewayRunMode, path string) (*ServerConfig, error) { if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { - return ReadServerConfigFromUrl(path) + return ReadServerConfigFromUrl(runMode, path) } else { - return ReadServerConfigFromFile(path) + return ReadServerConfigFromFile(runMode, path) } } // Reads a ServerConfig from a JSON file. -func ReadServerConfigFromFile(path string) (*ServerConfig, error) { +func ReadServerConfigFromFile(runMode SyncGatewayRunMode, path string) (*ServerConfig, error) { file, err := os.Open(path) if err != nil { return nil, err @@ -384,6 +424,8 @@ func ReadServerConfigFromFile(path string) (*ServerConfig, error) { return nil, err } + config.RunMode = runMode + // Validation: if err := config.setupAndValidateDatabases(); err != nil { return nil, err @@ -435,7 +477,14 @@ func (config *ServerConfig) validateDbConfig(dbConfig *DbConfig) error { dbConfig.modifyConfig() - return dbConfig.validate() + switch config.RunMode { + case SyncGatewayRunModeNormal: + return dbConfig.validateSgDbConfig() + case SyncGatewayRunModeAccel: + return dbConfig.validateSgAccelDbConfig() + } + + return fmt.Errorf("Unexpected RunMode: %v", config.RunMode) } @@ -477,7 +526,7 @@ func (self *ServerConfig) MergeWith(other *ServerConfig) error { } // Reads the command line flags and the optional config file. -func ParseCommandLine() { +func ParseCommandLine(runMode SyncGatewayRunMode) { addr := flag.String("interface", DefaultInterface, "Address to bind to") authAddr := flag.String("adminInterface", DefaultAdminInterface, "Address to bind admin interface to") profAddr := flag.String("profileInterface", "", "Address to bind profile interface to") @@ -499,7 +548,7 @@ func ParseCommandLine() { // Read the configuration file(s), if any: for i := 0; i < flag.NArg(); i++ { filename := flag.Arg(i) - c, err := ReadServerConfig(filename) + c, err := ReadServerConfig(runMode, filename) if err != nil { base.LogFatal("Error reading config file %s: %v", filename, err) } @@ -743,7 +792,7 @@ func ValidateConfigOrPanic(runMode SyncGatewayRunMode) { // Main entry point for a simple server; you can have your main() function just call this. // It parses command-line flags, reads the optional configuration file, then starts the server. func ServerMain(runMode SyncGatewayRunMode) { - ParseCommandLine() + ParseCommandLine(runMode) ValidateConfigOrPanic(runMode) RunServer(config) }