Files
upstream-corteza/extra/server-discovery/app/boot_levels.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

129 lines
3.0 KiB
Go

package app
import (
"context"
"fmt"
"github.com/cortezaproject/corteza/extra/server-discovery/indexer"
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/auth"
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/es"
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/healthcheck"
"github.com/cortezaproject/corteza/extra/server-discovery/searcher"
)
const (
bootLevelWaiting = iota
bootLevelSetup
bootLevelStoreInitialized
bootLevelProvisioned
bootLevelServicesInitialized
bootLevelActivated
)
// Setup configures all required services
func (app *CortezaDiscoveryApp) Setup() (err error) {
app.lvl = bootLevelSetup
hcd := healthcheck.Defaults()
if app.Opt.Searcher.Enabled {
hcd.Add(searcher.Healthcheck, "OpenSearch")
}
return nil
}
// InitStore initializes open search store and runs upgrade procedures
func (app *CortezaDiscoveryApp) InitStore(ctx context.Context) (err error) {
if app.lvl >= bootLevelStoreInitialized {
// Is store already initialised?
return nil
} else if err = app.Setup(); err != nil {
// Initialize previous level
return err
}
app.lvl = bootLevelStoreInitialized
return nil
}
// Provision instance with configuration and settings
// by importing preset configurations and running autodiscovery procedures
func (app *CortezaDiscoveryApp) Provision(ctx context.Context) (err error) {
if app.lvl >= bootLevelProvisioned {
return
}
if err = app.InitStore(ctx); err != nil {
return err
}
app.lvl = bootLevelProvisioned
return
}
// InitServices initializes all services used
func (app *CortezaDiscoveryApp) InitServices(ctx context.Context) (err error) {
if app.lvl >= bootLevelServicesInitialized {
return nil
}
if err = app.Provision(ctx); err != nil {
return err
}
if auth.HttpTokenVerifier, err = auth.TokenVerifierMiddlewareWithSecretSigner(string(app.Opt.Searcher.JwtSecret)); err != nil {
return fmt.Errorf("could not set token verifier")
}
//initialize Elastic search client
esClient, err := es.Connect(app.Opt.ES)
if err != nil {
return fmt.Errorf("failed to initialize Elasticsearch client: %s", err.Error())
}
if app.Opt.Indexer.Enabled {
err = indexer.Initialize(ctx, app.Log, indexer.Config{
Corteza: app.Opt.Corteza,
ES: app.Opt.ES,
Indexer: app.Opt.Indexer,
}, esClient)
if err != nil {
return
}
}
if app.Opt.Searcher.Enabled {
err = searcher.Initialize(ctx, app.Log, searcher.Config{
Corteza: app.Opt.Corteza,
ES: app.Opt.ES,
HttpServer: app.Opt.HTTPServer,
Searcher: app.Opt.Searcher,
}, esClient)
if err != nil {
return
}
}
app.lvl = bootLevelServicesInitialized
return
}
// Activate start all internal services and watchers
func (app *CortezaDiscoveryApp) Activate(ctx context.Context) (err error) {
if app.lvl >= bootLevelActivated {
return
}
if err := app.InitServices(ctx); err != nil {
return err
}
if app.Opt.Indexer.Enabled {
go indexer.Watchers(ctx)
}
app.lvl = bootLevelActivated
return nil
}