Skip to content

Commit 7494bec

Browse files
tboneleeReamer
authored andcommitted
[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> (cherry picked from commit 25cd340) Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com>
1 parent e74ffb2 commit 7494bec

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);
@@ -279,7 +274,7 @@ protected void configure() {
279274
}
280275
} catch (Exception e) {
281276
LOGGER.error("Error while running jettyServer", e);
282-
System.exit(-1);
277+
shutdown(-1);
283278
}
284279

285280
LOGGER.info("Done, zeppelin server started");
@@ -290,7 +285,7 @@ protected void configure() {
290285
}
291286
if (!errorDatas.isEmpty()) {
292287
LOGGER.error("{} error(s) while starting - Termination", errorDatas.size());
293-
System.exit(-1);
288+
shutdown(-1);
294289
}
295290
} catch (InterruptedException e) {
296291
// Many fast unit tests interrupt the Zeppelin server at this point
@@ -588,10 +583,12 @@ private static void setupHealthCheckContextHandler(WebAppContext webapp) {
588583
}
589584

590585
private static WebAppContext setupWebAppContext(
591-
ContextHandlerCollection contexts, ZeppelinConfiguration zConf, String warPath, String contextPath) {
586+
ContextHandlerCollection contexts, ZeppelinConfiguration zConf, String warPath, String contextPath, boolean shouldExist) {
592587
WebAppContext webApp = new WebAppContext();
593588
webApp.setContextPath(contextPath);
594589
LOGGER.info("warPath is: {}", warPath);
590+
LOGGER.info("The file or directory for the warPath should exist: {}", shouldExist);
591+
webApp.setThrowUnavailableOnStartupException(shouldExist);
595592
File warFile = new File(warPath);
596593
if (warFile.isDirectory()) {
597594
// Development mode, read from FS

0 commit comments

Comments
 (0)