func tearDownTests() { utils.PanicOnError(os.RemoveAll(config.GetConfig().DataDir)) utils.PanicOnError(os.RemoveAll(config.GetConfig().InfoDir)) utils.PanicOnError(os.Mkdir(config.GetConfig().DataDir, 0777)) utils.PanicOnError(os.Mkdir(config.GetConfig().InfoDir, 0777)) utils.PanicOnError(storage.CloseInfoDB()) sketchesManager.Destroy() }
/* Run ... */ func (srv *Server) Run() { conf := config.GetConfig() port := int(conf.GetPort()) logger.Info.Println("Server up and running on port: " + strconv.Itoa(port)) err := http.ListenAndServe(":"+strconv.Itoa(port), srv) utils.PanicOnError(err) err = gracehttp.Serve(&http.Server{Addr: ":" + strconv.Itoa(port), Handler: srv}) utils.PanicOnError(err) }
func (m *ManagerStruct) dumpInfo(info *abstract.Info) { // FIXME: Should we panic here? m.info[info.ID] = info manager := storage.GetManager() infoData, err := json.Marshal(info) utils.PanicOnError(err) err = manager.SaveInfo(info.ID, infoData) utils.PanicOnError(err) }
func setupTests() { utils.PanicOnError(os.Setenv("SKZ_DATA_DIR", "/tmp/skizze_data")) utils.PanicOnError(os.Setenv("SKZ_INFO_DIR", "/tmp/skizze_info")) path, err := os.Getwd() utils.PanicOnError(err) path = filepath.Dir(path) configPath := filepath.Join(path, "config/default.toml") utils.PanicOnError(os.Setenv("SKZ_CONFIG", configPath)) tearDownTests() }
func (m *ManagerStruct) dumpInfo(info *abstract.Info) { // FIXME: Should we panic here? id := fmt.Sprintf("%s.%s", info.ID, info.Type) m.info[id] = info manager := storage.Manager() infoData, err := json.Marshal(info) utils.PanicOnError(err) err = manager.SaveInfo(id, infoData) utils.PanicOnError(err) }
/* Stop ... */ func (srv *Server) Stop() { //FIXME make sure everything is written to disk logger.Info.Println("Stopping server...") err := storage.CloseInfoDB() utils.PanicOnError(err) os.Exit(0) }
func (m *ManagerStruct) dumpInfo(i *abstract.Info) { m.info[i.ID] = i manager := storage.GetManager() infoData, err := json.Marshal(i) utils.PanicOnError(err) manager.SaveInfo(i.ID, infoData) }
func parseConfigTOML() *Config { configPath := os.Getenv("SKZ_CONFIG") if configPath == "" { path, err := os.Getwd() utils.PanicOnError(err) path, err = filepath.Abs(path) utils.PanicOnError(err) configPath = filepath.Join(path, "config/default.toml") } _, err := os.Open(configPath) utils.PanicOnError(err) config = &Config{} if _, err := toml.DecodeFile(configPath, &config); err != nil { utils.PanicOnError(err) } return config }
func main() { var port uint flag.UintVar(&port, "p", 3596, "specifies the port for Counts to run on") flag.Parse() //TODO: Add arguments for dataDir and infoDir err := os.Setenv("COUNTS_PORT", strconv.Itoa(int(port))) utils.PanicOnError(err) logger.Info.Println("Starting counts...") conf := config.GetConfig() logger.Info.Println("Using data dir: ", conf.DataDir) server, err := server.New() utils.PanicOnError(err) server.Run() }
func newManager() *ManagerStruct { conf = config.GetConfig() dataPath = conf.DataDir cacheSize := int(conf.CacheSize) if cacheSize == 0 { cacheSize = 250 // default cache size } cache, err := lru.NewWithEvict(cacheSize, func(k interface{}, v interface{}) { f := v.(*os.File) err := f.Close() if err != nil { logger.Error.Println(err) } }) utils.PanicOnError(err) err = os.MkdirAll(dataPath, 0777) utils.PanicOnError(err) return &ManagerStruct{cache} }
// GetConfig returns a singleton Configuration func GetConfig() *Config { if config == nil { config = parseConfigTOML() usr, err := user.Current() utils.PanicOnError(err) dir := usr.HomeDir infoDir := strings.TrimSpace(os.Getenv("SKZ_INFO_DIR")) if len(infoDir) == 0 { if config.InfoDir[:2] == "~/" { infoDir = strings.Replace(config.InfoDir, "~", dir, 1) } } dataDir := strings.TrimSpace(os.Getenv("SKZ_DATA_DIR")) if len(dataDir) == 0 { if config.DataDir[:2] == "~/" { dataDir = strings.Replace(config.DataDir, "~", dir, 1) } } portInt, err := strconv.Atoi(strings.TrimSpace(os.Getenv("SKZ_PORT"))) port := uint(portInt) if err != nil { port = config.Port } saveThresholdSecondsInt, err := strconv.Atoi(strings.TrimSpace(os.Getenv("SKZ_SAVE_TRESHOLD_SECS"))) saveThresholdSeconds := uint(saveThresholdSecondsInt) if err != nil { saveThresholdSeconds = config.SaveThresholdSeconds } saveThresholdOpsInt, err := strconv.Atoi(strings.TrimSpace(os.Getenv("SKZ_SAVE_TRESHOLD_OPS"))) saveThresholdOps := uint(saveThresholdOpsInt) if err != nil { saveThresholdOps = config.SaveThresholdOps } if saveThresholdSeconds < 3 { saveThresholdSeconds = 3 } config = &Config{ infoDir, dataDir, config.SliceSize, config.CacheSize, config.SliceCacheSize, port, saveThresholdSeconds, saveThresholdOps, } } return config }
func setupTests() { os.Setenv("SKZ_DATA_DIR", "/tmp/skizze_manager_data") os.Setenv("SKZ_INFO_DIR", "/tmp/skizze_manager_info") os.Setenv("SKZ_SAVE_TRESHOLD_OPS", "1") path, err := os.Getwd() utils.PanicOnError(err) path = filepath.Dir(path) configPath := filepath.Join(path, "config/default.toml") os.Setenv("SKZ_CONFIG", configPath) tearDownTests() }
func setupTests() { if err := os.Setenv("SKZ_DATA_DIR", "/tmp/skizze_manager_data"); err != nil { panic(fmt.Sprintf("Could not set SKZ_DATA_DIR=/tmp/skizze_manager_data")) } if err := os.Setenv("SKZ_INFO_DIR", "/tmp/skizze_manager_info"); err != nil { panic(fmt.Sprintf("Could not set SKZ_INFO_DIR=/tmp/skizze_manager_info")) } if err := os.Setenv("SKZ_SAVE_TRESHOLD_OPS", "1"); err != nil { panic(fmt.Sprintf("Could not set SKZ_SAVE_TRESHOLD_OPS=1")) } path, err := os.Getwd() utils.PanicOnError(err) path = filepath.Dir(path) configPath := filepath.Join(path, "config/default.toml") if err := os.Setenv("SKZ_CONFIG", configPath); err != nil { panic(fmt.Sprintf("Could not set SKZ_CONFIG=%s", configPath)) } tearDownTests() }
/* GetConfig returns a singleton Configuration */ func GetConfig() *Config { if config == nil { config = parseConfigTOML() usr, err := user.Current() utils.PanicOnError(err) dir := usr.HomeDir infoDir := strings.TrimSpace(os.Getenv("SKZ_INFO_DIR")) if len(infoDir) == 0 { if config.InfoDir[:2] == "~/" { infoDir = strings.Replace(config.InfoDir, "~", dir, 1) } } dataDir := strings.TrimSpace(os.Getenv("SKZ_DATA_DIR")) if len(dataDir) == 0 { if config.DataDir[:2] == "~/" { dataDir = strings.Replace(config.DataDir, "~", dir, 1) } } portInt, err := strconv.Atoi(strings.TrimSpace(os.Getenv("SKZ_PORT"))) port := uint(portInt) if err != nil { port = config.Port } config = &Config{ infoDir, dataDir, config.SliceSize, config.CacheSize, config.SliceCacheSize, port, } } return config }
func unmarshalSketchResult(resp *httptest.ResponseRecorder) sketchResult { body, _ := ioutil.ReadAll(resp.Body) var r sketchResult utils.PanicOnError(json.Unmarshal(body, &r)) return r }