From 91251538af8046cb3add2befbf621def4c1a7f85 Mon Sep 17 00:00:00 2001 From: artaasadi Date: Sun, 29 Dec 2024 22:21:59 +0100 Subject: [PATCH] fix: reload views after migrator run --- .../job/migrations/compliance/populate.go | 10 ++++++++++ services/metadata/client/metadata.go | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/jobs/post-install-job/job/migrations/compliance/populate.go b/jobs/post-install-job/job/migrations/compliance/populate.go index 18c7a675c..639cba4c3 100644 --- a/jobs/post-install-job/job/migrations/compliance/populate.go +++ b/jobs/post-install-job/job/migrations/compliance/populate.go @@ -3,7 +3,10 @@ package compliance import ( "context" "fmt" + authApi "github.com/opengovern/og-util/pkg/api" + "github.com/opengovern/og-util/pkg/httpclient" "github.com/opengovern/opencomply/jobs/post-install-job/job/migrations/inventory" + metadataClient "github.com/opengovern/opencomply/services/metadata/client" "github.com/opengovern/opencomply/services/metadata/models" "github.com/opengovern/og-util/pkg/postgres" @@ -284,5 +287,12 @@ func (m Migration) Run(ctx context.Context, conf config.MigratorConfig, logger * return err } + mClient := metadataClient.NewMetadataServiceClient(conf.Metadata.BaseURL) + err = mClient.ReloadViews(&httpclient.Context{Ctx: ctx, UserRole: authApi.AdminRole}) + if err != nil { + logger.Error("failed to reload views", zap.Error(err)) + return fmt.Errorf("failed to reload views: %s", err.Error()) + } + return nil } diff --git a/services/metadata/client/metadata.go b/services/metadata/client/metadata.go index 2ce670930..c02b751c3 100644 --- a/services/metadata/client/metadata.go +++ b/services/metadata/client/metadata.go @@ -23,6 +23,7 @@ type MetadataServiceClient interface { SetQueryParameter(ctx *httpclient.Context, request api.SetQueryParameterRequest) error VaultConfigured(ctx *httpclient.Context) (*string, error) GetViewsCheckpoint(ctx *httpclient.Context) (*api.GetViewsCheckpointResponse, error) + ReloadViews(ctx *httpclient.Context) error GetAbout(ctx *httpclient.Context) (*api.About, error) } @@ -150,6 +151,18 @@ func (s *metadataClient) VaultConfigured(ctx *httpclient.Context) (*string, erro return &status, nil } +func (s *metadataClient) ReloadViews(ctx *httpclient.Context) error { + url := fmt.Sprintf("%s/api/v1/views/reload", s.baseURL) + + if statusCode, err := httpclient.DoRequest(ctx.Ctx, http.MethodPut, url, ctx.ToHeaders(), nil, nil); err != nil { + if 400 <= statusCode && statusCode < 500 { + return echo.NewHTTPError(statusCode, err.Error()) + } + return err + } + return nil +} + func (s *metadataClient) GetViewsCheckpoint(ctx *httpclient.Context) (*api.GetViewsCheckpointResponse, error) { url := fmt.Sprintf("%s/api/v1/views/checkpoint", s.baseURL) var resp api.GetViewsCheckpointResponse