General cleanup when making components (#1098)

* Remove ParseMonolith/LoadMonolith

* cleanup which components need to be made
This commit is contained in:
Kegsay 2020-06-05 09:28:15 +01:00 committed by GitHub
parent 2bd12f635c
commit 29a20d1da7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 22 additions and 79 deletions

View file

@ -21,7 +21,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI", true) base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck

View file

@ -16,14 +16,12 @@ package main
import ( import (
"github.com/matrix-org/dendrite/clientapi" "github.com/matrix-org/dendrite/clientapi"
"github.com/matrix-org/dendrite/eduserver"
"github.com/matrix-org/dendrite/eduserver/cache"
"github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/internal/basecomponent"
"github.com/matrix-org/dendrite/internal/transactions" "github.com/matrix-org/dendrite/internal/transactions"
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "ClientAPI", true) base := basecomponent.NewBaseDendrite(cfg, "ClientAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck
@ -38,8 +36,7 @@ func main() {
asQuery := base.AppserviceHTTPClient() asQuery := base.AppserviceHTTPClient()
rsAPI := base.RoomserverHTTPClient() rsAPI := base.RoomserverHTTPClient()
fsAPI := base.FederationSenderHTTPClient() fsAPI := base.FederationSenderHTTPClient()
rsAPI.SetFederationSenderAPI(fsAPI) eduInputAPI := base.EDUServerClient()
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New(), deviceDB)
clientapi.SetupClientAPIComponent( clientapi.SetupClientAPIComponent(
base, deviceDB, accountDB, federation, keyRing, base, deviceDB, accountDB, federation, keyRing,

View file

@ -22,7 +22,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI", true) base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI", true)
defer func() { defer func() {
if err := base.Close(); err != nil { if err := base.Close(); err != nil {

View file

@ -16,31 +16,25 @@ package main
import ( import (
"github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/eduserver"
"github.com/matrix-org/dendrite/eduserver/cache"
"github.com/matrix-org/dendrite/federationapi" "github.com/matrix-org/dendrite/federationapi"
"github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/internal/basecomponent"
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "FederationAPI", true) base := basecomponent.NewBaseDendrite(cfg, "FederationAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB() accountDB := base.CreateAccountsDB()
deviceDB := base.CreateDeviceDB() deviceDB := base.CreateDeviceDB()
federation := base.CreateFederationClient() federation := base.CreateFederationClient()
serverKeyAPI := base.ServerKeyAPIClient() serverKeyAPI := base.ServerKeyAPIClient()
keyRing := serverKeyAPI.KeyRing() keyRing := serverKeyAPI.KeyRing()
fsAPI := base.FederationSenderHTTPClient() fsAPI := base.FederationSenderHTTPClient()
rsAPI := base.RoomserverHTTPClient() rsAPI := base.RoomserverHTTPClient()
asAPI := base.AppserviceHTTPClient() asAPI := base.AppserviceHTTPClient()
rsAPI.SetFederationSenderAPI(fsAPI) // TODO: this isn't a producer
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New(), deviceDB) eduProducer := producers.NewEDUServerProducer(base.EDUServerClient())
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent( federationapi.SetupFederationAPIComponent(
base, accountDB, deviceDB, federation, keyRing, base, accountDB, deviceDB, federation, keyRing,

View file

@ -20,7 +20,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "FederationSender", true) base := basecomponent.NewBaseDendrite(cfg, "FederationSender", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck
@ -30,10 +30,9 @@ func main() {
keyRing := serverKeyAPI.KeyRing() keyRing := serverKeyAPI.KeyRing()
rsAPI := base.RoomserverHTTPClient() rsAPI := base.RoomserverHTTPClient()
fsAPI := federationsender.SetupFederationSenderComponent( federationsender.SetupFederationSenderComponent(
base, federation, rsAPI, keyRing, base, federation, rsAPI, keyRing,
) )
rsAPI.SetFederationSenderAPI(fsAPI)
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender), string(base.Cfg.Listen.FederationSender)) base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender), string(base.Cfg.Listen.FederationSender))

View file

@ -20,7 +20,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "KeyServer", true) base := basecomponent.NewBaseDendrite(cfg, "KeyServer", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck

View file

@ -20,7 +20,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "MediaAPI", true) base := basecomponent.NewBaseDendrite(cfg, "MediaAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck

View file

@ -49,7 +49,7 @@ var (
) )
func main() { func main() {
cfg := basecomponent.ParseMonolithFlags() cfg := basecomponent.ParseFlags(true)
if *enableHTTPAPIs { if *enableHTTPAPIs {
// If the HTTP APIs are enabled then we need to update the Listen // If the HTTP APIs are enabled then we need to update the Listen
// statements in the configuration so that we know where to find // statements in the configuration so that we know where to find

View file

@ -22,15 +22,13 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI", true) base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck
deviceDB := base.CreateDeviceDB() deviceDB := base.CreateDeviceDB()
fsAPI := base.FederationSenderHTTPClient()
rsAPI := base.RoomserverHTTPClient() rsAPI := base.RoomserverHTTPClient()
rsAPI.SetFederationSenderAPI(fsAPI)
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties(), cfg.Matrix.ServerName) publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties(), cfg.Matrix.ServerName)
if err != nil { if err != nil {

View file

@ -20,7 +20,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true) base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck
federation := base.CreateFederationClient() federation := base.CreateFederationClient()

View file

@ -20,7 +20,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "ServerKeyAPI", true) base := basecomponent.NewBaseDendrite(cfg, "ServerKeyAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck

View file

@ -20,7 +20,7 @@ import (
) )
func main() { func main() {
cfg := basecomponent.ParseFlags() cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "SyncAPI", true) base := basecomponent.NewBaseDendrite(cfg, "SyncAPI", true)
defer base.Close() // nolint: errcheck defer base.Close() // nolint: errcheck

View file

@ -25,33 +25,14 @@ import (
var configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.") var configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
// ParseFlags parses the commandline flags and uses them to create a config. // ParseFlags parses the commandline flags and uses them to create a config.
// If running as a monolith use `ParseMonolithFlags` instead. func ParseFlags(monolith bool) *config.Dendrite {
func ParseFlags() *config.Dendrite {
flag.Parse() flag.Parse()
if *configPath == "" { if *configPath == "" {
logrus.Fatal("--config must be supplied") logrus.Fatal("--config must be supplied")
} }
cfg, err := config.Load(*configPath) cfg, err := config.Load(*configPath, monolith)
if err != nil {
logrus.Fatalf("Invalid config file: %s", err)
}
return cfg
}
// ParseMonolithFlags parses the commandline flags and uses them to create a
// config. Should only be used if running a monolith. See `ParseFlags`.
func ParseMonolithFlags() *config.Dendrite {
flag.Parse()
if *configPath == "" {
logrus.Fatal("--config must be supplied")
}
cfg, err := config.LoadMonolithic(*configPath)
if err != nil { if err != nil {
logrus.Fatalf("Invalid config file: %s", err) logrus.Fatalf("Invalid config file: %s", err)

View file

@ -370,11 +370,9 @@ type LogrusHook struct {
// It implements the error interface. // It implements the error interface.
type configErrors []string type configErrors []string
// Load a yaml config file for a server run as multiple processes. // Load a yaml config file for a server run as multiple processes or as a monolith.
// Checks the config to ensure that it is valid. // Checks the config to ensure that it is valid.
// The checks are different if the server is run as a monolithic process instead func Load(configPath string, monolith bool) (*Dendrite, error) {
// of being split into multiple components
func Load(configPath string) (*Dendrite, error) {
configData, err := ioutil.ReadFile(configPath) configData, err := ioutil.ReadFile(configPath)
if err != nil { if err != nil {
return nil, err return nil, err
@ -385,27 +383,7 @@ func Load(configPath string) (*Dendrite, error) {
} }
// Pass the current working directory and ioutil.ReadFile so that they can // Pass the current working directory and ioutil.ReadFile so that they can
// be mocked in the tests // be mocked in the tests
monolithic := false return loadConfig(basePath, configData, ioutil.ReadFile, monolith)
return loadConfig(basePath, configData, ioutil.ReadFile, monolithic)
}
// LoadMonolithic loads a yaml config file for a server run as a single monolith.
// Checks the config to ensure that it is valid.
// The checks are different if the server is run as a monolithic process instead
// of being split into multiple components
func LoadMonolithic(configPath string) (*Dendrite, error) {
configData, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
basePath, err := filepath.Abs(".")
if err != nil {
return nil, err
}
// Pass the current working directory and ioutil.ReadFile so that they can
// be mocked in the tests
monolithic := true
return loadConfig(basePath, configData, ioutil.ReadFile, monolithic)
} }
func loadConfig( func loadConfig(

View file

@ -45,7 +45,6 @@ const (
type httpRoomserverInternalAPI struct { type httpRoomserverInternalAPI struct {
roomserverURL string roomserverURL string
httpClient *http.Client httpClient *http.Client
fsAPI fsInputAPI.FederationSenderInternalAPI
immutableCache caching.ImmutableCache immutableCache caching.ImmutableCache
} }
@ -66,11 +65,8 @@ func NewRoomserverClient(
}, nil }, nil
} }
// SetFederationSenderInputAPI passes in a federation sender input API reference // SetFederationSenderInputAPI no-ops in HTTP client mode as there is no chicken/egg scenario
// so that we can avoid the chicken-and-egg problem of both the roomserver input API
// and the federation sender input API being interdependent.
func (h *httpRoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsInputAPI.FederationSenderInternalAPI) { func (h *httpRoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsInputAPI.FederationSenderInternalAPI) {
h.fsAPI = fsAPI
} }
// SetRoomAlias implements RoomserverAliasAPI // SetRoomAlias implements RoomserverAliasAPI