예제 #1
0
def get_pm2(applications, storage, logger):
    pm2 = {}

    if storage.is_cluster_mode():
        hosts = storage.get_hosts(HOST_ALL)

        for host in hosts:
            pm2[host] = []

            for application in applications:
                pm2[host].append(application)

        return pm2

    web_servers = storage.get_servers(SERVER_WEB)
    bot_servers = storage.get_servers(SERVER_BOT)

    if web_servers:
        logger.info('configuring pm2 process file for web hosts: {}'.format(
            ', '.join(get_hosts(web_servers))))

    if bot_servers:
        logger.info('configuring pm2 process file for bot hosts: {}'.format(
            ', '.join(get_hosts(web_servers))))

    web_applications = get_applications_by_type(applications, SERVER_WEB)
    bot_applications = get_applications_by_type(applications, SERVER_BOT)

    balancing_applications = get_balancing_applications(bot_applications)
    mirroring_applications = get_mirroring_applications(bot_applications)

    balanced = balanced_by_host(balancing_applications, bot_servers)

    # compose applications by hosts
    for server in bot_servers:
        if server['host'] not in pm2:
            pm2[server['host']] = []

        for application in mirroring_applications:
            pm2[server['host']].append(application)

        for application in balanced[server['host']]:
            pm2[server['host']].append(application)

    # compose applications by hosts
    for server in web_servers:
        if server['host'] not in pm2:
            pm2[server['host']] = []

        for application in web_applications:
            pm2[server['host']].append(application)

    return pm2
예제 #2
0
    def configure(self, config):
        config = normalize_nginx(config)
        servers = self.storage.get_servers(SERVER_WEB)

        if not servers or not config:
            self.logger.warning('there are not web servers')

            return

        self.logger.info('configuring web hosts: {}'.format(
            ', '.join(get_hosts(servers)))
        )

        template_path = '{}/{}'.format(
            self.paths.get('local.templates'),
            self.module_config['template']
        )

        if not exists(template_path):
            raise ModuleException(
                'Nginx template by path "{}" does not found'.format(template_path)
            )

        configs = {}
        for server in servers:
            host = server['host']

            self.storage.start_host(host)

            configs[host] = render(
                template_path,
                config,
                self.storage,
                self.paths
            )

            self.storage.finish_host()

        return configs
예제 #3
0
    def get_hosts(self, host_type):
        if host_type not in (HOST_WEB, HOST_BOT, HOST_MAINTAIN, HOST_ALL):
            raise InvalidParameterException(
                'Invalid host type "{}"'.format(host_type))

        # deploy on cluster
        if CLUSTER in self.storage['place']:
            return get_hosts(self.storage['place'][CLUSTER])

        # deploy on cloud
        iteration_types = [host_type]
        if host_type == HOST_ALL:
            iteration_types = (HOST_WEB, HOST_BOT, HOST_MAINTAIN)

        hosts = []
        for iteration_type in iteration_types:
            if iteration_type not in self.storage['place'][CLOUD]:
                continue

            for server in self.storage['place'][CLOUD][iteration_type]:
                hosts.append(server['host'])

        return hosts
예제 #4
0
    def configure(self, config):
        demons = normalize_supervisor(config)
        servers = self.storage.get_servers(SERVER_BOT)

        if not servers or not config:
            self.logger.warning('there are not bot servers')

            return

        self.logger.info('configuring bot hosts: {}'.format(', '.join(
            get_hosts(servers))))

        supervisor = get_supervisor(demons, servers,
                                    self.storage.is_cluster_mode())

        configs = {}
        for host in supervisor:
            self.storage.start_host(host)

            configs[host] = render(supervisor[host], self.storage, self.paths)

            self.storage.finish_host()

        return configs
예제 #5
0
    def configure(self, config):
        crons = normalize_crons(config)
        servers = self.storage.get_servers(SERVER_BOT)

        if not servers or not config:
            self.logger.warning('there are not bot servers')

            return

        self.logger.info('configuring bot hosts: {}'.format(', '.join(
            get_hosts(servers))))

        crontab = get_crontab(self.storage, crons, servers)

        # render
        configs = {}
        for host in crontab:
            self.storage.start_host(host)

            configs[host] = render(crontab[host], self.storage, self.paths)

            self.storage.finish_host()

        return configs