示例#1
0
文件: builder.py 项目: zealxp/bundy
    def __handle_validate(self, args):
        """Handle 'validate' command.

        Command arguments are the same 'load' except the last one:
        'action': callable without any parameter itself, encapsulating
                  any segment-specific validation logic.  It returns
                  a result of the validation.

        This method simply calls the passed action, and returns the result
        back to the memmgr with other command arguments.  This is run in
        the builder thread simply because it may take time.

        """
        _, dsrc_info, rrclass, dsrc_name, action = args

        logger.debug(logger.DBGLVL_TRACE_BASIC,
                     LIBMEMMGR_BUILDER_SEGMENT_VALIDATE, dsrc_name, rrclass)
        try:
            result = action()
        except Exception as ex:
            logger.error(LIBMEMMGR_BUILDER_SEGMENT_VALIDATE_FAIL, dsrc_name,
                         rrclass, ex)
            result = False
        self.__send_response(('validate-completed', dsrc_info, rrclass,
                              dsrc_name, result))
示例#2
0
文件: builder.py 项目: zhangyut/bundy
    def __handle_validate(self, args):
        """Handle 'validate' command.

        Command arguments are the same 'load' except the last one:
        'action': callable without any parameter itself, encapsulating
                  any segment-specific validation logic.  It returns
                  a result of the validation.

        This method simply calls the passed action, and returns the result
        back to the memmgr with other command arguments.  This is run in
        the builder thread simply because it may take time.

        """
        _, dsrc_info, rrclass, dsrc_name, action = args

        logger.debug(logger.DBGLVL_TRACE_BASIC,
                     LIBMEMMGR_BUILDER_SEGMENT_VALIDATE, dsrc_name, rrclass)
        try:
            result = action()
        except Exception as ex:
            logger.error(LIBMEMMGR_BUILDER_SEGMENT_VALIDATE_FAIL, dsrc_name,
                         rrclass, ex)
            result = False
        self.__send_response(('validate-completed', dsrc_info, rrclass,
                              dsrc_name, result))
示例#3
0
文件: builder.py 项目: zhangyut/bundy
    def run(self):
        """ This is the method invoked when the builder thread is
            started.  In this thread, be careful when modifying
            variables passed-by-reference in the constructor. If they
            are reassigned, they will not refer to the main thread's
            objects any longer. Any use of command_queue and
            response_queue must be synchronized by acquiring the lock in
            the condition variable. This method must normally terminate
            only when the 'shutdown' command is sent to it.

        """
        while not self._shutdown:
            with self._cv:
                # Unless we've peeked and moved new commands in
                # __cmd_canceled(), wait for new one from the parent thread.
                if not self.__local_command_queue:
                    while not self._command_queue:
                        self._cv.wait()
                # Move the queue content to a local queue. Be careful of
                # not making assignments to reference variables.
                self.__local_command_queue.extend(self._command_queue[:])
                del self._command_queue[:]

            # Filter out commands that don't have to be executed.
            local_command_queue = \
                    self._handle_cancels(self.__local_command_queue)
            del self.__local_command_queue[:]

            # Run commands passed in the command queue sequentially
            # in the given order.  For now, it only supports the
            # "shutdown" command, which just exits the thread.
            for command_tuple in local_command_queue:
                command = command_tuple[0]
                logger.debug(logger.DBGLVL_TRACE_BASIC,
                             LIBMEMMGR_BUILDER_RECEIVED_COMMAND, command)
                if command == 'validate':
                    self.__handle_validate(command_tuple)
                elif command == 'load':
                    # See the comments for _handle_load() for
                    # details of the tuple passed to the "load"
                    # command.
                    _, zone_name, dsrc_info, rrclass, dsrc_name = \
                        command_tuple
                    self._handle_load(zone_name, dsrc_info, rrclass,
                                      dsrc_name)
                elif command == 'shutdown':
                    self.__handle_shutdown()
                    # When the shutdown command is received, we do
                    # not process any further commands.
                    break
                elif command == 'cancel':
                    # _handle_cancels() has done most of the work.  we can
                    # simply report it's completed.
                    self.__send_response(('cancel-completed', command_tuple[1]))
                else:
                    self.__handle_bad_command(command)
                    # When a bad command is received, we do not
                    # process any further commands.
                    break
示例#4
0
文件: builder.py 项目: zealxp/bundy
 def __reset_segment(self, clist, dsrc_name, rrclass, params):
     try:
         clist.reset_memory_segment(dsrc_name,
                                    ConfigurableClientList.READ_WRITE,
                                    params)
         logger.debug(logger.DBGLVL_TRACE_BASIC,
                      LIBMEMMGR_BUILDER_SEGMENT_RESET, dsrc_name, rrclass)
         return self.__RESET_SEGMENT_OK
     except Exception as ex:
         logger.error(LIBMEMMGR_BUILDER_RESET_SEGMENT_ERROR, dsrc_name,
                      rrclass, ex)
     try:
         clist.reset_memory_segment(dsrc_name, ConfigurableClientList.CREATE,
                                    params)
         logger.info(LIBMEMMGR_BUILDER_SEGMENT_CREATED, dsrc_name, rrclass)
         return self.__RESET_SEGMENT_CREATED
     except Exception as ex:
         logger.error(LIBMEMMGR_BUILDER_SEGMENT_CREATE_ERROR, dsrc_name,
                      rrclass, ex)
     return self.__RESET_SEGMENT_FAILED
示例#5
0
文件: builder.py 项目: zhangyut/bundy
 def __reset_segment(self, clist, dsrc_name, rrclass, params):
     try:
         clist.reset_memory_segment(dsrc_name,
                                    ConfigurableClientList.READ_WRITE,
                                    params)
         logger.debug(logger.DBGLVL_TRACE_BASIC,
                      LIBMEMMGR_BUILDER_SEGMENT_RESET, dsrc_name, rrclass)
         return self.__RESET_SEGMENT_OK
     except Exception as ex:
         logger.error(LIBMEMMGR_BUILDER_RESET_SEGMENT_ERROR, dsrc_name,
                      rrclass, ex)
     try:
         clist.reset_memory_segment(dsrc_name, ConfigurableClientList.CREATE,
                                    params)
         logger.info(LIBMEMMGR_BUILDER_SEGMENT_CREATED, dsrc_name, rrclass)
         return self.__RESET_SEGMENT_CREATED
     except Exception as ex:
         logger.error(LIBMEMMGR_BUILDER_SEGMENT_CREATE_ERROR, dsrc_name,
                      rrclass, ex)
     return self.__RESET_SEGMENT_FAILED