Skip to content

Commit

Permalink
feat: Add allowed resource provider database implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Jan 9, 2025
1 parent 96bd2a2 commit 3b217b7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/solver/store/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3b217b7

Please sign in to comment.