added remote_build_history tasks: parallel on several remote hosts;
authorwenzelm
Sat Oct 15 21:02:39 2016 +0200 (2016-10-15)
changeset 64231dbc8294c75d3
parent 64230 13a97c1d7d22
child 64232 367d83d6030e
added remote_build_history tasks: parallel on several remote hosts;
isabelle_identify: use self repos for robustness;
more logger context: options and ssh;
setup repository clones on demand;
clarified target repositories;
src/Pure/Admin/build_history.scala
src/Pure/Admin/isabelle_cronjob.scala
     1.1 --- a/src/Pure/Admin/build_history.scala	Sat Oct 15 20:51:41 2016 +0200
     1.2 +++ b/src/Pure/Admin/build_history.scala	Sat Oct 15 21:02:39 2016 +0200
     1.3 @@ -342,18 +342,14 @@
     1.4    {
     1.5      using(session.sftp())(sftp =>
     1.6        {
     1.7 -        val isabelle_admin = (isabelle_repos_self + Path.explode("Admin")).implode
     1.8 +        val isabelle_admin = sftp.path(isabelle_repos_self + Path.explode("Admin"))
     1.9  
    1.10  
    1.11          /* prepare repository clones */
    1.12  
    1.13 -        val ssh = Some(session)
    1.14 -
    1.15          val isabelle_hg =
    1.16 -          if (sftp.stat(isabelle_repos_self.implode).nonEmpty)
    1.17 -            Mercurial.repository(isabelle_repos_self, ssh = ssh)
    1.18 -          else
    1.19 -            Mercurial.clone_repository(isabelle_repos_source, isabelle_repos_self, ssh = ssh)
    1.20 +          Mercurial.setup_repository(
    1.21 +            isabelle_repos_source, isabelle_repos_self, ssh = Some(session))
    1.22  
    1.23          if (self_update) {
    1.24            isabelle_hg.pull()
    1.25 @@ -361,8 +357,8 @@
    1.26            session.execute(File.bash_string(isabelle_admin + "/build") + " jars_fresh").check
    1.27          }
    1.28  
    1.29 -        if (sftp.stat(isabelle_repos_other.implode).isEmpty)
    1.30 -          Mercurial.clone_repository(isabelle_repos_self.implode, isabelle_repos_other, ssh = ssh)
    1.31 +        Mercurial.setup_repository(
    1.32 +          sftp.path(isabelle_repos_self), isabelle_repos_other, ssh = Some(session))
    1.33  
    1.34  
    1.35          /* Admin/build_history */
    1.36 @@ -370,7 +366,7 @@
    1.37          val result =
    1.38            session.execute(
    1.39              File.bash_string(isabelle_admin + "/build_history") + " " + options + " " +
    1.40 -              File.bash_path(isabelle_repos_other) + " " + args,
    1.41 +              File.bash_string(sftp.path(isabelle_repos_other)) + " " + args,
    1.42              progress_stderr = progress.echo(_))
    1.43  
    1.44          result.check.out_lines.map(log => (Path.explode(log).base.implode, sftp.read_bytes(log)))
     2.1 --- a/src/Pure/Admin/isabelle_cronjob.scala	Sat Oct 15 20:51:41 2016 +0200
     2.2 +++ b/src/Pure/Admin/isabelle_cronjob.scala	Sat Oct 15 21:02:39 2016 +0200
     2.3 @@ -20,8 +20,9 @@
     2.4    val current_log = main_dir + Path.explode("run/main.log")  // owned by log service
     2.5    val cumulative_log = main_dir + Path.explode("log/main.log")  // owned by log service
     2.6  
     2.7 -  val isabelle_repos = main_dir + Path.explode("isabelle-build_history")
     2.8 -  val afp_repos = main_dir + Path.explode("AFP-build_history")
     2.9 +  val isabelle_repos = main_dir + Path.explode("isabelle")
    2.10 +  val isabelle_repos_test = main_dir + Path.explode("isabelle-test")
    2.11 +  val afp_repos = main_dir + Path.explode("AFP")
    2.12  
    2.13    val release_snapshot = Path.explode("~/html-data/release_snapshot")
    2.14  
    2.15 @@ -34,8 +35,10 @@
    2.16    private val isabelle_identify =
    2.17      Logger_Task("isabelle_identify", logger =>
    2.18        {
    2.19 -        val isabelle_id = Mercurial.repository(isabelle_repos).pull_id()
    2.20 -        val afp_id = Mercurial.repository(afp_repos).pull_id()
    2.21 +        val isabelle_id = Mercurial.repository(isabelle_repos).identify(options = "-i")
    2.22 +        val afp_id =
    2.23 +          Mercurial.setup_repository(
    2.24 +            logger.cronjob_options.string("afp_repos"), afp_repos).pull_id()
    2.25  
    2.26          File.write(logger.log_dir + Build_Log.log_filename("isabelle_identify", logger.start_date),
    2.27            terminate_lines(
    2.28 @@ -53,8 +56,8 @@
    2.29        {
    2.30          for {
    2.31            (result, log_path) <-
    2.32 -            Build_History.build_history(Mercurial.repository(isabelle_repos),
    2.33 -              rev = "build_history_base", fresh = true, build_args = List("FOL"))
    2.34 +            Build_History.build_history(Mercurial.repository(isabelle_repos_test),
    2.35 +              rev = "build_history_base", fresh = true, build_args = List("HOL"))
    2.36          } {
    2.37            result.check
    2.38            File.copy(log_path, logger.log_dir + log_path.base)
    2.39 @@ -83,12 +86,48 @@
    2.40          }))
    2.41  
    2.42  
    2.43 +  /* remote build_history */
    2.44 +
    2.45 +  private sealed case class Remote_Build(
    2.46 +    host: String,
    2.47 +    user: String = "",
    2.48 +    port: Int = SSH.default_port,
    2.49 +    shared_home: Boolean = false,
    2.50 +    options: String = "",
    2.51 +    args: String = "-a")
    2.52 +
    2.53 +  private val remote_builds =
    2.54 +    List(
    2.55 +      Remote_Build("lxbroy10", options = "-m32 -M4", shared_home = true),
    2.56 +      Remote_Build("macbroy2", options = "-m32 -M4"))
    2.57 +
    2.58 +  private def remote_build_history(rev: String, r: Remote_Build): Logger_Task =
    2.59 +    Logger_Task("build_history-" + r.host, logger =>
    2.60 +      {
    2.61 +        using(logger.ssh_context.open_session(host = r.host, user = r.user, port = r.port))(
    2.62 +          session =>
    2.63 +            {
    2.64 +              val results =
    2.65 +                Build_History.remote_build_history(session,
    2.66 +                  isabelle_repos,
    2.67 +                  isabelle_repos.ext(r.host),
    2.68 +                  isabelle_repos_source = logger.cronjob_options.string("isabelle_repos"),
    2.69 +                  self_update = !r.shared_home,
    2.70 +                  options = r.options + " -f -r " + File.bash_string(rev),
    2.71 +                  args = r.args)
    2.72 +              for ((log, bytes) <- results)
    2.73 +                Bytes.write(logger.log_dir + Path.explode(log), bytes)
    2.74 +            })
    2.75 +      })
    2.76 +
    2.77 +
    2.78  
    2.79    /** task logging **/
    2.80  
    2.81    sealed case class Logger_Task(name: String = "", body: Logger => Unit)
    2.82  
    2.83 -  class Log_Service private[Isabelle_Cronjob](progress: Progress)
    2.84 +  class Log_Service private[Isabelle_Cronjob](
    2.85 +    progress: Progress, val cronjob_options: Options, val ssh_context: SSH)
    2.86    {
    2.87      current_log.file.delete
    2.88  
    2.89 @@ -134,6 +173,9 @@
    2.90    class Logger private[Isabelle_Cronjob](
    2.91      val log_service: Log_Service, val start_date: Date, val task_name: String)
    2.92    {
    2.93 +    def cronjob_options: Options = log_service.cronjob_options
    2.94 +    def ssh_context: SSH = log_service.ssh_context
    2.95 +
    2.96      def log(date: Date, msg: String): Unit = log_service.log(date, task_name, msg)
    2.97  
    2.98      def log_end(end_date: Date, err: Option[String])
    2.99 @@ -161,8 +203,6 @@
   2.100  
   2.101    /** cronjob **/
   2.102  
   2.103 -  def init_options(): Options = Options.load(Path.explode("~~/Admin/cronjob/cronjob.options"))
   2.104 -
   2.105    def cronjob(progress: Progress, exclude_task: Set[String])
   2.106    {
   2.107      /* soft lock */
   2.108 @@ -180,7 +220,9 @@
   2.109  
   2.110      /* log service */
   2.111  
   2.112 -    val log_service = new Log_Service(progress)
   2.113 +    val cronjob_options = Options.load(Path.explode("~~/Admin/cronjob/cronjob.options"))
   2.114 +    val ssh_context = SSH.init(Options.init())
   2.115 +    val log_service = new Log_Service(progress, cronjob_options, ssh_context)
   2.116  
   2.117      def run(start_date: Date, task: Logger_Task) { log_service.run_task(start_date, task) }
   2.118  
   2.119 @@ -216,9 +258,13 @@
   2.120      val main_start_date = Date.now()
   2.121      File.write(main_state_file, main_start_date + " " + log_service.hostname)
   2.122  
   2.123 +    val rev = Mercurial.repository(isabelle_repos).identify(options = "-i")
   2.124 +
   2.125      run(main_start_date,
   2.126        Logger_Task("isabelle_cronjob", _ =>
   2.127 -        run_now(SEQ(isabelle_identify, build_history_base, build_release))))
   2.128 +        run_now(
   2.129 +          SEQ(isabelle_identify, build_history_base, build_release,
   2.130 +            PAR(remote_builds.map(remote_build_history(rev, _)):_*)))))
   2.131  
   2.132      log_service.shutdown()
   2.133