Пример #1
0
class PublishClient():
    """
      The purpose of this class is to setup the environment for processing various service objects
    """

    def __init__(self):
        self.client_list = []
        self.remove_structure("logs")
        wize_mkdir("logs")
        self.business_objects = []
        self.service_objects = []
        self.config = Config()
        self.log = Log(log_file=os.path.join(self.config.repo_dir, "logs/status.log"),
                       logger_name="definitions").get_logger()

    def remove_structure(self, dir):
        """
            Simple method that deletes a directory
        """
        cmd = ['rm', '-fr', dir]
        self.local_assert(subprocess.call(cmd), "failed to run command: {cmd}".format(cmd=str(cmd)))
        return 0

    def local_assert(self, exit_code, message):
        """
        Defines a cleaner version of an assert that is probably more helpful.
        """
        if exit_code != 0:
            self.log.error(message)
            sys.exit(exit_code)

    def create_structure(self):
        """
            Remove old directory structure and re-copy all the files and dependencies
            from the appropriate repos.
        """
        self.remove_structure(self.config.work_dir)
        os.mkdir(self.config.work_dir)

        self.business_objects = build_file_list(self.config.get_path(type="business_object"), ".thrift")
        self.service_objects = build_file_list(self.config.get_path(type="service_object"), ".thrift")
        self.enum_objects = build_file_list(self.config.get_path(type="enum_object"), ".thrift")
        self.exception_objects = build_file_list(self.config.get_path(type="exception_object"), ".thrift")


    def update_client_list(self, thrift_objects, compilers):
        """
          Build a list of all clients for each language and compiler type.

          Note: Multiple thrift compilers not currently supported.
        """
        self.client_list = []
        for item in compilers:
            if self.config.is_java and item.is_language_supported("java"):
                self.client_list.append(JavaClient(thrift_objects, item))
            if self.config.is_ruby and item.is_language_supported("ruby"):
                self.client_list.append(RubyClient(thrift_objects, item))
            if self.config.is_doc_enabled and item.is_language_supported("doc"):
                self.client_list.append(Documentation(thrift_objects, item))

    def process_thrift_services(self):
        """
            This method will iterate through all the service and business object thrift files, and
            deploy the maven artifacts and its dependencies
        """
        compiler_list = []
        for item in self.config.get_thrift_option("compilers"):
            t = ThriftCompiler(item)
            compiler_list.append(t)

        #ensure that vcs is enabled, and thrift-file override hasn't been passed in.
        thrift_objects = []
        if self.config.is_local() and self.config.get_service_override() is not None:
            pass
        elif not self.config.is_vcs or self.config.is_local():
            #flatten list
            thrift_objects = self.service_objects + self.business_objects + self.enum_objects + self.exception_objects
        else:
            vcs = self.config.get_vcs_instance()
            file_objects = vcs.get_modified_files()
            if file_objects is None or len(file_objects) == 0:
                self.config.is_vcs = False
                thrift_objects = self.service_objects + self.business_objects + self.enum_objects + self.exception_objects
            else:
                self.log.info("Using list of objects from VCS")
                thrift_objects = map(lambda current_file: os.path.basename(current_file), file_objects)
                self.log.info("VCS object list is: " + str(thrift_objects))

        if self.config.is_local() and self.config.get_service_override() is not None:
            self.service_objects = []
            thrift_objects = [self.config.get_service_override()]

        self.update_client_list(thrift_objects, compiler_list)

        process_list = []

        for client in self.client_list:
            p = Process(target=client.run)
            p.start()
            process_list.append(p)

        #wait for all threads that have been started to terminate.
        map(lambda proc: proc.join(), process_list)

        # #Check exit codes
        for proc in process_list:
            self.local_assert(proc.exitcode, str(proc))
Пример #2
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)
Пример #3
0
def main():
    parser = argparse.ArgumentParser(description='Client Generation Script')
    parser.add_argument('--local', action="store_true", dest="local", default=False, help="Enables Local Mode")
    parser.add_argument('--profile', action="store_true", dest="profile", default=False, help="Profiles App")
    parser.add_argument("--docOnly", action="store_true", dest="doc_only", default=False)
    parser.add_argument('--ruby', action="store_true", dest="ruby", default=False,
                        help="Enables RubyMode, default is Ruby + Java (Local Mode Only)")
    parser.add_argument('--java', action="store_true", dest="java", default=False,
                        help="Enables JavaMode, default is Ruby + Java  (Local Mode Only) ")
    parser.add_argument('--thrift-file', action="store", dest="thrift_file", type=str,
                        help="Override list of services, and use the one specified (Local Mode Only)\nThis overrides vcs intelligence")
    parser.add_argument('--config', action="store", dest="config", type=str,
                        help="Override default config file and specify your own yaml config")
    parser.add_argument('--compilers', action="store_true", dest="compilers", default=False,
                        help="will list all supported compilers. (Not fully supported)")
    parser.add_argument('--set-compiler', action="store", dest="compiler", type=str,
                        help="accepts a valid compiler name defined in the yaml config.")



    args = parser.parse_args()
    if args.config is None:
        config = Config()
    else:
        config = Config(args.config)

    config.set_local(args.local)

    if args.thrift_file is not None:
        config.set_service_override(os.path.basename(args.thrift_file))

    if args.thrift_file is not None:
        config.set_local(True)

    if args.compilers:
        display_compilers()

    if args.compiler is not None:
        set_compiler(args.compiler)

    publish_client = PublishClient()

    ## these options can only be used in conjunction with local mode
    if config.is_local():
        if args.ruby and args.java:
            print "WARNING: you really should use rubyOverride or JavaOverride, " \
                  "if you pass both it can will fall back on default behavior.  (ie. omit both of them)"
        elif args.ruby:
            config.set_languages({"ruby": True})
        elif args.java:
            config.set_languages({"java": True})

    if args.doc_only:
        config.set_languages({})
        config.is_doc_enabled = True

    if args.profile:
        import cProfile

        cProfile.run('profileProject()')
    else:
        # Create Repo Structure
        publish_client.create_structure()
        # Loop through all of our services check for updates
        publish_client.process_thrift_services()
Пример #4
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)