Example #1
0
    def Render(cls, handler):
        """Rendering method that can be called by main.py or get.

    This method executes no action, so the method by which it is accessed is
    immaterial.  Creating a form with get may be a desirable function.  That is,
    if this builtin is turned on, anyone can create a form to delete a kind by
    simply linking to the ConfirmDeleteHandler like so:
    <a href="/_ah/datastore_admin/confirm_delete?kind=trash">
        Delete all Trash Objects</a>

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
        namespace = handler.request.get('namespace')
        kinds = handler.request.get('kind', allow_multiple=True)
        sizes_known, size_total, remainder = cls._ParseKindsAndSizes(kinds)

        (namespace_str, kind_str) = _GetPrintableStrs(namespace, kinds)
        template_params = {
            'form_target': DoDeleteHandler.SUFFIX,
            'kind_list': kinds,
            'remainder': remainder,
            'sizes_known': sizes_known,
            'size_total': size_total,
            'app_id': handler.request.get('app_id'),
            'cancel_url': handler.request.get('cancel_url'),
            'kind_str': kind_str,
            'namespace_str': namespace_str,
            'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        }
        utils.RenderToResponse(handler, 'confirm_delete.html', template_params)
Example #2
0
  def Render(cls, handler, default_backup_id=None,
             default_delete_backup_after_restore=False):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
      default_backup_id: default value for handler.request
      default_delete_backup_after_restore: default value for handler.request
    """
    backup_id = handler.request.get('backup_id', default_backup_id)
    backup = db.get(backup_id) if backup_id else None
    notreadonly_warning = capabilities.CapabilitySet(
        'datastore_v3', capabilities=['write']).is_enabled()
    original_app_warning = backup.original_app
    if os.getenv('APPLICATION_ID') == original_app_warning:
      original_app_warning = None
    template_params = {
        'form_target': DoBackupRestoreHandler.SUFFIX,
        'queues': None,
        'cancel_url': handler.request.get('cancel_url'),
        'backup': backup,
        'delete_backup_after_restore': handler.request.get(
            'delete_backup_after_restore', default_delete_backup_after_restore),
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        'notreadonly_warning': notreadonly_warning,
        'original_app_warning': original_app_warning
    }
    utils.RenderToResponse(handler, 'confirm_restore_from_backup.html',
                           template_params)
Example #3
0
  def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
    namespace = handler.request.get('namespace', None)
    has_namespace = namespace is not None
    kinds = handler.request.get_all('kind')
    sizes_known, size_total, remainder = utils.ParseKindsAndSizes(kinds)
    notreadonly_warning = capabilities.CapabilitySet(
        'datastore_v3', capabilities=['write']).is_enabled()
    blob_warning = bool(blobstore.BlobInfo.all().count(1))
    template_params = {
        'form_target': DoBackupHandler.SUFFIX,
        'kind_list': kinds,
        'remainder': remainder,
        'sizes_known': sizes_known,
        'size_total': size_total,
        'queues': None,
        'cancel_url': handler.request.get('cancel_url'),
        'has_namespace': has_namespace,
        'namespace': namespace,
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        'notreadonly_warning': notreadonly_warning,
        'blob_warning': blob_warning,
        'backup_name': 'datastore_backup_%s' % time.strftime('%Y_%m_%d')
    }
    utils.RenderToResponse(handler, 'confirm_backup.html', template_params)
Example #4
0
    def Render(cls, handler):
        """Rendering method that can be called by main.py or get.

    This method executes no action, so the method by which it is accessed is
    immaterial.  Creating a form with get may be a desirable function.  That is,
    if this builtin is turned on, anyone can create a form to delete a kind by
    simply linking to the ConfirmDeleteHandler like so:
    <a href="/_ah/datastore_admin/confirm_delete?kind=trash">
        Delete all Trash Objects</a>

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
        readonly_warning = not capabilities.CapabilitySet(
            'datastore_v3', capabilities=['write']).is_enabled()
        namespace = handler.request.get('namespace')
        kinds = handler.request.get_all('kind')
        sizes_known, size_total, remainder = utils.ParseKindsAndSizes(kinds)

        (namespace_str, kind_str) = utils.GetPrintableStrs(namespace, kinds)
        template_params = {
            'readonly_warning': readonly_warning,
            'form_target': DoDeleteHandler.SUFFIX,
            'kind_list': kinds,
            'remainder': remainder,
            'sizes_known': sizes_known,
            'size_total': size_total,
            'app_id': handler.request.get('app_id'),
            'datastore_admin_home': utils.GenerateHomeUrl(handler.request),
            'kind_str': kind_str,
            'namespace_str': namespace_str,
            'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        }
        utils.RenderToResponse(handler, 'confirm_delete.html', template_params)
  def ListActions(self, error=None):
    """Handler for get requests to datastore_admin/confirm_delete."""
    use_stats_kinds = False
    kinds = []
    try:
      kinds = self.GetKinds()
      if not kinds:
        use_stats_kinds = True
    except datastore_errors.Error:
      use_stats_kinds = True

    last_stats_update, kind_stats = _GetDatastoreStats(
        kinds, use_stats_kinds=use_stats_kinds)

    template_params = {
        'kind_stats': kind_stats,
        'cancel_url': self.request.path + '?' + self.request.query_string,
        'last_stats_update': last_stats_update,
        'app_id': self.request.get('app_id'),
        'namespace': self.request.get('namespace'),
        'action_list': sorted(GET_ACTIONS.keys()),
        'error': error,
        'operations': utils.DatastoreAdminOperation.all().fetch(100),
    }
    utils.RenderToResponse(self, 'list_actions.html', template_params)
Example #6
0
  def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp2.RequestHandler invoking the method
    """
    namespace = handler.request.get('namespace')
    kinds = handler.request.get_all('kind')
    sizes_known, size_total, remainder = utils.ParseKindsAndSizes(kinds)

    (namespace_str, kind_str) = utils.GetPrintableStrs(namespace, kinds)
    notreadonly_warning = capabilities.CapabilitySet(
        'datastore_v3', capabilities=['write']).is_enabled()
    blob_warning = bool(blobstore.BlobInfo.all().fetch(1))
    datastore_type = datastore._GetConnection().get_datastore_type()
    high_replication_warning = (
        datastore_type == datastore_rpc.Connection.HIGH_REPLICATION_DATASTORE)

    template_params = {
        'form_target': DoCopyHandler.SUFFIX,
        'kind_list': kinds,
        'remainder': remainder,
        'sizes_known': sizes_known,
        'size_total': size_total,
        'app_id': handler.request.get('app_id'),
        'cancel_url': handler.request.get('cancel_url'),
        'kind_str': kind_str,
        'namespace_str': namespace_str,
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        'notreadonly_warning': notreadonly_warning,
        'blob_warning': blob_warning,
        'high_replication_warning': high_replication_warning,
    }
    utils.RenderToResponse(handler, 'confirm_copy.html', template_params)
Example #7
0
    def ListActions(self, error=None):
        """Handler for get requests to datastore_admin/confirm_delete."""
        use_stats_kinds = False
        kinds = []
        try:
            kinds = self.GetKinds()
            if not kinds:
                use_stats_kinds = True
        except datastore_errors.Error:
            use_stats_kinds = True

        last_stats_update, kind_stats = _GetDatastoreStats(
            kinds, use_stats_kinds=use_stats_kinds)

        template_params = {
            'kind_stats': kind_stats,
            'cancel_url': self.request.path + '?' + self.request.query_string,
            'last_stats_update': last_stats_update,
            'app_id': self.request.get('app_id'),
            'hosting_app_id': app_identity.get_application_id(),
            'has_namespace': self.request.get('namespace', None) is not None,
            'namespace': self.request.get('namespace'),
            'action_list': sorted(ENTITY_ACTIONS.keys()),
            'backup_action_list': sorted(BACKUP_ACTIONS.keys()),
            'pending_backup_action_list':
            sorted(PENDING_BACKUP_ACTIONS.keys()),
            'error': error,
            'completed_operations': self.GetOperations(active=False),
            'active_operations': self.GetOperations(active=True),
            'pending_backups': self.GetPendingBackups(),
            'backups': self.GetBackups(),
            'map_reduce_path': utils.config.MAPREDUCE_PATH + '/detail'
        }
        utils.RenderToResponse(self, 'list_actions.html', template_params)
Example #8
0
    def ListActions(self, error=None):
        """Handler for get requests to datastore_admin/confirm_delete."""
        use_stats_kinds = False
        kinds = []
        more_kinds = False
        try:
            kinds, more_kinds = self.GetKinds()
            if not kinds:
                use_stats_kinds = True
                logging.warning(
                    'Found no kinds. Using datastore stats instead.')
        except datastore_errors.Error as e:
            logging.exception(e)
            use_stats_kinds = True

        last_stats_update, kind_stats = _GetDatastoreStats(
            kinds, use_stats_kinds=use_stats_kinds)

        template_params = {
            'run_as_a_service':
            self.request.get('run_as_a_service'),
            'datastore_admin_home':
            utils.GenerateHomeUrl(None),
            'offer_service': (self.request.get('service')
                              and not self.request.get('run_as_a_service')),
            'kind_stats':
            kind_stats,
            'more_kinds':
            more_kinds,
            'last_stats_update':
            last_stats_update,
            'app_id':
            self.request.get('app_id'),
            'hosting_app_id':
            app_identity.get_application_id(),
            'has_namespace':
            self.request.get('namespace', None) is not None,
            'namespace':
            self.request.get('namespace'),
            'action_list':
            sorted(ENTITY_ACTIONS.keys()),
            'backup_action_list':
            sorted(BACKUP_ACTIONS.keys()),
            'pending_backup_action_list':
            sorted(PENDING_BACKUP_ACTIONS.keys()),
            'error':
            error,
            'completed_operations':
            self.GetOperations(active=False),
            'active_operations':
            self.GetOperations(active=True),
            'pending_backups':
            self.GetPendingBackups(),
            'backups':
            self.GetBackups(),
            'map_reduce_path':
            config.MAPREDUCE_PATH + '/detail'
        }
        utils.RenderToResponse(self, 'list_actions.html', template_params)
Example #9
0
  def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
    backup_ids = handler.request.get_all('backup_id')
    template_params = {
        'backups': db.get(backup_ids),
        'back_target': handler.request.get('cancel_url'),
    }
    utils.RenderToResponse(handler, 'backup_information.html', template_params)
Example #10
0
class ConfirmBackupImportHandler(webapp.RequestHandler):
  """Handler to import backup information."""

  SUFFIX = 'backup_information'

  @classmethod
  def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
    gs_handle = handler.request.get('gs_handle')
    error = None if gs_handle else 'Google Cloud Storage path is missing'
    other_backup_info_files = []
    selected_backup_info_file = None
    backup_info_specified = False
    if not error:
      try:
        gs_handle = gs_handle.rstrip()
        bucket_name, prefix = parse_gs_handle(gs_handle)
        validate_gs_bucket_name(bucket_name)
        if not is_accessible_bucket_name(bucket_name):
          raise BackupValidationException(
              'Bucket "%s" is not accessible' % bucket_name)
        if prefix.endswith('.backup_info'):
          prefix = prefix[0:prefix.rfind('/')]
          backup_info_specified = True
        elif prefix and not prefix.endswith('/'):
          prefix += '/'
        for backup_info_file in list_bucket_files(bucket_name, prefix):
          if backup_info_file.endswith('.backup_info'):
            backup_info_file = '/gs/%s/%s' % (bucket_name, backup_info_file)

            if backup_info_specified and backup_info_file == gs_handle:
              selected_backup_info_file = backup_info_file
            else:
              other_backup_info_files.append(backup_info_file)
      except Exception, ex:
        error = 'Failed to read bucket: %s' % ex
    template_params = {
        'error': error,
        'form_target': DoBackupImportHandler.SUFFIX,
        'cancel_url': handler.request.get('cancel_url'),
        'selected_backup_info_file': selected_backup_info_file,
        'other_backup_info_files': other_backup_info_files,
        'backup_info_specified': backup_info_specified,
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION)
    }
    utils.RenderToResponse(handler, 'confirm_backup_import.html',
                           template_params)
Example #11
0
    def get(self):
        """Handler for get requests to datastore_admin/delete.do.

    Status of executed jobs is displayed.
    """
        jobs = self.request.get('job', allow_multiple=True)
        error = self.request.get('error', '')

        template_params = {
            'job_list': jobs,
            'mapreduce_detail': self.MAPREDUCE_DETAIL,
            'error': error,
        }
        utils.RenderToResponse(self, 'do_delete.html', template_params)
Example #12
0
  def ListActions(self, error=None):
    """Handler for get requests to datastore_admin/confirm_delete."""
    kinds = self.request.get('kind', allow_multiple=True)
    last_stats_update, kind_stats = _GetDatastoreStats(kinds)

    template_params = {
        'kind_stats': kind_stats,
        'cancel_url': self.request.path + '?' + self.request.query_string,
        'last_stats_update': last_stats_update,
        'app_id': self.request.get('app_id'),
        'namespace': self.request.get('namespace'),
        'action_list': sorted(GET_ACTIONS.keys()),
        'error': error,
    }
    utils.RenderToResponse(self, 'list_actions.html', template_params)
Example #13
0
    def get(self):
        """Handler for get requests to datastore_admin/copy.do.

    Status of executed jobs is displayed.
    """
        jobs = self.request.get_all('job')
        error = self.request.get('error', '')
        xsrf_error = self.request.get('xsrf_error', '')

        template_params = {
            'job_list': jobs,
            'mapreduce_detail': self.MAPREDUCE_DETAIL,
            'error': error,
            'xsrf_error': xsrf_error,
            'datastore_admin_home': utils.config.BASE_PATH,
        }
        utils.RenderToResponse(self, 'do_copy.html', template_params)
Example #14
0
    def get(self):
        """Handler for get requests to datastore_admin backup operations.

    Status of executed jobs is displayed.
    """
        jobs = self.request.get('job', allow_multiple=True)
        tasks = self.request.get('task', allow_multiple=True)
        error = self.request.get('error', '')
        xsrf_error = self.request.get('xsrf_error', '')

        template_params = {
            'job_list': jobs,
            'task_list': tasks,
            'mapreduce_detail': self.MAPREDUCE_DETAIL,
            'error': error,
            'xsrf_error': xsrf_error,
            'datastore_admin_home': utils.config.BASE_PATH,
        }
        utils.RenderToResponse(self, self._get_html_page, template_params)
Example #15
0
  def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
    requested_backup_ids = handler.request.get_all('backup_id')
    backups = []
    if requested_backup_ids:
      for backup in db.get(requested_backup_ids):
        if backup:
          backups.append(backup)
    template_params = {
        'form_target': DoBackupAbortHandler.SUFFIX,
        'cancel_url': handler.request.get('cancel_url'),
        'backups': backups,
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION)
    }
    utils.RenderToResponse(handler, 'confirm_abort_backup.html',
                           template_params)
Example #16
0
    def Render(cls, handler):
        """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
        backup_id = handler.request.get('backup_id')
        backup = db.get(backup_id) if backup_id else None
        notreadonly_warning = capabilities.CapabilitySet(
            'datastore_v3', capabilities=['write']).is_enabled()
        app_id = handler.request.get('app_id')
        template_params = {
            'form_target': DoBackupRestoreHandler.SUFFIX,
            'app_id': app_id,
            'queues': None,
            'cancel_url': handler.request.get('cancel_url'),
            'backup': backup,
            'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
            'notreadonly_warning': notreadonly_warning
        }
        utils.RenderToResponse(handler, 'confirm_restore_from_backup.html',
                               template_params)
Example #17
0
  def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
    requested_backup_ids = handler.request.get_all('backup_id')
    backups = []
    gs_warning = False
    if requested_backup_ids:
      for backup in db.get(requested_backup_ids):
        if backup:
          backups.append(backup)
          gs_warning |= backup.filesystem == files.GS_FILESYSTEM
    template_params = {
        'form_target': DoBackupDeleteHandler.SUFFIX,
        'cancel_url': handler.request.get('cancel_url'),
        'backups': backups,
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        'gs_warning': gs_warning
    }
    utils.RenderToResponse(handler, 'confirm_delete_backup.html',
                           template_params)
Example #18
0
    def Render(cls, handler):
        """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
        backup_ids = handler.request.get_all('backup_id')
        if backup_ids:
            backups = db.get(backup_ids)
            backup_ids = [backup.key() for backup in backups]
            backup_names = [backup.name for backup in backups]
        else:
            backup_names = []
            backup_ids = []
        template_params = {
            'form_target': DoBackupDeleteHandler.SUFFIX,
            'app_id': handler.request.get('app_id'),
            'cancel_url': handler.request.get('cancel_url'),
            'backup_ids': backup_ids,
            'backup_names': backup_names,
            'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        }
        utils.RenderToResponse(handler, 'confirm_delete_backup.html',
                               template_params)