Exemplo n.º 1
0
  def _Merge(self):
    """Orchestrates the merge operation."""
    # Acquire op-lock for source user (should already have op-lock for target user).
    op_lock = yield gen.Task(Lock.Acquire,
                             self._client,
                             LockResourceType.Operation,
                             str(self._source_user_id),
                             owner_id=self._op.operation_id)
    try:
      # If checkpoint exists, may skip past viewpoint merge phase.
      state = self._op.checkpoint['state'] if self._op.checkpoint else 'vp'
      if state == 'vp':
        # Make target user a follower of all source user's viewpoints.
        yield self._MergeViewpoints()
        yield Operation.TriggerFailpoint(self._client)
        self._op.checkpoint = None
      else:
        assert state == 'id', state

      # Re-bind identities of the source user to the target user.
      yield self._MergeIdentities()
      yield Operation.TriggerFailpoint(self._client)

      # Terminate the source user.
      yield gen.Task(User.TerminateAccountOperation,
                     self._client,
                     user_id=self._source_user_id,
                     merged_with=self._target_user_id)
      yield Operation.TriggerFailpoint(self._client)
    finally:
      yield gen.Task(op_lock.Release, self._client)
Exemplo n.º 2
0
 def _InsertDeleteContact(contact_to_insert, contact_to_delete):
     """Insert followed by delete (after insert is complete)."""
     if contact_to_insert is not None:
         yield gen.Task(contact_to_insert.Update, self._client)
     yield Operation.TriggerFailpoint(self._client)
     if contact_to_delete is not None:
         yield gen.Task(contact_to_delete.Delete, self._client)
Exemplo n.º 3
0
    def _UpdateEpisode(self):
        """Orchestrates the update_episode operation by executing each of the phases in turn."""
        # Get the viewpoint_id from the episode (which must exist).
        self._episode = yield gen.Task(Episode.Query,
                                       self._client,
                                       self._episode_id,
                                       None,
                                       must_exist=False)
        if not self._episode:
            raise InvalidRequestError(
                'Episode "%s" does not exist and so cannot be updated.' %
                self._episode_id)
        self._viewpoint_id = self._episode.viewpoint_id

        lock = yield gen.Task(Viewpoint.AcquireLock, self._client,
                              self._viewpoint_id)
        try:
            yield self._Check()
            self._client.CheckDBNotModified()
            yield self._Update()
            yield self._Account()
            yield Operation.TriggerFailpoint(self._client)
            yield self._Notify()
        finally:
            yield gen.Task(Viewpoint.ReleaseLock, self._client,
                           self._viewpoint_id, lock)
Exemplo n.º 4
0
  def _CreateProspective(self):
    """Create the prospective user and identity."""
    self._new_user, _ = yield User.CreateProspective(self._client,
                                                     self._new_user_id,
                                                     self._webapp_dev_id,
                                                     self._identity_key,
                                                     self._op.timestamp)

    # If system user is defined, then create the welcome conversation.
    # For now, add a check to ensure the welcome conversation is not created in production.
    if system_users.NARRATOR_USER is not None:
      # Checkpoint the allocated asset id range used to create the welcome conversation.
      if self._op.checkpoint is None:
        # NOTE: Asset ids are allocated from the new user's ids. This is different than the
        #       usual practice of allocating from the sharer's ids. 
        self._unique_id_start = yield gen.Task(User.AllocateAssetIds,
                                               self._client,
                                               self._new_user_id,
                                               CreateProspectiveOperation._ASSET_ID_COUNT)

        checkpoint = {'id': self._unique_id_start}
        yield self._op.SetCheckpoint(self._client, checkpoint)
      else:
        self._unique_id_start = self._op.checkpoint['id']

      yield self._CreateWelcomeConversation()

    # Add an analytics entry for this user.
    analytics = Analytics.Create(entity='us:%d' % self._new_user_id,
                                 type=Analytics.USER_CREATE_PROSPECTIVE,
                                 timestamp=self._op.timestamp,
                                 payload=self._reason)
    yield gen.Task(analytics.Update, self._client)

    yield Operation.TriggerFailpoint(self._client)
Exemplo n.º 5
0
 def _FetchContactsOp(self):
     """Orchestrates the fetch contacts operation by executing each of the phases in turn."""
     yield self._Check()
     self._client.CheckDBNotModified()
     if self._do_fetch_and_update:
         yield self._Update()
     yield Operation.TriggerFailpoint(self._client)
     yield self._Notify()
Exemplo n.º 6
0
 def _RemoveContacts(self):
     """Orchestrates the remove contacts operation by executing each of the phases in turn."""
     yield self._Check()
     self._client.CheckDBNotModified()
     yield self._Update()
     # No accounting for this operation.
     yield Operation.TriggerFailpoint(self._client)
     yield self._Notify()
Exemplo n.º 7
0
 def _ReplaceRemovedContact(contact_dict_to_insert,
                            removed_contact_to_delete):
     contact_to_insert = Contact.CreateFromKeywords(
         **contact_dict_to_insert)
     yield gen.Task(contact_to_insert.Update, self._client)
     if removed_contact_to_delete is not None:
         yield Operation.TriggerFailpoint(self._client)
         yield gen.Task(removed_contact_to_delete.Delete, self._client)
Exemplo n.º 8
0
   def _RemoveContact(contact_to_remove):
       """Insert a 'removed' contact with the same contact_id as the one being removed and then
 delete the actual contact that's being removed."""
       removed_contact = Contact.CreateRemovedContact(
           contact_to_remove.user_id, contact_to_remove.contact_id,
           self._notify_timestamp)
       yield gen.Task(removed_contact.Update, self._client)
       yield Operation.TriggerFailpoint(self._client)
       yield gen.Task(contact_to_remove.Delete, self._client)
Exemplo n.º 9
0
 def _UpdateFollower(self):
     """Orchestrates the update follower operation by executing each of the phases in turn."""
     lock = yield gen.Task(Viewpoint.AcquireLock, self._client,
                           self._viewpoint_id)
     try:
         yield self._Check()
         self._client.CheckDBNotModified()
         yield self._Update()
         yield Operation.TriggerFailpoint(self._client)
         yield self._Notify()
     finally:
         yield gen.Task(Viewpoint.ReleaseLock, self._client,
                        self._viewpoint_id, lock)
Exemplo n.º 10
0
 def _UploadEpisode(self):
   """Orchestrates the upload_episode operation by executing each of the phases in turn."""
   # Lock the viewpoint while sharing into it.
   lock = yield gen.Task(Viewpoint.AcquireLock, self._client, self._user.private_vp_id)
   try:
     yield self._Check()
     self._client.CheckDBNotModified()
     yield self._Update()
     yield self._Account()
     yield Operation.TriggerFailpoint(self._client)
     yield self._Notify()
   finally:
     yield gen.Task(Viewpoint.ReleaseLock, self._client, self._user.private_vp_id, lock)
Exemplo n.º 11
0
 def _PostComment(self):
   """Orchestrates the post_comment operation by executing each of the phases in turn."""
   lock = yield gen.Task(Viewpoint.AcquireLock, self._client, self._viewpoint_id)
   try:
     if not (yield self._Check()):
       return
     self._client.CheckDBNotModified()
     yield self._Update()
     yield self._Account()
     yield Operation.TriggerFailpoint(self._client)
     yield self._Notify()
   finally:
     yield gen.Task(Viewpoint.ReleaseLock, self._client, self._viewpoint_id, lock)
Exemplo n.º 12
0
 def _HidePhotos(self):
     """Orchestrates the hide photos operation by executing each of the phases in turn."""
     lock = yield gen.Task(Viewpoint.AcquireLock, self._client,
                           self._user.private_vp_id)
     try:
         yield self._Check()
         self._client.CheckDBNotModified()
         yield self._Update()
         # No accounting changes for hide_photos.
         yield Operation.TriggerFailpoint(self._client)
         yield self._Notify()
     finally:
         yield gen.Task(Viewpoint.ReleaseLock, self._client,
                        self._user.private_vp_id, lock)
Exemplo n.º 13
0
 def _RemoveFollowers(self):
     """Orchestrates the remove followers operation by executing each of the phases in turn."""
     # Lock the viewpoint while removing followers.
     lock = yield gen.Task(Viewpoint.AcquireLock, self._client,
                           self._viewpoint_id)
     try:
         yield self._Check()
         self._client.CheckDBNotModified()
         yield self._Update()
         yield self._Account()
         yield Operation.TriggerFailpoint(self._client)
         yield self._Notify()
     finally:
         yield gen.Task(Viewpoint.ReleaseLock, self._client,
                        self._viewpoint_id, lock)
Exemplo n.º 14
0
  def _SavePhotos(self):
    """Orchestrates the save_photos operation by executing each of the phases in turn."""
    # Lock the viewpoint while sharing into it.
    try:
      yield self._lock_tracker.AcquireViewpointLock(self._user.private_vp_id)

      yield self._Check()
      self._client.CheckDBNotModified()
      yield self._Update()
      yield self._Account()
      yield Operation.TriggerFailpoint(self._client)
      yield self._Notify()
    finally:
      # Release all locks acquired while processing this operation.
      yield self._lock_tracker.ReleaseAllViewpointLocks()
Exemplo n.º 15
0
    def _ShareExisting(self):
        """Orchestrates the share_existing operation by executing each of the phases in turn."""
        # Lock the viewpoint while sharing into it.
        lock = yield gen.Task(Viewpoint.AcquireLock, self._client,
                              self._viewpoint_id)
        try:
            yield self._Check()
            self._client.CheckDBNotModified()
            yield self._Update()
            yield self._Account()
            yield Operation.TriggerFailpoint(self._client)
            yield self._Notify()

            # Trigger any save_photos operations for followers that have marked the viewpoint to be auto-saved.
            yield self._AutoSave()

        finally:
            yield gen.Task(Viewpoint.ReleaseLock, self._client,
                           self._viewpoint_id, lock)