当前位置: 首页>>代码示例>>Python>>正文


Python ActionQueue.ActionQueue类代码示例

本文整理汇总了Python中ambari_agent.ActionQueue.ActionQueue的典型用法代码示例。如果您正苦于以下问题:Python ActionQueue类的具体用法?Python ActionQueue怎么用?Python ActionQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ActionQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_execute_status_command_with_alerts

  def test_execute_status_command_with_alerts(self, CustomServiceOrchestrator_mock,
                                  build_mock, execute_command_mock,
                                  requestComponentStatus_mock, read_stack_version_mock,
                                  status_update_callback):
    CustomServiceOrchestrator_mock.return_value = None
    dummy_controller = MagicMock()
    actionQueue = ActionQueue(AmbariConfig().getConfig(), dummy_controller)


    requestComponentStatus_mock.reset_mock()
    requestComponentStatus_mock.return_value = {
      'exitcode': 0,
      'stdout': 'out',
      'stderr': 'err',
      'structuredOut': {'alerts': [ {'name': 'flume_alert'} ] }
    }
    build_mock.return_value = {'somestatusresult': 'aresult'}

    actionQueue.execute_status_command(self.status_command_for_alerts)

    report = actionQueue.result()

    self.assertTrue(requestComponentStatus_mock.called)
    self.assertEqual(len(report['componentStatus']), 1)
    self.assertTrue(report['componentStatus'][0].has_key('alerts'))
开发者ID:wbear2,项目名称:ambari,代码行数:25,代码来源:TestActionQueue.py

示例2: test_installAndConfigAction

  def test_installAndConfigAction(self):
    action={'id' : 'tttt'}
    actionQueue = ActionQueue(AmbariConfig().getConfig())
    path = actionQueue.getInstallFilename(action['id'])
    configFile = {
      "data"       : "test",
      "owner"      : os.getuid(),
      "group"      : os.getgid() ,
      "permission" : 0700,
      "path"       : path,
      "umask"      : 022
    }

    #note that the command in the action is just a listing of the path created
    #we just want to ensure that 'ls' can run on the data file (in the actual world
    #this 'ls' would be a puppet or a chef command that would work on a data
    #file
    path=getFilePath(action,path)
    action = { 
      'id' : 'tttt',
      'kind' : 'INSTALL_AND_CONFIG_ACTION',
      'workDirComponent' : 'abc-hdfs',
      'file' : configFile,
      'clusterDefinitionRevision' : 12,
      'command' : ['/bin/ls',path]
    }
    result = { }
    actionQueue = ActionQueue(AmbariConfig().getConfig())
    result = actionQueue.installAndConfigAction(action)
    cmdResult = result['commandResult']
    self.assertEqual(cmdResult['exitCode'], 0, "installAndConfigAction test failed. Returned %d " % cmdResult['exitCode'])
    self.assertEqual(cmdResult['output'], path + "\n", "installAndConfigAction test failed Returned %s " % cmdResult['output'])
开发者ID:sreev,项目名称:ambari,代码行数:32,代码来源:TestAgentActions.py

示例3: test_heartbeat_with_status_multiple

  def test_heartbeat_with_status_multiple(self, read_stack_version_method):
    actionQueue = ActionQueue(AmbariConfig.AmbariConfig().getConfig())
    actionQueue.IDLE_SLEEP_TIME = 0.01
    read_stack_version_method.return_value="1.3.0"
    heartbeat = Heartbeat(actionQueue)
    actionQueue.start()
    max_number_of_status_entries = 0
    for i in range(1,5):
      statusCommand = {
        "serviceName" : 'HDFS',
        "commandType" : "STATUS_COMMAND",
        "clusterName" : "",
        "componentName" : "DATANODE",
        'configurations':{'global' : {}}
      }
      actionQueue.put(statusCommand)
      time.sleep(0.1)
      result = heartbeat.build(101)
      number_of_status_entries = len(result['componentStatus'])
#      print "Heartbeat with status: " + str(result) + " XXX " + str(number_of_status_entries)
      if max_number_of_status_entries < number_of_status_entries:
        max_number_of_status_entries = number_of_status_entries
    actionQueue.stop()
    actionQueue.join()

    NUMBER_OF_COMPONENTS = 1
    self.assertEquals(max_number_of_status_entries == NUMBER_OF_COMPONENTS, True)
开发者ID:adamosloizou,项目名称:fiware-cosmos-ambari,代码行数:27,代码来源:TestHeartbeat.py

示例4: test_execute_retryable_command_with_time_lapse

  def test_execute_retryable_command_with_time_lapse(self, CustomServiceOrchestrator_mock,
                                     read_stack_version_mock, sleep_mock, time_mock
  ):
    CustomServiceOrchestrator_mock.return_value = None
    dummy_controller = MagicMock()
    actionQueue = ActionQueue(AmbariConfig(), dummy_controller)
    python_execution_result_dict = {
      'exitcode': 1,
      'stdout': 'out',
      'stderr': 'stderr',
      'structuredOut': '',
      'status': 'FAILED'
    }
    time_mock.side_effect = [4, 8, 10, 14, 18, 22]

    def side_effect(command, tmpoutfile, tmperrfile, override_output_files=True, retry=False):
      return python_execution_result_dict

    command = copy.deepcopy(self.retryable_command)
    with patch.object(CustomServiceOrchestrator, "runCommand") as runCommand_mock:
      runCommand_mock.side_effect = side_effect
      actionQueue.execute_command(command)

    #assert that python executor start
    self.assertTrue(runCommand_mock.called)
    self.assertEqual(2, runCommand_mock.call_count)
    self.assertEqual(1, sleep_mock.call_count)
    sleep_mock.assert_has_calls([call(2)], False)
    runCommand_mock.assert_has_calls([
      call(command, '/tmp/ambari-agent/output-19.txt', '/tmp/ambari-agent/errors-19.txt', override_output_files=True, retry=False),
      call(command, '/tmp/ambari-agent/output-19.txt', '/tmp/ambari-agent/errors-19.txt', override_output_files=False, retry=True)])
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:31,代码来源:TestActionQueue.py

示例5: test_execute_retryable_command_fail_and_succeed

  def test_execute_retryable_command_fail_and_succeed(self, CustomServiceOrchestrator_mock,
                                                      read_stack_version_mock, sleep_mock
  ):
    CustomServiceOrchestrator_mock.return_value = None
    dummy_controller = MagicMock()
    actionQueue = ActionQueue(AmbariConfig(), dummy_controller)
    execution_result_fail_dict = {
      'exitcode': 1,
      'stdout': 'out',
      'stderr': 'stderr',
      'structuredOut': '',
      'status': 'FAILED'
    }
    execution_result_succ_dict = {
      'exitcode': 0,
      'stdout': 'out',
      'stderr': 'stderr',
      'structuredOut': '',
      'status': 'COMPLETED'
    }

    command = copy.deepcopy(self.retryable_command)
    with patch.object(CustomServiceOrchestrator, "runCommand") as runCommand_mock:
      runCommand_mock.side_effect = [execution_result_fail_dict, execution_result_succ_dict]
      actionQueue.execute_command(command)

    #assert that python executor start
    self.assertTrue(runCommand_mock.called)
    self.assertEqual(2, runCommand_mock.call_count)
    self.assertEqual(1, sleep_mock.call_count)
    sleep_mock.assert_any_call(2)
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:31,代码来源:TestActionQueue.py

示例6: test_heartbeat_with_task_in_progress

 def test_heartbeat_with_task_in_progress(self):
   actionQueue = ActionQueue(AmbariConfig.AmbariConfig().getConfig())
   actionQueue.commandInProgress= {
     'role' : "role",
     'actionId' : "actionId",
     'taskId' : "taskId",
     'stdout' : "stdout",
     'clusterName' : "clusterName",
     'stderr' : 'none',
     'exitCode' : 777,
     'serviceName' : "serviceName",
     'status' : 'IN_PROGRESS',
     'configurations':{'global' : {}},
     'roleCommand' : 'START'
   }
   heartbeat = Heartbeat(actionQueue)
   result = heartbeat.build(100)
   #print "Heartbeat: " + str(result)
   self.assertEquals(len(result['reports']), 1)
   self.assertEquals(result['reports'][0]['role'], "role")
   self.assertEquals(result['reports'][0]['actionId'], "actionId")
   self.assertEquals(result['reports'][0]['taskId'], "taskId")
   self.assertEquals(result['reports'][0]['stdout'], "...")
   self.assertEquals(result['reports'][0]['clusterName'], "clusterName")
   self.assertEquals(result['reports'][0]['stderr'], "...")
   self.assertEquals(result['reports'][0]['exitCode'], 777)
   self.assertEquals(result['reports'][0]['serviceName'], "serviceName")
   self.assertEquals(result['reports'][0]['status'], "IN_PROGRESS")
   self.assertEquals(result['reports'][0]['roleCommand'], "START")
   pass
开发者ID:adamosloizou,项目名称:fiware-cosmos-ambari,代码行数:30,代码来源:TestHeartbeat.py

示例7: test_execute_status_command

  def test_execute_status_command(self, CustomServiceOrchestrator_mock,
                                  build_mock, execute_command_mock, requestComponentSecurityState_mock,
                                  requestComponentStatus_mock, read_stack_version_mock,
                                  status_update_callback):
    CustomServiceOrchestrator_mock.return_value = None
    dummy_controller = MagicMock()
    actionQueue = ActionQueue(AmbariConfig(), dummy_controller)

    build_mock.return_value = {'dummy report': '' }

    dummy_controller.recovery_manager = RecoveryManager(tempfile.mktemp())

    requestComponentStatus_mock.reset_mock()
    requestComponentStatus_mock.return_value = {'exitcode': 0 }

    requestComponentSecurityState_mock.reset_mock()
    requestComponentSecurityState_mock.return_value = 'UNKNOWN'

    actionQueue.execute_status_command(self.status_command)
    report = actionQueue.result()
    expected = {'dummy report': '',
                'securityState' : 'UNKNOWN'}

    self.assertEqual(len(report['componentStatus']), 1)
    self.assertEqual(report['componentStatus'][0], expected)
    self.assertTrue(requestComponentStatus_mock.called)
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:26,代码来源:TestActionQueue.py

示例8: test_ActionQueueStartStop

 def test_ActionQueueStartStop(self):
   actionQueue = ActionQueue(AmbariConfig().getConfig())
   actionQueue.IDLE_SLEEP_TIME = 0.01
   actionQueue.start()
   actionQueue.stop()
   actionQueue.join()
   self.assertEqual(actionQueue.stopped(), True, 'Action queue is not stopped.')
开发者ID:adamosloizou,项目名称:fiware-cosmos-ambari,代码行数:7,代码来源:TestActionQueue.py

示例9: test_run_unrecognized_command

 def test_run_unrecognized_command(self, logger_method, stopped_method):
   config = AmbariConfig().getConfig()
   actionQueue = ActionQueue(config)
   command = {
       "serviceName" : 'HDFS',
       "commandType" : "SOME_UNRECOGNIZED_COMMAND",
       "clusterName" : "",
       "componentName" : "DATANODE",
       'configurations':{}
   }
   actionQueue.commandQueue.put(command)
   actionQueue.stopped = stopped_method
   stopped_method.side_effect = [False, False, True, True, True]
   actionQueue.IDLE_SLEEP_TIME = 0.001
   actionQueue.run()
   self.assertTrue(logger_method.call_args[0][0].startswith('Unrecognized command'))
开发者ID:adamosloizou,项目名称:fiware-cosmos-ambari,代码行数:16,代码来源:TestActionQueue.py

示例10: test_parallel_exec

 def test_parallel_exec(self, CustomServiceOrchestrator_mock,
                        process_command_mock, gpeo_mock):
   CustomServiceOrchestrator_mock.return_value = None
   dummy_controller = MagicMock()
   config = MagicMock()
   gpeo_mock.return_value = 1
   config.get_parallel_exec_option = gpeo_mock
   actionQueue = ActionQueue(config, dummy_controller)
   actionQueue.put([self.datanode_install_command, self.hbase_install_command])
   self.assertEqual(2, actionQueue.commandQueue.qsize())
   actionQueue.start()
   time.sleep(1)
   actionQueue.stop()
   actionQueue.join()
   self.assertEqual(actionQueue.stopped(), True, 'Action queue is not stopped.')
   self.assertEqual(2, process_command_mock.call_count)
   process_command_mock.assert_any_calls([call(self.datanode_install_command), call(self.hbase_install_command)])
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:17,代码来源:TestActionQueue.py

示例11: test_cancel_backgound_command

  def test_cancel_backgound_command(self, read_stack_version_mock, resolve_hook_script_path_mock, resolve_script_path_mock, FileCache_mock,
                                      kill_process_with_children_mock):
    FileCache_mock.return_value = None
    FileCache_mock.cache_dir = MagicMock()
    resolve_hook_script_path_mock.return_value = None
#     shell.kill_process_with_children = MagicMock()
    dummy_controller = MagicMock()
    cfg = AmbariConfig().getConfig()
    cfg.set('agent', 'tolerate_download_failures', 'true')
    cfg.set('agent', 'prefix', '.')
    cfg.set('agent', 'cache_dir', 'background_tasks')

    actionQueue = ActionQueue(cfg, dummy_controller)

    dummy_controller.actionQueue = actionQueue
    orchestrator = CustomServiceOrchestrator(cfg, dummy_controller)
    orchestrator.file_cache = MagicMock()
    def f (a, b):
      return ""
    orchestrator.file_cache.get_service_base_dir = f
    actionQueue.customServiceOrchestrator = orchestrator

    import TestActionQueue
    import copy

    TestActionQueue.patch_output_file(orchestrator.python_executor)
    orchestrator.python_executor.prepare_process_result = MagicMock()
    orchestrator.dump_command_to_json = MagicMock()

    lock = threading.RLock()
    complete_done = threading.Condition(lock)

    complete_was_called = {}
    def command_complete_w(process_condenced_result, handle):
      with lock:
        complete_was_called['visited']= ''
        complete_done.wait(3)

    actionQueue.on_background_command_complete_callback = TestActionQueue.wraped(actionQueue.on_background_command_complete_callback, command_complete_w, None)
    execute_command = copy.deepcopy(TestActionQueue.TestActionQueue.background_command)
    actionQueue.put([execute_command])
    actionQueue.processBackgroundQueueSafeEmpty()

    time.sleep(.1)

    orchestrator.cancel_command(19,'')
    self.assertTrue(kill_process_with_children_mock.called)
    kill_process_with_children_mock.assert_called_with(33)

    with lock:
      complete_done.notifyAll()

    with lock:
      self.assertTrue(complete_was_called.has_key('visited'))

    time.sleep(.1)

    runningCommand = actionQueue.commandStatuses.get_command_status(19)
    self.assertTrue(runningCommand is not None)
    self.assertEqual(runningCommand['status'], ActionQueue.FAILED_STATUS)
开发者ID:fanzhidongyzby,项目名称:ambari,代码行数:60,代码来源:TestCustomServiceOrchestrator.py

示例12: test_status_command_without_globals_section

 def test_status_command_without_globals_section(self, stopped_method,
                                                 read_stack_version_method):
   config = AmbariConfig().getConfig()
   config.set('agent', 'prefix', TestStackVersionsFileHandler.dummyVersionsFile)
   queue = ActionQueue(config)
   statusCommand = {
     "serviceName" : 'HDFS',
     "commandType" : "STATUS_COMMAND",
     "clusterName" : "",
     "componentName" : "DATANODE",
     'configurations':{}
   }
   queue.stopped = stopped_method
   stopped_method.side_effect = [False, False, True, True, True]
   read_stack_version_method.return_value="1.3.0"
   queue.IDLE_SLEEP_TIME = 0.001
   queue.put(statusCommand)
   queue.run()
   returned_result = queue.resultQueue.get()
   returned_result[1]['status'] = 'INSTALLED' # Patch live value
   self.assertEquals(returned_result, ('STATUS_COMMAND',
                                       {'clusterName': '',
                                        'componentName': 'DATANODE',
                                        'msg': '',
                                        'serviceName': 'HDFS',
                                        'stackVersion': '1.3.0',
                                        'status': 'INSTALLED'}))
开发者ID:adamosloizou,项目名称:fiware-cosmos-ambari,代码行数:27,代码来源:TestActionQueue.py

示例13: test_execute_status_command

  def test_execute_status_command(self, CustomServiceOrchestrator_mock,
                                  build_mock, execute_command_mock,
                                  requestComponentStatus_mock, read_stack_version_mock,
                                  status_update_callback):
    CustomServiceOrchestrator_mock.return_value = None
    dummy_controller = MagicMock()
    actionQueue = ActionQueue(AmbariConfig().getConfig(), dummy_controller)

    build_mock.return_value = "dummy report"

    requestComponentStatus_mock.reset_mock()
    requestComponentStatus_mock.return_value = {'exitcode': 0}
    actionQueue.execute_status_command(self.status_command)
    report = actionQueue.result()
    expected = 'dummy report'
    self.assertEqual(len(report['componentStatus']), 1)
    self.assertEqual(report['componentStatus'][0], expected)
    self.assertTrue(requestComponentStatus_mock.called)
开发者ID:wbear2,项目名称:ambari,代码行数:18,代码来源:TestActionQueue.py

示例14: test_execute_python_executor

  def test_execute_python_executor(self, read_stack_version_mock, resolve_script_path_mock,
                                   get_py_executor_mock):
    
    dummy_controller = MagicMock()
    cfg = AmbariConfig()
    cfg.set('agent', 'tolerate_download_failures', 'true')
    cfg.set('agent', 'prefix', '.')
    cfg.set('agent', 'cache_dir', 'background_tasks')
    
    actionQueue = ActionQueue(cfg, dummy_controller)
    pyex = PythonExecutor(actionQueue.customServiceOrchestrator.tmp_dir, actionQueue.customServiceOrchestrator.config)
    patch_output_file(pyex)
    get_py_executor_mock.return_value = pyex
    actionQueue.customServiceOrchestrator.dump_command_to_json = MagicMock()
   
    result = {}
    lock = threading.RLock()
    complete_done = threading.Condition(lock)
    
    def command_complete_w(process_condensed_result, handle):
      with lock:
        result['command_complete'] = {'condensed_result' : copy.copy(process_condensed_result),
                                      'handle' : copy.copy(handle),
                                      'command_status' : actionQueue.commandStatuses.get_command_status(handle.command['taskId'])
                                      }
        complete_done.notifyAll()

    actionQueue.on_background_command_complete_callback = wraped(actionQueue.on_background_command_complete_callback,
                                                                 None, command_complete_w)
    actionQueue.put([self.background_command])
    actionQueue.processBackgroundQueueSafeEmpty();
    actionQueue.processStatusCommandQueueSafeEmpty();
    
    with lock:
      complete_done.wait(0.1)
      
      finished_status = result['command_complete']['command_status']
      self.assertEqual(finished_status['status'], ActionQueue.COMPLETED_STATUS)
      self.assertEqual(finished_status['stdout'], 'process_out')
      self.assertEqual(finished_status['stderr'], 'process_err')
      self.assertEqual(finished_status['exitCode'], 0)
      
    
    runningCommand = actionQueue.commandStatuses.current_state.get(self.background_command['taskId'])
    self.assertTrue(runningCommand is not None)
    
    report = actionQueue.result()
    self.assertEqual(len(report['reports']),1)
    self.assertEqual(report['reports'][0]['stdout'],'process_out')
开发者ID:OpenPOWER-BigData,项目名称:HDP-ambari,代码行数:49,代码来源:TestActionQueue.py

示例15: test_ActionQueueStartStop

 def test_ActionQueueStartStop(self, CustomServiceOrchestrator_mock,
                               get_mock, process_command_mock):
   CustomServiceOrchestrator_mock.return_value = None
   dummy_controller = MagicMock()
   config = MagicMock()
   actionQueue = ActionQueue(config, dummy_controller)
   actionQueue.start()
   time.sleep(0.1)
   actionQueue.stop()
   actionQueue.join()
   self.assertEqual(actionQueue.stopped(), True, 'Action queue is not stopped.')
   self.assertTrue(process_command_mock.call_count > 1)
开发者ID:wbear2,项目名称:ambari,代码行数:12,代码来源:TestActionQueue.py


注:本文中的ambari_agent.ActionQueue.ActionQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。