Пример #1
0
    def run(self):
        database = SQLDB(self.sql_config.driver, self.sql_config.host, self.sql_config.port, self.sql_config.database,
                         self.sql_config.username, self.sql_config.password, self.sql_config.pool_size)
        database.connect()

        with database.session() as session:
            Base.metadata.create_all(bind=session.get_bind())

        ldap = None

        if self.ldap_config is not None:
            ldap = LDAP(self.ldap_config.host, self.ldap_config.domain, self.ldap_config.base_dn,
                        self.ldap_config.bind_username, self.ldap_config.bind_password)

        hosts = []
        for host in self.rabbitmq_config.hosts:
            (ip, port) = host.split(":")
            hosts.append((ip, int(port)))

        self.rabbitmq = RabbitMQ(hosts, self.rabbitmq_config.username, self.rabbitmq_config.password,
                                 self.rabbitmq_config.virtual_host)
        self.rabbitmq.setup_database()

        if 'driver' not in self.base_config.identity:
            self.logger.error("Identity Config does not have a driver")
            return False

        identity_module = self.base_config.identity['driver'].split(".")
        module = __import__(self.base_config.identity['driver'])
        identity_module.pop(0)
        for m in identity_module:
            module = getattr(module, m)
        identity = getattr(module, 'IdentityDriver')
        identity = identity()

        if not identity.validate_config(self.base_config.identity):
            self.logger.error("Error validating identity config")
            return False

        identity.db_connections(database=database, rabbitmq=self.rabbitmq, ldap=ldap)

        if 'driver' not in self.base_config.assignment:
            self.logger.error("Assignment Config does not have a driver set")
            return

        assignment_modules = self.base_config.assignment['driver'].split(".")
        module = __import__(self.base_config.assignment['driver'])
        assignment_modules.pop(0)
        for m in assignment_modules:
            module = getattr(module, m)
        assignment = getattr(module, 'AssignmentDriver')
        assignment = assignment()

        if not assignment.validate_config(self.base_config.assignment):
            self.logger.error("Error validating assignment config")
            return False

        assignment.db_connections(database=database, rabbitmq=self.rabbitmq, ldap=ldap)

        RegisterFrameworkSubscriber(self.rabbitmq).start()
        TaskStatusSubscriber(self.rabbitmq, database).start()
        TaskLaunchSubscriber(self.rabbitmq, database).start()
        WorkerRegister(self.rabbitmq, database).start()
        WorkerReload(self.rabbitmq, database).start()
        WorkerGet(self.rabbitmq, database).start()
        Validate(self.rabbitmq, assignment).start()
        hqmanager.api.setup(self.rabbitmq, database, identity, assignment)

        return True
Пример #2
0
    def run(self):
        database = SQLDB(self.sql_config.driver, self.sql_config.host, self.sql_config.port, self.sql_config.database,
                         self.sql_config.username, self.sql_config.password, self.sql_config.pool_size)
        database.connect()

        hosts = []
        for host in self.rabbitmq_config.hosts:
            (ip, port) = host.split(":")
            hosts.append((ip, int(port)))

        self.rabbitmq = RabbitMQ(hosts, self.rabbitmq_config.username, self.rabbitmq_config.password,
                                 self.rabbitmq_config.virtual_host)
        self.rabbitmq.setup_database()

        framework_utils = FrameworkUtils(self.rabbitmq)
        cherrypy.tools.auth = cherrypy.Tool("on_start_resource", framework_utils.auth)

        self.logger.info("Starting Framework")

        for config_name in os.listdir(self.path_config.framework_configs):

            if not config_name.endswith(".yml") and not config_name.endswith(".yaml"):
                continue

            config_path = self.path_config.framework_configs + "/" + config_name
            try:
                framework_config = parse_config(config_path)
            except YAMLError as e:
                self.logger.error("Could load framework config " + config_name + " " + str(e))
                continue

            if 'module' not in framework_config:
                self.logger.error("Framework config " + config_name + " does not have a module to load.")
                continue

            modules = framework_config['module'].split(".")

            try:
                module = __import__(framework_config['module'])
                modules.pop(0)
                for m in modules:
                    module = getattr(module, m)
                api = getattr(module, 'FrameworkAPI')
                framework = getattr(module, 'Framework')
                framework = framework()
                self.frameworks.append(framework)
                api = api(framework)
            except:
                self.logger.exception("Error loading framework module " + framework_config['module'])
                continue

            if not framework.register_framework(self.rabbitmq, database, config_path):
                self.logger.error("Framework " + framework.name + " could not register")
                continue

            api.register()

        if len(self.frameworks) == 0:
            self.logger.warning("No frameworks loaded")
            return False

        cherrypy.config.update({'engine.autoreload.on': False,
                                'engine.timeout_monitor.on': False,
                                'error_page.default': framework_utils.jsonify_error,
                                'server.socket_port': 8081})
        cherrypy.engine.start()

        return True