def _GetImpl(self):
    path = self._request.path.strip('/')
    parts = self._request.path.split('/', 1)
    source_name = parts[0]
    if len(parts) == 2:
      source_path = parts[1]
    else:
      source_path = None

    _log.info('starting refresh of %s DataSource %s' %
        (source_name, '' if source_path is None else '[%s]' % source_path))

    if 'commit' in self._request.arguments:
      commit = self._request.arguments['commit']
    else:
      _log.warning('No commit given; refreshing from master. '
                   'This is probably NOT what you want.')
      commit = None

    server_instance = self._CreateServerInstance(commit)
    success = True
    try:
      if source_name == 'platform_bundle':
        data_source = server_instance.platform_bundle
      elif source_name == 'content_providers':
        data_source = server_instance.content_providers
      else:
        data_source = CreateDataSource(source_name, server_instance)

      class_name = data_source.__class__.__name__
      refresh_future = data_source.Refresh(source_path)
      assert isinstance(refresh_future, Future), (
          '%s.Refresh() did not return a Future' % class_name)
      timer = Timer()
      try:
        refresh_future.Get()
      except Exception as e:
        _log.error('%s: error %s' % (class_name, traceback.format_exc()))
        success = False
        if IsFileSystemThrottledError(e):
          return Response.ThrottledError('Throttled')
        raise
      finally:
        _log.info('Refreshing %s took %s' %
            (class_name, timer.Stop().FormatElapsed()))

    except:
      success = False
      # This should never actually happen.
      _log.error('uncaught error: %s' % traceback.format_exc())
      raise
    finally:
      _log.info('finished (%s)', 'success' if success else 'FAILED')
      return (Response.Ok('Success') if success else
              Response.InternalError('Failure'))
Esempio n. 2
0
    def _GetImpl(self):
        path = self._request.path.strip('/')
        parts = self._request.path.split('/', 1)
        source_name = parts[0]
        if len(parts) == 2:
            source_path = parts[1]
        else:
            source_path = None

        _log.info(
            'starting refresh of %s DataSource %s' %
            (source_name, '' if source_path is None else '[%s]' % source_path))

        if 'commit' in self._request.arguments:
            commit = self._request.arguments['commit']
        else:
            _log.warning('No commit given; refreshing from master. '
                         'This is probably NOT what you want.')
            commit = None

        server_instance = self._CreateServerInstance(commit)
        commit_tracker = CommitTracker(server_instance.object_store_creator)
        refresh_tracker = RefreshTracker(server_instance.object_store_creator)

        # If no commit was given, use the ID of the last cached master commit.
        # This allows sources external to the chromium repository to be updated
        # independently from individual refresh cycles.
        if commit is None:
            commit = commit_tracker.Get('master').Get()

        success = True
        try:
            if source_name == 'platform_bundle':
                data_source = server_instance.platform_bundle
            elif source_name == 'content_providers':
                data_source = server_instance.content_providers
            else:
                data_source = CreateDataSource(source_name, server_instance)

            class_name = data_source.__class__.__name__
            refresh_future = data_source.Refresh(source_path)
            assert isinstance(
                refresh_future,
                Future), ('%s.Refresh() did not return a Future' % class_name)
            timer = Timer()
            try:
                refresh_future.Get()

                # Mark this (commit, task) pair as completed and then see if this
                # concludes the full cache refresh. The list of tasks required to
                # complete a cache refresh is registered (and keyed on commit ID) by the
                # CronServlet before kicking off all the refresh tasks.
                (refresh_tracker.MarkTaskComplete(
                    commit,
                    path).Then(lambda _: refresh_tracker.GetRefreshComplete(
                        commit)).Then(lambda is_complete: commit_tracker.Set(
                            'master', commit) if is_complete else None).Get())
            except Exception as e:
                _log.error('%s: error %s' %
                           (class_name, traceback.format_exc()))
                success = False
                if IsFileSystemThrottledError(e):
                    return Response.ThrottledError('Throttled')
                raise
            finally:
                _log.info('Refreshing %s took %s' %
                          (class_name, timer.Stop().FormatElapsed()))

        except:
            success = False
            # This should never actually happen.
            _log.error('uncaught error: %s' % traceback.format_exc())
            raise
        finally:
            _log.info('finished (%s)', 'success' if success else 'FAILED')
            return (Response.Ok('Success')
                    if success else Response.InternalError('Failure'))