datastore

package
v0.0.0-...-e560ebb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package datastore contains datastore-related logic.

Package datastore contains datastore-related logic.

Index

Constants

View Source
const AssetEntityName string = "Asset"

AssetEntityName is the datastore entity kind for Asset entities.

View Source
const AssetInfoEntityKind = "AssetInfo"

AssetInfoEntityKind is the datastore entity kind for AssetInfo entities.

View Source
const AssetStateEntityName string = "AssetState"

AssetStateEntityName is the datastore entity kind for Asset state entities.

View Source
const DeviceKind string = "Device"

DeviceKind is the datastore entity kind for Device entities.

View Source
const DeviceManualRepairRecordEntityKind = "DeviceManualRepairRecord"

DeviceManualRepairRecordEntityKind is the datastore entity kind for DeviceManualRepairRecord entities.

View Source
const MRLastScannedID = "ManualRepairLastScanned"

MRLastScannedID is the ID for the entity that will always store the last scanned time.

View Source
const MRMetadataEntityKind = "MRMetadata"

MRMetadataEntityKind is the datastore entity kind for MRMetadata entities.

View Source
const (
	// UUIDPrefix is the prefix we used to identify the system generated ID.
	UUIDPrefix = "UUID"
)

Variables

This section is empty.

Functions

func BatchUpdateDevices

func BatchUpdateDevices(ctx context.Context, duts []*DeviceProperty) error

BatchUpdateDevices updates devices of some specific properties in a batch.

func GenerateRepairRecordID

func GenerateRepairRecordID(hostname string, assetTag string, createdTime string) (string, error)

GenerateRepairRecordID returns the predefined ID format of $hostname-$assetTag-$createdTime

func GetAllAssetInfo

func GetAllAssetInfo(ctx context.Context, keysOnly bool) ([]*ufs.AssetInfo, error)

GetAllAssetInfo returns all AssetInfo from datastore.

If keysOnly is true, then only key field is populated in returned assets

func GetAllAssets

func GetAllAssets(ctx context.Context, keysOnly bool) ([]*fleet.ChopsAsset, error)

GetAllAssets returns all assets from datastore.

If keysOnly is true, then only key field is populated in returned assets

func SaveLastScannedTime

func SaveLastScannedTime(ctx context.Context, lastScannedTime time.Time) error

SaveLastScannedTime saves the newest LastScanned time into an entity. If one does not exist, it will create a new entity in the Datastore.

func UpdateDeviceID

func UpdateDeviceID(ctx context.Context, oldDev, newDev string) error

UpdateDeviceID of the old device to the new device

Changes the timestamp to reflect this change.

func UpdateLabstations

func UpdateLabstations(ctx context.Context, hostname string, servoToDelete, addedDUTs []string) (*lab.ChromeOSDevice, error)

UpdateLabstations updates a labstation's info, e.g. servos

Types

type AssetEntity

type AssetEntity struct {
	ID       string `gae:"$id"`
	Lab      string
	Location []byte         `gae:",noindex"`
	Parent   *datastore.Key `gae:"$parent"`
	// contains filtered or unexported fields
}

AssetEntity is a datastore entity that tracks the asset.

func NewAssetEntity

func NewAssetEntity(a *fleet.ChopsAsset, parent *datastore.Key) (*AssetEntity, error)

NewAssetEntity creates an AssetEntity object from ChopsAsset object

func (*AssetEntity) String

func (e *AssetEntity) String() string

func (*AssetEntity) ToChopsAsset

func (e *AssetEntity) ToChopsAsset() (*fleet.ChopsAsset, error)

ToChopsAsset returns a ChopsAsset object

type AssetInfoEntity

type AssetInfoEntity struct {
	AssetTag string        `gae:"$id"`
	Info     ufs.AssetInfo `gae:",noindex"`
	// contains filtered or unexported fields
}

AssetInfoEntity is a datastore entity that tracks the asset info from HaRT.

func NewAssetInfo

func NewAssetInfo(a *ufs.AssetInfo) (*AssetInfoEntity, error)

NewAssetInfo creates an AssetInfoEntity object from AssetInfo object

type AssetInfoOpRes

type AssetInfoOpRes struct {
	AssetInfo *ufs.AssetInfo
	Entity    *AssetInfoEntity
	Err       error
}

AssetInfoOpRes is return type for AssetInfo related operations

func AddAssetInfo

func AddAssetInfo(ctx context.Context, assetInfo []*ufs.AssetInfo) []*AssetInfoOpRes

AddAssetInfo adds the AssetInfo from HaRT to datastore.

All inputs [assetInfo] will get a corresponding response in the order of inputs on return, if res.Err != nil then that insert operation failed. Does not return an error if the AssetInfo entity already exists in the datastore. If assetInfo contains more than one instance with same asset tag, Only one of them is inserted into the database and the returned AssetInfoOpRes corresponds to the same inserted data for both.

func GetAssetInfo

func GetAssetInfo(ctx context.Context, ids []string) []*AssetInfoOpRes

GetAssetInfo returns the AssetInfo matching the AssetID

type AssetOpResult

type AssetOpResult struct {
	Asset       *fleet.ChopsAsset
	Entity      *AssetEntity
	StateEntity *AssetStateEntity
	Err         error
}

AssetOpResult is for use in Datastore to RPC conversions

func AddAssets

func AddAssets(ctx context.Context, assets []*fleet.ChopsAsset) ([]*AssetOpResult, error)

AddAssets creates a new Asset datastore entity

func DeleteAsset

func DeleteAsset(ctx context.Context, ids []string) []*AssetOpResult

DeleteAsset removes the asset from the database

func GetAssetStatesByID

func GetAssetStatesByID(ctx context.Context, ids []string) []*AssetOpResult

GetAssetStatesByID returns the asset(s) matching the AssetID

func GetAssetsByID

func GetAssetsByID(ctx context.Context, ids []string) []*AssetOpResult

GetAssetsByID returns the asset(s) matching the AssetID

func UpdateAssets

func UpdateAssets(ctx context.Context, assets []*fleet.ChopsAsset) ([]*AssetOpResult, error)

UpdateAssets changes the location of the asset

func (*AssetOpResult) ToAsset

func (device *AssetOpResult) ToAsset() *fleet.ChopsAsset

ToAsset converts AssetOpResult (format used for datastore) to ChopsAsset (RPC format)

type AssetOpResults

type AssetOpResults []AssetOpResult

AssetOpResults is a list of AssetOpResult.

func (AssetOpResults) Passed

func (rs AssetOpResults) Passed() []AssetOpResult

Passed generates the list of devices passed the operation.

type AssetStateEntity

type AssetStateEntity struct {
	ID      string           `gae:"$id"`
	State   fleet.AssetState `gae:",noindex"`
	Updated time.Time
	Parent  *datastore.Key `gae:"$parent"`
	// contains filtered or unexported fields
}

AssetStateEntity is the datastore that tracks the asset state.

func NewAssetStateEntity

func NewAssetStateEntity(a *fleet.ChopsAsset, state fleet.State, updated time.Time, parent *datastore.Key) (*AssetStateEntity, error)

NewAssetStateEntity creates an AssetStateEntity object based on input.

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

func (*DeviceEntity) UpdatePayload

func (e *DeviceEntity) UpdatePayload(p proto.Message, t time.Time) (changes changehistory.Changes, err error)

UpdatePayload sets the proto data to the entity.

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.

func ListDevices

func ListDevices(ctx context.Context, pageSize int32, pageToken string) (res []DeviceOpResult, nextPageToken string, err error)

ListDevices lists the devices

Does a query over device entities. Returns up to pageSize entities, plus non-nil cursor (if there are more results). pageSize must be positive.

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 DeleteDevicesByHostnames

func DeleteDevicesByHostnames(ctx context.Context, hostnames []string) DeviceOpResults

DeleteDevicesByHostnames deletes entities by specified hostnames.

As additional deleting servo from labstation for deleted device.

func DeleteDevicesByIds

func DeleteDevicesByIds(ctx context.Context, ids []string) DeviceOpResults

DeleteDevicesByIds deletes entities by specified Ids. The datastore implementation doesn't raise error when deleting non-existing entities: https://github.com/googleapis/google-cloud-go/issues/501

As additional deleting servo from labstation for deleted device.

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 GetDevicesByIds

func GetDevicesByIds(ctx context.Context, ids []string) DeviceOpResults

GetDevicesByIds returns entities by specified ids.

func GetDevicesByModels

func GetDevicesByModels(ctx context.Context, models []string) (DeviceOpResults, error)

GetDevicesByModels returns all device entities of models.

TODO(guocb) optimize for performance if needed.

func UpdateDeviceSetup

func UpdateDeviceSetup(ctx context.Context, devices []*lab.ChromeOSDevice, assignServoPort bool) (DeviceOpResults, error)

UpdateDeviceSetup updates the content of lab.ChromeOSDevice.

func UpdateDutMeta

func UpdateDutMeta(ctx context.Context, meta map[string]DutMeta) (DeviceOpResults, error)

UpdateDutMeta updates dut serial number and hwid for a given host.

func UpdateDutsStatus

func UpdateDutsStatus(ctx context.Context, states []*lab.DutState) (DeviceOpResults, error)

UpdateDutsStatus updates dut status of testing related.

func UpdateLabMeta

func UpdateLabMeta(ctx context.Context, meta map[string]LabMeta) (DeviceOpResults, error)

UpdateLabMeta updates servo_type and smart_usbhub flag for a given host.

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 DeviceProperty

type DeviceProperty struct {
	Hostname        string
	Pool            string
	PowerunitName   string
	PowerunitOutlet string
}

DeviceProperty specifies some device property.

type DutMeta

type DutMeta struct {
	SerialNumber string
	HwID         string
	DeviceSku    string
}

DutMeta refers to the metadata to be stored for a DUT.

type LabMeta

type LabMeta struct {
	ServoType     string
	SmartUsbhub   bool
	ServoTopology *lab.ServoTopology
}

LabMeta refers to the metadata to be stored for a DUT.

type LabstationNotDeployedError

type LabstationNotDeployedError struct {
	// contains filtered or unexported fields
}

LabstationNotDeployedError is the error raised when the DUT has no deployed labstation yet.

func (*LabstationNotDeployedError) Error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL