This is an automated email from the ASF dual-hosted git repository. pdallig pushed a commit to branch surefire in repository https://gitbox.apache.org/repos/asf/zeppelin.git
commit 1e9a7f56919f1fdaca429f71ed5e00853238a6a4 Author: Philipp Dallig <philipp.dal...@gmail.com> AuthorDate: Fri Mar 11 17:30:50 2022 +0100 Try to solve surefire update --- .../org/apache/zeppelin/server/ZeppelinServer.java | 133 +++++++++++---------- .../zeppelin/socket/SessionConfigurator.java | 3 +- .../java/org/apache/zeppelin/utils/TestUtils.java | 2 +- .../zeppelin/cluster/ZeppelinServerMock.java | 2 +- .../org/apache/zeppelin/recovery/RecoveryTest.java | 3 +- .../apache/zeppelin/rest/AbstractTestRestApi.java | 7 +- .../apache/zeppelin/rest/NotebookRestApiTest.java | 4 +- 7 files changed, 84 insertions(+), 70 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java index 428cdd9..fb7baa7 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java @@ -135,30 +135,36 @@ public class ZeppelinServer extends ResourceConfig { private static final Logger LOG = LoggerFactory.getLogger(ZeppelinServer.class); private static final String WEB_APP_CONTEXT_NEXT = "/next"; - public static Server jettyWebServer; - public static ServiceLocator sharedServiceLocator; + //private static Server jettyWebServer; + //public static ServiceLocator sharedServiceLocator; - private static ZeppelinConfiguration conf; - private static PrometheusMeterRegistry promMetricRegistry; + //private static ZeppelinConfiguration conf; + //private static PrometheusMeterRegistry promMetricRegistry; public static void reset() { - conf = null; - jettyWebServer = null; - sharedServiceLocator = null; + //conf = null; + //jettyWebServer = null; + //sharedServiceLocator = null; } @Inject - public ZeppelinServer() { + public ZeppelinServer(ZeppelinConfiguration conf) { LOG.info("Instantiated ZeppelinServer"); InterpreterOutput.LIMIT = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_OUTPUT_LIMIT); packages("org.apache.zeppelin.rest"); } - public static void main(String[] args) throws InterruptedException, IOException { - ZeppelinServer.conf = ZeppelinConfiguration.create(); + public static void main(String[] args) throws IOException { + ZeppelinConfiguration conf = ZeppelinConfiguration.create(); - jettyWebServer = setupJettyServer(conf); + Server jettyWebServer = setupJettyServer(conf); + + PrometheusMeterRegistry promMetricRegistry = null; + if (conf.isPrometheusMetricEnabled()) { + promMetricRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); + Metrics.addRegistry(promMetricRegistry); + } initMetrics(conf); TimedHandler timedHandler = new TimedHandler(Metrics.globalRegistry, Tags.empty()); @@ -167,7 +173,7 @@ public class ZeppelinServer extends ResourceConfig { ContextHandlerCollection contexts = new ContextHandlerCollection(); timedHandler.setHandler(contexts); - sharedServiceLocator = ServiceLocatorFactory.getInstance().create("shared-locator"); + ServiceLocator sharedServiceLocator = ServiceLocatorFactory.getInstance().create("shared-locator"); ServiceLocatorUtilities.enableImmediateScope(sharedServiceLocator); ServiceLocatorUtilities.addClasses(sharedServiceLocator, NotebookRepoSync.class, @@ -230,10 +236,10 @@ public class ZeppelinServer extends ResourceConfig { final WebAppContext defaultWebApp = setupWebAppContext(contexts, conf, conf.getString(ConfVars.ZEPPELIN_WAR), conf.getServerContextPath()); final WebAppContext nextWebApp = setupWebAppContext(contexts, conf, conf.getString(ConfVars.ZEPPELIN_ANGULAR_WAR), WEB_APP_CONTEXT_NEXT); - initWebApp(defaultWebApp); - initWebApp(nextWebApp); + initWebApp(defaultWebApp, conf, sharedServiceLocator, promMetricRegistry); + initWebApp(nextWebApp, conf, sharedServiceLocator, promMetricRegistry); // Cluster Manager Server - setupClusterManagerServer(sharedServiceLocator); + setupClusterManagerServer(sharedServiceLocator, conf); // JMX Enable if (conf.isJMXEnabled()) { @@ -251,25 +257,9 @@ public class ZeppelinServer extends ResourceConfig { LOG.info("JMX Enabled with port: {}", port); } - LOG.info("Starting zeppelin server"); - try { - jettyWebServer.start(); // Instantiates ZeppelinServer - List<ErrorData> errorData = handler.waitForAtLeastOneConstructionError(5 * 1000); - if(errorData.size() > 0 && errorData.get(0).getThrowable() != null) { - throw new Exception(errorData.get(0).getThrowable()); - } - if (conf.getJettyName() != null) { - org.eclipse.jetty.http.HttpGenerator.setJettyVersion(conf.getJettyName()); - } - } catch (Exception e) { - LOG.error("Error while running jettyServer", e); - System.exit(-1); - } - LOG.info("Done, zeppelin server started"); - - runNoteOnStart(conf); + runNoteOnStart(conf, jettyWebServer, sharedServiceLocator); - Runtime.getRuntime().addShutdownHook(shutdown(conf)); + Runtime.getRuntime().addShutdownHook(shutdown(conf, jettyWebServer, sharedServiceLocator)); // Try to get Notebook from ServiceLocator, because Notebook instantiation is lazy, it is // created when user open zeppelin in browser if we don't get it explicitly here. @@ -283,28 +273,42 @@ public class ZeppelinServer extends ResourceConfig { // Try to recover here, don't do it in constructor of Notebook, because it would cause deadlock. notebook.recoveryIfNecessary(); - // when zeppelin is started inside of ide (especially for eclipse) - // for graceful shutdown, input any key in console window - if (System.getenv("ZEPPELIN_IDENT_STRING") == null) { - try { - System.in.read(); - } catch (IOException e) { - LOG.error("Exception in ZeppelinServer while main ", e); + try { + List<ErrorData> errorDatas = handler.waitForAtLeastOneConstructionError(5000); + for (ErrorData errorData : errorDatas) { + LOG.error("Error in Construction", errorData.getThrowable()); + } + if (!errorDatas.isEmpty()) { + LOG.error("{} error(s) while starting - Termination", errorDatas.size()); + System.exit(-1); } - System.exit(0); + } catch (InterruptedException e) { + LOG.error("Error while Constrcut Services", e); + System.exit(-1); } - jettyWebServer.join(); + + LOG.info("Starting zeppelin server"); + try { + jettyWebServer.start(); // Instantiates ZeppelinServer + } catch (Exception e) { + LOG.error("Error while running jettyServer", e); + System.exit(-1); + } + LOG.info("Done, zeppelin server started"); + + try { + jettyWebServer.join(); + } catch (InterruptedException e) { + shutdown(conf, jettyWebServer, sharedServiceLocator).start(); + Thread.currentThread().interrupt(); + } if (!conf.isRecoveryEnabled()) { sharedServiceLocator.getService(InterpreterSettingManager.class).close(); } } private static void initMetrics(ZeppelinConfiguration conf) { - if (conf.isPrometheusMetricEnabled()) { - promMetricRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); - Metrics.addRegistry(promMetricRegistry); - } if (conf.isJMXEnabled()) { Metrics.addRegistry(new JmxMeterRegistry(JmxConfig.DEFAULT, Clock.SYSTEM)); } @@ -317,7 +321,7 @@ public class ZeppelinServer extends ResourceConfig { new JVMInfoBinder().bindTo(Metrics.globalRegistry); } - private static Thread shutdown(ZeppelinConfiguration conf) { + private static Thread shutdown(ZeppelinConfiguration conf, Server jettyWebServer, ServiceLocator sharedServiceLocator) { return new Thread( () -> { LOG.info("Shutting down Zeppelin Server ... "); @@ -346,10 +350,10 @@ public class ZeppelinServer extends ResourceConfig { conf.getInt(ConfVars.ZEPPELIN_SERVER_JETTY_THREAD_POOL_MIN), conf.getInt(ConfVars.ZEPPELIN_SERVER_JETTY_THREAD_POOL_TIMEOUT)); final Server server = new Server(threadPool); - initServerConnector(server, conf.getServerPort(), conf.getServerSslPort()); + initServerConnector(server, conf); return server; } - private static void initServerConnector(Server server, int port, int sslPort) { + private static void initServerConnector(Server server, ZeppelinConfiguration conf) { ServerConnector connector; HttpConfiguration httpConfig = new HttpConfiguration(); @@ -357,9 +361,9 @@ public class ZeppelinServer extends ResourceConfig { httpConfig.setSendServerVersion(conf.sendJettyName()); httpConfig.setRequestHeaderSize(conf.getJettyRequestHeaderSize()); if (conf.useSsl()) { - LOG.debug("Enabling SSL for Zeppelin Server on port {}", sslPort); + LOG.debug("Enabling SSL for Zeppelin Server on port {}", conf.getServerSslPort()); httpConfig.setSecureScheme(HttpScheme.HTTPS.asString()); - httpConfig.setSecurePort(sslPort); + httpConfig.setSecurePort(conf.getServerSslPort()); HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); @@ -371,7 +375,7 @@ public class ZeppelinServer extends ResourceConfig { server, sslConnectionFactory, httpsConnectionFactory); - connector.setPort(sslPort); + connector.setPort(conf.getServerSslPort()); connector.addBean(new JettySslHandshakeMetrics(Metrics.globalRegistry, Tags.empty())); } else { HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfig); @@ -379,7 +383,7 @@ public class ZeppelinServer extends ResourceConfig { new ServerConnector( server, httpConnectionFactory); - connector.setPort(port); + connector.setPort(conf.getServerPort()); } // Set some timeout options to make debugging easier. int timeout = 1000 * 30; @@ -389,7 +393,7 @@ public class ZeppelinServer extends ResourceConfig { server.addConnector(connector); } - private static void runNoteOnStart(ZeppelinConfiguration conf) throws IOException, InterruptedException { + private static void runNoteOnStart(ZeppelinConfiguration conf, Server jettyWebServer, ServiceLocator sharedServiceLocator) throws IOException { String noteIdToRun = conf.getNotebookRunId(); if (!StringUtils.isEmpty(noteIdToRun)) { LOG.info("Running note {} on start", noteIdToRun); @@ -422,9 +426,14 @@ public class ZeppelinServer extends ResourceConfig { }); if (conf.getNotebookRunAutoShutdown()) { - Thread t = shutdown(conf); + Thread t = shutdown(conf, jettyWebServer, sharedServiceLocator); t.start(); - t.join(); + try { + t.join(); + } catch (InterruptedException e) { + LOG.error("Interrupt during shutdown - immediate termination"); + System.exit(1); + } System.exit(success ? 0 : 1); } } @@ -440,7 +449,7 @@ public class ZeppelinServer extends ResourceConfig { }); } - private static void setupClusterManagerServer(ServiceLocator serviceLocator) { + private static void setupClusterManagerServer(ServiceLocator serviceLocator, ZeppelinConfiguration conf) { if (conf.isClusterMode()) { LOG.info("Cluster mode is enabled, starting ClusterManagerServer"); ClusterManagerServer clusterManagerServer = ClusterManagerServer.getInstance(conf); @@ -458,7 +467,7 @@ public class ZeppelinServer extends ResourceConfig { // when the zeppelin service starts, Create a ClusterInterpreterLauncher object, // This allows the ClusterInterpreterLauncher to listen for cluster events. try { - InterpreterSettingManager intpSettingManager = sharedServiceLocator.getService(InterpreterSettingManager.class); + InterpreterSettingManager intpSettingManager = serviceLocator.getService(InterpreterSettingManager.class); RecoveryStorage recoveryStorage = ReflectionUtils.createClazzInstance( conf.getRecoveryStorageClass(), new Class[] {ZeppelinConfiguration.class, InterpreterSettingManager.class}, @@ -567,7 +576,7 @@ public class ZeppelinServer extends ResourceConfig { } } - private static void setupPrometheusContextHandler(WebAppContext webapp) { + private static void setupPrometheusContextHandler(WebAppContext webapp, PrometheusMeterRegistry promMetricRegistry) { webapp.addServlet(new ServletHolder(new PrometheusServlet(promMetricRegistry)), "/metrics"); } @@ -647,7 +656,7 @@ public class ZeppelinServer extends ResourceConfig { }; } - private static void initWebApp(WebAppContext webApp) { + private static void initWebApp(WebAppContext webApp, ZeppelinConfiguration conf, ServiceLocator sharedServiceLocator, PrometheusMeterRegistry promMetricRegistry) { webApp.addEventListener( new ServletContextListener() { @Override @@ -665,7 +674,9 @@ public class ZeppelinServer extends ResourceConfig { setupRestApiContextHandler(webApp, conf); // prometheus endpoint - setupPrometheusContextHandler(webApp); + if (promMetricRegistry != null) { + setupPrometheusContextHandler(webApp, promMetricRegistry); + } // health endpoints setupHealthCheckContextHandler(webApp); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/SessionConfigurator.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/SessionConfigurator.java index e6f6727..b6bd59e 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/SessionConfigurator.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/SessionConfigurator.java @@ -25,6 +25,7 @@ import javax.websocket.server.ServerEndpointConfig; import org.apache.zeppelin.server.ZeppelinServer; import org.apache.zeppelin.util.WatcherSecurityKey; import org.apache.zeppelin.utils.CorsUtils; +import org.glassfish.hk2.api.ServiceLocatorFactory; /** * This class set headers to websocket sessions and inject hk2 when initiating instances by ServerEndpoint annotation. @@ -44,6 +45,6 @@ public class SessionConfigurator extends ServerEndpointConfig.Configurator { @Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { - return ZeppelinServer.sharedServiceLocator.getService(endpointClass); + return ServiceLocatorFactory.getInstance().find("shared-locator").getService(endpointClass); } } diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/utils/TestUtils.java b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/TestUtils.java index 930817b..2806f49 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/utils/TestUtils.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/TestUtils.java @@ -25,7 +25,7 @@ import org.glassfish.hk2.api.ServiceLocatorFactory; public class TestUtils { public static <T> T getInstance(Class<T> clazz) { checkCalledByTestMethod(); - return getInstance(ZeppelinServer.sharedServiceLocator, clazz); + return getInstance(ServiceLocatorFactory.getInstance().find("shared-locator"), clazz); } public static void clearInstances() { diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ZeppelinServerMock.java b/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ZeppelinServerMock.java index fa6d859..d8004a8 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ZeppelinServerMock.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ZeppelinServerMock.java @@ -145,7 +145,7 @@ public class ZeppelinServerMock { } } LOG.info("ZeppelinServerMock shutDown..."); - ZeppelinServer.jettyWebServer.stop(); + //ZeppelinServer.jettyWebServer.stop(); executor.shutdown(); System.clearProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName()); System.clearProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_WAR.getVarName()); diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java index fb51806..ec7968f 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java @@ -35,6 +35,7 @@ import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.server.ZeppelinServer; import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.utils.TestUtils; +import org.glassfish.hk2.api.ServiceLocatorFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -66,7 +67,7 @@ public class RecoveryTest extends AbstractTestRestApi { recoveryDir.getAbsolutePath()); startUp(RecoveryTest.class.getSimpleName()); - notebook = ZeppelinServer.sharedServiceLocator.getService(Notebook.class); + notebook = ServiceLocatorFactory.getInstance().find("shared-locator").getService(Notebook.class); } @After diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java index 912183d..93a6f42 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java @@ -326,10 +326,11 @@ public abstract class AbstractTestRestApi { FileUtils.deleteQuietly(shiroIni); } LOG.info("Terminating Zeppelin Server..."); - ZeppelinServer.jettyWebServer.stop(); + //ZeppelinServer.jettyWebServer.stop(); executor.shutdown(); - PluginManager.reset(); - ZeppelinConfiguration.reset(); + executor.shutdownNow(); + //PluginManager.reset(); + //ZeppelinConfiguration.reset(); long s = System.currentTimeMillis(); boolean started = true; diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java index dc95df5..4178919 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java @@ -120,7 +120,7 @@ public class NotebookRestApiTest extends AbstractTestRestApi { } } } - + @Test public void testGetNoteByPath() throws IOException { LOG.info("Running testGetNoteByPath"); @@ -890,7 +890,7 @@ public class NotebookRestApiTest extends AbstractTestRestApi { new TypeToken<Map<String, Object>>() {}.getType()); assertEquals("OK", resp.get("status")); post2.close(); - + Thread.sleep(60000); TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0);