本文整理汇总了Python中airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook._resolve_connection方法的典型用法代码示例。如果您正苦于以下问题:Python SparkSubmitHook._resolve_connection方法的具体用法?Python SparkSubmitHook._resolve_connection怎么用?Python SparkSubmitHook._resolve_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook
的用法示例。
在下文中一共展示了SparkSubmitHook._resolve_connection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resolve_connection
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection(self):
# Default to the standard yarn connection because conn_id does not exists
hook = SparkSubmitHook(conn_id='')
self.assertEqual(hook._resolve_connection(), ('yarn', None, None, None))
assert "--master yarn" in ' '.join(hook._build_command(self._spark_job_file))
# Default to the standard yarn connection
hook = SparkSubmitHook(conn_id='spark_default')
self.assertEqual(
hook._resolve_connection(),
('yarn', 'root.default', None, None)
)
cmd = ' '.join(hook._build_command(self._spark_job_file))
assert "--master yarn" in cmd
assert "--queue root.default" in cmd
# Connect to a mesos master
hook = SparkSubmitHook(conn_id='spark_default_mesos')
self.assertEqual(
hook._resolve_connection(),
('mesos://host:5050', None, None, None)
)
cmd = ' '.join(hook._build_command(self._spark_job_file))
assert "--master mesos://host:5050" in cmd
# Set specific queue and deploy mode
hook = SparkSubmitHook(conn_id='spark_yarn_cluster')
self.assertEqual(
hook._resolve_connection(),
('yarn://yarn-master', 'root.etl', 'cluster', None)
)
cmd = ' '.join(hook._build_command(self._spark_job_file))
assert "--master yarn://yarn-master" in cmd
assert "--queue root.etl" in cmd
assert "--deploy-mode cluster" in cmd
# Set the spark home
hook = SparkSubmitHook(conn_id='spark_home_set')
self.assertEqual(
hook._resolve_connection(),
('yarn://yarn-master', None, None, '/opt/myspark')
)
cmd = ' '.join(hook._build_command(self._spark_job_file))
assert cmd.startswith('/opt/myspark/bin/spark-submit')
# Spark home not set
hook = SparkSubmitHook(conn_id='spark_home_not_set')
self.assertEqual(
hook._resolve_connection(),
('yarn://yarn-master', None, None, None)
)
cmd = ' '.join(hook._build_command(self._spark_job_file))
assert cmd.startswith('spark-submit')
示例2: test_resolve_connection_spark_standalone_cluster_connection
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection_spark_standalone_cluster_connection(self):
# Given
hook = SparkSubmitHook(conn_id='spark_standalone_cluster')
# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)
# Then
expected_spark_connection = {"master": "spark://spark-standalone-master:6066",
"spark_binary": "spark-submit",
"deploy_mode": "cluster",
"queue": None,
"spark_home": "/path/to/spark_home"}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(cmd[0], '/path/to/spark_home/bin/spark-submit')
示例3: test_resolve_connection_spark_binary_set_connection
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection_spark_binary_set_connection(self):
# Given
hook = SparkSubmitHook(conn_id='spark_binary_set')
# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)
# Then
expected_spark_connection = {"master": "yarn",
"spark_binary": "custom-spark-submit",
"deploy_mode": None,
"queue": None,
"spark_home": None}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(cmd[0], 'custom-spark-submit')
示例4: test_resolve_connection_mesos_default_connection
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection_mesos_default_connection(self):
# Given
hook = SparkSubmitHook(conn_id='spark_default_mesos')
# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)
# Then
dict_cmd = self.cmd_args_to_dict(cmd)
expected_spark_connection = {"master": "mesos://host:5050",
"spark_binary": "spark-submit",
"deploy_mode": None,
"queue": None,
"spark_home": None}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(dict_cmd["--master"], "mesos://host:5050")
示例5: test_resolve_connection_spark_home_set_connection
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection_spark_home_set_connection(self):
# Given
hook = SparkSubmitHook(conn_id='spark_home_set')
# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)
# Then
expected_spark_connection = {"master": "yarn://yarn-master",
"spark_binary": "spark-submit",
"deploy_mode": None,
"queue": None,
"spark_home": "/opt/myspark",
"namespace": 'default'}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(cmd[0], '/opt/myspark/bin/spark-submit')
示例6: test_resolve_connection_yarn_default
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection_yarn_default(self):
# Given
hook = SparkSubmitHook(conn_id='')
# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)
# Then
dict_cmd = self.cmd_args_to_dict(cmd)
expected_spark_connection = {"master": "yarn",
"spark_binary": "spark-submit",
"deploy_mode": None,
"queue": None,
"spark_home": None,
"namespace": 'default'}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(dict_cmd["--master"], "yarn")
示例7: test_resolve_connection_spark_yarn_cluster_connection
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection_spark_yarn_cluster_connection(self):
# Given
hook = SparkSubmitHook(conn_id='spark_yarn_cluster')
# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)
# Then
dict_cmd = self.cmd_args_to_dict(cmd)
expected_spark_connection = {"master": "yarn://yarn-master",
"spark_binary": "spark-submit",
"deploy_mode": "cluster",
"queue": "root.etl",
"spark_home": None}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(dict_cmd["--master"], "yarn://yarn-master")
self.assertEqual(dict_cmd["--queue"], "root.etl")
self.assertEqual(dict_cmd["--deploy-mode"], "cluster")
示例8: test_resolve_connection_spark_k8s_cluster_connection
# 需要导入模块: from airflow.contrib.hooks.spark_submit_hook import SparkSubmitHook [as 别名]
# 或者: from airflow.contrib.hooks.spark_submit_hook.SparkSubmitHook import _resolve_connection [as 别名]
def test_resolve_connection_spark_k8s_cluster_connection(self):
# Given
hook = SparkSubmitHook(conn_id='spark_k8s_cluster')
# When
connection = hook._resolve_connection()
cmd = hook._build_spark_submit_command(self._spark_job_file)
# Then
dict_cmd = self.cmd_args_to_dict(cmd)
expected_spark_connection = {"spark_home": "/opt/spark",
"queue": None,
"spark_binary": "spark-submit",
"master": "k8s://https://k8s-master",
"deploy_mode": "cluster",
"namespace": "mynamespace"}
self.assertEqual(connection, expected_spark_connection)
self.assertEqual(dict_cmd["--master"], "k8s://https://k8s-master")
self.assertEqual(dict_cmd["--deploy-mode"], "cluster")