Files
query-orchestration/cmd/queryService/main.go
T

124 lines
3.6 KiB
Go
Raw Normal View History

2025-03-05 13:50:43 +00:00
// This API currently manages all user entities to be managed. This allows users of the service to change required entities and processes.
//
// The entities in question:
//
// - Client - A client is a single client of the Doczy project, all configurations and clients for a client will be in reference to the respective client.
2025-03-05 13:50:43 +00:00
//
// - Collector - A collector specifies the required queries for export for a given client.
2025-03-05 13:50:43 +00:00
//
// - Sample - A sample is a subset of documents to be used for testing. When it is active a client will only process documents in the sample.
2025-03-05 13:50:43 +00:00
//
// - Query - A query is a block of processing of data which takes an input and produces an output.
//
// - Export - An export is a manually started process which outputs the results for a client to a given location.
2024-12-18 18:54:48 +00:00
package main
import (
"context"
"fmt"
"log/slog"
"os"
2025-03-05 12:05:46 +00:00
2025-03-18 15:52:58 -07:00
"queryorchestration/internal/serviceconfig"
2025-01-15 19:45:51 +00:00
queryservice "queryorchestration/api/queryService"
2025-01-21 18:24:14 +00:00
"queryorchestration/internal/client"
"queryorchestration/internal/collector"
collectorset "queryorchestration/internal/collector/set"
"queryorchestration/internal/document"
2024-12-24 17:13:48 +00:00
"queryorchestration/internal/export"
"queryorchestration/internal/query"
"queryorchestration/internal/query/result"
querytest "queryorchestration/internal/query/test"
queryupdate "queryorchestration/internal/query/update"
service "queryorchestration/internal/server/service"
"queryorchestration/internal/serviceconfig/queue/clientsync"
"queryorchestration/internal/serviceconfig/queue/queryversionsync"
2025-03-18 15:52:58 -07:00
"queryorchestration/internal/serviceconfig/rbac"
2024-12-18 18:54:48 +00:00
"github.com/getkin/kin-openapi/openapi3"
2024-12-18 18:54:48 +00:00
_ "github.com/lib/pq"
)
type QueryServiceConfig struct {
service.BaseConfig
clientsync.ClientSyncConfig
queryversionsync.QueryVersionSyncConfig
}
2024-12-18 18:54:48 +00:00
func main() {
ctx := context.Background()
cfg := &QueryServiceConfig{}
cfg.RegisterHandlersFunc = func() (*openapi3.T, error) {
exp := export.New()
que := query.New(cfg)
res := result.New(cfg, &result.Services{
Query: que,
})
col := collector.New(cfg)
colupdate := collectorset.New(cfg, &collectorset.Services{
Collector: col,
2025-01-23 14:56:20 +00:00
})
cli := client.New(cfg)
doc := document.New(cfg)
quetest := querytest.New(cfg, &querytest.Services{
Collector: col,
Result: res,
Document: doc,
})
qupdate := queryupdate.New(cfg, &queryupdate.Services{
Query: que,
})
2024-12-18 18:54:48 +00:00
2025-01-15 19:45:51 +00:00
services := &queryservice.Services{
Export: exp,
Collector: col,
CollectorSet: colupdate,
Query: que,
QueryUpdate: qupdate,
QueryTest: quetest,
Client: cli,
Document: doc,
2025-01-15 19:45:51 +00:00
}
cons := queryservice.NewControllers(cfg.GetValidator(), services)
2025-01-15 19:45:51 +00:00
queryservice.RegisterHandlers(cfg.Router, cons)
2025-01-15 19:45:51 +00:00
swagger, err := queryservice.GetSwagger()
if err != nil {
return nil, fmt.Errorf("error loading swagger: %s", err)
2025-01-15 19:45:51 +00:00
}
return swagger, nil
2024-12-18 18:54:48 +00:00
}
2025-03-18 16:28:00 -07:00
// Both of these operations (InitializeConfig and InitializeAuthProvider)
// would be better off in the service.new but there are temporal dependencies
// that make this not possible right now without more refactoring.
// This must be done before the rbac.InitializeAuthProvider
2025-03-18 15:52:58 -07:00
errInitializingConfig := serviceconfig.InitializeConfig(cfg)
if errInitializingConfig != nil {
slog.Error(errInitializingConfig.Error())
os.Exit(1)
}
2025-03-18 16:28:00 -07:00
// Initialize the rbac config here since only the API service needs it
2025-03-18 15:52:58 -07:00
errorGettingAuthProvider := rbac.InitializeAuthProvider(&cfg.AuthConfig)
if errorGettingAuthProvider != nil {
slog.Error(errorGettingAuthProvider.Error())
os.Exit(1)
}
server, err := service.New(ctx, cfg)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
2024-12-18 18:54:48 +00:00
2025-01-10 11:12:03 +00:00
server.Listen()
2024-12-18 18:54:48 +00:00
}