Example #1
0
 def __init__(self, services, thrift_compiler):
     self.compiler = thrift_compiler
     self.config = Config()
     self.sandbox_work = self.config.work_dir
     self.status = Status()
     self.thrift_helper = Thrift(self.compiler)
     self.log = Log(log_file="status.log", logger_name="status").log
     self.services = services
Example #2
0
    def setUp(self):
        self.config = Config()
        self.config.reset_configuration()
        compilers = self.config.get_thrift_option("compilers")
        if compilers is None or len(compilers) == 0:
            self.helper = Thrift(None)
        else:
            thrift_compiler = ThriftCompiler(compilers[0])
            self.helper = Thrift(thrift_compiler)

        project_path = os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "../")
        project_path = os.path.realpath(project_path)
        self.config.repo_dir = project_path
Example #3
0
    def setUp(self):
        self.config = Config()
        self.config.reset_configuration()
        compilers = self.config.get_thrift_option("compilers")
        if compilers is None or len(compilers) == 0:
            self.helper = Thrift(None)
        else:
            thrift_compiler = ThriftCompiler(compilers[0])
            self.helper = Thrift(thrift_compiler)

        project_path = os.path.join(
            os.path.dirname(
                os.path.abspath(inspect.getfile(inspect.currentframe()))),
            "../")
        project_path = os.path.realpath(project_path)
        self.config.repo_dir = project_path
Example #4
0
 def __init__(self, services, thrift_compiler):
     self.compiler = thrift_compiler
     self.config = Config()
     self.sandbox_work = self.config.work_dir
     self.status = Status()
     self.thrift_helper = Thrift(self.compiler)
     self.log = Log(log_file="status.log", logger_name="status").log
     self.services = services
Example #5
0
 def test_special_case_object_name(self):
     th = Thrift(None)
     src = "/home/user/foobar/blah/wizecommerce.services.sellerprogramrecord.thrift"
     result = th.get_object_name(src)
     expected = "sellerprogramrecord-client"
     self.failUnlessEqual(expected, result)
Example #6
0
 def test_complex_object_name(self):
     th = Thrift(None)
     src = "/home/user/foobar/blah/wizecommerce.bizobj.search.foobar.sellerprogramrecord.thrift"
     result = th.get_object_name(src)
     expected = "search-foobar-sellerprogramrecord-bizobj"
     self.failUnlessEqual(expected, result)
Example #7
0
class ThriftTests(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.config.reset_configuration()
        compilers = self.config.get_thrift_option("compilers")
        if compilers is None or len(compilers) == 0:
            self.helper = Thrift(None)
        else:
            thrift_compiler = ThriftCompiler(compilers[0])
            self.helper = Thrift(thrift_compiler)

        project_path = os.path.join(
            os.path.dirname(
                os.path.abspath(inspect.getfile(inspect.currentframe()))),
            "../")
        project_path = os.path.realpath(project_path)
        self.config.repo_dir = project_path

    def test_extract_string(self):
        raw = \
            """
namespace java com.wizecommerce.service.common

const string VERSION = "0.0.6"

# Type Definitions
typedef i32 Integer

        """
        expected = "0.0.6"

        result = self.helper.__extract_string__("VERSION", raw, "0.0.0")
        self.failUnlessEqual(result, expected)

    # def reset_config(self):
    #     self.config.reset_configuration()
    #     project_path = os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "../")
    #     project_path = os.path.realpath(project_path)
    #     self.config.repo_dir = project_path

    def test_check_file(self):
        thrift_file = "wizecommerce.services.example.thrift"
        self.helper.check_file(thrift_file)
        #we should reach this point, without any exception thrown.
        thrift_file = "wizecommerce.service.dummyfile.thrift"
        self.assertRaises(IOError, self.helper.check_file, thrift_file)

    def test_thrift_java_build(self):
        real_methods = {
            'subprocess': subprocess.call,
            'system': os.system,
            'chdir': os.chdir,
            'get_thrift_full_path': self.helper.get_thrift_full_path
        }
        subprocess.call = MagicMock()
        os.system = MagicMock()
        os.chdir = MagicMock()
        self.helper.get_thrift_full_path = MagicMock()
        thrift_file = "dummy.thrift"
        self.helper.get_thrift_full_path.return_value = thrift_file
        subprocess.call.return_value = 0
        self.helper.thrift_build(thrift_file)
        #########################
        # verify subprocess.call
        #########################
        expected_values = {
            'compiler': "/usr/local/bin/thrift",
            'options': "java:private-members,hashcode",
            'size': 12,
            'file': thrift_file
        }
        call_list = subprocess.call.call_args_list
        self.assertEquals(len(call_list), 1)
        self.verify_subprocess_call(subprocess.call.call_args, expected_values)
        #########################
        # verify chdir calls
        #########################
        call_list = os.chdir.call_args_list
        self.assertEquals(len(call_list), 1)
        call_args = os.chdir.call_args[0][0]
        self.assertEquals(call_args, self.config.work_dir)
        #########################
        # verify system calls
        #########################
        call_list = os.system.call_args_list
        call = call_list[0]
        self.assertEquals(len(call_list), 1)
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        self.assertNotEqual(parameter.find("gen-java"), -1)
        #########################
        # reset all system calls
        #########################
        subprocess.call = real_methods['subprocess']
        os.system = real_methods['system']
        os.chdir = real_methods['chdir']
        self.helper.get_thrift_full_path = real_methods['get_thrift_full_path']

    def test_thrift_ruby_build(self):
        thrift_file = "dummy.thrift"
        real_methods = {
            'subprocess': subprocess.call,
            'system': os.system,
            'chdir': os.chdir,
            'get_thrift_full_path': self.helper.get_thrift_full_path
        }
        subprocess.call = MagicMock()
        os.system = MagicMock()
        os.chdir = MagicMock()
        self.helper.get_thrift_full_path = MagicMock()
        self.helper.get_thrift_full_path.return_value = thrift_file
        subprocess.call.return_value = 0
        self.helper.thrift_build(thrift_file=thrift_file, language="ruby")
        #########################
        # verify subprocess.call
        #########################
        expected_values = {
            'compiler': "/usr/local/bin/thrift",
            'options': "--gen rb",
            'size': 12,
            'file': thrift_file
        }
        call_list = subprocess.call.call_args_list
        self.assertEquals(len(call_list), 1)
        self.verify_subprocess_call(subprocess.call.call_args, expected_values)
        #########################
        # verify chdir calls
        #########################
        call_list = os.chdir.call_args_list
        self.assertEquals(len(call_list), 1)
        call_args = os.chdir.call_args[0][0]
        self.assertEquals(call_args, self.config.work_dir)
        #########################
        # verify system calls
        #########################
        call_list = os.system.call_args_list
        call = call_list[0]
        self.assertEquals(len(call_list), 2)
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        self.assertNotEqual(parameter.find("gen-rb"), -1)
        #next call
        call = call_list[1]
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        print parameter
        self.assertNotEqual(parameter.find("work/ruby"), -1)
        #########################
        # reset all system calls
        #########################
        subprocess.call = real_methods['subprocess']
        os.system = real_methods['system']
        os.chdir = real_methods['chdir']
        self.helper.get_thrift_full_path = real_methods['get_thrift_full_path']

    def intercept_thrift_doc_full_path(self, request):
        """
        This method intercepts the call for self.helper.read_full_path and simply returns the
        value passed in.
        """
        return request

    def verify_subprocess_call(self, method_call_args, expected_values):
        call_args = method_call_args[0][0]
        self.assertEquals(len(call_args), expected_values['size'])
        parameter = " ".join(call_args)
        #verify compiler
        self.assertNotEqual(parameter.find(expected_values['compiler']), -1)
        #verify file name
        self.assertNotEqual(parameter.find(expected_values['file']), -1)
        #verify language/options
        self.assertNotEqual(parameter.find(expected_values['options']), -1)
        #verify includes
        self.assertNotEqual(parameter.format("thrift/services"), -1)
        self.assertNotEqual(parameter.format("business-objects"), -1)

    def test_thrift_doc_build(self):
        thrift_file = "dummy.thrift"
        real_methods = {
            'subprocess':
            subprocess.call,
            'system':
            os.system,
            'get_thrift_full_path':
            self.helper.get_thrift_full_path,
            'read_thrift_dependencies_recursively':
            self.helper.read_thrift_dependencies_recursively
        }
        dependencies = ['dependency1.thrift', 'dependency2.thrift']
        subprocess.call = MagicMock()
        os.system = MagicMock()
        self.helper.get_thrift_full_path = MagicMock()
        self.helper.get_thrift_full_path.return_value = thrift_file
        self.helper.get_thrift_full_path = self.intercept_thrift_doc_full_path
        subprocess.call.return_value = 0
        self.helper.read_thrift_dependencies_recursively = MagicMock()
        self.helper.read_thrift_dependencies_recursively.return_value = dependencies
        self.helper.thrift_build(thrift_file=thrift_file, language="doc")
        #########################
        # verify subprocess.call
        #########################
        expected_values = {
            'compiler': "/usr/local/bin/thrift",
            'options': "--gen html",
            'size': 14,
            'file': thrift_file
        }
        call_list = subprocess.call.call_args_list
        self.assertEquals(len(call_list), 3)
        count = 0
        for dependency_file in dependencies:
            call = call_list[count]
            expected_values['file'] = dependency_file
            call_list = subprocess.call.call_args_list
            self.verify_subprocess_call(call, expected_values)
            count += 1
        #verify client
        expected_values['file'] = thrift_file
        call = call_list[count]
        self.verify_subprocess_call(call, expected_values)
        #########################
        # verify system calls
        #########################
        call_list = os.system.call_args_list
        call = call_list[0]
        self.assertEquals(len(call_list), 1)
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        self.assertNotEqual(parameter.find("gen-html"), -1)
        #########################
        # reset all system calls
        #########################
        subprocess.call = real_methods['subprocess']
        os.system = real_methods['system']
        self.helper.get_thrift_full_path = real_methods['get_thrift_full_path']
        self.helper.read_thrift_dependencies_recursively = real_methods[
            'read_thrift_dependencies_recursively']

    def test_is_service(self):
        dummy = "foobar.services.thrift"
        result = self.helper.is_service(dummy)
        self.assertTrue(result)
        dummy = "foobar.dummy.thrift"
        result = self.helper.is_service(dummy)
        self.assertFalse(result)

    def test_read_thrift_dependencies(self):
        real_file = "wizecommerce.services.example.thrift"
        dependencies = self.helper.read_thrift_dependencies_recursively(
            real_file)
        self.assertEquals(len(dependencies), 3)
        all_deps = " ".join(dependencies)
        self.assertNotEqual(all_deps.find("exception.invalid"), -1)
        self.assertNotEqual(all_deps.find("enum.example_change"), -1)
        self.assertNotEqual(all_deps.find("bizobj.example"), -1)

    ##TODO: possible enhancement, mock out the file we're reading.
    def test_read_thrift_properties(self):
        thrift_file = "wizecommerce.services.example.thrift"
        properties = self.helper.read_thrift_properties(thrift_file)
        self.assertEquals('example-client', properties['ARTIFACTID'])
        self.assertEquals('0.0.5', properties['VERSION'])
        self.assertEquals('com.wizecommerce.data', properties['GROUPID'])
        print properties

    def test_thrift_compiler(self):
        init = {}
        init['name'] = 'testThrift'
        init['bin'] = '/dev/null'
        init['options'] = 'testoptions'
        init['supported_languages'] = ['java', 'ruby', 'python']
        t = ThriftCompiler(init)
        self.failUnless('testThrift' == t.name)
        self.failUnless('/dev/null' == t.bin)
        self.failUnless('testoptions' == t.options)
        self.failUnless(len(t.languages) == 3)
        self.failUnless(t.is_language_supported('ruby'))
        self.failUnless(not t.is_language_supported('erlang'))

    def test_object_name(self):
        th = Thrift(None)
        src = "/home/user/foobar/blah/wizecommerce.bizobj.sellerprogramrecord.thrift"
        result = th.get_object_name(src)
        expected = "sellerprogramrecord-bizobj"
        self.failUnlessEqual(expected, result)

    def test_complex_object_name(self):
        th = Thrift(None)
        src = "/home/user/foobar/blah/wizecommerce.bizobj.search.foobar.sellerprogramrecord.thrift"
        result = th.get_object_name(src)
        expected = "search-foobar-sellerprogramrecord-bizobj"
        self.failUnlessEqual(expected, result)

    def test_special_case_object_name(self):
        th = Thrift(None)
        src = "/home/user/foobar/blah/wizecommerce.services.sellerprogramrecord.thrift"
        result = th.get_object_name(src)
        expected = "sellerprogramrecord-client"
        self.failUnlessEqual(expected, result)
Example #8
0
 def test_special_case_object_name(self):
     th = Thrift(None)
     src = "/home/user/foobar/blah/wizecommerce.services.sellerprogramrecord.thrift"
     result = th.get_object_name(src)
     expected = "sellerprogramrecord-client"
     self.failUnlessEqual(expected, result)
Example #9
0
 def test_complex_object_name(self):
     th = Thrift(None)
     src = "/home/user/foobar/blah/wizecommerce.bizobj.search.foobar.sellerprogramrecord.thrift"
     result = th.get_object_name(src)
     expected = "search-foobar-sellerprogramrecord-bizobj"
     self.failUnlessEqual(expected, result)
Example #10
0
class ThriftTests(unittest.TestCase):

    def setUp(self):
        self.config = Config()
        self.config.reset_configuration()
        compilers = self.config.get_thrift_option("compilers")
        if compilers is None or len(compilers) == 0:
            self.helper = Thrift(None)
        else:
            thrift_compiler = ThriftCompiler(compilers[0])
            self.helper = Thrift(thrift_compiler)

        project_path = os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "../")
        project_path = os.path.realpath(project_path)
        self.config.repo_dir = project_path

    def test_extract_string(self):
        raw = \
            """
namespace java com.wizecommerce.service.common

const string VERSION = "0.0.6"

# Type Definitions
typedef i32 Integer

        """
        expected = "0.0.6"

        result = self.helper.__extract_string__("VERSION", raw, "0.0.0")
        self.failUnlessEqual(result, expected)

    # def reset_config(self):
    #     self.config.reset_configuration()
    #     project_path = os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "../")
    #     project_path = os.path.realpath(project_path)
    #     self.config.repo_dir = project_path


    def test_check_file(self):
        thrift_file = "wizecommerce.services.example.thrift"
        self.helper.check_file(thrift_file)
        #we should reach this point, without any exception thrown.
        thrift_file = "wizecommerce.service.dummyfile.thrift"
        self.assertRaises(IOError,  self.helper.check_file,thrift_file)

    def test_thrift_java_build(self):
        real_methods = {'subprocess': subprocess.call, 'system': os.system, 'chdir': os.chdir,
                        'get_thrift_full_path': self.helper.get_thrift_full_path}
        subprocess.call = MagicMock()
        os.system = MagicMock()
        os.chdir = MagicMock()
        self.helper.get_thrift_full_path = MagicMock()
        thrift_file = "dummy.thrift"
        self.helper.get_thrift_full_path.return_value = thrift_file
        subprocess.call.return_value = 0
        self.helper.thrift_build(thrift_file)
        #########################
        # verify subprocess.call
        #########################
        expected_values = {'compiler': "/usr/local/bin/thrift",
                           'options': "java:private-members,hashcode", 'size': 12,
                           'file': thrift_file}
        call_list = subprocess.call.call_args_list
        self.assertEquals(len(call_list), 1)
        self.verify_subprocess_call(subprocess.call.call_args, expected_values)
        #########################
        # verify chdir calls
        #########################
        call_list = os.chdir.call_args_list
        self.assertEquals(len(call_list), 1)
        call_args = os.chdir.call_args[0][0]
        self.assertEquals(call_args, self.config.work_dir)
        #########################
        # verify system calls
        #########################
        call_list = os.system.call_args_list
        call = call_list[0]
        self.assertEquals(len(call_list), 1)
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        self.assertNotEqual(parameter.find("gen-java"), -1)
        #########################
        # reset all system calls
        #########################
        subprocess.call = real_methods['subprocess']
        os.system = real_methods['system']
        os.chdir = real_methods['chdir']
        self.helper.get_thrift_full_path = real_methods['get_thrift_full_path']


    def test_thrift_ruby_build(self):
        thrift_file = "dummy.thrift"
        real_methods = {'subprocess' : subprocess.call, 'system' : os.system, 'chdir' : os.chdir,
                        'get_thrift_full_path' : self.helper.get_thrift_full_path}
        subprocess.call = MagicMock()
        os.system = MagicMock()
        os.chdir = MagicMock()
        self.helper.get_thrift_full_path = MagicMock()
        self.helper.get_thrift_full_path.return_value = thrift_file
        subprocess.call.return_value = 0
        self.helper.thrift_build(thrift_file=thrift_file, language="ruby")
        #########################
        # verify subprocess.call
        #########################
        expected_values = {'compiler': "/usr/local/bin/thrift",
                           'options': "--gen rb", 'size': 12,
                           'file': thrift_file}
        call_list = subprocess.call.call_args_list
        self.assertEquals(len(call_list), 1)
        self.verify_subprocess_call(subprocess.call.call_args, expected_values)
        #########################
        # verify chdir calls
        #########################
        call_list = os.chdir.call_args_list
        self.assertEquals(len(call_list), 1)
        call_args = os.chdir.call_args[0][0]
        self.assertEquals(call_args, self.config.work_dir)
        #########################
        # verify system calls
        #########################
        call_list = os.system.call_args_list
        call = call_list[0]
        self.assertEquals(len(call_list), 2)
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        self.assertNotEqual(parameter.find("gen-rb"), -1)
        #next call
        call = call_list[1]
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        print parameter
        self.assertNotEqual(parameter.find("work/ruby"), -1)
        #########################
        # reset all system calls
        #########################
        subprocess.call = real_methods['subprocess']
        os.system = real_methods['system']
        os.chdir = real_methods['chdir']
        self.helper.get_thrift_full_path = real_methods['get_thrift_full_path']



    def intercept_thrift_doc_full_path(self, request):
        """
        This method intercepts the call for self.helper.read_full_path and simply returns the
        value passed in.
        """
        return request

    def verify_subprocess_call(self, method_call_args, expected_values):
        call_args = method_call_args[0][0]
        self.assertEquals(len(call_args), expected_values['size'])
        parameter = " ".join(call_args)
        #verify compiler
        self.assertNotEqual(parameter.find(expected_values['compiler']), -1)
        #verify file name
        self.assertNotEqual(parameter.find(expected_values['file']), -1)
        #verify language/options
        self.assertNotEqual(parameter.find(expected_values['options']), -1)
        #verify includes
        self.assertNotEqual(parameter.format("thrift/services"), -1)
        self.assertNotEqual(parameter.format("business-objects"), -1)


    def test_thrift_doc_build(self):
        thrift_file = "dummy.thrift"
        real_methods = {'subprocess' : subprocess.call, 'system' : os.system,
                        'get_thrift_full_path' : self.helper.get_thrift_full_path,
                        'read_thrift_dependencies_recursively': self.helper.read_thrift_dependencies_recursively }
        dependencies = ['dependency1.thrift', 'dependency2.thrift']
        subprocess.call = MagicMock()
        os.system = MagicMock()
        self.helper.get_thrift_full_path = MagicMock()
        self.helper.get_thrift_full_path.return_value = thrift_file
        self.helper.get_thrift_full_path = self.intercept_thrift_doc_full_path
        subprocess.call.return_value = 0
        self.helper.read_thrift_dependencies_recursively = MagicMock()
        self.helper.read_thrift_dependencies_recursively.return_value = dependencies
        self.helper.thrift_build(thrift_file=thrift_file, language="doc")
         #########################
        # verify subprocess.call
        #########################
        expected_values = {'compiler': "/usr/local/bin/thrift",
                           'options': "--gen html", 'size': 14,
                           'file': thrift_file}
        call_list = subprocess.call.call_args_list
        self.assertEquals(len(call_list), 3)
        count = 0
        for dependency_file in dependencies:
            call = call_list[count]
            expected_values['file'] = dependency_file
            call_list = subprocess.call.call_args_list
            self.verify_subprocess_call(call, expected_values)
            count += 1
        #verify client
        expected_values['file'] = thrift_file
        call = call_list[count]
        self.verify_subprocess_call(call, expected_values)
        #########################
        # verify system calls
        #########################
        call_list = os.system.call_args_list
        call = call_list[0]
        self.assertEquals(len(call_list), 1)
        parameter = call[0][0]
        self.assertNotEqual(parameter.find("rm -fr"), -1)
        self.assertNotEqual(parameter.find("gen-html"), -1)
        #########################
        # reset all system calls
        #########################
        subprocess.call = real_methods['subprocess']
        os.system = real_methods['system']
        self.helper.get_thrift_full_path = real_methods['get_thrift_full_path']
        self.helper.read_thrift_dependencies_recursively = real_methods['read_thrift_dependencies_recursively']

    def test_is_service(self):
        dummy = "foobar.services.thrift"
        result = self.helper.is_service(dummy)
        self.assertTrue(result)
        dummy = "foobar.dummy.thrift"
        result = self.helper.is_service(dummy)
        self.assertFalse(result)

    def test_read_thrift_dependencies(self):
        real_file = "wizecommerce.services.example.thrift"
        dependencies = self.helper.read_thrift_dependencies_recursively(real_file)
        self.assertEquals(len(dependencies), 3)
        all_deps = " ".join(dependencies)
        self.assertNotEqual(all_deps.find("exception.invalid"), -1)
        self.assertNotEqual(all_deps.find("enum.example_change"), -1)
        self.assertNotEqual(all_deps.find("bizobj.example"), -1)



    ##TODO: possible enhancement, mock out the file we're reading.
    def test_read_thrift_properties(self):
        thrift_file = "wizecommerce.services.example.thrift"
        properties = self.helper.read_thrift_properties(thrift_file)
        self.assertEquals('example-client', properties['ARTIFACTID'])
        self.assertEquals('0.0.5', properties['VERSION'])
        self.assertEquals('com.wizecommerce.data', properties['GROUPID'])
        print properties


    def test_thrift_compiler(self):
        init = {}
        init['name'] = 'testThrift'
        init['bin'] = '/dev/null'
        init['options'] = 'testoptions'
        init['supported_languages'] = ['java', 'ruby', 'python']
        t = ThriftCompiler(init)
        self.failUnless('testThrift' == t.name)
        self.failUnless('/dev/null' == t.bin)
        self.failUnless('testoptions' == t.options)
        self.failUnless(len(t.languages) == 3)
        self.failUnless(t.is_language_supported('ruby'))
        self.failUnless(not t.is_language_supported('erlang') )

    def test_object_name(self):
        th = Thrift(None)
        src = "/home/user/foobar/blah/wizecommerce.bizobj.sellerprogramrecord.thrift"
        result = th.get_object_name(src)
        expected = "sellerprogramrecord-bizobj"
        self.failUnlessEqual(expected, result)

    def test_complex_object_name(self):
        th = Thrift(None)
        src = "/home/user/foobar/blah/wizecommerce.bizobj.search.foobar.sellerprogramrecord.thrift"
        result = th.get_object_name(src)
        expected = "search-foobar-sellerprogramrecord-bizobj"
        self.failUnlessEqual(expected, result)

    def test_special_case_object_name(self):
        th = Thrift(None)
        src = "/home/user/foobar/blah/wizecommerce.services.sellerprogramrecord.thrift"
        result = th.get_object_name(src)
        expected = "sellerprogramrecord-client"
        self.failUnlessEqual(expected, result)
Example #11
0
class Client():
    """
        For the most part, the purpose fo this class is to define an API that you can extend
        to implement your own Client for any language that isn't already supported.
    """
    def get_sandbox(self):
        return self.sandbox

    def set_sandbox(self, value):
        self.sandbox = value

    def __init__(self, services, thrift_compiler):
        self.compiler = thrift_compiler
        self.config = Config()
        self.sandbox_work = self.config.work_dir
        self.status = Status()
        self.thrift_helper = Thrift(self.compiler)
        self.log = Log(log_file="status.log", logger_name="status").log
        self.services = services

    def run(self):
        self.initialize()

        for service in self.services:
            self.process_service(service)

        self.finalize()

    def __build_dependency__(self, business_object):
        """
            Recursively build the dependency and return a list of all dependencies found and successfully built.
        """
        raise NotImplementedError("Build Dependency needs to be overridden")
        ##if previous error code has been found, aborting.

    def __build_client__(self, service):
        """
            This method is called to build the actual client, in our case that includes
            all of our services.
        """
        raise NotImplementedError("Build Client needs to be overridden")

    def deploy_object(self, properties, business_object, postfix=""):
        """
            The purpose of this method is to handle the deployment / install.
            If set to localMode it will call the appropriate method for handling local installs,
            if doing a production deployment it will call the appropriate method

            postfix str:  a string appended to the artifact name used for releasing snapshot for example.
            properties dict:  list of properties used for doing deployment.
            businessObject str: string containing the name of the thrift file.

        """
        ##Local mode will only build snapshots, for now.
        if self.config.is_local():
            return self.__deploy_local_artifact__(
                properties=properties,
                thrift_object=business_object,
                postfix=postfix)
        else:
            return self.__deploy_production_artifact__(
                properties=properties,
                thrift_object=business_object,
                postfix=postfix)
        return 0

    def check_version(self, **kwargs):
        """
            Returns a boolean checking if the artifact exists on the deployment server.
        """
        raise NotImplementedError("Check Version needs to be overridden")

    def __deploy_production_artifact__(self,
                                       properties,
                                       thrift_object,
                                       postfix=""):
        """
            Implement a method responsible for deploying your artifact to your production server.
        """
        raise NotImplementedError(
            "Deploy Production Artifact needs to be overridden")

    def __deploy_local_artifact__(self, properties, thrift_object, postfix=""):
        """
            Implement a method responsible for performing a local install.
        """
        raise NotImplementedError(
            "Deploy Local Artifact needs to be overridden")

    def finalize(self):
        """
            This method is called as a last step to either clean , publish or whatever needs to be done.
        """
        raise NotImplementedError("Finalize needs to be overridden")

    def initialize(self):
        """
            Optional, used to initialize/construct any environment or file system settings that need
            to be setup that are specific to the client.
        """
        raise NotImplementedError("Initialize method has not been overridden")

    def process_service(self, service):
        """
            This method builds the client and all dependencies assuming appropriate
            metadata is contained in the thrift file.
        """
        os.chdir(self.sandbox_work)

        dependencies = self.thrift_helper.read_thrift_dependencies(service)

        #Adding the service file as well to the list.
        if len(dependencies) == 0:
            print "No dependencies for %s" % service
        else:
            for dependency in dependencies:
                self.local_assert(
                    self.__build_dependency__(dependency),
                    "Failed to process dependencies for {service}".format(
                        service=dependency))

        self.local_assert(
            self.__build_client__(service),
            "Failed to build Client for {service}".format(
                service=str(service)))
        return 0

    def local_assert(self, exit_code, message, prefix="ERROR: "):
        if exit_code != 0:
            self.log(prefix + message)
            sys.exit(exit_code)
Example #12
0
class Client():
    """
        For the most part, the purpose fo this class is to define an API that you can extend
        to implement your own Client for any language that isn't already supported.
    """
    def get_sandbox(self):
        return self.sandbox

    def set_sandbox(self, value):
        self.sandbox = value


    def __init__(self, services, thrift_compiler):
        self.compiler = thrift_compiler
        self.config = Config()
        self.sandbox_work = self.config.work_dir
        self.status = Status()
        self.thrift_helper = Thrift(self.compiler)
        self.log = Log(log_file="status.log", logger_name="status").log
        self.services = services

    def run(self):
        self.initialize()

        for service in self.services:
            self.process_service(service)

        self.finalize()

    def __build_dependency__(self, business_object):
        """
            Recursively build the dependency and return a list of all dependencies found and successfully built.
        """
        raise NotImplementedError("Build Dependency needs to be overridden")
        ##if previous error code has been found, aborting.

    def __build_client__(self, service):
        """
            This method is called to build the actual client, in our case that includes
            all of our services.
        """
        raise NotImplementedError("Build Client needs to be overridden")

    def deploy_object(self, properties, business_object, postfix=""):
        """
            The purpose of this method is to handle the deployment / install.
            If set to localMode it will call the appropriate method for handling local installs,
            if doing a production deployment it will call the appropriate method

            postfix str:  a string appended to the artifact name used for releasing snapshot for example.
            properties dict:  list of properties used for doing deployment.
            businessObject str: string containing the name of the thrift file.

        """
        ##Local mode will only build snapshots, for now.
        if self.config.is_local():
            return self.__deploy_local_artifact__(properties=properties, thrift_object=business_object, postfix=postfix)
        else:
            return self.__deploy_production_artifact__(properties=properties, thrift_object=business_object, postfix=postfix)
        return 0

    def check_version(self, **kwargs):
        """
            Returns a boolean checking if the artifact exists on the deployment server.
        """
        raise NotImplementedError("Check Version needs to be overridden")

    def __deploy_production_artifact__(self, properties, thrift_object, postfix=""):
        """
            Implement a method responsible for deploying your artifact to your production server.
        """
        raise NotImplementedError("Deploy Production Artifact needs to be overridden")

    def __deploy_local_artifact__(self, properties, thrift_object, postfix=""):
        """
            Implement a method responsible for performing a local install.
        """
        raise NotImplementedError("Deploy Local Artifact needs to be overridden")

    def finalize(self):
        """
            This method is called as a last step to either clean , publish or whatever needs to be done.
        """
        raise NotImplementedError("Finalize needs to be overridden")

    def initialize(self):
        """
            Optional, used to initialize/construct any environment or file system settings that need
            to be setup that are specific to the client.
        """
        raise NotImplementedError("Initialize method has not been overridden")

    def process_service(self, service):
        """
            This method builds the client and all dependencies assuming appropriate
            metadata is contained in the thrift file.
        """
        os.chdir(self.sandbox_work)

        dependencies = self.thrift_helper.read_thrift_dependencies(service)

        #Adding the service file as well to the list.
        if len(dependencies) == 0:
            print "No dependencies for %s" % service
        else:
            for dependency in dependencies:
                self.local_assert(self.__build_dependency__(dependency), "Failed to process dependencies for {service}".format(service=dependency))

        self.local_assert(self.__build_client__(service),  "Failed to build Client for {service}".format(service=str(service)))
        return 0

    def local_assert(self, exit_code, message, prefix="ERROR: "):
        if exit_code != 0:
            self.log(prefix + message)
            sys.exit(exit_code)