def run_contest_remotely(self, hosts, resume_folder=None, first=True):
        self.prepare_dirs()

        if resume_folder is not None:
            contest_folder = os.path.split(self.tmp_dir)[1]
            resume_folder = os.path.join(resume_folder, contest_folder)
            shutil.rmtree(self.tmp_logs_dir)
            shutil.copytree(os.path.join(resume_folder, "logs-run"),
                            self.tmp_logs_dir)
            shutil.rmtree(self.tmp_replays_dir)
            shutil.copytree(os.path.join(resume_folder, "replays-run"),
                            self.tmp_replays_dir)
            jobs = self.resume_contest_jobs()
        else:
            jobs = self.run_contest_jobs()

        #  This is the core package to be transferable to each host
        core_req_file = TransferableFile(
            local_path=os.path.join(TMP_DIR, CORE_CONTEST_TEAM_ZIP_FILE),
            remote_path=os.path.join("/tmp", CORE_CONTEST_TEAM_ZIP_FILE),
        )

        # create cluster with hosts and jobs and run it by starting it, and then analyze output results
        # results will contain all outputs from every game played
        if first:
            cm = ClusterManager(hosts, jobs, [core_req_file])
        else:
            # subsequent contests don't need to transfer the files again
            cm = ClusterManager(hosts, jobs, None)
        # sys.exit(0)
        results = cm.start()

        print(
            "========================= GAMES FINISHED - NEXT ANALYSING OUTPUT OF GAMES ========================= "
        )
        self._analyse_all_outputs(results)
        self._calculate_team_stats()
Exemplo n.º 2
0
            jobs.append(
                Job(commands=commands,
                    required_files=required_files,
                    return_files=return_files,
                    id=job_id))
    return jobs


def create_hosts(workers_settings):
    hosts = []
    for worker in workers_settings:
        host = Host(
            no_cpu=worker['no_cpu'],
            hostname=worker['hostname'],
            username=worker['username'],
            password=worker['password'],
            key_filename=worker['private_key_file']
        )
        hosts.append(host)
    return hosts


if __name__ == "__main__":
    args = load_settings()
    settings = load_json(args.config_file)
    jobs = create_jobs(settings)
    workers_settings = load_json("workers.json")
    hosts = create_hosts(args.workers_file)
    cm = ClusterManager(hosts, jobs)
    results = cm.start()