From 1d4d42f6bd98fd39eb6022a576ce2d5188672d41 Mon Sep 17 00:00:00 2001 From: vikrantgupta25 Date: Mon, 18 Nov 2024 17:06:33 +0530 Subject: [PATCH 1/3] feat: use the license v2 key to fill licenses v3 on startup --- ee/query-service/license/manager.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ee/query-service/license/manager.go b/ee/query-service/license/manager.go index 6dcc704e3a..d5bab652bb 100644 --- a/ee/query-service/license/manager.go +++ b/ee/query-service/license/manager.go @@ -67,6 +67,26 @@ func StartManager(dbType string, db *sqlx.DB, useLicensesV3 bool, features ...ba repo: &repo, } + if useLicensesV3 { + // get active license from the db + active, err := m.repo.GetActiveLicense(context.Background()) + if err != nil { + return m, err + } + + // fetch the new license structure from control plane + licenseV3, apiError := validate.ValidateLicenseV3(active.Key) + if apiError != nil { + return m, apiError + } + + // insert the licenseV3 in sqlite db + apiError = m.repo.InsertLicenseV3(context.Background(), licenseV3) + if apiError != nil { + return m, apiError + } + } + if err := m.start(useLicensesV3, features...); err != nil { return m, err } From a75b4f8e5941fc65a7c5ddec5fab5426e611c9f7 Mon Sep 17 00:00:00 2001 From: vikrantgupta25 Date: Mon, 18 Nov 2024 17:15:40 +0530 Subject: [PATCH 2/3] chore: make the init only if the licenses v2 is present --- ee/query-service/license/manager.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ee/query-service/license/manager.go b/ee/query-service/license/manager.go index d5bab652bb..0c60f0924f 100644 --- a/ee/query-service/license/manager.go +++ b/ee/query-service/license/manager.go @@ -74,16 +74,19 @@ func StartManager(dbType string, db *sqlx.DB, useLicensesV3 bool, features ...ba return m, err } - // fetch the new license structure from control plane - licenseV3, apiError := validate.ValidateLicenseV3(active.Key) - if apiError != nil { - return m, apiError - } + // if we have an active license then need to fetch the complete details + if active != nil { + // fetch the new license structure from control plane + licenseV3, apiError := validate.ValidateLicenseV3(active.Key) + if apiError != nil { + return m, apiError + } - // insert the licenseV3 in sqlite db - apiError = m.repo.InsertLicenseV3(context.Background(), licenseV3) - if apiError != nil { - return m, apiError + // insert the licenseV3 in sqlite db + apiError = m.repo.InsertLicenseV3(context.Background(), licenseV3) + if apiError != nil { + return m, apiError + } } } From b1cd9335708a2fa24ca22b28b8fb61f70f4edd54 Mon Sep 17 00:00:00 2001 From: vikrantgupta25 Date: Mon, 18 Nov 2024 17:24:43 +0530 Subject: [PATCH 3/3] chore: address review comments --- ee/query-service/license/manager.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ee/query-service/license/manager.go b/ee/query-service/license/manager.go index 0c60f0924f..aa58e7e5a5 100644 --- a/ee/query-service/license/manager.go +++ b/ee/query-service/license/manager.go @@ -84,7 +84,8 @@ func StartManager(dbType string, db *sqlx.DB, useLicensesV3 bool, features ...ba // insert the licenseV3 in sqlite db apiError = m.repo.InsertLicenseV3(context.Background(), licenseV3) - if apiError != nil { + // if the license already exists move ahead. + if apiError != nil && apiError.Typ != model.ErrorConflict { return m, apiError } }