Пример #1
0
class VersionedFile(ndb.Model):
  """Versionned entity.

  Root is ROOT_MODEL. id is datastore_utils.HIGH_KEY_ID - version number.
  """
  created_ts = ndb.DateTimeProperty(indexed=False, auto_now_add=True)
  who = auth.IdentityProperty(indexed=False)
  content = ndb.BlobProperty(compressed=True)

  ROOT_MODEL = datastore_utils.get_versioned_root_model('VersionedFileRoot')

  @property
  def version(self):
    return datastore_utils.HIGH_KEY_ID - self.key.integer_id()

  @classmethod
  def fetch(cls, name):
    """Returns the current version of the instance."""
    return datastore_utils.get_versioned_most_recent(
        cls, cls._gen_root_key(name))

  def store(self, name):
    """Stores a new version of the instance."""
    # Create an incomplete key.
    self.key = ndb.Key(self.__class__, None, parent=self._gen_root_key(name))
    self.who = auth.get_current_identity()
    return datastore_utils.store_new_version(self, self.ROOT_MODEL)

  @classmethod
  def _gen_root_key(cls, name):
    return ndb.Key(cls.ROOT_MODEL, name)
Пример #2
0
 def _get_root_model(cls):
   return datastore_utils.get_versioned_root_model('%sRoot' % cls.__name__)
Пример #3
0
 def _get_root_model(cls):
     return datastore_utils.get_versioned_root_model('%sRoot' %
                                                     cls.__name__)
Пример #4
0
from components import datastore_utils
from components import utils
from server import config
from server import task_pack

# Margin of randomization of BOT_REBOOT_PERIOD_SECS. Per-bot period will be in
# range [period * (1 - margin), period * (1 + margin)).
BOT_REBOOT_PERIOD_RANDOMIZATION_MARGIN = 0.2

### Models.

# There is one BotRoot entity per bot id. Multiple bots could run on a single
# host, for example with multiple phones connected to a host. In this case, the
# id is specific to each device acting as a bot.
BotRoot = datastore_utils.get_versioned_root_model('BotRoot')


class _BotCommon(ndb.Model):
    """Data that is copied from the BotEvent into BotInfo for performance."""
    # State is purely informative. It is completely free form.
    state = datastore_utils.DeterministicJsonProperty(json_type=dict)

    # TODO(maruel): For previous entities. Delete as soon as all old dead bots
    # have been deleted.
    dimensions_old = datastore_utils.DeterministicJsonProperty(
        json_type=dict, name='dimensions')

    # IP address as seen by the HTTP handler.
    external_ip = ndb.StringProperty(indexed=False)
Пример #5
0
from components import utils
from server import config
from server import task_pack


# Margin of randomization of BOT_REBOOT_PERIOD_SECS. Per-bot period will be in
# range [period * (1 - margin), period * (1 + margin)).
BOT_REBOOT_PERIOD_RANDOMIZATION_MARGIN = 0.2


### Models.

# There is one BotRoot entity per bot id. Multiple bots could run on a single
# host, for example with multiple phones connected to a host. In this case, the
# id is specific to each device acting as a bot.
BotRoot = datastore_utils.get_versioned_root_model('BotRoot')


class _BotCommon(ndb.Model):
  """Data that is copied from the BotEvent into BotInfo for performance."""
  # Dimensions are used for task selection.
  dimensions = datastore_utils.DeterministicJsonProperty(json_type=dict)

  # State is purely informative.
  state = datastore_utils.DeterministicJsonProperty(json_type=dict)

  # IP address as seen by the HTTP handler.
  external_ip = ndb.StringProperty(indexed=False)

  # Version of swarming_bot.zip the bot is currently running.
  version = ndb.StringProperty(default='', indexed=False)