本文整理汇总了Python中ambari_commons.os_check.OSCheck.is_windows_family方法的典型用法代码示例。如果您正苦于以下问题:Python OSCheck.is_windows_family方法的具体用法?Python OSCheck.is_windows_family怎么用?Python OSCheck.is_windows_family使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ambari_commons.os_check.OSCheck
的用法示例。
在下文中一共展示了OSCheck.is_windows_family方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_packages
# 需要导入模块: from ambari_commons.os_check import OSCheck [as 别名]
# 或者: from ambari_commons.os_check.OSCheck import is_windows_family [as 别名]
def install_packages(self, env, exclude_packages=[]):
"""
List of packages that are required< by service is received from the server
as a command parameter. The method installs all packages
from this list
"""
config = self.get_config()
try:
package_list_str = config['hostLevelParams']['package_list']
if isinstance(package_list_str, basestring) and len(package_list_str) > 0:
package_list = json.loads(package_list_str)
for package in package_list:
if not package['name'] in exclude_packages:
name = package['name']
if OSCheck.is_windows_family():
if name[-4:] == ".msi":
#TODO all msis must be located in resource folder of server, change it to repo later
Msi(name, http_source=os.path.join(config['hostLevelParams']['jdk_location']))
else:
Package(name)
except KeyError:
pass # No reason to worry
if OSCheck.is_windows_family():
#TODO hacky install of windows msi, remove it or move to old(2.1) stack definition when component based install will be implemented
install_windows_msi(os.path.join(config['hostLevelParams']['jdk_location'], "hdp.msi"),
config["hostLevelParams"]["agentCacheDir"], "hdp.msi", self.get_password("hadoop"),
str(config['hostLevelParams']['stack_version']))
reload_windows_env()
pass
示例2: on_failure
# 需要导入模块: from ambari_commons.os_check import OSCheck [as 别名]
# 或者: from ambari_commons.os_check.OSCheck import is_windows_family [as 别名]
def on_failure(self, pythonCommand, result):
"""
Log some useful information after task failure.
"""
logger.info("Command " + pprint.pformat(pythonCommand) + " failed with exitcode=" + str(result['exitcode']))
if OSCheck.is_windows_family():
cmd_list = ["WMIC path win32_process get Caption,Processid,Commandline", "netstat -an"]
else:
cmd_list = ["ps faux", "netstat -tulpn"]
shell_runner = shellRunner()
for cmd in cmd_list:
ret = shell_runner.run(cmd)
logger.info("Command '{0}' returned {1}. {2}{3}".format(cmd, ret["exitCode"], ret["error"], ret["output"]))
示例3: execute_java_home_available_check
# 需要导入模块: from ambari_commons.os_check import OSCheck [as 别名]
# 或者: from ambari_commons.os_check.OSCheck import is_windows_family [as 别名]
def execute_java_home_available_check(self, config):
print "Java home check started."
java_home = config['commandParams']['java_home']
print "Java home to check: " + java_home
java_bin = "java"
if OSCheck.is_windows_family():
java_bin = "java.exe"
if not os.path.isfile(os.path.join(java_home, "bin", java_bin)):
print "Java home doesn't exist!"
java_home_check_structured_output = {"exit_code" : 1, "message": "Java home doesn't exist!"}
else:
print "Java home exists!"
java_home_check_structured_output = {"exit_code" : 0, "message": "Java home exists!"}
return java_home_check_structured_output
示例4:
# 需要导入模块: from ambari_commons.os_check import OSCheck [as 别名]
# 或者: from ambari_commons.os_check.OSCheck import is_windows_family [as 别名]
from resource_management.core.resources import Execute
from resource_management.core.shell import call
from resource_management.libraries.functions import format
from resource_management.libraries.functions import get_kinit_path
from resource_management.libraries.functions import get_klist_path
from ambari_commons.os_check import OSConst, OSCheck
from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
from urlparse import urlparse
import os
import re
RESULT_CODE_OK = 'OK'
RESULT_CODE_CRITICAL = 'CRITICAL'
RESULT_CODE_UNKNOWN = 'UNKNOWN'
if OSCheck.is_windows_family():
OOZIE_ENV_HTTPS_RE = r"set\s+OOZIE_HTTPS_PORT=(\d+)"
else:
OOZIE_ENV_HTTPS_RE = r"export\s+OOZIE_HTTPS_PORT=(\d+)"
# The configured Kerberos executable search paths, if any
KERBEROS_EXECUTABLE_SEARCH_PATHS_KEY = '{{kerberos-env/executable_search_paths}}'
OOZIE_URL_KEY = '{{oozie-site/oozie.base.url}}'
SECURITY_ENABLED = '{{cluster-env/security_enabled}}'
OOZIE_USER = '{{oozie-env/oozie_user}}'
OOZIE_CONF_DIR = '/usr/hdp/current/oozie-server/conf'
OOZIE_CONF_DIR_LEGACY = '/etc/oozie/conf'
OOZIE_HTTPS_PORT = '{{oozie-site/oozie.https.port}}'
OOZIE_ENV_CONTENT = '{{oozie-env/content}}'
示例5: execute_db_connection_check
# 需要导入模块: from ambari_commons.os_check import OSCheck [as 别名]
# 或者: from ambari_commons.os_check.OSCheck import is_windows_family [as 别名]
def execute_db_connection_check(self, config, tmp_dir):
print "DB connection check started."
# initialize needed data
ambari_server_hostname = config['commandParams']['ambari_server_host']
check_db_connection_jar_name = "DBConnectionVerification.jar"
jdk_location = config['commandParams']['jdk_location']
java_home = config['commandParams']['java_home']
db_name = config['commandParams']['db_name']
if db_name == DB_MYSQL:
jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_MYSQL
jdbc_driver_class = JDBC_DRIVER_CLASS_MYSQL
jdbc_name = JDBC_DRIVER_SYMLINK_MYSQL
elif db_name == DB_ORACLE:
jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_ORACLE
jdbc_driver_class = JDBC_DRIVER_CLASS_ORACLE
jdbc_name = JDBC_DRIVER_SYMLINK_ORACLE
elif db_name == DB_POSTGRESQL:
jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_POSTGRESQL
jdbc_driver_class = JDBC_DRIVER_CLASS_POSTGRESQL
jdbc_name = JDBC_DRIVER_SYMLINK_POSTGRESQL
elif db_name == DB_MSSQL:
jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_MSSQL
jdbc_driver_class = JDBC_DRIVER_CLASS_MSSQL
jdbc_name = JDBC_DRIVER_SYMLINK_MSSQL
elif db_name == DB_SQLA:
jdbc_url = jdk_location + JDBC_DRIVER_SYMLINK_SQLA
jdbc_driver_class = JDBC_DRIVER_CLASS_SQLA
jdbc_name = JDBC_DRIVER_SYMLINK_SQLA
db_connection_url = config['commandParams']['db_connection_url']
user_name = config['commandParams']['user_name']
user_passwd = config['commandParams']['user_passwd']
agent_cache_dir = os.path.abspath(config["hostLevelParams"]["agentCacheDir"])
check_db_connection_url = jdk_location + check_db_connection_jar_name
jdbc_path = os.path.join(agent_cache_dir, jdbc_name)
class_path_delimiter = ":"
if db_name == DB_SQLA:
jdbc_jar_path = agent_cache_dir + JDBC_DRIVER_SQLA_JAR_PATH_IN_ARCHIVE
java_library_path = agent_cache_dir + JARS_PATH_IN_ARCHIVE_SQLA + class_path_delimiter + agent_cache_dir + \
LIBS_PATH_IN_ARCHIVE_SQLA
else:
jdbc_jar_path = jdbc_path
java_library_path = agent_cache_dir
check_db_connection_path = os.path.join(agent_cache_dir, check_db_connection_jar_name)
java_bin = "java"
if OSCheck.is_windows_family():
java_bin = "java.exe"
class_path_delimiter = ";"
java_exec = os.path.join(java_home, "bin",java_bin)
if ('jdk_name' not in config['commandParams'] or config['commandParams']['jdk_name'] == None \
or config['commandParams']['jdk_name'] == '') and not os.path.isfile(java_exec):
message = "Custom java is not available on host. Please install it. Java home should be the same as on server. " \
"\n"
print message
db_connection_check_structured_output = {"exit_code" : 1, "message": message}
return db_connection_check_structured_output
environment = { "no_proxy": format("{ambari_server_hostname}") }
# download and install java if it doesn't exists
if not os.path.isfile(java_exec):
jdk_name = config['commandParams']['jdk_name']
jdk_url = "{0}/{1}".format(jdk_location, jdk_name)
jdk_download_target = os.path.join(agent_cache_dir, jdk_name)
java_dir = os.path.dirname(java_home)
try:
download_file(jdk_url, jdk_download_target)
except Exception, e:
message = "Error downloading JDK from Ambari Server resources. Check network access to " \
"Ambari Server.\n" + str(e)
print message
db_connection_check_structured_output = {"exit_code" : 1, "message": message}
return db_connection_check_structured_output
if jdk_name.endswith(".exe"):
install_cmd = "{0} /s INSTALLDIR={1} STATIC=1 WEB_JAVA=0 /L \\var\\log\\ambari-agent".format(
os_utils.quote_path(jdk_download_target), os_utils.quote_path(java_home),
)
install_path = [java_dir]
try:
Execute(install_cmd, path = install_path)
except Exception, e:
message = "Error installing java.\n" + str(e)
print message
db_connection_check_structured_output = {"exit_code" : 1, "message": message}
return db_connection_check_structured_output
示例6: download_file
# 需要导入模块: from ambari_commons.os_check import OSCheck [as 别名]
# 或者: from ambari_commons.os_check.OSCheck import is_windows_family [as 别名]
# download DBConnectionVerification.jar from ambari-server resources
try:
download_file(check_db_connection_url, check_db_connection_path)
except Exception, e:
message = "Error downloading DBConnectionVerification.jar from Ambari Server resources. Check network access to " \
"Ambari Server.\n" + str(e)
print message
db_connection_check_structured_output = {"exit_code" : 1, "message": message}
return db_connection_check_structured_output
# download jdbc driver from ambari-server resources
try:
download_file(jdbc_url, jdbc_path)
if db_name == DB_MSSQL and OSCheck.is_windows_family():
jdbc_auth_path = os.path.join(agent_cache_dir, JDBC_AUTH_SYMLINK_MSSQL)
jdbc_auth_url = jdk_location + JDBC_AUTH_SYMLINK_MSSQL
download_file(jdbc_auth_url, jdbc_auth_path)
elif db_name == DB_SQLA:
# unpack tar.gz jdbc which was donaloaded
untar_sqla_type2_driver = ('tar', '-xvf', jdbc_path, '-C', agent_cache_dir)
Execute(untar_sqla_type2_driver, sudo = True)
except Exception, e:
message = format("Error: Ambari Server cannot download the database JDBC driver and is unable to test the " \
"database connection. You must run ambari-server setup --jdbc-db={db_name} " \
"--jdbc-driver=/path/to/your/{db_name}/driver.jar on the Ambari Server host to make the JDBC " \
"driver available for download and to enable testing the database connection.\n") + str(e)
print message
db_connection_check_structured_output = {"exit_code" : 1, "message": message}
return db_connection_check_structured_output
示例7: execute
# 需要导入模块: from ambari_commons.os_check import OSCheck [as 别名]
# 或者: from ambari_commons.os_check.OSCheck import is_windows_family [as 别名]
def execute(self):
"""
Sets up logging;
Parses command parameters and executes method relevant to command type
"""
logger, chout, cherr = Logger.initialize_logger()
# parse arguments
if len(sys.argv) < 7:
logger.error("Script expects at least 6 arguments")
print USAGE.format(os.path.basename(sys.argv[0])) # print to stdout
sys.exit(1)
command_name = str.lower(sys.argv[1])
self.command_data_file = sys.argv[2]
self.basedir = sys.argv[3]
self.stroutfile = sys.argv[4]
self.load_structured_out()
self.logging_level = sys.argv[5]
Script.tmp_dir = sys.argv[6]
logging_level_str = logging._levelNames[self.logging_level]
chout.setLevel(logging_level_str)
logger.setLevel(logging_level_str)
# on windows we need to reload some of env variables manually because there is no default paths for configs(like
# /etc/something/conf on linux. When this env vars created by one of the Script execution, they can not be updated
# in agent, so other Script executions will not be able to access to new env variables
if OSCheck.is_windows_family():
reload_windows_env()
try:
with open(self.command_data_file) as f:
pass
Script.config = ConfigDictionary(json.load(f))
# load passwords here(used on windows to impersonate different users)
Script.passwords = {}
for k, v in _PASSWORD_MAP.iteritems():
if get_path_from_configuration(k, Script.config) and get_path_from_configuration(v, Script.config):
Script.passwords[get_path_from_configuration(k, Script.config)] = get_path_from_configuration(v, Script.config)
except IOError:
logger.exception("Can not read json file with command parameters: ")
sys.exit(1)
# Run class method depending on a command type
try:
method = self.choose_method_to_execute(command_name)
with Environment(self.basedir, tmp_dir=Script.tmp_dir) as env:
env.config.download_path = Script.tmp_dir
method(env)
if command_name == "install":
self.set_version()
except ClientComponentHasNoStatus or ComponentIsNotRunning:
# Support of component status checks.
# Non-zero exit code is interpreted as an INSTALLED status of a component
sys.exit(1)
except Fail:
logger.exception("Error while executing command '{0}':".format(command_name))
sys.exit(1)
finally:
if self.should_expose_component_version(command_name):
self.save_component_version_to_structured_out()