Пример #1
0
func parseConfig(config dvid.StoreConfig) (path string, testing bool, err error) {
	c := config.GetAll()

	v, found := c["path"]
	if !found {
		err = fmt.Errorf("%q must be specified for leveldb configuration", "path")
		return
	}
	var ok bool
	path, ok = v.(string)
	if !ok {
		err = fmt.Errorf("%q setting must be a string (%v)", "path", v)
		return
	}
	v, found = c["testing"]
	if found {
		testing, ok = v.(bool)
		if !ok {
			err = fmt.Errorf("%q setting must be a bool (%v)", "testing", v)
			return
		}
	}
	if testing {
		path = filepath.Join(os.TempDir(), path)
	}
	return
}
Пример #2
0
func parseConfig(config dvid.StoreConfig) (*BigTable, error) {
	c := config.GetAll()

	v, found := c["project"]
	if !found {
		return nil, fmt.Errorf("%q must be specified for BigTable configuration", "project")
	}
	project, ok := v.(string)
	if !ok {
		return nil, fmt.Errorf("%q setting must be a string (%v)", "project", v)
	}

	v, found = c["zone"]
	if !found {
		return nil, fmt.Errorf("%q must be specified for BigTable configuration", "zone")
	}
	zone, ok := v.(string)
	if !ok {
		return nil, fmt.Errorf("%q setting must be a string (%v)", "zone", v)
	}

	v, found = c["cluster"]
	if !found {
		return nil, fmt.Errorf("%q must be specified for BigTable configuration", "cluster")
	}
	cluster, ok := v.(string)
	if !ok {
		return nil, fmt.Errorf("%q setting must be a string (%v)", "cluster", v)
	}

	v, found = c["table"]
	if !found {
		return nil, fmt.Errorf("%q must be specified for BigTable configuration", "table")
	}
	table, ok := v.(string)
	if !ok {
		return nil, fmt.Errorf("%q setting must be a string (%v)", "table", v)
	}

	var testing bool
	v, found = c["testing"]
	if !found {
		testing, ok = v.(bool)
		if !ok {
			return nil, fmt.Errorf("%q setting must be a bool (%v)", "testing", v)
		}
	}

	bt := &BigTable{
		project: project,
		zone:    zone,
		cluster: cluster,
		table:   table,
		testing: testing,
		ctx:     context.Background(),
	}

	return bt, nil
}
Пример #3
0
func parseConfig(config dvid.StoreConfig) (path string, timeout time.Duration, owner string, collection dvid.UUID, err error) {
	c := config.GetAll()

	v, found := c["path"]
	if !found {
		err = fmt.Errorf("%q must be specified for kvautobus configuration", "path")
		return
	}
	var ok bool
	path, ok = v.(string)
	if !ok {
		err = fmt.Errorf("%q setting must be a string (%v)", "path", v)
		return
	}

	v, found = c["timeout"]
	if found {
		t, ok := v.(int64)
		if !ok {
			err = fmt.Errorf("%q setting must be an int64 for # seconds, not %s (%v)", "timeout", reflect.TypeOf(v), v)
			return
		}
		if t != 0 {
			timeout = time.Duration(t) * time.Second
		}
	}

	v, found = c["collection"]
	if !found {
		err = fmt.Errorf("kvautobus store must have collection specification for billing.")
		return
	}
	cstr, ok := v.(string)
	if !ok {
		err = fmt.Errorf("%q setting must be a string, not %s (%v)", "collection", reflect.TypeOf(v), v)
		return
	}
	collection = dvid.UUID(cstr)

	v, found = c["owner"]
	if !found {
		err = fmt.Errorf("kvautobus store must have owner specification for billing.")
		return
	}
	owner, ok = v.(string)
	if !ok {
		err = fmt.Errorf("%q setting must be a string, not %s (%v)", "owner", reflect.TypeOf(v), v)
		return
	}
	return
}