Documentation ¶
Overview ¶
Package model contains datastore model implementation.
Index ¶
- Constants
- Variables
- func BucketKey(ctx context.Context, project, bucket string) *datastore.Key
- func BuilderKey(ctx context.Context, project, bucket, builder string) *datastore.Key
- func GetBuildAndBucket(ctx context.Context, id int64) (*Build, *Bucket, error)
- func GetIgnoreMissing(ctx context.Context, dst ...interface{}) error
- func LoadBuildBundles(ctx context.Context, pbBuilds []*pb.Build, m mask.Mask) error
- func ProjectKey(ctx context.Context, project string) *datastore.Key
- type Bucket
- type Build
- type BuildInfra
- type BuildInputProperties
- type BuildOutputProperties
- type BuildSteps
- type Builder
- type DSBuildInfra
- type DSStruct
- type LeaseProperties
- type LegacyCancelationReason
- type LegacyFailureReason
- type LegacyProperties
- type LegacyResult
- type LegacyStatus
- type Project
- type PubSubCallback
- type TagIndex
- type TagIndexEntry
- type UnusedProperties
Constants ¶
const (
// BucketKind is a bucket entity's kind in the datastore.
BucketKind = "BucketV2"
)
const (
// BuildKind is a Build entity's kind in the datastore.
BuildKind = "Build"
)
const BuildStepsMaxBytes = 1e6
BuildStepsMaxBytes is the maximum length of BuildSteps.Bytes. If Bytes exceeds this maximum, this package will try to compress it, setting IsZipped accordingly, but if this length is still exceeded it's an error to write such entities to the datastore. Use FromProto to ensure this maximum is respected.
const BuilderKind = "Bucket.Builder"
BuilderKind is the kind of the Builder entity.
const MaxTagIndexEntries = 1000
MaxTagIndexEntries is the maximum number of entries that may be associated with a single TagIndex entity.
const TagIndexShardCount = 16
TagIndexShardCount is the number of shards used by the TagIndex.
Variables ¶
var TagIndexIncomplete = errors.BoolTag{Key: errors.NewTagKey("tag index incomplete")}
TagIndexIncomplete means the tag index is incomplete and thus cannot be searched.
Functions ¶
func BuilderKey ¶
BuilderKey returns a datastore key of a builder.
func GetBuildAndBucket ¶
GetBuildAndBucket returns the build with the given ID as well as the bucket it belongs to. Returns datastore.ErrNoSuchEntity if either is not found.
func GetIgnoreMissing ¶
GetIgnoreMissing fetches the given entities from the datastore, ignoring datastore.ErrNoSuchEntity errors. All other errors are returned. For valid values of dst, see datastore.Get.
func LoadBuildBundles ¶
LoadBuildBundles load the build bundles into the proto builds and trim them according to the mask.
Types ¶
type Bucket ¶
type Bucket struct { // ID is the bucket in v2 format. // e.g. try (never luci.chromium.try). ID string `gae:"$id"` Parent *datastore.Key `gae:"$parent"` // Bucket is the bucket in v2 format. // e.g. try (never luci.chromium.try). Bucket string `gae:"bucket_name"` // Proto is the pb.Bucket proto representation of the bucket. // // acl_sets is zeroed by inlining acls. swarming.builders is // zeroed and stored in separate Builder datastore entities due to // potentially large size. // // noindex is not respected here, it's set in pb.Bucket.ToProperty. Proto pb.Bucket `gae:"config,noindex"` // Revision is the config revision this entity was created from. // TODO(crbug/1042991): Switch to noindex. Revision string `gae:"revision"` // Schema is this entity's schema version. // TODO(crbug/1042991): Switch to noindex. Schema int32 `gae:"entity_schema_version"` // contains filtered or unexported fields }
Bucket is a representation of a bucket in the datastore.
type Build ¶
type Build struct { ID int64 `gae:"$id"` // LegacyProperties are properties set for v1 legacy builds. LegacyProperties // UnusedProperties are properties set previously but currently unused. UnusedProperties // Proto is the pb.Build proto representation of the build. // // infra, input.properties, output.properties, and steps // are zeroed and stored in separate datastore entities // due to their potentially large size (see details.go). // tags are given their own field so they can be indexed. // // noindex is not respected here, it's set in pb.Build.ToProperty. Proto pb.Build `gae:"proto,noindex"` Project string `gae:"project"` // <project>/<bucket>. Bucket is in v2 format. // e.g. chromium/try (never chromium/luci.chromium.try). BucketID string `gae:"bucket_id"` // <project>/<bucket>/<builder>. Bucket is in v2 format. // e.g. chromium/try/linux-rel. BuilderID string `gae:"builder_id"` Canary bool `gae:"canary"` CreatedBy identity.Identity `gae:"created_by"` // TODO(nodir): Replace reliance on create_time indices with id. CreateTime time.Time `gae:"create_time"` // Experimental, if true, means to exclude from monitoring and search results // (unless specifically requested in search results). Experimental bool `gae:"experimental"` // Experiments is a slice of experiments enabled or disabled on this build. // Each element should look like "[-+]$experiment_name". Experiments []string `gae:"experiments"` Incomplete bool `gae:"incomplete"` IsLuci bool `gae:"is_luci"` ResultDBUpdateToken string `gae:"resultdb_update_token,noindex"` Status pb.Status `gae:"status_v2"` StatusChangedTime time.Time `gae:"status_changed_time"` // Tags is a slice of "<key>:<value>" strings taken from Proto.Tags. // Stored separately in order to index. Tags []string `gae:"tags"` // PubSubCallback, if set, creates notifications for build status changes. PubSubCallback PubSubCallback `gae:"pubsub_callback,noindex"` // contains filtered or unexported fields }
Build is a representation of a build in the datastore. Implements datastore.PropertyLoadSaver.
func (*Build) Load ¶
func (b *Build) Load(p datastore.PropertyMap) error
Load overwrites this representation of a build by reading the given datastore.PropertyMap. Mutates this entity.
func (*Build) Save ¶
func (b *Build) Save(withMeta bool) (datastore.PropertyMap, error)
Save returns the datastore.PropertyMap representation of this build. Mutates this entity to reflect computed datastore fields in the returned PropertyMap.
type BuildInfra ¶
type BuildInfra struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // Proto is the pb.BuildInfra proto representation of the infra field. Proto DSBuildInfra `gae:"infra,noindex"` // contains filtered or unexported fields }
BuildInfra is a representation of a build proto's infra field in the datastore.
type BuildInputProperties ¶
type BuildInputProperties struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // Proto is the struct.Struct representation of the properties field. Proto DSStruct `gae:"properties,noindex"` // contains filtered or unexported fields }
BuildInputProperties is a representation of a build proto's input field's properties field in the datastore.
type BuildOutputProperties ¶
type BuildOutputProperties struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // Proto is the struct.Struct representation of the properties field. Proto DSStruct `gae:"properties,noindex"` // contains filtered or unexported fields }
BuildOutputProperties is a representation of a build proto's output field's properties field in the datastore.
type BuildSteps ¶
type BuildSteps struct { // ID is always 1 because only one such entity exists. ID int `gae:"$id"` // Build is the key for the build this entity belongs to. Build *datastore.Key `gae:"$parent"` // IsZipped indicates whether or not Bytes is zlib compressed. // Use ToProto to ensure this compression is respected. IsZipped bool `gae:"step_container_bytes_zipped,noindex"` // Bytes is the pb.Build proto representation of the build proto where only steps is set. // IsZipped determines whether this value is compressed or not. Bytes []byte `gae:"steps,noindex"` // contains filtered or unexported fields }
BuildSteps is a representation of a build proto's steps field in the datastore.
func (*BuildSteps) CancelIncomplete ¶
func (s *BuildSteps) CancelIncomplete(ctx context.Context, now *timestamppb.Timestamp) (bool, error)
CancelIncomplete marks any incomplete steps as cancelled, returning whether at least one step was cancelled. The caller is responsible for writing the entity to the datastore if any steps were cancelled. This entity will not be mutated if an error occurs.
type Builder ¶
type Builder struct { // ID is the builder name, e.g. "linux-rel". ID string `gae:"$id"` // Parent is the key of the parent Bucket. Parent *datastore.Key `gae:"$parent"` // Config is the builder configuration feched from luci-config. Config pb.Builder `gae:"config"` // ConfigHash is used for fast deduplication of configs. ConfigHash string `gae:"config_hash"` // contains filtered or unexported fields }
Builder is a Datastore entity that stores builder configuration. It is a child of Bucket entity.
Builder entities are updated together with their parents, in a cron job.
type DSBuildInfra ¶
type DSBuildInfra struct {
pb.BuildInfra
}
DSBuildInfra is a wrapper around pb.BuildInfra. Although pb.BuildInfra already implements datastore.PropertyConverter, override FromProto to apply defaultStructValues.
func (*DSBuildInfra) FromProperty ¶
func (b *DSBuildInfra) FromProperty(p datastore.Property) error
FromProperty deserializes pb.BuildInfra protos from the datastore. Implements datastore.PropertyConverter.
type DSStruct ¶
DSStruct is a wrapper around structpb.Struct. Implements datastore.PropertyConverter, allowing reads from and writes to the datastore.
func (*DSStruct) FromProperty ¶
FromProperty deserializes structpb.Struct protos from the datastore. Implements datastore.PropertyConverter.
type LeaseProperties ¶
type LeaseProperties struct { IsLeased bool `gae:"is_leased"` // TODO(crbug/1042991): Create datastore.PropertyConverter in server/auth. Leasee []byte `gae:"leasee"` LeaseExpirationDate time.Time `gae:"lease_expiration_date"` // LeaseKey is a random value used to verify the leaseholder's identity. LeaseKey int `gae:"lease_key"` NeverLeased bool `gae:"never_leased"` }
LeaseProperties are properties associated with the legacy leasing API.
type LegacyCancelationReason ¶
type LegacyCancelationReason int
LegacyCancelationReason is the reason for a canceled legacy build.
const ( // ExplicitlyCanceled means the build was canceled (likely via API call). ExplicitlyCanceled LegacyCancelationReason // TimeoutCanceled means Buildbucket timed the build out. TimeoutCanceled )
type LegacyFailureReason ¶
type LegacyFailureReason int
LegacyFailureReason is the reason for a legacy build failure.
const ( // BuildFailure means the build itself failed. BuildFailure LegacyFailureReason // BuildbucketFailure means something went wrong within Buildbucket. BuildbucketFailure // InfraFailure means something went wrong outside the build and Buildbucket. InfraFailure // InvalidBuildDefinition means the build system rejected the build definition. InvalidBuildDefinition )
type LegacyProperties ¶
type LegacyProperties struct { LeaseProperties CancelationReason LegacyCancelationReason `gae:"cancelation_reason"` FailureReason LegacyFailureReason `gae:"failure_reason"` Parameters []byte `gae:"parameters"` Result LegacyResult `gae:"result"` ResultDetails []byte `gae:"result_details"` // ID of the Build this is a retry of. RetryOf int `gae:"retry_of"` Status LegacyStatus `gae:"status"` URL string `gae:"url,noindex"` }
LegacyProperties are properties of legacy builds.
Parameters and ResultDetails are byte slices interpretable as JSON. TODO(crbug/1042991): Create datastore.PropertyConverter for JSON properties.
type LegacyResult ¶
type LegacyResult int
LegacyResult is the result of a completed legacy build.
const ( // Success means the build completed successfully. Success LegacyResult // Failure means the build failed and has an associated LegacyFailureReason. Failure // Canceled means the build was canceled // and has an associated LegacyCancelationReason. Canceled )
type LegacyStatus ¶
type LegacyStatus int
LegacyStatus is the status of a legacy build request.
const ( // Scheduled builds may be leased and started. Scheduled LegacyStatus // Started builds are leased and marked as started. Started // Completed builds are finished and have an associated LegacyResult. Completed )
type Project ¶
type Project struct {
ID string `gae:"$id"`
}
Project is the parent entity of buckets in the datastore. Entities of this kind don't exist in the datastore.
type PubSubCallback ¶
type PubSubCallback struct { AuthToken string `gae:"auth_token,noindex"` Topic string `gae:"topic,noindex"` UserData string `gae:"user_data,noindex"` }
PubSubCallback encapsulates parameters for a Pub/Sub callback.
type TagIndex ¶
type TagIndex struct { // ID is a "<key>:<value>" or ":<index>:<key>:<value>" string for index > 0. ID string `gae:"$id"` // Incomplete means there are more than MaxTagIndexEntries entities // with the same ID, and therefore the index is incomplete and cannot be // searched. Incomplete bool `gae:"permanently_incomplete,noindex"` // Entries is a slice of TagIndexEntries matching this ID. Entries []TagIndexEntry `gae:"entries,noindex"` // contains filtered or unexported fields }
TagIndex is an index used to search Build entities by tag.
type TagIndexEntry ¶
type TagIndexEntry struct { // BuildID is the ID of the Build entity this entry refers to. BuildID int64 `json:"build_id"` // <project>/<bucket>. Bucket is in v2 format. // e.g. chromium/try (never chromium/luci.chromium.try). BucketID string `json:"bucket_id"` // CreatedTime is the time this entry was created. CreatedTime time.Time `json:"created_time"` }
TagIndexEntry refers to a particular Build entity.
func SearchTagIndex ¶
func SearchTagIndex(ctx context.Context, key, val string) ([]*TagIndexEntry, error)
SearchTagIndex searches the tag index for the given tag. Returns an error tagged with TagIndexIncomplete if the tag index is incomplete and thus cannot be searched.
func (*TagIndexEntry) FromProperty ¶
func (e *TagIndexEntry) FromProperty(p datastore.Property) error
FromProperty deserializes TagIndexEntries from the datastore. Implements datastore.PropertyConverter.
func (*TagIndexEntry) ToProperty ¶
func (e *TagIndexEntry) ToProperty() (datastore.Property, error)
ToProperty serializes TagIndexEntries to datastore format. Implements datastore.PropertyConverter.
type UnusedProperties ¶
type UnusedProperties struct { // PubSubCallback is normally a struct (see build.go), which translates into datastore // fields pubsub_callback.auth_token, pubsub_callback.topic, pubsub_callback.user_data // with no actual field called pubsub_callback. However, nil values in the datastore // may exist for pubsub_callback (should instead be represented by having all three // pubsub_callback.* fields nil, but isn't). Capture such nil values here. // TODO(crbug/1042991): Support this case properly in gae datastore package. PubSubCallback []byte `gae:"pubsub_callback,noindex"` }
UnusedProperties are properties previously set but currently unused.