Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Datastore models for the Machine Provider messages.""" | 5 """Datastore models for the Machine Provider messages.""" |
| 6 | 6 |
| 7 import hashlib | 7 import hashlib |
| 8 | 8 |
| 9 from google.appengine.ext import ndb | 9 from google.appengine.ext import ndb |
| 10 from google.appengine.ext.ndb import msgprop | 10 from google.appengine.ext.ndb import msgprop |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 Key: | 32 Key: |
| 33 id: Hash of the client + client-generated request ID which issued the | 33 id: Hash of the client + client-generated request ID which issued the |
| 34 original rpc_messages.LeaseRequest instance. Used for easy deduplication. | 34 original rpc_messages.LeaseRequest instance. Used for easy deduplication. |
| 35 kind: LeaseRequest. This root entity does not reference any parents. | 35 kind: LeaseRequest. This root entity does not reference any parents. |
| 36 """ | 36 """ |
| 37 # DateTime indicating original datastore write time. | 37 # DateTime indicating original datastore write time. |
| 38 created_ts = ndb.DateTimeProperty(auto_now_add=True) | 38 created_ts = ndb.DateTimeProperty(auto_now_add=True) |
| 39 # Checksum of the rpc_messages.LeaseRequest instance. Used to compare incoming | 39 # Checksum of the rpc_messages.LeaseRequest instance. Used to compare incoming |
| 40 # LeaseRequets for deduplication. | 40 # LeaseRequets for deduplication. |
| 41 deduplication_checksum = ndb.StringProperty(required=True, indexed=False) | 41 deduplication_checksum = ndb.StringProperty(required=True, indexed=False) |
| 42 # DateTime indicating the last modification time. | |
| 43 last_modified_ts = ndb.DateTimeProperty(auto_now=True) | |
|
M-A Ruel
2016/07/30 01:41:58
FYI only. auto_now is impossible to work around wh
smut
2016/08/02 23:26:33
Acknowledged.
| |
| 42 # ID of the CatalogMachineEntry provided for this lease. | 44 # ID of the CatalogMachineEntry provided for this lease. |
| 43 machine_id = ndb.StringProperty() | 45 machine_id = ndb.StringProperty() |
| 44 # auth.model.Identity of the issuer of the original request. | 46 # auth.model.Identity of the issuer of the original request. |
| 45 owner = auth.IdentityProperty(required=True) | 47 owner = auth.IdentityProperty(required=True) |
| 46 # Whether this lease request has been released voluntarily by the owner. | 48 # Whether this lease request has been released voluntarily by the owner. |
| 47 released = ndb.BooleanProperty() | 49 released = ndb.BooleanProperty() |
| 48 # rpc_messages.LeaseRequest instance representing the original request. | 50 # rpc_messages.LeaseRequest instance representing the original request. |
| 49 request = msgprop.MessageProperty(rpc_messages.LeaseRequest, required=True) | 51 request = msgprop.MessageProperty(rpc_messages.LeaseRequest, required=True) |
| 50 # rpc_messages.LeaseResponse instance representing the current response. | 52 # rpc_messages.LeaseResponse instance representing the current response. |
| 51 # This field will be updated as the request is being processed. | 53 # This field will be updated as the request is being processed. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 98 |
| 97 class CatalogEntry(ndb.Model): | 99 class CatalogEntry(ndb.Model): |
| 98 """Datastore representation of an entry in the catalog.""" | 100 """Datastore representation of an entry in the catalog.""" |
| 99 # rpc_messages.Dimensions describing this machine. | 101 # rpc_messages.Dimensions describing this machine. |
| 100 dimensions = msgprop.MessageProperty( | 102 dimensions = msgprop.MessageProperty( |
| 101 rpc_messages.Dimensions, | 103 rpc_messages.Dimensions, |
| 102 indexed_fields=[ | 104 indexed_fields=[ |
| 103 field.name for field in rpc_messages.Dimensions.all_fields() | 105 field.name for field in rpc_messages.Dimensions.all_fields() |
| 104 ], | 106 ], |
| 105 ) | 107 ) |
| 108 # DateTime indicating the last modified time. | |
| 109 last_modified_ts = ndb.DateTimeProperty(auto_now=True) | |
| 106 | 110 |
| 107 | 111 |
| 108 class CatalogCapacityEntry(CatalogEntry): | 112 class CatalogCapacityEntry(CatalogEntry): |
| 109 """Datastore representation of machine capacity in the catalog. | 113 """Datastore representation of machine capacity in the catalog. |
| 110 | 114 |
| 111 Key: | 115 Key: |
| 112 id: Hash of the non-None dimensions, where backend is the only required | 116 id: Hash of the non-None dimensions, where backend is the only required |
| 113 dimension. Used to enforce per-backend dimension uniqueness. | 117 dimension. Used to enforce per-backend dimension uniqueness. |
| 114 kind: CatalogCapacityEntry. This root entity does not reference any parents. | 118 kind: CatalogCapacityEntry. This root entity does not reference any parents. |
| 115 """ | 119 """ |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 # rpc_messages.Policies governing this machine. | 187 # rpc_messages.Policies governing this machine. |
| 184 policies = msgprop.MessageProperty(rpc_messages.Policies) | 188 policies = msgprop.MessageProperty(rpc_messages.Policies) |
| 185 # Cloud Pub/Sub subscription the machine must listen to for instructions. | 189 # Cloud Pub/Sub subscription the machine must listen to for instructions. |
| 186 pubsub_subscription = ndb.StringProperty(indexed=False) | 190 pubsub_subscription = ndb.StringProperty(indexed=False) |
| 187 # Project the Cloud Pub/Sub subscription exists in. | 191 # Project the Cloud Pub/Sub subscription exists in. |
| 188 pubsub_subscription_project = ndb.StringProperty(indexed=False) | 192 pubsub_subscription_project = ndb.StringProperty(indexed=False) |
| 189 # Cloud Pub/Sub topic the machine must be subscribed to. | 193 # Cloud Pub/Sub topic the machine must be subscribed to. |
| 190 pubsub_topic = ndb.StringProperty(indexed=False) | 194 pubsub_topic = ndb.StringProperty(indexed=False) |
| 191 # Project the Cloud Pub/Sub topic exists in. | 195 # Project the Cloud Pub/Sub topic exists in. |
| 192 pubsub_topic_project = ndb.StringProperty(indexed=False) | 196 pubsub_topic_project = ndb.StringProperty(indexed=False) |
| 197 # Determines sorted order relative to other CatalogMachineEntries. | |
| 198 sort_ordering = ndb.ComputedProperty(lambda self: '%s:%s' % ( | |
| 199 self.dimensions.backend, self.dimensions.hostname)) | |
| 193 # Element of CatalogMachineEntryStates giving the state of this entry. | 200 # Element of CatalogMachineEntryStates giving the state of this entry. |
| 194 state = ndb.StringProperty( | 201 state = ndb.StringProperty( |
| 195 choices=CatalogMachineEntryStates, | 202 choices=CatalogMachineEntryStates, |
| 196 default=CatalogMachineEntryStates.AVAILABLE, | 203 default=CatalogMachineEntryStates.AVAILABLE, |
| 197 indexed=True, | 204 indexed=True, |
| 198 required=True, | 205 required=True, |
| 199 ) | 206 ) |
| 200 | 207 |
| 201 @classmethod | 208 @classmethod |
| 202 def create_and_put(cls, dimensions, policies, state): | 209 def create_and_put(cls, dimensions, policies, state): |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 | 247 |
| 241 Args: | 248 Args: |
| 242 *filters: Any additional filters to include in the query. | 249 *filters: Any additional filters to include in the query. |
| 243 | 250 |
| 244 Yields: | 251 Yields: |
| 245 CatalogMachineEntry keys in no guaranteed order. | 252 CatalogMachineEntry keys in no guaranteed order. |
| 246 """ | 253 """ |
| 247 available = cls.state == CatalogMachineEntryStates.AVAILABLE | 254 available = cls.state == CatalogMachineEntryStates.AVAILABLE |
| 248 for machine in cls.query(available, *filters).fetch(keys_only=True): | 255 for machine in cls.query(available, *filters).fetch(keys_only=True): |
| 249 yield machine | 256 yield machine |
| OLD | NEW |