Skip to content

Commit 3a4753e

Browse files
authored
Merge pull request #6264 from entur/otp2_add_task_to_status_logging
Add main operation to startup/shutdown logging
2 parents cfbc7e0 + f7f2b93 commit 3a4753e

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

application/src/main/java/org/opentripplanner/model/projectinfo/OtpProjectInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public String toString() {
8080
* dev-2.x}
8181
*/
8282
public String getVersionString() {
83-
String format = "version: %s, ser.ver.id: %s, commit: %s, branch: %s";
83+
String format = "Version: %s, ser.ver.id: %s, commit: %s, branch: %s";
8484
return String.format(
8585
format,
8686
version.version,
@@ -91,17 +91,17 @@ public String getVersionString() {
9191
}
9292

9393
/**
94-
* This method compare the maven project version, an return {@code true} if both are the same. Two
95-
* different SNAPSHOT versions are considered the same - work in progress.
94+
* This method compares the maven project version, and return {@code true} if both are the same.
95+
* Two different SNAPSHOT versions are considered the same version - they are work in progress.
9696
*/
9797
public boolean sameVersion(OtpProjectInfo other) {
9898
return this.version.sameVersion(other.version);
9999
}
100100

101101
/**
102102
* The OTP Serialization version id is used to determine if OTP and a serialized blob(Graph.obj)
103-
* of the otp internal model are compatible. This filed is writen into the Graph.obj file header
104-
* and checked when loading the graph later.
103+
* of the otp internal model are compatible. This field is written into the <em>Graph.obj</em>
104+
* file header and checked when loading the graph later.
105105
*/
106106
public String getOtpSerializationVersionId() {
107107
return graphFileHeaderInfo.otpSerializationVersionId();

application/src/main/java/org/opentripplanner/standalone/OTPMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void main(String[] args) {
5252
try {
5353
Thread.currentThread().setName("main");
5454
CommandLineParameters params = parseAndValidateCmdLine(args);
55-
OtpStartupInfo.logInfo();
55+
OtpStartupInfo.logInfo(params.logTaskInfo());
5656
startOTPServer(params);
5757
} catch (OtpAppException ae) {
5858
LOG.error(ae.getMessage(), ae);

application/src/main/java/org/opentripplanner/standalone/OtpStartupInfo.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ private static String info() {
3434
);
3535
}
3636

37-
public static void logInfo() {
37+
public static void logInfo(String cliTaskInfo) {
3838
// This is good when aggregating logs across multiple load balanced instances of OTP
3939
// Hint: a regexp filter like "^OTP (START|SHUTTING)" will list nodes going up/down
40-
LOG.info("OTP STARTING UP ({}) using Java {}", projectInfo().getVersionString(), javaVersion());
40+
LOG.info(
41+
"OTP STARTING UP - {} - {} - Java {}",
42+
cliTaskInfo,
43+
projectInfo().getVersionString(),
44+
javaVersion()
45+
);
4146
ApplicationShutdownSupport.addShutdownHook(
4247
"server-shutdown-info",
43-
() -> LOG.info("OTP SHUTTING DOWN ({})", projectInfo().getVersionString())
48+
() -> LOG.info("OTP SHUTTING DOWN - {} - {}", cliTaskInfo, projectInfo().getVersionString())
4449
);
4550
LOG.info(NEW_LINE + "{}", info());
4651
}

application/src/main/java/org/opentripplanner/standalone/config/CommandLineParameters.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ public boolean doServe() {
201201
return load || (serve && doBuildTransit());
202202
}
203203

204+
public String logTaskInfo() {
205+
var mainCommands = new ArrayList<String>();
206+
if (doBuildStreet() & doBuildTransit()) {
207+
mainCommands.add("Build Street & Transit Graph");
208+
} else if (doBuildStreet()) {
209+
mainCommands.add("Build Street Graph");
210+
} else if (doBuildTransit()) {
211+
mainCommands.add("Build Transit Graph");
212+
}
213+
if (doServe()) {
214+
mainCommands.add("Run Server");
215+
}
216+
return String.join(", ", mainCommands);
217+
}
218+
204219
/**
205220
* @param port a port that we plan to bind to
206221
* @throws ParameterException if that port is not available

application/src/test/java/org/opentripplanner/standalone/config/CommandLineParametersTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public void everyThingOffByDefault() {
4141
assertFalse(subject.doLoadStreetGraph());
4242
assertFalse(subject.doSaveGraph());
4343
assertFalse(subject.doServe());
44+
var ex = assertThrows(ParameterException.class, () -> subject.inferAndValidate());
45+
assertEquals("Nothing to do. Use --help to see available options.", ex.getMessage());
4446
}
4547

4648
@Test
@@ -50,6 +52,7 @@ public void build() {
5052
assertTrue(subject.doBuildTransit());
5153
assertFalse(subject.doSaveGraph());
5254
assertFalse(subject.doServe());
55+
assertEquals("Build Street & Transit Graph", subject.logTaskInfo());
5356

5457
subject.save = true;
5558
subject.serve = false;
@@ -58,6 +61,7 @@ public void build() {
5861
assertTrue(subject.doSaveGraph());
5962
assertFalse(subject.doServe());
6063
subject.inferAndValidate();
64+
assertEquals("Build Street & Transit Graph", subject.logTaskInfo());
6165

6266
subject.save = false;
6367
subject.serve = true;
@@ -66,6 +70,7 @@ public void build() {
6670
assertFalse(subject.doSaveGraph());
6771
assertTrue(subject.doServe());
6872
subject.inferAndValidate();
73+
assertEquals("Build Street & Transit Graph, Run Server", subject.logTaskInfo());
6974

7075
subject.save = true;
7176
subject.serve = true;
@@ -74,6 +79,7 @@ public void build() {
7479
assertTrue(subject.doSaveGraph());
7580
assertTrue(subject.doServe());
7681
subject.inferAndValidate();
82+
assertEquals("Build Street & Transit Graph, Run Server", subject.logTaskInfo());
7783
}
7884

7985
@Test
@@ -83,13 +89,15 @@ public void buildStreet() {
8389
assertFalse(subject.doBuildTransit());
8490
assertTrue(subject.doSaveStreetGraph());
8591
assertFalse(subject.doSaveGraph());
92+
assertEquals("Build Street Graph", subject.logTaskInfo());
8693
}
8794

8895
@Test
8996
public void doLoadGraph() {
9097
subject.load = true;
9198
assertTrue(subject.doLoadGraph());
9299
assertTrue(subject.doServe());
100+
assertEquals("Run Server", subject.logTaskInfo());
93101
}
94102

95103
@Test
@@ -99,6 +107,7 @@ public void doLoadStreetGraph() {
99107
assertFalse(subject.doBuildStreet());
100108
assertFalse(subject.doSaveStreetGraph());
101109
assertFalse(subject.doSaveGraph());
110+
assertEquals("Build Transit Graph", subject.logTaskInfo());
102111

103112
subject.save = true;
104113
subject.serve = true;
@@ -119,6 +128,7 @@ public void validateLoad() {
119128

120129
// Implicit given, but should be ok to set
121130
subject.serve = true;
131+
assertEquals("Run Server", subject.logTaskInfo());
122132

123133
// No exception thrown
124134
subject.inferAndValidate();

application/src/test/java/org/opentripplanner/transit/speed_test/SpeedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public TestStatus status() {
144144

145145
public static void main(String[] args) {
146146
try {
147-
OtpStartupInfo.logInfo();
147+
OtpStartupInfo.logInfo("Run Speed Test");
148148
// Given the following setup
149149
SpeedTestCmdLineOpts opts = new SpeedTestCmdLineOpts(args);
150150
var config = SpeedTestConfig.config(opts.rootDir());

0 commit comments

Comments
 (0)