Skip to content

Commit 25cd340

Browse files
authored
[ZEPPELIN-6241] Fail fast when default web app context fails to initialize due to missing resources
### What is this PR for? Currently, the server keeps running even when all web app contexts fail to initialize due to missing files or directories for web resources. In my opinion, if the web resource path for the default web app context does not exist, it would be better to shut down the server immediately, since the context initialization will fail anyway. In such cases, other essential features like REST APIs and WebSocket communication also won’t work properly, so keeping the server running doesn’t seem meaningful. The absence of non-default web resources, however, seems generally acceptable. So this PR ensures that we only fail fast when the default web app context is missing its required resources. ### What type of PR is it? Improvement ### What is the Jira issue? - https://issues.apache.org/jira/browse/ZEPPELIN-6241 ### How should this be tested? - Start the server with the default web app directory intentionally missing. - Verify that the server fails to start and exit immediately. - Ensure that non-default apps can still be missing without preventing startup ### Questions: * Does the license files need to update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Closes #4969 from tbonelee/fail-fast. Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com>
1 parent e9608f7 commit 25cd340

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

bin/common.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ if [[ -z "${ZEPPELIN_WAR}" ]]; then
4646
export ZEPPELIN_WAR="${ZEPPELIN_HOME}/zeppelin-web/dist"
4747
else
4848
ZEPPELIN_WAR=$(find -L "${ZEPPELIN_HOME}" -name "zeppelin-web-[0-9]*.war")
49-
export ZEPPELIN_WAR
49+
if [[ -n "${ZEPPELIN_WAR}" ]]; then
50+
export ZEPPELIN_WAR
51+
fi
5052
fi
5153
fi
5254

@@ -55,7 +57,9 @@ if [[ -z "${ZEPPELIN_ANGULAR_WAR}" ]]; then
5557
export ZEPPELIN_ANGULAR_WAR="${ZEPPELIN_HOME}/zeppelin-web-angular/dist/zeppelin"
5658
else
5759
ZEPPELIN_ANGULAR_WAR=$(find -L "${ZEPPELIN_HOME}" -name "zeppelin-web-angular*.war")
58-
export ZEPPELIN_ANGULAR_WAR
60+
if [[ -n "${ZEPPELIN_ANGULAR_WAR}" ]]; then
61+
export ZEPPELIN_ANGULAR_WAR
62+
fi
5963
fi
6064
fi
6165

zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,14 @@ protected void configure() {
221221
});
222222

223223
// Multiple Web UI
224-
String classicUiWebAppContextPath;
225-
String newUiWebAppContextPath;
226-
if (isNewUiDefault(zConf)) {
227-
classicUiWebAppContextPath = NON_DEFAULT_CLASSIC_UI_WEB_APP_CONTEXT_PATH;
228-
newUiWebAppContextPath = zConf.getServerContextPath();
229-
} else {
230-
classicUiWebAppContextPath = zConf.getServerContextPath();
231-
newUiWebAppContextPath = NON_DEFAULT_NEW_UI_WEB_APP_CONTEXT_PATH;
232-
}
224+
String newUiWebAppContextPath = isNewUiDefault(zConf) ? zConf.getServerContextPath() : NON_DEFAULT_NEW_UI_WEB_APP_CONTEXT_PATH;
225+
boolean newUiWebAppShouldExist = isNewUiDefault(zConf);
226+
String classicUiWebAppContextPath = !isNewUiDefault(zConf) ? zConf.getServerContextPath() : NON_DEFAULT_CLASSIC_UI_WEB_APP_CONTEXT_PATH;
227+
boolean classicUiWebAppShouldExist = !isNewUiDefault(zConf);
233228
final WebAppContext newUiWebApp = setupWebAppContext(contexts, zConf, zConf.getString(ConfVars.ZEPPELIN_ANGULAR_WAR),
234-
newUiWebAppContextPath);
229+
newUiWebAppContextPath, newUiWebAppShouldExist);
235230
final WebAppContext classicUiWebApp = setupWebAppContext(contexts, zConf, zConf.getString(ConfVars.ZEPPELIN_WAR),
236-
classicUiWebAppContextPath);
231+
classicUiWebAppContextPath, classicUiWebAppShouldExist);
237232

238233
initWebApp(newUiWebApp);
239234
initWebApp(classicUiWebApp);
@@ -276,7 +271,7 @@ protected void configure() {
276271
jettyWebServer.start(); // Instantiates ZeppelinServer
277272
} catch (Exception e) {
278273
LOGGER.error("Error while running jettyServer", e);
279-
System.exit(-1);
274+
shutdown(-1);
280275
}
281276

282277
LOGGER.info("Done, zeppelin server started");
@@ -287,7 +282,7 @@ protected void configure() {
287282
}
288283
if (!errorDatas.isEmpty()) {
289284
LOGGER.error("{} error(s) while starting - Termination", errorDatas.size());
290-
System.exit(-1);
285+
shutdown(-1);
291286
}
292287
} catch (InterruptedException e) {
293288
// Many fast unit tests interrupt the Zeppelin server at this point
@@ -586,10 +581,12 @@ private static void setupHealthCheckContextHandler(WebAppContext webapp) {
586581
}
587582

588583
private static WebAppContext setupWebAppContext(
589-
ContextHandlerCollection contexts, ZeppelinConfiguration zConf, String warPath, String contextPath) {
584+
ContextHandlerCollection contexts, ZeppelinConfiguration zConf, String warPath, String contextPath, boolean shouldExist) {
590585
WebAppContext webApp = new WebAppContext();
591586
webApp.setContextPath(contextPath);
592587
LOGGER.info("warPath is: {}", warPath);
588+
LOGGER.info("The file or directory for the warPath should exist: {}", shouldExist);
589+
webApp.setThrowUnavailableOnStartupException(shouldExist);
593590
File warFile = new File(warPath);
594591
if (warFile.isDirectory()) {
595592
// Development mode, read from FS

0 commit comments

Comments
 (0)