Exemplo n.º 1
0
func LoadConfig(filename string) (*dvid.LogConfig, error) {
	if filename == "" {
		return nil, nil
	}
	if _, err := toml.DecodeFile(filename, &(localConfig.settings)); err != nil {
		return nil, fmt.Errorf("Could not decode TOML config: %v\n", err)
	}
	return &(localConfig.settings.Server.Logging), nil
}
Exemplo n.º 2
0
func LoadConfig(filename string) (*datastore.InstanceConfig, *dvid.LogConfig, *dvid.StoreConfig, error) {
	if filename == "" {
		return nil, nil, nil, fmt.Errorf("No server TOML configuration file provided")
	}
	if _, err := toml.DecodeFile(filename, &tc); err != nil {
		return nil, nil, nil, fmt.Errorf("Could not decode TOML config: %v\n", err)
	}

	// The server config could be local, cluster, gcloud-specific config.  Here it is local.
	config = &tc
	ic := datastore.InstanceConfig{tc.Server.IIDGen, dvid.InstanceID(tc.Server.IIDStart)}
	return &ic, &(tc.Logging), &(tc.Store), nil
}
Exemplo n.º 3
0
// LoadConfig loads DVID server configuration from a TOML file.
func LoadConfig(filename string) (*datastore.InstanceConfig, *dvid.LogConfig, *storage.Backend, error) {
	if filename == "" {
		return nil, nil, nil, fmt.Errorf("No server TOML configuration file provided")
	}
	if _, err := toml.DecodeFile(filename, &tc); err != nil {
		return nil, nil, nil, fmt.Errorf("Could not decode TOML config: %v\n", err)
	}

	// Get all defined stores.
	backend := new(storage.Backend)
	backend.Groupcache = tc.Groupcache
	var err error
	backend.Stores, err = tc.Stores()
	if err != nil {
		return nil, nil, nil, err
	}

	// Get default store if there's only one store defined.
	if len(backend.Stores) == 1 {
		for k := range backend.Stores {
			backend.Default = storage.Alias(strings.Trim(string(k), "\""))
		}
	}

	// Create the backend mapping.
	backend.Mapping = make(map[dvid.DataSpecifier]storage.Alias)
	for k, v := range tc.Backend {
		// lookup store config
		_, found := backend.Stores[v.Store]
		if !found {
			return nil, nil, nil, fmt.Errorf("Backend for %q specifies unknown store %q", k, v.Store)
		}
		spec := dvid.DataSpecifier(strings.Trim(string(k), "\""))
		backend.Mapping[spec] = v.Store
	}
	defaultAlias, found := backend.Mapping["default"]
	if found {
		backend.Default = defaultAlias
	} else {
		if backend.Default == "" {
			return nil, nil, nil, fmt.Errorf("if no default backend specified, must have exactly one store defined in config file")
		}
	}
	defaultMetadataName, found := backend.Mapping["metadata"]
	if found {
		backend.Metadata = defaultMetadataName
	} else {
		if backend.Default == "" {
			return nil, nil, nil, fmt.Errorf("can't set metadata if no default backend specified, must have exactly one store defined in config file")
		}
		backend.Metadata = backend.Default
	}

	// The server config could be local, cluster, gcloud-specific config.  Here it is local.
	config = &tc
	ic := datastore.InstanceConfig{
		Gen:   tc.Server.IIDGen,
		Start: dvid.InstanceID(tc.Server.IIDStart),
	}
	return &ic, &(tc.Logging), backend, nil
}