Documentation
¶
Overview ¶
Package datastore contains datastore-related logic.
Index ¶
- Constants
- func GenerateRepairRecordID(hostname string, assetTag string, createdTime string) (string, error)
- func SaveLastScannedTime(ctx context.Context, lastScannedTime time.Time) error
- type DeviceEntity
- type DeviceEntityID
- type DeviceManualRepairRecordEntity
- type DeviceManualRepairRecordsOpRes
- func AddDeviceManualRepairRecords(ctx context.Context, records []*invlibs.DeviceManualRepairRecord) ([]*DeviceManualRepairRecordsOpRes, error)
- func GetDeviceManualRepairRecords(ctx context.Context, ids []string) []*DeviceManualRepairRecordsOpRes
- func GetRepairRecordByPropertyName(ctx context.Context, propMap map[string]string, limit int32, offset int32, ...) ([]*DeviceManualRepairRecordsOpRes, error)
- func UpdateDeviceManualRepairRecords(ctx context.Context, records map[string]*invlibs.DeviceManualRepairRecord) ([]*DeviceManualRepairRecordsOpRes, error)
- type DeviceOpResult
- type DeviceOpResults
- type MRMetadataEntity
Constants ¶
const DeviceKind string = "Device"
DeviceKind is the datastore entity kind for Device entities.
const DeviceManualRepairRecordEntityKind = "DeviceManualRepairRecord"
DeviceManualRepairRecordEntityKind is the datastore entity kind for DeviceManualRepairRecord entities.
const MRLastScannedID = "ManualRepairLastScanned"
MRLastScannedID is the ID for the entity that will always store the last scanned time.
const MRMetadataEntityKind = "MRMetadata"
MRMetadataEntityKind is the datastore entity kind for MRMetadata entities.
const (
// UUIDPrefix is the prefix we used to identify the system generated ID.
UUIDPrefix = "UUID"
)
Variables ¶
This section is empty.
Functions ¶
func GenerateRepairRecordID ¶
GenerateRepairRecordID returns the predefined ID format of $hostname-$assetTag-$createdTime
Types ¶
type DeviceEntity ¶
type DeviceEntity struct { ID DeviceEntityID `gae:"$id"` Hostname string LabConfig []byte `gae:",noindex"` DutState []byte `gae:",noindex"` Updated time.Time Parent *datastore.Key `gae:"$parent"` // contains filtered or unexported fields }
DeviceEntity is a datastore entity that tracks a device.
func (*DeviceEntity) GetCrosDeviceProto ¶
func (e *DeviceEntity) GetCrosDeviceProto(p *lab.ChromeOSDevice) error
GetCrosDeviceProto gets the unmarshaled proto message data.
func (*DeviceEntity) GetDutStateProto ¶
func (e *DeviceEntity) GetDutStateProto(p *lab.DutState) error
GetDutStateProto gets the unmarshaled proto message data.
func (*DeviceEntity) String ¶
func (e *DeviceEntity) String() string
type DeviceEntityID ¶
type DeviceEntityID string
DeviceEntityID represents the ID of a device. We prefer use asset id as the id.
type DeviceManualRepairRecordEntity ¶
type DeviceManualRepairRecordEntity struct { ID string `gae:"$id"` Hostname string `gae:"hostname"` AssetTag string `gae:"asset_tag"` RepairState string `gae:"repair_state"` UserLdap string `gae:"user_ldap"` UpdatedTime time.Time `gae:"updated_time"` Content []byte `gae:",noindex"` // contains filtered or unexported fields }
DeviceManualRepairRecordEntity is a datastore entity that tracks a manual repair record of a device.
Possible RepairState based on proto enum:
STATE_INVALID = 0; STATE_NOT_STARTED = 1; STATE_IN_PROGRESS = 2; STATE_COMPLETED = 3;
func NewDeviceManualRepairRecordEntity ¶
func NewDeviceManualRepairRecordEntity(r *inv.DeviceManualRepairRecord) (*DeviceManualRepairRecordEntity, error)
NewDeviceManualRepairRecordEntity creates a new DeviceManualRepairRecordEntity from a DeviceManualRepairRecord object.
func (*DeviceManualRepairRecordEntity) UpdateDeviceManualRepairRecordEntity ¶
func (e *DeviceManualRepairRecordEntity) UpdateDeviceManualRepairRecordEntity(r *inv.DeviceManualRepairRecord) error
UpdateDeviceManualRepairRecordEntity sets the proto data to the entity.
type DeviceManualRepairRecordsOpRes ¶
type DeviceManualRepairRecordsOpRes struct { Record *invlibs.DeviceManualRepairRecord Entity *DeviceManualRepairRecordEntity Err error }
DeviceManualRepairRecordsOpRes is for use in Datastore to RPC conversions
func AddDeviceManualRepairRecords ¶
func AddDeviceManualRepairRecords(ctx context.Context, records []*invlibs.DeviceManualRepairRecord) ([]*DeviceManualRepairRecordsOpRes, error)
AddDeviceManualRepairRecords creates a DeviceManualRepairRecord with the device hostname and adds it to the datastore.
func GetDeviceManualRepairRecords ¶
func GetDeviceManualRepairRecords(ctx context.Context, ids []string) []*DeviceManualRepairRecordsOpRes
GetDeviceManualRepairRecords returns the DeviceManualRepairRecord matching the device id ($hostname-$assetTag-$createdTime).
func GetRepairRecordByPropertyName ¶
func GetRepairRecordByPropertyName(ctx context.Context, propMap map[string]string, limit int32, offset int32, order []string) ([]*DeviceManualRepairRecordsOpRes, error)
GetRepairRecordByPropertyName queries DeviceManualRepairRecord entity in the datastore using a map of property names and values. Should return both a Record and an Entity for each Entity in the datastore.
func UpdateDeviceManualRepairRecords ¶
func UpdateDeviceManualRepairRecords(ctx context.Context, records map[string]*invlibs.DeviceManualRepairRecord) ([]*DeviceManualRepairRecordsOpRes, error)
UpdateDeviceManualRepairRecords updates the DeviceManualRepairRecord matching the device hostname in the datastore. Given a map of ids and records, it gets entities from the datastore first and updates the entities with the new record values.
type DeviceOpResult ¶
type DeviceOpResult struct { Data proto.Message Entity *DeviceEntity Err error Timestamp time.Time // Only used when logging errors. }
DeviceOpResult is the common response of all device-related datastore functions.
type DeviceOpResults ¶
type DeviceOpResults []DeviceOpResult
DeviceOpResults is a list of DeviceOpResult.
func AddDevices ¶
func AddDevices(ctx context.Context, devices []*lab.ChromeOSDevice, assignServoPort bool) (*DeviceOpResults, error)
AddDevices creates a new Device datastore entity with a unique ID.
func GetAllDevices ¶
func GetAllDevices(ctx context.Context) (DeviceOpResults, error)
GetAllDevices returns all device entities.
TODO(guocb) optimize for performance if needed.
func GetDevicesByHostnames ¶
func GetDevicesByHostnames(ctx context.Context, hostnames []string) DeviceOpResults
GetDevicesByHostnames returns entities by specified hostnames.
func (DeviceOpResults) Failed ¶
func (rs DeviceOpResults) Failed() []DeviceOpResult
Failed generates the list of devices failed the operation.
func (DeviceOpResults) Passed ¶
func (rs DeviceOpResults) Passed() []DeviceOpResult
Passed generates the list of devices passed the operation.
type MRMetadataEntity ¶
type MRMetadataEntity struct { ID string `gae:"$id"` LastScanned time.Time // contains filtered or unexported fields }
MRMetadataEntity is a datastore entity that tracks miscellaneous information used for data operations for a device repair record.
func GetLastScannedTime ¶
func GetLastScannedTime(ctx context.Context) (*MRMetadataEntity, error)
GetLastScannedTime returns a list of 1 with the entity with the latest LastScanned time.