Example #1
0
def _FixTest(test_key):
    """Changes Row and Anomaly entities from using timestamps to SVN revisions."""
    futures = _MoveRowsForTest(test_key)
    futures.extend(_UpdateAlertsForTest(test_key))

    # Clear graph revisions cache. This is done so that the cached data
    # will not be inconsistent with the actual data.
    graph_revisions.DeleteCache(utils.TestPath(test_key))
    return futures
Example #2
0
def _MigrateTestRows(old_parent_key, new_parent_key):
    """Copies Row entities from one parent to another, deleting old ones.

  Args:
    old_parent_key: Test entity key of the test to move from.
    new_parent_key: Test entity key of the test to move to.

  Returns:
    A dictionary with the following keys:
      put_future: A list of Future objects for entities being put.
      delete_future: A list of Future objects for entities being deleted.
      moved_rows: Whether or not any entities were moved.
  """
    # In this function we'll build up lists of entities to put and delete
    # before returning Future objects for the entities being put and deleted.
    rows_to_put = []
    rows_to_delete = []

    # Add some Row entities to the lists of entities to put and delete.
    query = graph_data.Row.query(graph_data.Row.parent_test == old_parent_key)
    rows = query.fetch(limit=_MAX_DATASTORE_PUTS_PER_PUT_MULTI_CALL)
    for row in rows:
        rows_to_put.append(
            _CreateRenamedEntityIfNotExists(graph_data.Row, row, row.key.id(),
                                            new_parent_key, _ROW_EXCLUDE))
        rows_to_delete.append(row.key)

    # Clear the cached revision range selector data for both the old and new
    # tests because it will no longer be valid after migration. The cache should
    # be updated with accurate data the next time it's set, which will happen
    # when someone views the graph.
    graph_revisions.DeleteCache(utils.TestPath(old_parent_key))
    graph_revisions.DeleteCache(utils.TestPath(new_parent_key))

    return {
        'put_future': ndb.put_multi_async(rows_to_put),
        'delete_future': ndb.delete_multi_async(rows_to_delete),
        'moved_rows': bool(rows_to_put),
    }