# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest2
from savanna.service.edp.workflow_creator import hive_workflow as hw
from savanna.service.edp.workflow_creator import mapreduce_workflow as mrw
from savanna.service.edp.workflow_creator import pig_workflow as pw
from savanna.utils import patches as p
class TestPigWorkflowCreator(unittest2.TestCase):
def setUp(self):
p.patch_minidom_writexml()
self.prepare = {'delete': ['delete_dir_1', 'delete_dir_2'],
'mkdir': ['mkdir_1']}
self.job_xml = 'job_xml.xml'
self.configuration = {'conf_param_1': 'conf_value_1',
'conf_param_2': 'conf_value_3'}
self.files = ['file1', 'file2']
self.archives = ['arch1']
def test_create_mapreduce_workflow(self):
mr_workflow = mrw.MapReduceWorkFlowCreator()
mr_workflow.build_workflow_xml(self.prepare, self.job_xml,
self.configuration, self.files,
self.archives)
res = mr_workflow.get_built_workflow_xml()
mr_action = """
${jobTracker}
${nameNode}
job_xml.xml
conf_param_1
conf_value_1
conf_param_2
conf_value_3
file1
file2
arch1
"""
self.assertIn(mr_action, res)
def test_create_pig_workflow(self):
pig_workflow = pw.PigWorkflowCreator()
pig_script = 'script.pig'
param_dict = {'param1': 'param_value1'}
arg_dict = {'arg1': 'arg_value1', 'arg2': 'arg_value2'}
pig_workflow.build_workflow_xml(pig_script, self.prepare,
self.job_xml, self.configuration,
param_dict, arg_dict,
self.files, self.archives)
res = pig_workflow.get_built_workflow_xml()
pig_action = """
${jobTracker}
${nameNode}
job_xml.xml
conf_param_1
conf_value_1
conf_param_2
conf_value_3
param1=param_value1
arg1=arg_value1
arg2=arg_value2
file1
file2
arch1
"""
self.assertIn(pig_action, res)
def test_create_hive_workflow(self):
hive_workflow = hw.HiveWorkflowCreator()
hive_script = "script.q"
params = {"key": "value", "key2": "value2"}
hive_workflow.build_workflow_xml(hive_script, self.job_xml,
self.prepare, self.configuration,
params, self.files, self.archives)
res = hive_workflow.get_built_workflow_xml()
hive_action = """
${jobTracker}
${nameNode}
job_xml.xml
conf_param_1
conf_value_1
conf_param_2
conf_value_3
key2=value2
key=value
file1
file2
arch1
"""
self.assertIn(hive_action, res)