author | wenzelm |
Sat, 14 Oct 2017 22:05:22 +0200 | |
changeset 66865 | c8b18abf23e1 |
parent 66864 | 5cb8ccc46e3e |
child 66868 | 740d22146cb6 |
permissions | -rw-r--r-- |
64148 | 1 |
/* Title: Pure/Admin/isabelle_cronjob.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Main entry point for administrative cronjob at TUM. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
64170 | 10 |
import scala.annotation.tailrec |
11 |
import scala.collection.mutable |
|
12 |
||
13 |
||
64148 | 14 |
object Isabelle_Cronjob |
15 |
{ |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
16 |
/* file-system state: owned by main cronjob */ |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
17 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
18 |
val main_dir = Path.explode("~/cronjob") |
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
19 |
val main_state_file = main_dir + Path.explode("run/main.state") |
64219 | 20 |
val current_log = main_dir + Path.explode("run/main.log") // owned by log service |
21 |
val cumulative_log = main_dir + Path.explode("log/main.log") // owned by log service |
|
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
22 |
|
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
23 |
val isabelle_repos = main_dir + Path.explode("isabelle") |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
24 |
val isabelle_repos_test = main_dir + Path.explode("isabelle-test") |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
25 |
val afp_repos = main_dir + Path.explode("AFP") |
64236
358f9ff08681
discontinued somewhat pointless cronjob.options -- compile-time constants are sufficient;
wenzelm
parents:
64235
diff
changeset
|
26 |
|
65736 | 27 |
val jenkins_jobs = "identify" :: Jenkins.build_log_jobs |
65666
45d0692bb019
incremental download of Jenkins log files, which are also added to database;
wenzelm
parents:
65647
diff
changeset
|
28 |
|
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
29 |
|
64192 | 30 |
|
31 |
/** particular tasks **/ |
|
32 |
||
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
33 |
/* identify Isabelle + AFP repository snapshots and build release */ |
64192 | 34 |
|
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
35 |
private val build_release = |
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
36 |
Logger_Task("build_release", logger => |
66859 | 37 |
{ |
38 |
Isabelle_Devel.make_index() |
|
65771 | 39 |
|
66859 | 40 |
val rev = Mercurial.repository(isabelle_repos).id() |
41 |
val afp_rev = Mercurial.setup_repository(AFP.repos_source, afp_repos).id() |
|
64192 | 42 |
|
66859 | 43 |
File.write(logger.log_dir + Build_Log.log_filename("isabelle_identify", logger.start_date), |
44 |
Build_Log.Identify.content(logger.start_date, Some(rev), Some(afp_rev))) |
|
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
45 |
|
66859 | 46 |
Isabelle_Devel.release_snapshot(rev = rev, afp_rev = afp_rev, |
47 |
parallel_jobs = 4, remote_mac = "macbroy31") |
|
48 |
}) |
|
64192 | 49 |
|
50 |
||
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
51 |
/* integrity test of build_history vs. build_history_base */ |
64193 | 52 |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
53 |
private val build_history_base = |
64193 | 54 |
Logger_Task("build_history_base", logger => |
55 |
{ |
|
64251 | 56 |
val hg = |
57 |
Mercurial.setup_repository( |
|
58 |
File.standard_path(isabelle_repos), isabelle_repos_test) |
|
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
59 |
for { |
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
60 |
(result, log_path) <- |
66861
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66860
diff
changeset
|
61 |
Build_History.build_history(logger.options, isabelle_repos_test, |
66860
54ae2cc05325
support for AFP in build_history and remote_build_history;
wenzelm
parents:
66859
diff
changeset
|
62 |
rev = "build_history_base", fresh = true, build_args = List("HOL")) |
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
63 |
} { |
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
64 |
result.check |
64482
43f6c28ff496
clarified File.move: target directory like File.copy;
wenzelm
parents:
64481
diff
changeset
|
65 |
File.move(log_path, logger.log_dir + log_path.base) |
64194
b5ada7dcceaa
integrity test of build_history vs. build_history_base;
wenzelm
parents:
64193
diff
changeset
|
66 |
} |
64193 | 67 |
}) |
68 |
||
69 |
||
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
70 |
/* remote build_history */ |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
71 |
|
66864 | 72 |
sealed case class Item( |
73 |
known: Boolean, |
|
74 |
isabelle_version: String, |
|
75 |
afp_version: Option[String], |
|
76 |
pull_date: Date) |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
77 |
{ |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
78 |
def unknown: Boolean = !known |
66864 | 79 |
def versions: (String, Option[String]) = (isabelle_version, afp_version) |
80 |
||
81 |
def known_versions(rev: String, afp_rev: Option[String]): Boolean = |
|
82 |
known && rev != "" && isabelle_version == rev && |
|
83 |
(afp_rev.isEmpty || afp_rev.get != "" && afp_version == afp_rev.get) |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
84 |
} |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
85 |
|
66864 | 86 |
def recent_items(db: SQL.Database, |
87 |
days: Int, rev: String, afp_rev: Option[String], sql: SQL.Source): List[Item] = |
|
65807 | 88 |
{ |
89 |
val select = |
|
66864 | 90 |
Build_Log.Data.select_recent_versions( |
91 |
days = days, rev = rev, afp_rev = afp_rev, sql = "WHERE " + sql) |
|
65807 | 92 |
|
93 |
db.using_statement(select)(stmt => |
|
94 |
stmt.execute_query().iterator(res => |
|
95 |
{ |
|
96 |
val known = res.bool(Build_Log.Data.known) |
|
97 |
val isabelle_version = res.string(Build_Log.Prop.isabelle_version) |
|
66864 | 98 |
val afp_version = |
99 |
if (afp_rev.isEmpty) None |
|
100 |
else proper_string(res.string(Build_Log.Prop.afp_version)) |
|
65807 | 101 |
val pull_date = res.date(Build_Log.Data.pull_date) |
66864 | 102 |
Item(known, isabelle_version, afp_version, pull_date) |
65807 | 103 |
}).toList) |
104 |
} |
|
105 |
||
106 |
def unknown_runs(items: List[Item]): List[List[Item]] = |
|
107 |
{ |
|
108 |
val (run, rest) = Library.take_prefix[Item](_.unknown, items.dropWhile(_.known)) |
|
109 |
if (run.nonEmpty) run :: unknown_runs(rest) else Nil |
|
110 |
} |
|
111 |
||
64409
70c87ca55f2c
tuned signature -- more friendly for experimentation;
wenzelm
parents:
64405
diff
changeset
|
112 |
sealed case class Remote_Build( |
65764 | 113 |
description: String, |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
114 |
host: String, |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
115 |
user: String = "", |
65594 | 116 |
port: Int = 0, |
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
117 |
shared_home: Boolean = true, |
65820 | 118 |
historic: Boolean = false, |
65789 | 119 |
history: Int = 0, |
65820 | 120 |
history_base: String = "build_history_base", |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
121 |
options: String = "", |
65732 | 122 |
args: String = "", |
66864 | 123 |
afp: Boolean = false, |
65732 | 124 |
detect: SQL.Source = "") |
125 |
{ |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
126 |
def sql: SQL.Source = |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
127 |
Build_Log.Prop.build_engine + " = " + SQL.string(Build_History.engine) + " AND " + |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
128 |
Build_Log.Prop.build_host + " = " + SQL.string(host) + |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
129 |
(if (detect == "") "" else " AND " + SQL.enclose(detect)) |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
130 |
|
65747 | 131 |
def profile: Build_Status.Profile = |
65798 | 132 |
Build_Status.Profile(description, history, sql) |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
133 |
|
66865 | 134 |
def history_base_filter(hg: Mercurial.Repository): Item => Boolean = |
65820 | 135 |
{ |
136 |
val rev0 = hg.id(history_base) |
|
66865 | 137 |
val nodes = hg.graph().all_succs(List(rev0)).toSet |
138 |
(item: Item) => nodes(item.isabelle_version) |
|
65820 | 139 |
} |
140 |
||
66864 | 141 |
def pick( |
142 |
options: Options, |
|
143 |
rev: String = "", |
|
66865 | 144 |
filter: Item => Boolean = _ => true): Option[(String, Option[String])] = |
65747 | 145 |
{ |
66864 | 146 |
val afp_rev = if (afp) Some(Mercurial.repository(afp_repos).id()) else None |
147 |
||
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
148 |
val store = Build_Log.store(options) |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
149 |
using(store.open_database())(db => |
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
150 |
{ |
66864 | 151 |
def pick_days(days: Int, gap: Int): Option[(String, Option[String])] = |
65810 | 152 |
{ |
66865 | 153 |
val items = recent_items(db, days, rev, afp_rev, sql).filter(filter) |
66007 | 154 |
def runs = unknown_runs(items).filter(run => run.length >= gap) |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
155 |
|
66864 | 156 |
if (historic || items.exists(_.known_versions(rev, afp_rev))) { |
65810 | 157 |
val longest_run = |
158 |
(List.empty[Item] /: runs)({ case (item1, item2) => |
|
159 |
if (item1.length >= item2.length) item1 else item2 |
|
160 |
}) |
|
161 |
if (longest_run.isEmpty) None |
|
66864 | 162 |
else Some(longest_run(longest_run.length / 2).versions) |
65810 | 163 |
} |
66864 | 164 |
else if (rev != "") Some((rev, afp_rev)) |
165 |
else runs.flatten.headOption.map(_.versions) |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
166 |
} |
65810 | 167 |
|
66007 | 168 |
pick_days(options.int("build_log_history") max history, 2) orElse |
169 |
pick_days(200, 5) orElse |
|
170 |
pick_days(2000, 1) |
|
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
171 |
}) |
65747 | 172 |
} |
65732 | 173 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
174 |
|
65806 | 175 |
val remote_builds_old: List[Remote_Build] = |
176 |
List( |
|
66762 | 177 |
Remote_Build("Poly/ML 5.7 Linux", "lxbroy8", |
178 |
history_base = "37074e22e8be", |
|
179 |
options = "-m32 -B -M1x2,2 -t polyml-5.7 -i 'init_component /home/isabelle/contrib/polyml-5.7'", |
|
180 |
args = "-N -g timing", |
|
181 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("polyml-5.7") + " AND " + |
|
182 |
Build_Log.Settings.ML_OPTIONS + " <> " + SQL.string("-H 500")), |
|
183 |
Remote_Build("Poly/ML 5.7 Mac OS X", "macbroy2", |
|
184 |
history_base = "37074e22e8be", |
|
185 |
options = "-m32 -B -M1x4,4 -t polyml-5.7 -i 'init_component /home/isabelle/contrib/polyml-5.7'", |
|
186 |
args = "-a", |
|
187 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("polyml-5.7")), |
|
65806 | 188 |
Remote_Build("Poly/ML test", "lxbroy8", |
65843
d547173212d2
proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents:
65840
diff
changeset
|
189 |
options = "-m32 -B -M1x2,2 -t polyml-test -i 'init_component /home/isabelle/contrib/polyml-5.7-20170217'", |
65806 | 190 |
args = "-N -g timing", |
191 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("polyml-test")), |
|
192 |
Remote_Build("Mac OS X 10.8 Mountain Lion", "macbroy30", options = "-m32 -M2", args = "-a", |
|
193 |
detect = Build_Log.Prop.build_start + " < date '2017-03-03'")) |
|
194 |
||
195 |
||
196 |
val remote_builds: List[List[Remote_Build]] = |
|
65732 | 197 |
{ |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
198 |
List( |
66762 | 199 |
List(Remote_Build("Poly/ML 5.7.1 Linux", "lxbroy8", |
65820 | 200 |
history_base = "37074e22e8be", |
66762 | 201 |
options = "-m32 -B -M1x2,2 -t polyml-5.7.1-pre1 -i 'init_component /home/isabelle/contrib/polyml-test-e7a662f8f9c4'", |
65732 | 202 |
args = "-N -g timing", |
66762 | 203 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("polyml-5.7.1-pre1"))), |
65764 | 204 |
List(Remote_Build("Linux A", "lxbroy9", |
65732 | 205 |
options = "-m32 -B -M1x2,2", args = "-N -g timing")), |
65820 | 206 |
List(Remote_Build("Linux B", "lxbroy10", historic = true, history = 90, |
65732 | 207 |
options = "-m32 -B -M1x4,2,4,6", args = "-N -g timing")), |
64351 | 208 |
List( |
65902 | 209 |
Remote_Build("Mac OS X 10.9 Mavericks", "macbroy2", |
65906 | 210 |
options = "-m32 -M8" + |
211 |
" -e ISABELLE_GHC=ghc -e ISABELLE_MLTON=mlton -e ISABELLE_OCAML=ocaml" + |
|
212 |
" -e ISABELLE_OCAMLC=ocamlc -e ISABELLE_SMLNJ=/mnt/nfsbroy/home/smlnj/bin/sml", |
|
65902 | 213 |
args = "-a", |
66856 | 214 |
detect = Build_Log.Prop.build_tags.undefined), |
65768 | 215 |
Remote_Build("Mac OS X 10.9 Mavericks, quick_and_dirty", "macbroy2", |
65732 | 216 |
options = "-m32 -M8 -t quick_and_dirty", args = "-a -o quick_and_dirty", |
217 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("quick_and_dirty")), |
|
65768 | 218 |
Remote_Build("Mac OS X 10.9 Mavericks, skip_proofs", "macbroy2", |
65732 | 219 |
options = "-m32 -M8 -t skip_proofs", args = "-a -o skip_proofs", |
66009 | 220 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("skip_proofs")), |
66762 | 221 |
Remote_Build("Poly/ML 5.7.1 Mac OS X", "macbroy2", |
66009 | 222 |
history_base = "37074e22e8be", |
66762 | 223 |
options = "-m32 -B -M1x4,4 -t polyml-5.7.1-pre1 -i 'init_component /home/isabelle/contrib/polyml-test-e7a662f8f9c4'", |
66009 | 224 |
args = "-a", |
66762 | 225 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("polyml-5.7.1-pre1"))), |
65768 | 226 |
List( |
227 |
Remote_Build("Mac OS X 10.12 Sierra", "macbroy30", options = "-m32 -M2", args = "-a", |
|
228 |
detect = Build_Log.Prop.build_start + " > date '2017-03-03'")), |
|
229 |
List(Remote_Build("Mac OS X 10.10 Yosemite", "macbroy31", options = "-m32 -M2", args = "-a")), |
|
64351 | 230 |
List( |
66008 | 231 |
Remote_Build("Windows", "vmnipkow9", historic = true, history = 90, shared_home = false, |
65906 | 232 |
options = "-m32 -M4" + |
233 |
" -e ISABELLE_OCAML=ocaml -e ISABELLE_OCAMLC=ocamlc" + |
|
234 |
" -e ISABELLE_GHC=/usr/local/ghc-8.0.2/bin/ghc" + |
|
235 |
" -e ISABELLE_SMLNJ=/usr/local/smlnj-110.81/bin/sml", |
|
65902 | 236 |
args = "-a", |
65732 | 237 |
detect = Build_Log.Settings.ML_PLATFORM + " = " + SQL.string("x86-windows")), |
66008 | 238 |
Remote_Build("Windows", "vmnipkow9", historic = true, history = 90, shared_home = false, |
65906 | 239 |
options = "-m64 -M4" + |
240 |
" -e ISABELLE_OCAML=ocaml -e ISABELLE_OCAMLC=ocamlc" + |
|
241 |
" -e ISABELLE_GHC=/usr/local/ghc-8.0.2/bin/ghc" + |
|
242 |
" -e ISABELLE_SMLNJ=/usr/local/smlnj-110.81/bin/sml", |
|
65902 | 243 |
args = "-a", |
66864 | 244 |
detect = Build_Log.Settings.ML_PLATFORM + " = " + SQL.string("x86_64-windows"))) |
245 |
) ::: |
|
246 |
{ |
|
247 |
for { (host, n) <- List("lxbroy6" -> 1, "lxbroy7" -> 2) } |
|
248 |
yield { |
|
249 |
List(Remote_Build("AFP " + n, host = host, |
|
250 |
options = "-m32 -M1x2 -t AFP -P" + n, |
|
251 |
args = "-N -X slow", |
|
252 |
afp = true, |
|
253 |
detect = Build_Log.Prop.build_tags + " = " + SQL.string("AFP"))) |
|
254 |
} |
|
255 |
} |
|
65732 | 256 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
257 |
|
66864 | 258 |
private def remote_build_history( |
259 |
rev: String, afp_rev: Option[String], i: Int, r: Remote_Build): Logger_Task = |
|
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
260 |
{ |
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
261 |
val task_name = "build_history-" + r.host |
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
262 |
Logger_Task(task_name, logger => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
263 |
{ |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
264 |
using(logger.ssh_context.open_session(host = r.host, user = r.user, port = r.port))( |
64259 | 265 |
ssh => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
266 |
{ |
64348
4c253e84ae62
clarified push/pull chain: current ISABELLE_HOME may server as source for changes that are not published on isabelle_repos_source yet (e.g. isabelle-release branch);
wenzelm
parents:
64346
diff
changeset
|
267 |
val self_update = !r.shared_home |
4c253e84ae62
clarified push/pull chain: current ISABELLE_HOME may server as source for changes that are not published on isabelle_repos_source yet (e.g. isabelle-release branch);
wenzelm
parents:
64346
diff
changeset
|
268 |
val push_isabelle_home = self_update && Mercurial.is_repository(Path.explode("~~")) |
4c253e84ae62
clarified push/pull chain: current ISABELLE_HOME may server as source for changes that are not published on isabelle_repos_source yet (e.g. isabelle-release branch);
wenzelm
parents:
64346
diff
changeset
|
269 |
|
65929
de3adcf6a276
prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents:
65917
diff
changeset
|
270 |
val results = |
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
271 |
Build_History.remote_build_history(ssh, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
272 |
isabelle_repos, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
273 |
isabelle_repos.ext(r.host), |
65917
2b7d4678bce6
proper ISABELLE_IDENTIFIER for remote Admin/build_history, e.g. relevant for settings;
wenzelm
parents:
65915
diff
changeset
|
274 |
isabelle_identifier = "cronjob_build_history", |
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
275 |
self_update = self_update, |
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
276 |
push_isabelle_home = push_isabelle_home, |
66106
b5333fc056da
always start with fresh clone (with explicitly given rev): more robust on Windows;
wenzelm
parents:
66009
diff
changeset
|
277 |
rev = rev, |
66864 | 278 |
afp_rev = afp_rev, |
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
279 |
options = |
65949 | 280 |
" -N " + Bash.string(task_name) + (if (i < 0) "" else "_" + (i + 1).toString) + |
65887
cc6fdf8d1dc2
more systematic separation of build_history directories (see also 80c1c1f53e72);
wenzelm
parents:
65871
diff
changeset
|
281 |
" -f " + r.options, |
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
282 |
args = "-o timeout=10800 " + r.args) |
64346 | 283 |
|
64481 | 284 |
for ((log_name, bytes) <- results) { |
285 |
logger.log(Date.now(), log_name) |
|
64468
ed8940d6295c
back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents:
64452
diff
changeset
|
286 |
Bytes.write(logger.log_dir + Path.explode(log_name), bytes) |
64481 | 287 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
288 |
}) |
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
289 |
}) |
64294
303976a45afe
shared_home is default for classic isatest home setup;
wenzelm
parents:
64277
diff
changeset
|
290 |
} |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
291 |
|
65747 | 292 |
val build_status_profiles: List[Build_Status.Profile] = |
65768 | 293 |
(remote_builds_old :: remote_builds).flatten.map(_.profile) |
65747 | 294 |
|
65746 | 295 |
|
64192 | 296 |
|
297 |
/** task logging **/ |
|
64171 | 298 |
|
64193 | 299 |
sealed case class Logger_Task(name: String = "", body: Logger => Unit) |
64154 | 300 |
|
64257 | 301 |
class Log_Service private[Isabelle_Cronjob](progress: Progress, val ssh_context: SSH.Context) |
64171 | 302 |
{ |
64219 | 303 |
current_log.file.delete |
304 |
||
64171 | 305 |
private val thread: Consumer_Thread[String] = |
306 |
Consumer_Thread.fork("cronjob: logger", daemon = true)( |
|
307 |
consume = (text: String) => |
|
64219 | 308 |
{ // critical |
309 |
File.append(current_log, text + "\n") |
|
310 |
File.append(cumulative_log, text + "\n") |
|
64171 | 311 |
progress.echo(text) |
312 |
true |
|
313 |
}) |
|
314 |
||
315 |
def shutdown() { thread.shutdown() } |
|
316 |
||
317 |
val hostname = Isabelle_System.hostname() |
|
318 |
||
319 |
def log(date: Date, task_name: String, msg: String): Unit = |
|
64193 | 320 |
if (task_name != "") |
321 |
thread.send( |
|
322 |
"[" + Build_Log.print_date(date) + ", " + hostname + ", " + task_name + "]: " + msg) |
|
64171 | 323 |
|
324 |
def start_logger(start_date: Date, task_name: String): Logger = |
|
325 |
new Logger(this, start_date, task_name) |
|
64154 | 326 |
|
64171 | 327 |
def run_task(start_date: Date, task: Logger_Task) |
328 |
{ |
|
329 |
val logger = start_logger(start_date, task.name) |
|
330 |
val res = Exn.capture { task.body(logger) } |
|
331 |
val end_date = Date.now() |
|
332 |
val err = |
|
333 |
res match { |
|
334 |
case Exn.Res(_) => None |
|
64295 | 335 |
case Exn.Exn(exn) => |
64410 | 336 |
System.err.println("Exception trace for " + quote(task.name) + ":") |
64397 | 337 |
exn.printStackTrace() |
64295 | 338 |
val first_line = Library.split_lines(Exn.message(exn)).headOption getOrElse "exception" |
339 |
Some(first_line) |
|
64171 | 340 |
} |
341 |
logger.log_end(end_date, err) |
|
342 |
} |
|
343 |
||
344 |
def fork_task(start_date: Date, task: Logger_Task): Task = |
|
345 |
new Task(task.name, run_task(start_date, task)) |
|
346 |
} |
|
347 |
||
348 |
class Logger private[Isabelle_Cronjob]( |
|
349 |
val log_service: Log_Service, val start_date: Date, val task_name: String) |
|
64162 | 350 |
{ |
64257 | 351 |
def ssh_context: SSH.Context = log_service.ssh_context |
65640 | 352 |
def options: Options = ssh_context.options |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
353 |
|
64171 | 354 |
def log(date: Date, msg: String): Unit = log_service.log(date, task_name, msg) |
355 |
||
356 |
def log_end(end_date: Date, err: Option[String]) |
|
357 |
{ |
|
358 |
val elapsed_time = end_date.time - start_date.time |
|
359 |
val msg = |
|
360 |
(if (err.isEmpty) "finished" else "ERROR " + err.get) + |
|
64197 | 361 |
(if (elapsed_time.seconds < 3.0) "" else " (" + elapsed_time.message_hms + " elapsed time)") |
64171 | 362 |
log(end_date, msg) |
363 |
} |
|
364 |
||
64195 | 365 |
val log_dir: Path = main_dir + Build_Log.log_subdir(start_date) |
366 |
||
367 |
Isabelle_System.mkdirs(log_dir) |
|
64171 | 368 |
log(start_date, "started") |
369 |
} |
|
370 |
||
371 |
class Task private[Isabelle_Cronjob](name: String, body: => Unit) |
|
372 |
{ |
|
373 |
private val future: Future[Unit] = Future.thread("cronjob: " + name) { body } |
|
374 |
def is_finished: Boolean = future.is_finished |
|
64162 | 375 |
} |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
376 |
|
64170 | 377 |
|
378 |
||
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
379 |
/** cronjob **/ |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
380 |
|
64187 | 381 |
def cronjob(progress: Progress, exclude_task: Set[String]) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
382 |
{ |
64171 | 383 |
/* soft lock */ |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
384 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
385 |
val still_running = |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
386 |
try { Some(File.read(main_state_file)) } |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
387 |
catch { case ERROR(_) => None } |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
388 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
389 |
still_running match { |
64170 | 390 |
case None | Some("") => |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
391 |
case Some(running) => |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
392 |
error("Isabelle cronjob appears to be still running: " + running) |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
393 |
} |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
394 |
|
64199 | 395 |
|
396 |
/* log service */ |
|
397 |
||
64257 | 398 |
val log_service = new Log_Service(progress, SSH.init_context(Options.init())) |
64154 | 399 |
|
64199 | 400 |
def run(start_date: Date, task: Logger_Task) { log_service.run_task(start_date, task) } |
401 |
||
402 |
def run_now(task: Logger_Task) { run(Date.now(), task) } |
|
64154 | 403 |
|
404 |
||
64199 | 405 |
/* structured tasks */ |
64184 | 406 |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
407 |
def SEQ(tasks: List[Logger_Task]): Logger_Task = Logger_Task(body = _ => |
64193 | 408 |
for (task <- tasks.iterator if !exclude_task(task.name) || task.name == "") |
64199 | 409 |
run_now(task)) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
410 |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
411 |
def PAR(tasks: List[Logger_Task]): Logger_Task = Logger_Task(body = _ => |
64170 | 412 |
{ |
64199 | 413 |
@tailrec def join(running: List[Task]) |
414 |
{ |
|
415 |
running.partition(_.is_finished) match { |
|
416 |
case (Nil, Nil) => |
|
417 |
case (Nil, _ :: _) => Thread.sleep(500); join(running) |
|
418 |
case (_ :: _, remaining) => join(remaining) |
|
419 |
} |
|
64170 | 420 |
} |
64199 | 421 |
val start_date = Date.now() |
422 |
val running = |
|
64350
3af8566788e7
remote_builds has PAR-SEQ semantics of old isatest-makedist;
wenzelm
parents:
64348
diff
changeset
|
423 |
for (task <- tasks if !exclude_task(task.name)) |
64199 | 424 |
yield log_service.fork_task(start_date, task) |
425 |
join(running) |
|
426 |
}) |
|
64193 | 427 |
|
64170 | 428 |
|
429 |
/* main */ |
|
430 |
||
64199 | 431 |
val main_start_date = Date.now() |
432 |
File.write(main_state_file, main_start_date + " " + log_service.hostname) |
|
433 |
||
65820 | 434 |
val hg = Mercurial.repository(isabelle_repos) |
435 |
val rev = hg.id() |
|
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
436 |
|
64193 | 437 |
run(main_start_date, |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
438 |
Logger_Task("isabelle_cronjob", logger => |
64231
dbc8294c75d3
added remote_build_history tasks: parallel on several remote hosts;
wenzelm
parents:
64220
diff
changeset
|
439 |
run_now( |
64405
81bac77929d9
just one task to identify Isabelle + AFP repository snapshots and build release;
wenzelm
parents:
64399
diff
changeset
|
440 |
SEQ(List(build_release, build_history_base, |
65783
d3d5cb2d6866
pick isabelle_version based on build_log database;
wenzelm
parents:
65771
diff
changeset
|
441 |
PAR(remote_builds.map(seq => |
65915 | 442 |
SEQ( |
443 |
for { |
|
444 |
(r, i) <- (if (seq.length <= 1) seq.map((_, -1)) else seq.zipWithIndex) |
|
66864 | 445 |
(isabelle_rev, afp_rev) <- r.pick(logger.options, rev, r.history_base_filter(hg)) |
446 |
} yield remote_build_history(isabelle_rev, afp_rev, i, r)))), |
|
65666
45d0692bb019
incremental download of Jenkins log files, which are also added to database;
wenzelm
parents:
65647
diff
changeset
|
447 |
Logger_Task("jenkins_logs", _ => Jenkins.download_logs(jenkins_jobs, main_dir)), |
65770 | 448 |
Logger_Task("build_log_database", |
449 |
logger => Isabelle_Devel.build_log_database(logger.options)), |
|
450 |
Logger_Task("build_status", |
|
65793 | 451 |
logger => Isabelle_Devel.build_status(logger.options))))))) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
452 |
|
64171 | 453 |
log_service.shutdown() |
64170 | 454 |
|
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
455 |
main_state_file.file.delete |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
456 |
} |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
457 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
458 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
459 |
|
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
460 |
/** command line entry point **/ |
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
461 |
|
64148 | 462 |
def main(args: Array[String]) |
463 |
{ |
|
464 |
Command_Line.tool0 { |
|
465 |
var force = false |
|
466 |
var verbose = false |
|
64187 | 467 |
var exclude_task = Set.empty[String] |
64148 | 468 |
|
469 |
val getopts = Getopts(""" |
|
470 |
Usage: Admin/cronjob/main [OPTIONS] |
|
471 |
||
472 |
Options are: |
|
473 |
-f apply force to do anything |
|
474 |
-v verbose |
|
64187 | 475 |
-x NAME exclude tasks with this name |
64148 | 476 |
""", |
477 |
"f" -> (_ => force = true), |
|
64187 | 478 |
"v" -> (_ => verbose = true), |
479 |
"x:" -> (arg => exclude_task += arg)) |
|
64148 | 480 |
|
481 |
val more_args = getopts(args) |
|
482 |
if (more_args.nonEmpty) getopts.usage() |
|
483 |
||
64909 | 484 |
val progress = if (verbose) new Console_Progress() else No_Progress |
64148 | 485 |
|
64187 | 486 |
if (force) cronjob(progress, exclude_task) |
64153
769791954872
some timing and logging, similar to old isatest.log;
wenzelm
parents:
64148
diff
changeset
|
487 |
else error("Need to apply force to do anything") |
64148 | 488 |
} |
489 |
} |
|
490 |
} |