Example #1
0
    def _poll_task(self, task):
        """Poll the given task until completion.

        If the task completes successfully, the method returns the task info
        using the input event (param done). In case of any error, appropriate
        exception is set in the event.

        :param task: managed object reference of the task
        """
        LOG.debug("Invoking VCA API to read info of task: %s.", task)
        try:
            task_info = self.invoke_api(self.vca, "get_task_result", task)
        except exceptions.VCloudDriverException:
            with excutils.save_and_reraise_exception():
                LOG.exception(
                    "Error occurred while reading info of "
                    "task: %s.", task)
        else:
            if task_info['status'] in ['queued', 'running']:
                if hasattr(task_info, 'progress'):
                    LOG.debug("Task: %(task)s progress is %(progress)s%%.", {
                        'task': task,
                        'progress': task_info.progress
                    })
            elif task_info['status'] == 'success':
                LOG.debug("Task: %s status is success.", task)
                raise loopingcall.LoopingCallDone(task_info)
            else:
                raise exceptions.VCloudDriverException(
                    "Task execute failed, task:%s", task)
Example #2
0
 def _func(*args, **kwargs):
     func_name = f.__name__
     result = None
     try:
         if self._retry_count:
             LOG.debug(
                 "Invoking %(func_name)s; retry count is "
                 "%(retry_count)d.", {
                     'func_name': func_name,
                     'retry_count': self._retry_count
                 })
         result = f(*args, **kwargs)
     except self._exceptions:
         with excutils.save_and_reraise_exception() as ctxt:
             LOG.warn(_LW("Exception which is in the suggested list of "
                          "exceptions occurred while invoking function:"
                          " %s."),
                      func_name,
                      exc_info=True)
             if (self._max_retry_count != -1
                     and self._retry_count >= self._max_retry_count):
                 LOG.error(
                     _LE("Cannot retry upon suggested exception "
                         "since retry count (%(retry_count)d) "
                         "reached max retry count "
                         "(%(max_retry_count)d)."), {
                             'retry_count': self._retry_count,
                             'max_retry_count': self._max_retry_count
                         })
             else:
                 ctxt.reraise = False
                 self._retry_count += 1
                 self._sleep_time += self._inc_sleep_time
                 return self._sleep_time
     raise loopingcall.LoopingCallDone(result)
Example #3
0
    def _poll_task(self, task):
        """Poll the given task until completion.

        If the task completes successfully, the method returns the task info
        using the input event (param done). In case of any error, appropriate
        exception is set in the event.

        :param task: managed object reference of the task
        """
        LOG.debug("Invoking VIM API to read info of task: %s.", task)
        try:
            task_info = self.invoke_api(vim_util, 'get_object_property',
                                        self.vim, task, 'info')
        except exceptions.VimException:
            with excutils.save_and_reraise_exception():
                LOG.exception(
                    _LE("Error occurred while reading info of "
                        "task: %s."), task)
        else:
            if task_info.state in ['queued', 'running']:
                if hasattr(task_info, 'progress'):
                    LOG.debug("Task: %(task)s progress is %(progress)s%%.", {
                        'task': task,
                        'progress': task_info.progress
                    })
            elif task_info.state == 'success':
                LOG.debug("Task: %s status is success.", task)
                raise loopingcall.LoopingCallDone(task_info)
            else:
                error_msg = six.text_type(task_info.error.localizedMessage)
                error = task_info.error
                name = error.fault.__class__.__name__
                task_ex = exceptions.get_fault_class(name)(error_msg)
                raise task_ex
Example #4
0
    def _poll_lease(self, lease):
        """Poll the state of the given lease.

        When the lease is ready, the event (param done) is notified. In case
        of any error, appropriate exception is set in the event.

        :param lease: lease whose state is to be polled
        """
        LOG.debug("Invoking VIM API to read state of lease: %s.", lease)
        try:
            state = self.invoke_api(vim_util, 'get_object_property', self.vim,
                                    lease, 'state')
        except exceptions.VimException:
            with excutils.save_and_reraise_exception():
                LOG.exception(
                    _LE("Error occurred while checking "
                        "state of lease: %s."), lease)
        else:
            if state == 'ready':
                LOG.debug("Lease: %s is ready.", lease)
                raise loopingcall.LoopingCallDone()
            elif state == 'initializing':
                LOG.debug("Lease: %s is initializing.", lease)
            elif state == 'error':
                LOG.debug("Invoking VIM API to read lease: %s error.", lease)
                error_msg = self._get_error_message(lease)
                excep_msg = _("Lease: %(lease)s is in error state. Details: "
                              "%(error_msg)s.") % {
                                  'lease': lease,
                                  'error_msg': error_msg
                              }
                LOG.error(excep_msg)
                raise exceptions.VimException(excep_msg)
            else:
                # unknown state
                excep_msg = _("Unknown state: %(state)s for lease: "
                              "%(lease)s.") % {
                                  'state': state,
                                  'lease': lease
                              }
                LOG.error(excep_msg)
                raise exceptions.VimException(excep_msg)
Example #5
0
 def _func(*args, **kwargs):
     func_name = f.__name__
     try:
         LOG.debug(_("Invoking %(func_name)s; retry count is "
                     "%(retry_count)d."),
                   {'func_name': func_name,
                    'retry_count': self._retry_count})
         result = f(*args, **kwargs)
         LOG.debug(_("Function %(func_name)s returned successfully "
                     "after %(retry_count)d retries."),
                   {'func_name': func_name,
                    'retry_count': self._retry_count})
     except self._exceptions as excep:
         LOG.warn(_("Exception which is in the suggested list of "
                    "exceptions occurred while invoking function:"
                    " %s."),
                  func_name,
                  exc_info=True)
         if (self._max_retry_count != -1 and
                 self._retry_count >= self._max_retry_count):
             LOG.error(_("Cannot retry upon suggested exception since "
                         "retry count (%(retry_count)d) reached "
                         "max retry count (%(max_retry_count)d)."),
                       {'retry_count': self._retry_count,
                        'max_retry_count': self._max_retry_count})
             raise excep
         else:
             self._retry_count += 1
             self._sleep_time += self._inc_sleep_time
             return self._sleep_time
     except Exception as excep:
         LOG.exception(_("Exception which is not in the suggested list "
                         "of exceptions occurred while invoking %s."),
                       func_name)
         raise excep
     raise loopingcall.LoopingCallDone(result)