Skip to content

Commit

Permalink
feat: Add allowed resource provider memory implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Jan 17, 2025
1 parent e8ca213 commit b86f022
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions pkg/solver/store/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ import (
)

type SolverStoreMemory struct {
jobOfferMap map[string]*data.JobOfferContainer
resourceOfferMap map[string]*data.ResourceOfferContainer
dealMap map[string]*data.DealContainer
resultMap map[string]*data.Result
matchDecisionMap map[string]*data.MatchDecision
mutex sync.RWMutex
jobOfferMap map[string]*data.JobOfferContainer
resourceOfferMap map[string]*data.ResourceOfferContainer
dealMap map[string]*data.DealContainer
resultMap map[string]*data.Result
matchDecisionMap map[string]*data.MatchDecision
allowedResourceProviderMap map[string]string
mutex sync.RWMutex
}

func NewSolverStoreMemory() (*SolverStoreMemory, error) {
return &SolverStoreMemory{
jobOfferMap: map[string]*data.JobOfferContainer{},
resourceOfferMap: map[string]*data.ResourceOfferContainer{},
dealMap: map[string]*data.DealContainer{},
resultMap: map[string]*data.Result{},
matchDecisionMap: map[string]*data.MatchDecision{},
jobOfferMap: map[string]*data.JobOfferContainer{},
resourceOfferMap: map[string]*data.ResourceOfferContainer{},
dealMap: map[string]*data.DealContainer{},
resultMap: map[string]*data.Result{},
matchDecisionMap: map[string]*data.MatchDecision{},
allowedResourceProviderMap: map[string]string{},
}, nil
}

Expand Down Expand Up @@ -79,6 +81,14 @@ func (s *SolverStoreMemory) AddMatchDecision(resourceOffer string, jobOffer stri
return decision, nil
}

func (store *SolverStoreMemory) AddAllowedResourceProvider(resourceProvider string) (string, error) {
store.mutex.Lock()
defer store.mutex.Unlock()
store.allowedResourceProviderMap[resourceProvider] = resourceProvider

return resourceProvider, nil
}

func (s *SolverStoreMemory) GetJobOffers(query store.GetJobOffersQuery) ([]data.JobOfferContainer, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()
Expand Down Expand Up @@ -190,6 +200,18 @@ func (s *SolverStoreMemory) GetMatchDecisions() ([]data.MatchDecision, error) {
return results, nil
}

func (store *SolverStoreMemory) GetAllowedResourceProviders() ([]string, error) {
store.mutex.RLock()
defer store.mutex.RUnlock()

providers := []string{}
for provider := range store.allowedResourceProviderMap {
providers = append(providers, provider)
}

return providers, nil
}

func (s *SolverStoreMemory) GetJobOffer(id string) (*data.JobOfferContainer, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()
Expand Down Expand Up @@ -414,6 +436,13 @@ func (s *SolverStoreMemory) RemoveMatchDecision(resourceOffer string, jobOffer s
return nil
}

func (store *SolverStoreMemory) RemoveAllowedResourceProvider(resourceProvider string) error {
store.mutex.Lock()
defer store.mutex.Unlock()
delete(store.allowedResourceProviderMap, resourceProvider)
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 b86f022

Please sign in to comment.