本文整理汇总了Python中CustomServiceOrchestrator.CustomServiceOrchestrator.requestComponentStatus方法的典型用法代码示例。如果您正苦于以下问题:Python CustomServiceOrchestrator.requestComponentStatus方法的具体用法?Python CustomServiceOrchestrator.requestComponentStatus怎么用?Python CustomServiceOrchestrator.requestComponentStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CustomServiceOrchestrator.CustomServiceOrchestrator
的用法示例。
在下文中一共展示了CustomServiceOrchestrator.requestComponentStatus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_requestComponentStatus
# 需要导入模块: from CustomServiceOrchestrator import CustomServiceOrchestrator [as 别名]
# 或者: from CustomServiceOrchestrator.CustomServiceOrchestrator import requestComponentStatus [as 别名]
def test_requestComponentStatus(self, FileCache_mock, runCommand_mock):
FileCache_mock.return_value = None
status_command = {
"serviceName" : 'HDFS',
"commandType" : "STATUS_COMMAND",
"clusterName" : "",
"componentName" : "DATANODE",
'configurations':{}
}
dummy_controller = MagicMock()
orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)
# Test alive case
runCommand_mock.return_value = {
"exitcode" : 0
}
status = orchestrator.requestComponentStatus(status_command)
self.assertEqual(runCommand_mock.return_value, status)
# Test dead case
runCommand_mock.return_value = {
"exitcode" : 1
}
status = orchestrator.requestComponentStatus(status_command)
self.assertEqual(runCommand_mock.return_value, status)
示例2: test_requestComponentStatus
# 需要导入模块: from CustomServiceOrchestrator import CustomServiceOrchestrator [as 别名]
# 或者: from CustomServiceOrchestrator.CustomServiceOrchestrator import requestComponentStatus [as 别名]
def test_requestComponentStatus(self, runCommand_mock):
status_command = {
"serviceName": 'HDFS',
"commandType": "STATUS_COMMAND",
"clusterName": "",
"componentName": "DATANODE",
'configurations': {},
'roleCommand': "STATUS"
}
dummy_controller = MagicMock()
tempdir = tempfile.gettempdir()
config = MagicMock()
config.get.return_value = "something"
config.getResolvedPath.return_value = tempdir
config.getWorkRootPath.return_value = tempdir
config.getLogPath.return_value = tempdir
orchestrator = CustomServiceOrchestrator(config, dummy_controller, self.agentToggleLogger)
# Test alive case
runCommand_mock.return_value = {
"exitcode": 0
}
status = orchestrator.requestComponentStatus(status_command)
self.assertEqual(CustomServiceOrchestrator.LIVE_STATUS, status['exitcode'])
# Test dead case
runCommand_mock.return_value = {
"exitcode": 1
}
status = orchestrator.requestComponentStatus(status_command)
self.assertEqual(CustomServiceOrchestrator.DEAD_STATUS, status['exitcode'])
示例3: test_runCommand_with_config
# 需要导入模块: from CustomServiceOrchestrator import CustomServiceOrchestrator [as 别名]
# 或者: from CustomServiceOrchestrator.CustomServiceOrchestrator import requestComponentStatus [as 别名]
def test_runCommand_with_config(self,
run_file_mock,
resolve_script_path_mock, unlink_mock,
isfile_mock, hostname_mock):
hostname_mock.return_value = "test.hst"
isfile_mock.return_value = True
command = {
'role': 'REGION_SERVER',
'componentName': 'REGION_SERVER',
'hostLevelParams': {
'stack_name': 'HDP',
'stack_version': '2.0.7',
'jdk_location': 'some_location'
},
'commandParams': {
'script_type': 'PYTHON',
'script': 'scripts/hbase_regionserver.py',
'command_timeout': '600',
'service_package_folder': 'HBASE'
},
'configurations': {
"hbase-site": {
"hbase.log": "${AGENT_LOG_ROOT}",
"hbase.number": "10485760"},
"hbase-log4j": {"a": "b"}
},
'taskId': '3',
'roleCommand': 'INSTALL',
'commandType': 'EXECUTION_COMMAND',
'commandId': '1-1'
}
command_get = {
'roleCommand': 'GET_CONFIG',
'commandType': 'STATUS_COMMAND'
}
command_get_specific = {
'roleCommand': 'GET_CONFIG',
'commandType': 'STATUS_COMMAND',
'commandParams': {
'config_type': 'hbase-site'
}
}
tempdir = tempfile.gettempdir()
config = MagicMock()
config.get.return_value = "something"
config.getResolvedPath.return_value = tempdir
config.getWorkRootPath.return_value = tempdir
config.getLogPath.return_value = tempdir
resolve_script_path_mock.return_value = "/basedir/scriptpath"
dummy_controller = MagicMock()
orchestrator = CustomServiceOrchestrator(config, dummy_controller, self.agentToggleLogger)
# normal run case
run_file_mock.return_value = {
'stdout': 'sss',
'stderr': 'eee',
'exitcode': 0,
}
expected = {
'hbase-site': {
'hbase.log': tempdir, 'hbase.number': '10485760'},
'hbase-log4j': {'a': 'b'}}
expected_specific = {
'hbase-site': {
'hbase.log': tempdir, 'hbase.number': '10485760'},
}
ret = orchestrator.runCommand(command, "out.txt", "err.txt", True, True)
self.assertEqual.__self__.maxDiff = None
self.assertEqual(ret['exitcode'], 0)
self.assertTrue(run_file_mock.called)
ret = orchestrator.requestComponentStatus(command_get)
self.assertEqual(ret['configurations'], expected)
ret = orchestrator.requestComponentStatus(command_get_specific)
self.assertEqual(ret['configurations'], expected_specific)
pass
示例4: test_runCommand_with_shell_config
# 需要导入模块: from CustomServiceOrchestrator import CustomServiceOrchestrator [as 别名]
# 或者: from CustomServiceOrchestrator.CustomServiceOrchestrator import requestComponentStatus [as 别名]
def test_runCommand_with_shell_config(self,
run_file_mock,
unlink_mock,
isfile_mock,
hostname_mock):
hostname_mock.return_value = "test.hst"
isfile_mock.return_value = True
command = {
'role': 'MEMCACHED',
'componentName': 'MEMCACHED',
'hostLevelParams': {
'jdk_location': 'some_location'
},
'commandParams': {
'script_type': 'SHELL',
'command_timeout': '600'
},
'configurations': {
"memcached-site": {
"memcached.log": "${AGENT_LOG_ROOT}",
"memcached.number": "10485760"},
"memcached-log4j": {"a": "b"}
},
'taskId': '3',
'roleCommand': 'INSTALL',
'commandType': 'EXECUTION_COMMAND',
'commandId': '1-1'
}
command_get = {
'roleCommand': 'GET_CONFIG',
'commandType': 'STATUS_COMMAND'
}
command_get_specific = {
'roleCommand': 'GET_CONFIG',
'commandType': 'STATUS_COMMAND',
'commandParams': {
'config_type': 'memcached-site'
}
}
tempdir = tempfile.gettempdir()
config = MagicMock()
config.get.return_value = "something"
config.getResolvedPath.return_value = tempdir
config.getWorkRootPath.return_value = tempdir
config.getLogPath.return_value = tempdir
dummy_controller = MagicMock()
orchestrator = CustomServiceOrchestrator(config, dummy_controller, self.agentToggleLogger)
# normal run case
run_file_mock.return_value = {
'stdout': 'sss',
'stderr': 'eee',
'exitcode': 0,
}
expected = {
'memcached-site': {
'memcached.log': tempdir, 'memcached.number': '10485760'},
'memcached-log4j': {'a': 'b'}}
expected_specific = {
'memcached-site': {
'memcached.log': tempdir, 'memcached.number': '10485760'},
}
ret = orchestrator.runCommand(command, "out.txt", "err.txt", True, True)
self.assertEqual.__self__.maxDiff = None
self.assertEqual(ret['exitcode'], 0)
self.assertTrue(run_file_mock.called)
ret = orchestrator.requestComponentStatus(command_get)
self.assertEqual(ret['configurations'], expected)
ret = orchestrator.requestComponentStatus(command_get_specific)
self.assertEqual(ret['configurations'], expected_specific)
script_path = os.path.realpath(posixpath.join(tempdir,
"infra", "agent", "slider-agent", "scripts",
"shell_cmd", "basic_installer.py"))
run_file_mock.assert_has_calls([call(
script_path,
['INSTALL', os.path.realpath(posixpath.join(tempdir, 'command-3.json')),
os.path.realpath(posixpath.join(tempdir, 'package'))],
'out.txt', 'err.txt', 600,
os.path.realpath(posixpath.join(tempdir, 'structured-out-3.json')),
'INFO', True,
[('PYTHONPATH', ":".join([os.path.realpath(posixpath.join(tempdir, 'infra', 'agent', 'slider-agent', 'jinja2')),
os.path.realpath(posixpath.join(tempdir, 'infra', 'agent', 'slider-agent'))]))])])
pass
示例5: ActionQueue
# 需要导入模块: from CustomServiceOrchestrator import CustomServiceOrchestrator [as 别名]
# 或者: from CustomServiceOrchestrator.CustomServiceOrchestrator import requestComponentStatus [as 别名]
#.........这里部分代码省略.........
Returns exponentially growing delay. The idea being if number of retries is high then the reason to retry
is probably a host or environment specific issue requiring longer waits
"""
return last_delay * 2
def command_was_canceled(self):
self.customServiceOrchestrator
def on_background_command_complete_callback(self, process_condensed_result, handle):
logger.debug('Start callback: %s' % process_condensed_result)
logger.debug('The handle is: %s' % handle)
status = self.COMPLETED_STATUS if handle.exitCode == 0 else self.FAILED_STATUS
aborted_postfix = self.customServiceOrchestrator.command_canceled_reason(handle.command['taskId'])
if aborted_postfix:
status = self.FAILED_STATUS
logger.debug('Set status to: %s , reason = %s' % (status, aborted_postfix))
else:
aborted_postfix = ''
roleResult = self.commandStatuses.generate_report_template(handle.command)
roleResult.update({
'stdout': process_condensed_result['stdout'] + aborted_postfix,
'stderr': process_condensed_result['stderr'] + aborted_postfix,
'exitCode': process_condensed_result['exitcode'],
'structuredOut': str(json.dumps(process_condensed_result['structuredOut'])) if 'structuredOut' in process_condensed_result else '',
'status': status,
})
self.commandStatuses.put_command_status(handle.command, roleResult)
def execute_status_command(self, command):
'''
Executes commands of type STATUS_COMMAND
'''
try:
cluster = command['clusterName']
service = command['serviceName']
component = command['componentName']
configurations = command['configurations']
if configurations.has_key('global'):
globalConfig = configurations['global']
else:
globalConfig = {}
livestatus = LiveStatus(cluster, service, component,
globalConfig, self.config, self.configTags)
component_extra = None
# For custom services, responsibility to determine service status is
# delegated to python scripts
component_status_result = self.customServiceOrchestrator.requestComponentStatus(command)
component_security_status_result = self.customServiceOrchestrator.requestComponentSecurityState(command)
if component_status_result['exitcode'] == 0:
component_status = LiveStatus.LIVE_STATUS
if self.controller.recovery_manager.enabled() \
and self.controller.recovery_manager.configured_for_recovery(component):
self.controller.recovery_manager.update_current_status(component, component_status)
else:
component_status = LiveStatus.DEAD_STATUS
if self.controller.recovery_manager.enabled() \
and self.controller.recovery_manager.configured_for_recovery(component):
if (self.controller.recovery_manager.get_current_status(component) != self.controller.recovery_manager.INSTALL_FAILED):
self.controller.recovery_manager.update_current_status(component, component_status)
request_execution_cmd = self.controller.recovery_manager.requires_recovery(component) and \
not self.controller.recovery_manager.command_exists(component, ActionQueue.EXECUTION_COMMAND)
if 'structuredOut' in component_status_result:
component_extra = component_status_result['structuredOut']
result = livestatus.build(component_status=component_status)
if self.controller.recovery_manager.enabled():
result['sendExecCmdDet'] = str(request_execution_cmd)
# Add security state to the result
result['securityState'] = component_security_status_result
if component_extra is not None and len(component_extra) != 0:
if component_extra.has_key('alerts'):
result['alerts'] = component_extra['alerts']
del component_extra['alerts']
result['extra'] = component_extra
logger.debug("Got live status for component " + component + \
" of service " + str(service) + \
" of cluster " + str(cluster))
logger.debug(pprint.pformat(result))
if result is not None:
self.commandStatuses.put_command_status(command, result)
except Exception, err:
traceback.print_exc()
logger.warn(err)
pass