Removed possibility to run job w/o Oozie

* Added a validation function which checks if cluster contains oozie
  service in its node groups
* Added unit-test covers both valid and invalid cases when cluster
  contains and doesn't oozie service in attempt of job execution
* Fixed small issue in unit tests in validation utils where pathced
  api.get_cluster function had never been unpatched.

Change-Id: I5c5de6cfb1812ff6795797df63b8ec0292395fd1
Closes-Bug: #1291649
This commit is contained in:
Alexander Ignatov 2014-04-03 14:24:39 +04:00
parent 2984d3c8da
commit cd583756a0
5 changed files with 46 additions and 3 deletions

View File

@ -307,3 +307,14 @@ def check_required_image_tags(plugin_name, hadoop_version, image_id):
(image_id,
plugin_name,
hadoop_version))
## EDP
def check_cluster_contains_oozie(cluster_id):
cluster = api.get_cluster(cluster_id)
if not plugin_base.PLUGINS.get_plugin(
cluster.plugin_name).get_oozie_server(cluster):
raise ex.InvalidDataException('MapReduce job could not be run, '
'Oozie service is not found.')

View File

@ -62,6 +62,9 @@ def check_job_executor(data, job_id):
job = api.get_job(job_id)
job_type, subtype = edp.split_job_type(job.type)
# Check if cluster contains Oozie service to run job
main_base.check_cluster_contains_oozie(data['cluster_id'])
# All types except Java require input and output objects
if job_type == 'Java':
if not _is_main_class_present(data):

View File

@ -18,8 +18,11 @@ import uuid
import mock
import six
from sahara.service import api
from sahara.service.validations import base as validation_base
from sahara.service.validations.edp import job_executor as je
from sahara.tests.unit.service.validation import utils as u
from sahara.tests.unit import testutils as tu
def wrap_it(data):
@ -36,10 +39,13 @@ class TestJobExecValidation(u.ValidationTestCase):
def setUp(self):
self._create_object_fun = wrap_it
self.scheme = je.JOB_EXEC_SCHEMA
api.plugin_base.setup_plugins()
@mock.patch('sahara.service.validations.edp.base.'
'check_data_sources_are_different', lambda x, y: None)
@mock.patch('sahara.service.validations.base.check_cluster_exists')
@mock.patch('sahara.service.validations.base.check_cluster_exists',
lambda x: None)
@mock.patch('sahara.service.validations.base.check_cluster_contains_oozie')
@mock.patch('sahara.service.validations'
'.edp.base.check_data_source_exists')
@mock.patch('sahara.service.edp.api.get_job')
@ -77,6 +83,8 @@ class TestJobExecValidation(u.ValidationTestCase):
@mock.patch('sahara.service.validations.base.check_cluster_exists',
lambda x: None)
@mock.patch('sahara.service.validations.base.check_cluster_contains_oozie',
lambda x: None)
@mock.patch('sahara.service.edp.api.get_data_source')
@mock.patch('sahara.service.edp.api.get_job')
def test_data_sources_differ(self, get_job, get_data_source):
@ -123,3 +131,22 @@ class TestJobExecValidation(u.ValidationTestCase):
"args": []}
},
bad_req_i=(1, "INVALID_DATA", err_msg))
@mock.patch('sahara.service.api.get_cluster')
@mock.patch('sahara.service.edp.api.get_job')
def test_check_oozie(self, get_job, get_cluster):
get_job.return_value = FakeJob()
self._assert_create_object_validation(
data={
"cluster_id": six.text_type(uuid.uuid4()),
"input_id": six.text_type(uuid.uuid4()),
"output_id": six.text_type(uuid.uuid4())
},
bad_req_i=(1, "INVALID_DATA", "MapReduce job could not be run, "
"Oozie service is not found."))
ng = tu.make_ng_dict('master', 42, ['oozie'], 1,
instances=[tu.make_inst_dict('id', 'name')])
get_cluster.return_value = tu.create_cluster("cluster", "tenant1",
"vanilla", "1.2.1", [ng])
validation_base.check_cluster_contains_oozie('some_id')

View File

@ -37,10 +37,12 @@ class TestJobExecValidation(u.ValidationTestCase):
self._create_object_fun = wrap_it
self.scheme = je.JOB_EXEC_SCHEMA
@mock.patch('sahara.service.validations.base.check_cluster_contains_oozie')
@mock.patch('sahara.service.validations.base.check_cluster_exists')
@mock.patch('sahara.service.edp.api.get_job')
def test_java(self, get_job, check_cluster):
def test_java(self, get_job, check_cluster, check_oozie):
check_cluster.return_value = True
check_oozie.return_value = None
get_job.return_value = FakeJob()
self._assert_create_object_validation(

View File

@ -206,7 +206,7 @@ def start_patch(patch_templates=True):
if patch_templates:
get_ng_template.side_effect = _get_ng_template
# request data to validate
patchers = [get_clusters_p, get_plugins_p, get_plugin_p,
patchers = [get_clusters_p, get_cluster_p, get_plugins_p, get_plugin_p,
nova_p, keystone_p, get_image_p, heat_p]
if patch_templates:
patchers.extend([get_ng_template_p, get_ng_templates_p,