go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/appengine/model/legacy.go (about)

     1  // Copyright 2020 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package model
    16  
    17  import (
    18  	"time"
    19  )
    20  
    21  // LegacyStatus is the status of a legacy build request.
    22  type LegacyStatus int
    23  
    24  const (
    25  	_ LegacyStatus = iota
    26  	// Scheduled builds may be leased and started.
    27  	Scheduled
    28  	// Started builds are leased and marked as started.
    29  	Started
    30  	// Completed builds are finished and have an associated LegacyResult.
    31  	Completed
    32  )
    33  
    34  var LegacyStatus_name = []string{
    35  	0:         "UNSET",
    36  	Scheduled: "SCHEDULED",
    37  	Started:   "STARTED",
    38  	Completed: "COMPLETED",
    39  }
    40  
    41  func (r LegacyStatus) String() string {
    42  	return LegacyStatus_name[r]
    43  }
    44  
    45  // LegacyResult is the result of a completed legacy build.
    46  type LegacyResult int
    47  
    48  var LegacyResult_name = []string{
    49  	0:        "UNSET",
    50  	Success:  "SUCCESS",
    51  	Failure:  "FAILURE",
    52  	Canceled: "CANCELED",
    53  }
    54  
    55  func (r LegacyResult) String() string {
    56  	return LegacyResult_name[r]
    57  }
    58  
    59  const (
    60  	_ LegacyResult = iota
    61  	// Success means the build completed successfully.
    62  	Success
    63  	// Failure means the build failed and has an associated LegacyFailureReason.
    64  	Failure
    65  	// Canceled means the build was canceled
    66  	// and has an associated LegacyCancelationReason.
    67  	Canceled
    68  )
    69  
    70  // LegacyFailureReason is the reason for a legacy build failure.
    71  type LegacyFailureReason int
    72  
    73  var LegacyFailureReason_name = []string{
    74  	0:                      "UNSET",
    75  	BuildFailure:           "BUILD_FAILURE",
    76  	BuildbucketFailure:     "BUILDBUCKET_FAILURE",
    77  	InfraFailure:           "INFRA_FAILURE",
    78  	InvalidBuildDefinition: "INVALID_BUILD_DEFINITION",
    79  }
    80  
    81  func (r LegacyFailureReason) String() string {
    82  	return LegacyFailureReason_name[r]
    83  }
    84  
    85  const (
    86  	_ LegacyFailureReason = iota
    87  	// BuildFailure means the build itself failed.
    88  	BuildFailure
    89  	// BuildbucketFailure means something went wrong within Buildbucket.
    90  	BuildbucketFailure
    91  	// InfraFailure means something went wrong outside the build and Buildbucket.
    92  	InfraFailure
    93  	// InvalidBuildDefinition means the build system rejected the build definition.
    94  	InvalidBuildDefinition
    95  )
    96  
    97  // LegacyCancelationReason is the reason for a canceled legacy build.
    98  type LegacyCancelationReason int
    99  
   100  var LegacyCancelationReason_name = []string{
   101  	0:                  "UNSET",
   102  	ExplicitlyCanceled: "CANCELED_EXPLICITLY",
   103  	TimeoutCanceled:    "TIMEOUT",
   104  }
   105  
   106  func (r LegacyCancelationReason) String() string {
   107  	return LegacyCancelationReason_name[r]
   108  }
   109  
   110  const (
   111  	_ LegacyCancelationReason = iota
   112  	// ExplicitlyCanceled means the build was canceled (likely via API call).
   113  	ExplicitlyCanceled
   114  	// TimeoutCanceled means Buildbucket timed the build out.
   115  	TimeoutCanceled
   116  )
   117  
   118  // LeaseProperties are properties associated with the legacy leasing API.
   119  type LeaseProperties struct {
   120  	IsLeased bool `gae:"is_leased"`
   121  	// TODO(crbug/1042991): Create datastore.PropertyConverter in server/auth.
   122  	Leasee              []byte    `gae:"leasee"`
   123  	LeaseExpirationDate time.Time `gae:"lease_expiration_date"`
   124  	// LeaseKey is a random value used to verify the leaseholder's identity.
   125  	LeaseKey    int  `gae:"lease_key"`
   126  	NeverLeased bool `gae:"never_leased"`
   127  }
   128  
   129  // LegacyProperties are properties of legacy builds.
   130  //
   131  // Parameters and ResultDetails are byte slices interpretable as JSON.
   132  // TODO(crbug/1042991): Create datastore.PropertyConverter for JSON properties.
   133  type LegacyProperties struct {
   134  	LeaseProperties
   135  
   136  	CancelationReason LegacyCancelationReason `gae:"cancelation_reason"`
   137  	FailureReason     LegacyFailureReason     `gae:"failure_reason"`
   138  	Parameters        []byte                  `gae:"parameters"`
   139  	Result            LegacyResult            `gae:"result"`
   140  	ResultDetails     []byte                  `gae:"result_details"`
   141  	// ID of the Build this is a retry of.
   142  	RetryOf int          `gae:"retry_of"`
   143  	Status  LegacyStatus `gae:"status"`
   144  	URL     string       `gae:"url,noindex"`
   145  }