當前位置: 首頁>>代碼示例>>Python>>正文


Python ActionQueue.tasks_in_progress_or_pending方法代碼示例

本文整理匯總了Python中ambari_agent.ActionQueue.ActionQueue.tasks_in_progress_or_pending方法的典型用法代碼示例。如果您正苦於以下問題:Python ActionQueue.tasks_in_progress_or_pending方法的具體用法?Python ActionQueue.tasks_in_progress_or_pending怎麽用?Python ActionQueue.tasks_in_progress_or_pending使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ambari_agent.ActionQueue.ActionQueue的用法示例。


在下文中一共展示了ActionQueue.tasks_in_progress_or_pending方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_reset_queue

# 需要導入模塊: from ambari_agent.ActionQueue import ActionQueue [as 別名]
# 或者: from ambari_agent.ActionQueue.ActionQueue import tasks_in_progress_or_pending [as 別名]
 def test_reset_queue(self, CustomServiceOrchestrator_mock,
                               get_mock, process_command_mock, gpeo_mock):
   CustomServiceOrchestrator_mock.return_value = None
   dummy_controller = MagicMock()
   dummy_controller.recovery_manager = RecoveryManager(tempfile.mktemp())
   config = MagicMock()
   gpeo_mock.return_value = 0
   config.get_parallel_exec_option = gpeo_mock
   actionQueue = ActionQueue(config, dummy_controller)
   actionQueue.start()
   actionQueue.put([self.datanode_install_command, self.hbase_install_command])
   self.assertEqual(2, actionQueue.commandQueue.qsize())
   self.assertTrue(actionQueue.tasks_in_progress_or_pending())
   actionQueue.reset()
   self.assertTrue(actionQueue.commandQueue.empty())
   self.assertFalse(actionQueue.tasks_in_progress_or_pending())
   time.sleep(0.1)
   actionQueue.stop()
   actionQueue.join()
   self.assertEqual(actionQueue.stopped(), True, 'Action queue is not stopped.')
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:22,代碼來源:TestActionQueue.py

示例2: test_execute_command

# 需要導入模塊: from ambari_agent.ActionQueue import ActionQueue [as 別名]
# 或者: from ambari_agent.ActionQueue.ActionQueue import tasks_in_progress_or_pending [as 別名]
  def test_execute_command(self, status_update_callback_mock, open_mock):
    # Make file read calls visible
    def open_side_effect(file, mode):
      if mode == 'r':
        file_mock = MagicMock()
        file_mock.read.return_value = "Read from " + str(file)
        return file_mock
      else:
        return self.original_open(file, mode)
    open_mock.side_effect = open_side_effect

    config = AmbariConfig()
    tempdir = tempfile.gettempdir()
    config.set('agent', 'prefix', tempdir)
    config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache")
    config.set('agent', 'tolerate_download_failures', "true")
    dummy_controller = MagicMock()
    actionQueue = ActionQueue(config, dummy_controller)
    unfreeze_flag = threading.Event()
    python_execution_result_dict = {
      'stdout': 'out',
      'stderr': 'stderr',
      'structuredOut' : ''
      }

    def side_effect(command, tmpoutfile, tmperrfile, override_output_files=True, retry=False):
      unfreeze_flag.wait()
      return python_execution_result_dict
    def patched_aq_execute_command(command):
      # We have to perform patching for separate thread in the same thread
      with patch.object(CustomServiceOrchestrator, "runCommand") as runCommand_mock:
          runCommand_mock.side_effect = side_effect
          actionQueue.execute_command(command)
    ### Test install/start/stop command ###
    ## Test successful execution with configuration tags
    python_execution_result_dict['status'] = 'COMPLETE'
    python_execution_result_dict['exitcode'] = 0
    # We call method in a separate thread
    execution_thread = Thread(target = patched_aq_execute_command ,
                              args = (self.datanode_install_command, ))
    execution_thread.start()
    #  check in progress report
    # wait until ready
    while True:
      time.sleep(0.1)
      report = actionQueue.result()
      if len(report['reports']) != 0:
        break
    expected = {'status': 'IN_PROGRESS',
                'stderr': 'Read from {0}'.format(os.path.join(tempdir, "errors-3.txt")),
                'stdout': 'Read from {0}'.format(os.path.join(tempdir, "output-3.txt")),
                'structuredOut' : 'Read from {0}'.format(os.path.join(tempdir, "structured-out-3.json")),
                'clusterName': u'cc',
                'roleCommand': u'INSTALL',
                'serviceName': u'HDFS',
                'role': u'DATANODE',
                'actionId': '1-1',
                'taskId': 3,
                'exitCode': 777}
    self.assertEqual(report['reports'][0], expected)
    self.assertTrue(actionQueue.tasks_in_progress_or_pending())

  # Continue command execution
    unfreeze_flag.set()
    # wait until ready
    while report['reports'][0]['status'] == 'IN_PROGRESS':
      time.sleep(0.1)
      report = actionQueue.result()
    # check report
    configname = os.path.join(tempdir, 'config.json')
    expected = {'status': 'COMPLETED',
                'stderr': 'stderr',
                'stdout': 'out',
                'clusterName': u'cc',
                'structuredOut': '""',
                'roleCommand': u'INSTALL',
                'serviceName': u'HDFS',
                'role': u'DATANODE',
                'actionId': '1-1',
                'taskId': 3,
                'configurationTags': {'global': {'tag': 'v1'}},
                'exitCode': 0}
    self.assertEqual(len(report['reports']), 1)
    self.assertEqual(report['reports'][0], expected)
    self.assertTrue(os.path.isfile(configname))
    # Check that we had 2 status update calls ( IN_PROGRESS and COMPLETE)
    self.assertEqual(status_update_callback_mock.call_count, 2)
    os.remove(configname)

    # now should not have reports (read complete/failed reports are deleted)
    report = actionQueue.result()
    self.assertEqual(len(report['reports']), 0)

    ## Test failed execution
    python_execution_result_dict['status'] = 'FAILED'
    python_execution_result_dict['exitcode'] = 13
    # We call method in a separate thread
    execution_thread = Thread(target = patched_aq_execute_command ,
                              args = (self.datanode_install_command, ))
    execution_thread.start()
#.........這裏部分代碼省略.........
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:103,代碼來源:TestActionQueue.py

示例3: test_auto_execute_command

# 需要導入模塊: from ambari_agent.ActionQueue import ActionQueue [as 別名]
# 或者: from ambari_agent.ActionQueue.ActionQueue import tasks_in_progress_or_pending [as 別名]
  def test_auto_execute_command(self, status_update_callback_mock, open_mock):
    # Make file read calls visible
    def open_side_effect(file, mode):
      if mode == 'r':
        file_mock = MagicMock()
        file_mock.read.return_value = "Read from " + str(file)
        return file_mock
      else:
        return self.original_open(file, mode)
    open_mock.side_effect = open_side_effect

    config = AmbariConfig()
    tempdir = tempfile.gettempdir()
    config.set('agent', 'prefix', tempdir)
    config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache")
    config.set('agent', 'tolerate_download_failures', "true")
    dummy_controller = MagicMock()
    dummy_controller.recovery_manager = RecoveryManager(tempfile.mktemp())
    dummy_controller.recovery_manager.update_config(5, 5, 1, 11, True, False, "", "")

    actionQueue = ActionQueue(config, dummy_controller)
    unfreeze_flag = threading.Event()
    python_execution_result_dict = {
      'stdout': 'out',
      'stderr': 'stderr',
      'structuredOut' : ''
    }

    def side_effect(command, tmpoutfile, tmperrfile, override_output_files=True, retry=False):
      unfreeze_flag.wait()
      return python_execution_result_dict
    def patched_aq_execute_command(command):
      # We have to perform patching for separate thread in the same thread
      with patch.object(CustomServiceOrchestrator, "runCommand") as runCommand_mock:
        runCommand_mock.side_effect = side_effect
        actionQueue.process_command(command)

    python_execution_result_dict['status'] = 'COMPLETE'
    python_execution_result_dict['exitcode'] = 0
    self.assertFalse(actionQueue.tasks_in_progress_or_pending())
    # We call method in a separate thread
    execution_thread = Thread(target = patched_aq_execute_command ,
                              args = (self.datanode_auto_start_command, ))
    execution_thread.start()
    #  check in progress report
    # wait until ready
    while True:
      time.sleep(0.1)
      if actionQueue.tasks_in_progress_or_pending():
        break
    # Continue command execution
    unfreeze_flag.set()
    # wait until ready
    while actionQueue.tasks_in_progress_or_pending():
      time.sleep(0.1)
      report = actionQueue.result()

    self.assertEqual(len(report['reports']), 0)

    ## Test failed execution
    python_execution_result_dict['status'] = 'FAILED'
    python_execution_result_dict['exitcode'] = 13
    # We call method in a separate thread
    execution_thread = Thread(target = patched_aq_execute_command ,
                              args = (self.datanode_auto_start_command, ))
    execution_thread.start()
    unfreeze_flag.set()
    #  check in progress report
    # wait until ready
    report = actionQueue.result()
    while actionQueue.tasks_in_progress_or_pending():
      time.sleep(0.1)
      report = actionQueue.result()

    self.assertEqual(len(report['reports']), 0)
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:77,代碼來源:TestActionQueue.py


注:本文中的ambari_agent.ActionQueue.ActionQueue.tasks_in_progress_or_pending方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。