snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
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
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
This commit is contained in:
24
extra/server-discovery/indexer/internal.go
Normal file
24
extra/server-discovery/indexer/internal.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package indexer
|
||||
|
||||
var (
|
||||
status struct {
|
||||
Index string `json:"index"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Full bool
|
||||
}
|
||||
)
|
||||
|
||||
//func pushStatus(ctx context.Context, esc *elasticsearch.Client) error {
|
||||
// var (
|
||||
// buf = &bytes.Buffer{}
|
||||
// st = struct {
|
||||
//
|
||||
// }
|
||||
// )
|
||||
//
|
||||
// json.NewEncoder(buf).Encode()
|
||||
//
|
||||
// spew.Dump(esc.Create("index", "", ))
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
118
extra/server-discovery/indexer/service.go
Normal file
118
extra/server-discovery/indexer/service.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package indexer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/api"
|
||||
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/es"
|
||||
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/es/mapping"
|
||||
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/es/reindex"
|
||||
"github.com/cortezaproject/corteza/extra/server-discovery/pkg/options"
|
||||
"github.com/elastic/go-elasticsearch/v7"
|
||||
"github.com/elastic/go-elasticsearch/v7/esutil"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type (
|
||||
Config struct {
|
||||
Corteza options.CortezaOpt
|
||||
ES options.EsOpt
|
||||
Indexer options.IndexerOpt
|
||||
}
|
||||
|
||||
esService interface {
|
||||
BulkIndexer() (esutil.BulkIndexer, error)
|
||||
}
|
||||
|
||||
apiClientService interface {
|
||||
HttpClient() *http.Client
|
||||
Mappings() (*http.Request, error)
|
||||
Feed(url.Values) (*http.Request, error)
|
||||
Resources(string, url.Values) (*http.Request, error)
|
||||
Request(string) (*http.Request, error)
|
||||
Authenticate() error
|
||||
}
|
||||
|
||||
mappingService interface {
|
||||
Mappings(ctx context.Context, esc *elasticsearch.Client, indexPrefix string) (err error)
|
||||
ConfigurationMapping(ctx context.Context) (err error)
|
||||
}
|
||||
|
||||
reIndexService interface {
|
||||
ReindexAll(ctx context.Context, esb esutil.BulkIndexer, indexPrefix string) error
|
||||
Watch(ctx context.Context)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultEs esService
|
||||
DefaultApiClient apiClientService
|
||||
DefaultMapper mappingService
|
||||
DefaultReIndexer reIndexService
|
||||
)
|
||||
|
||||
func Initialize(ctx context.Context, log *zap.Logger, c Config, esClient *elasticsearch.Client) (err error) {
|
||||
DefaultEs, err = es.ES(log, esClient)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
schema := c.Indexer.Schemas[0]
|
||||
if len(schema.ClientKey) == 0 || len(schema.ClientSecret) == 0 {
|
||||
return fmt.Errorf("client key and secret is missing")
|
||||
}
|
||||
DefaultApiClient, err = api.Client(c.Corteza, schema.ClientKey, schema.ClientSecret)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Map indexing for resources
|
||||
DefaultMapper = mapping.Mapper(log, esClient, DefaultApiClient)
|
||||
|
||||
err = DefaultMapper.ConfigurationMapping(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// @todo: private/public/protected indexing
|
||||
err = DefaultMapper.Mappings(ctx, esClient, "private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Reindexing existing mapping if needed
|
||||
DefaultReIndexer = reindex.ReIndexer(log, DefaultEs, esClient, DefaultApiClient, c.ES, func(ctx context.Context) (err error) {
|
||||
err = DefaultMapper.Mappings(ctx, esClient, "private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
})
|
||||
|
||||
esb, err := DefaultEs.BulkIndexer()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to prepare bulk indexer: %w", err)
|
||||
}
|
||||
|
||||
err = DefaultReIndexer.ReindexAll(ctx, esb, "private")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = esb.Close(ctx); err != nil {
|
||||
return fmt.Errorf("failed to close bulk indexer: %w", err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func Watchers(ctx context.Context) {
|
||||
// Initiate watcher for reindexing resource
|
||||
DefaultReIndexer.Watch(ctx)
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user