Beispiel #1
0
    def _handle_file_operation(self, operation):
        """Handle the given operation.

        Download operations need an authorization token from the server,
        while local deletion can be directly sent to workers.
        """
        if operation.verb != 'DOWNLOAD':
            raise Exception("Unexpected operation verb while in state %s: %s"
                % (self.__class__.__name__, operation))
        self.logger.info(u'Synchronizing pathname: %s "%s"'
            % (operation.verb, operation.pathname))
        operation.register_reject_handler(sync_on_operation_rejected)
        CryptoUtils.prepare_operation(operation, self._context.temp_dir)
        op_id = self._next_id()
        self._context._pathname2id[operation.pathname] = op_id
        self._context.transaction.add_operation(op_id, operation)
        if operation.is_leaf:
            request = SYNC_GET_REQUEST(
                "SYNC_GET_REQUEST",
                {'pathname': operation.pathname})
            #self.logger.debug(u"Produced Request message: %s", request)
            self._context.output_message_queue.put(request)
        else:
            self._context.transaction.authorize_operation(op_id)
            self._context.worker_pool.send_operation(operation)
    def _handle_operation(self, file_operation):
        """Here is an operation to do for replicating a local pathname.
        Do everything needed to synchronize it.

        If it's OK to serve it (e.g. it hasn't been aborted) then it's
        first declared to the server and then given to some worker.
        """
        assert file_operation.verb in ['UPLOAD', 'DELETE', 'REMOTE_COPY'], \
            "Unexpected operation verb while in state %s: %s" \
            % (self.__class__.__name__, file_operation)

        self.logger.debug(u"Received file operation: %s" % file_operation)
        if file_operation.is_aborted():
            return

        file_operation.register_reject_handler(on_operation_rejected)
        self._context._internal_facade.set_global_status(GStatuses.C_NOTALIGNED)

        # The "encrypted" folder is invariantly part of the warebox and gets
        # automatically re-created when deleted by the user.
        # The server won't accept to delete it.
        if file_operation.verb == 'DELETE' \
        and file_operation.pathname == u'encrypted/':
            file_operation.complete()
            self._try_set_global_status_aligned()
            return

        CryptoUtils.prepare_operation(file_operation)
        if CryptoUtils.to_encrypt(file_operation):
            self.logger.debug(u"Sending operation to encryption: %s" % file_operation)
            self._context.cryptoAdapter.put(file_operation)
            return

        op_id = self._next_id()
        must_declare = self._context.transaction_manager.handle_operation(
            op_id, file_operation, self)
        if not must_declare:
            self._try_set_global_status_aligned()
            return

        # The operation is not aborted nor ignored, process it
        if file_operation.verb == 'UPLOAD':
            # Note: operations different from uploads don't need workers
            if not self._context.worker_pool.acquire_worker():
                raise FileRockException(
                    u"Concurrency trouble in %s: could not acquire a worker"
                    " although some should have been available"
                    % (self.__class__.__name__ + "._handle_file_operation"))

            if __debug__:
                self._context.worker_pool.track_acquire_anonymous_worker(
                    file_operation.pathname)

            if not self._context.worker_pool.exist_free_workers():
                self._context.listening_operations = False

        self._declare_operation(file_operation, op_id)
        self._check_time_to_commit()
    def _handle_operation(self, file_operation):
        """Here is an operation to do for replicating a local pathname.
        Do everything needed to synchronize it.

        If it's OK to serve it (e.g. it hasn't been aborted) then it's
        first declared to the server and then given to some worker.
        """
        assert file_operation.verb in ['UPLOAD', 'DELETE', 'REMOTE_COPY'], \
            "Unexpected operation verb while in state %s: %s" \
            % (self.__class__.__name__, file_operation)

        self.logger.debug(u"Received file operation: %s" % file_operation)
        if file_operation.is_aborted():
            return

        file_operation.register_reject_handler(on_operation_rejected)
        self._context._internal_facade.set_global_status(GStatuses.C_NOTALIGNED)

        # The "encrypted" folder is invariantly part of the warebox and gets
        # automatically re-created when deleted by the user.
        # The server won't accept to delete it.
        if file_operation.verb == 'DELETE' \
        and file_operation.pathname == u'encrypted/':
            file_operation.complete()
            self._try_set_global_status_aligned()
            return

        CryptoUtils.prepare_operation(file_operation)
        if CryptoUtils.to_encrypt(file_operation):
            self.logger.debug(u"Sending operation to encryption: %s" % file_operation)
            self._context.cryptoAdapter.put(file_operation)
            return

        op_id = self._next_id()
        must_declare = self._context.transaction_manager.handle_operation(
            op_id, file_operation, self)
        if not must_declare:
            self._try_set_global_status_aligned()
            return

        # The operation is not aborted nor ignored, process it
        if file_operation.verb == 'UPLOAD':
            # Note: operations different from uploads don't need workers
            if not self._context.worker_pool.acquire_worker():
                raise FileRockException(
                    u"Concurrency trouble in %s: could not acquire a worker"
                    " although some should have been available"
                    % (self.__class__.__name__ + "._handle_file_operation"))
            if not self._context.worker_pool.exist_free_workers():
                self._context.listening_operations = False
        self._declare_operation(file_operation, op_id)
        self._check_time_to_commit()
Beispiel #4
0
    def _handle_operation(self, operation):
        if operation == 'NO_MORE_OPERATIONS':
            self._received_all_operations = True
            with self._lock:
                num_finished = self._num_finished_operations
                num_received = self._num_received_operations
                if num_received == num_finished:
                    self._set_next_state(StateRegister.get('SyncDoneState'))
            return

        self._num_received_operations += 1

        if not self._context.worker_pool.acquire_worker():
            raise FileRockException(
                u"Concurrency trouble in %s: could not acquire a worker"
                " although some should have been available"
                % (self.__class__.__name__ + "._handle_file_operation"))

        if __debug__:
            self._context.worker_pool.track_acquire_anonymous_worker(
                operation.pathname)

        if not self._context.worker_pool.exist_free_workers():
            self._listening_operations = False

        self.logger.info(u'Synchronizing pathname: %s "%s"'
                         % (operation.verb, operation.pathname))

        with operation.lock:
            if operation.is_working():
                operation.register_complete_handler(self._on_complete_operation)
                operation.register_abort_handler(self._on_complete_operation)
                operation.register_reject_handler(sync_on_operation_rejected)
            else:
                self.logger.debug(u"Ignoring aborted operation:%s" % operation)
                self._num_received_operations -= 1
                self._context.worker_pool.release_worker()
                return

        CryptoUtils.prepare_operation(operation, self._context.temp_dir)
        self._pathname2operation[operation.pathname] = operation
        request = SYNC_GET_REQUEST("SYNC_GET_REQUEST",
                                   {'pathname': operation.pathname})
        #self.logger.debug(u"Produced Request message: %s", request)
        self._context.output_message_queue.put(request)