Esempio n. 1
0
    def execute(self, args, server_pub_key=None):
        
        # Service list 1)
        # We need to check if we're the first server to join the cluster. If we
        # are then we need to populate the ODB with a list of internal services
        # available in the server. At this point we only check what
        # the command-line parameters were and later on, in point 2),
        # the actual list gets added to the ODB.
        cluster_name = args.cluster if 'cluster' in args else self.cluster_name

        if not self.dirs_prepared:
            self.prepare_directories()

        repo_dir = os.path.join(self.target_dir, 'config/repo')
        pub_key = open(os.path.join(repo_dir, 'zs-pub-key.pem')).read()

        repo_manager = RepoManager(repo_dir)
        repo_manager.ensure_repo_consistency()
        print('\nCreated a Bazaar repo in {repo_dir}'.format(repo_dir=repo_dir))

        print('')
        print('Creating files..')
        for file_name, contents in sorted(files.items()):
            file_name = os.path.join(self.target_dir, file_name)
            print('Creating {file_name}'.format(file_name=file_name))
            f = file(file_name, 'w')
            f.write(contents)
            f.close()

        logging_conf_loc = os.path.join(self.target_dir, 'config/repo/logging.conf')

        logging_conf = open(logging_conf_loc).read()
        open(logging_conf_loc, 'w').write(logging_conf.format(
            log_path=os.path.join(self.target_dir, 'logs', 'zato.log')))

        print('')
        print('Logging configuration stored in {logging_conf_loc}'.format(logging_conf_loc=logging_conf_loc))

        server_conf_loc = os.path.join(self.target_dir, 'config/repo/server.conf')
        server_conf = open(server_conf_loc, 'w')
        server_conf.write(server_conf_template.format(odb_db_name=args.odb_dbname,
                            odb_engine=args.odb_type,
                        odb_host=args.odb_host,
                        odb_password=encrypt(args.odb_password, pub_key),
                        odb_pool_size=default_odb_pool_size, 
                        odb_user=args.odb_user,
                        odb_token=self.odb_token))
        server_conf.close()
        
        print('Core configuration stored in {server_conf_loc}'.format(server_conf_loc=server_conf_loc))

        
        # Service list 2)
        # We'll need to add the list of services to the ODB depending on just 
        # how many active servers there are in the cluster.
        
        engine = self._get_engine(args)
        session = self._get_session(engine)

        cluster = session.query(Cluster).filter(Cluster.name==cluster_name).first()
        if not cluster:
            should_add = True # A new cluster so it can't have any services yet.
        else:
            # .Need to add the list if there aren't any servers yet.
            should_add = not session.query(Server).\
                   filter(Server.cluster_id==cluster.id).\
                   filter(Server.last_join_status==ZATO_JOIN_REQUEST_ACCEPTED+'a').\
                   count()
        
        #if should_add
        
        msg = """\nSuccessfully created a new server.
You can now start it with the 'zato start {path}' command.
""".format(path=os.path.abspath(os.path.join(os.getcwd(), self.target_dir)))

        print(msg)
Esempio n. 2
0
File: app.py Progetto: brtsz/zato
    def config_repo_manager(self):
        repo_manager = RepoManager()
        repo_manager.sql_pool_list_location = self.sql_pool_list_location()

        return repo_manager