From 7ac5bc0ec93bcfcde701c5201620693f2af22019 Mon Sep 17 00:00:00 2001 From: Brian Ginsburg Date: Thu, 9 Jan 2025 15:08:38 -0800 Subject: [PATCH] feat: Add allowed resource provider database implementations --- pkg/solver/store/db/db.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/solver/store/db/db.go b/pkg/solver/store/db/db.go index a38e72a9..6c5a421c 100644 --- a/pkg/solver/store/db/db.go +++ b/pkg/solver/store/db/db.go @@ -134,6 +134,19 @@ func (store *SolverStoreDatabase) AddMatchDecision(resourceOffer string, jobOffe return decision, nil } +func (store *SolverStoreDatabase) AddAllowedResourceProvider(resourceProvider string) (string, error) { + record := AllowedResourceProvider{ + ResourceProvider: resourceProvider, + } + + result := store.db.Create(&record) + if result.Error != nil { + return "", result.Error + } + + return resourceProvider, nil +} + func (store *SolverStoreDatabase) GetJobOffers(query store.GetJobOffersQuery) ([]data.JobOfferContainer, error) { q := store.db.Where([]JobOffer{}) @@ -267,6 +280,20 @@ func (store *SolverStoreDatabase) GetMatchDecisions() ([]data.MatchDecision, err return decisions, nil } +func (store *SolverStoreDatabase) GetAllowedResourceProviders() ([]string, error) { + var records []AllowedResourceProvider + if err := store.db.Find(&records).Error; err != nil { + return nil, err + } + + providers := make([]string, len(records)) + for i, record := range records { + providers[i] = record.ResourceProvider + } + + return providers, nil +} + func (store *SolverStoreDatabase) GetJobOffer(id string) (*data.JobOfferContainer, error) { // Offers are unique by CID, so we can query first var record JobOffer @@ -614,6 +641,14 @@ func (store *SolverStoreDatabase) RemoveMatchDecision(resourceOffer string, jobO return nil } +func (store *SolverStoreDatabase) RemoveAllowedResourceProvider(resourceProvider string) error { + result := store.db.Where("resource_provider = ?", resourceProvider).Delete(&AllowedResourceProvider{}) + if result.Error != nil { + return result.Error + } + return nil +} + // Strictly speaking, the compiler will check the interface // implementation without this check. But some code editors // report errors more effectively when we have it.