예제 #1
0
func aStartedRouter() (*router, auth.AccessManager, store.MessageStore, kvstore.KVStore) {
	am := auth.NewAllowAllAccessManager(true)
	kvs := kvstore.NewMemoryKVStore()
	ms := dummystore.New(kvs)
	router := New(am, ms, kvs, nil).(*router)
	router.Start()
	return router, am, ms, kvs
}
예제 #2
0
func StartService() *server.Service {
	accessManager := auth.NewAllowAllAccessManager(true)
	messageStore := CreateMessageStore()
	kvStore := CreateKVStore()

	var c *cluster.Cluster
	var err error
	if *config.Cluster.NodeID > 0 {
		exitIfInvalidClusterParams(*config.Cluster.NodeID, *config.Cluster.NodePort, *config.Cluster.Remotes)
		logger.Info("Starting in cluster-mode")
		c, err = cluster.New(&cluster.Config{
			ID:      *config.Cluster.NodeID,
			Port:    *config.Cluster.NodePort,
			Remotes: *config.Cluster.Remotes,
		})
		if err != nil {
			logger.WithField("err", err).Fatal("Service could not be started (cluster)")
		}
	} else {
		logger.Info("Starting in standalone-mode")
	}

	router := server.NewRouter(accessManager, messageStore, kvStore, c)
	webserver := webserver.New(*config.HttpListen)

	service := server.NewService(router, webserver).
		HealthEndpoint(*config.HealthEndpoint).
		MetricsEndpoint(*config.Metrics.Endpoint)

	service.RegisterModules(CreateModules(router)...)

	if err = service.Start(); err != nil {
		if err = service.Stop(); err != nil {
			logger.WithField("err", err).Error("Error when stopping service after Start() failed")
		}
		logger.WithField("err", err).Fatal("Service could not be started")
	}

	return service
}
예제 #3
0
func runNewWebSocket(
	wsconn *MockWSConnection,
	routerMock *MockRouter,
	messageStore store.MessageStore,
	accessManager auth.AccessManager) *WebSocket {

	if accessManager == nil {
		accessManager = auth.NewAllowAllAccessManager(true)
	}
	websocket := NewWebSocket(
		testWSHandler(routerMock, accessManager),
		wsconn,
		"testuser",
	)

	go func() {
		websocket.Start()
	}()

	time.Sleep(time.Millisecond * 2)
	return websocket
}
예제 #4
0
파일: gubled.go 프로젝트: smancke/guble
		testfile := path.Join(*Config.StoragePath, "write-test-file")
		f, err := os.Create(testfile)
		if err != nil {
			logger.WithError(err).WithField("storagePath", *Config.StoragePath).Error("Storage path not present/writeable.")
			return err
		}
		f.Close()
		os.Remove(testfile)
	}
	return nil
}

// CreateAccessManager is a func which returns a auth.AccessManager implementation
// (currently: AllowAllAccessManager).
var CreateAccessManager = func() auth.AccessManager {
	return auth.NewAllowAllAccessManager(true)
}

// CreateKVStore is a func which returns a kvstore.KVStore implementation
// (currently, based on guble configuration).
var CreateKVStore = func() kvstore.KVStore {
	switch *Config.KVS {
	case "memory":
		return kvstore.NewMemoryKVStore()
	case "file":
		db := kvstore.NewSqliteKVStore(path.Join(*Config.StoragePath, "kv-store.db"), true)
		if err := db.Open(); err != nil {
			logger.WithError(err).Panic("Could not open sqlite database connection")
		}
		return db
	case "postgres":