2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-11-16 23:29:59 +00:00
|
|
|
package devicemanager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-12-17 18:19:51 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/base"
|
2018-11-16 23:29:59 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/device"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ReserveFn func(d *structs.AllocatedDeviceResource) (*device.ContainerReservation, error)
|
|
|
|
type AllStatsFn func() []*device.DeviceGroupStats
|
|
|
|
type DeviceStatsFn func(d *structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error)
|
|
|
|
|
|
|
|
func NoopReserve(*structs.AllocatedDeviceResource) (*device.ContainerReservation, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NoopAllStats() []*device.DeviceGroupStats {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NoopDeviceStats(*structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NoopMockManager() *MockManager {
|
|
|
|
return &MockManager{
|
|
|
|
ReserveF: NoopReserve,
|
|
|
|
AllStatsF: NoopAllStats,
|
|
|
|
DeviceStatsF: NoopDeviceStats,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MockManager struct {
|
|
|
|
ReserveF ReserveFn
|
|
|
|
AllStatsF AllStatsFn
|
|
|
|
DeviceStatsF DeviceStatsFn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockManager) Run() {}
|
|
|
|
func (m *MockManager) Shutdown() {}
|
2018-12-17 18:19:51 +00:00
|
|
|
func (m *MockManager) PluginType() string { return base.PluginTypeDevice }
|
2018-11-16 23:29:59 +00:00
|
|
|
func (m *MockManager) AllStats() []*device.DeviceGroupStats { return m.AllStatsF() }
|
|
|
|
|
|
|
|
func (m *MockManager) Reserve(d *structs.AllocatedDeviceResource) (*device.ContainerReservation, error) {
|
|
|
|
return m.ReserveF(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockManager) DeviceStats(d *structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error) {
|
|
|
|
return m.DeviceStatsF(d)
|
|
|
|
}
|