Skip to content

Commit

Permalink
Merge pull request opentripplanner#6264 from entur/otp2_add_task_to_s…
Browse files Browse the repository at this point in the history
…tatus_logging

Add main operation to startup/shutdown logging
  • Loading branch information
t2gran authored Nov 26, 2024
2 parents cfbc7e0 + f7f2b93 commit 3a4753e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String toString() {
* dev-2.x}
*/
public String getVersionString() {
String format = "version: %s, ser.ver.id: %s, commit: %s, branch: %s";
String format = "Version: %s, ser.ver.id: %s, commit: %s, branch: %s";
return String.format(
format,
version.version,
Expand All @@ -91,17 +91,17 @@ public String getVersionString() {
}

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

/**
* The OTP Serialization version id is used to determine if OTP and a serialized blob(Graph.obj)
* of the otp internal model are compatible. This filed is writen into the Graph.obj file header
* and checked when loading the graph later.
* of the otp internal model are compatible. This field is written into the <em>Graph.obj</em>
* file header and checked when loading the graph later.
*/
public String getOtpSerializationVersionId() {
return graphFileHeaderInfo.otpSerializationVersionId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void main(String[] args) {
try {
Thread.currentThread().setName("main");
CommandLineParameters params = parseAndValidateCmdLine(args);
OtpStartupInfo.logInfo();
OtpStartupInfo.logInfo(params.logTaskInfo());
startOTPServer(params);
} catch (OtpAppException ae) {
LOG.error(ae.getMessage(), ae);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ private static String info() {
);
}

public static void logInfo() {
public static void logInfo(String cliTaskInfo) {
// This is good when aggregating logs across multiple load balanced instances of OTP
// Hint: a regexp filter like "^OTP (START|SHUTTING)" will list nodes going up/down
LOG.info("OTP STARTING UP ({}) using Java {}", projectInfo().getVersionString(), javaVersion());
LOG.info(
"OTP STARTING UP - {} - {} - Java {}",
cliTaskInfo,
projectInfo().getVersionString(),
javaVersion()
);
ApplicationShutdownSupport.addShutdownHook(
"server-shutdown-info",
() -> LOG.info("OTP SHUTTING DOWN ({})", projectInfo().getVersionString())
() -> LOG.info("OTP SHUTTING DOWN - {} - {}", cliTaskInfo, projectInfo().getVersionString())
);
LOG.info(NEW_LINE + "{}", info());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ public boolean doServe() {
return load || (serve && doBuildTransit());
}

public String logTaskInfo() {
var mainCommands = new ArrayList<String>();
if (doBuildStreet() & doBuildTransit()) {
mainCommands.add("Build Street & Transit Graph");
} else if (doBuildStreet()) {
mainCommands.add("Build Street Graph");
} else if (doBuildTransit()) {
mainCommands.add("Build Transit Graph");
}
if (doServe()) {
mainCommands.add("Run Server");
}
return String.join(", ", mainCommands);
}

/**
* @param port a port that we plan to bind to
* @throws ParameterException if that port is not available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void everyThingOffByDefault() {
assertFalse(subject.doLoadStreetGraph());
assertFalse(subject.doSaveGraph());
assertFalse(subject.doServe());
var ex = assertThrows(ParameterException.class, () -> subject.inferAndValidate());
assertEquals("Nothing to do. Use --help to see available options.", ex.getMessage());
}

@Test
Expand All @@ -50,6 +52,7 @@ public void build() {
assertTrue(subject.doBuildTransit());
assertFalse(subject.doSaveGraph());
assertFalse(subject.doServe());
assertEquals("Build Street & Transit Graph", subject.logTaskInfo());

subject.save = true;
subject.serve = false;
Expand All @@ -58,6 +61,7 @@ public void build() {
assertTrue(subject.doSaveGraph());
assertFalse(subject.doServe());
subject.inferAndValidate();
assertEquals("Build Street & Transit Graph", subject.logTaskInfo());

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

subject.save = true;
subject.serve = true;
Expand All @@ -74,6 +79,7 @@ public void build() {
assertTrue(subject.doSaveGraph());
assertTrue(subject.doServe());
subject.inferAndValidate();
assertEquals("Build Street & Transit Graph, Run Server", subject.logTaskInfo());
}

@Test
Expand All @@ -83,13 +89,15 @@ public void buildStreet() {
assertFalse(subject.doBuildTransit());
assertTrue(subject.doSaveStreetGraph());
assertFalse(subject.doSaveGraph());
assertEquals("Build Street Graph", subject.logTaskInfo());
}

@Test
public void doLoadGraph() {
subject.load = true;
assertTrue(subject.doLoadGraph());
assertTrue(subject.doServe());
assertEquals("Run Server", subject.logTaskInfo());
}

@Test
Expand All @@ -99,6 +107,7 @@ public void doLoadStreetGraph() {
assertFalse(subject.doBuildStreet());
assertFalse(subject.doSaveStreetGraph());
assertFalse(subject.doSaveGraph());
assertEquals("Build Transit Graph", subject.logTaskInfo());

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

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

// No exception thrown
subject.inferAndValidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public TestStatus status() {

public static void main(String[] args) {
try {
OtpStartupInfo.logInfo();
OtpStartupInfo.logInfo("Run Speed Test");
// Given the following setup
SpeedTestCmdLineOpts opts = new SpeedTestCmdLineOpts(args);
var config = SpeedTestConfig.config(opts.rootDir());
Expand Down

0 comments on commit 3a4753e

Please sign in to comment.