You are viewing a plain text version of this content. The canonical link for it is here.
Posted to submarine-dev@hadoop.apache.org by GitBox <gi...@apache.org> on 2019/10/18 16:15:32 UTC

[GitHub] [hadoop-submarine] liuxunorg commented on a change in pull request #56: [SUBMARINE-248]. Add websocket interface to submarine workbench server.

liuxunorg commented on a change in pull request #56: [SUBMARINE-248]. Add websocket interface to submarine workbench server.
URL: https://github.com/apache/hadoop-submarine/pull/56#discussion_r336567844
 
 

 ##########
 File path: submarine-workbench/workbench-server/src/test/java/org/apache/submarine/server/AbstractWorkbenchServerTest.java
 ##########
 @@ -0,0 +1,304 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.submarine.server;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.io.FileUtils;
+import org.apache.submarine.commons.utils.SubmarineConfiguration;
+import org.apache.submarine.utils.TestUtils;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public abstract class AbstractWorkbenchServerTest {
+  protected static final Logger LOG =
+      LoggerFactory.getLogger(AbstractWorkbenchServerTest.class);
+
+  static final String WEBSOCKET_API_URL = "/ws";
+  static final String URL = getUrlToTest();
+  protected static final boolean WAS_RUNNING = checkIfServerIsRunning();
+
+  protected static File workbenchServerHome;
+  protected static File confDir;
+  protected static File notebookDir;
+
+  private String getUrl(String path) {
+    String url;
+    if (System.getProperty("url") != null) {
+      url = System.getProperty("url");
+    } else {
+      url = "http://localhost:8080";
+    }
+    if (path != null) {
+      url += path;
+    }
+    return url;
+  }
+
+  public static String getWebsocketApiUrlToTest() {
+    String websocketUrl = "ws://localhost:8080" + WEBSOCKET_API_URL;
+    if (System.getProperty("websocketUrl") != null) {
+      websocketUrl = System.getProperty("websocketurl");
+    }
+    return websocketUrl;
+  }
+
+  public static String getUrlToTest() {
+    String url = "http://localhost:8080";
+    if (System.getProperty("url") != null) {
+      url = System.getProperty("url");
+    }
+    return url;
+  }
+
+  static ExecutorService executor;
+  protected static final Runnable SERVER = new Runnable() {
+    @Override
+    public void run() {
+      try {
+        TestUtils.clearInstances();
+        WorkbenchServer.main(new String[]{""});
+      } catch (Exception e) {
+        LOG.error("Exception in WebDriverManager while getWebDriver ", e);
+        throw new RuntimeException(e);
+      }
+    }
+  };
+
+  private static void start(boolean withAuth, String testClassName,
+      boolean withKnox, boolean cleanData) throws Exception {
+    LOG.info("Starting WorkbenchServer withAuth: {}, testClassName: {}, withKnox: {}",
+        withAuth, testClassName, withKnox);
+
+    if (!WAS_RUNNING) {
+      // copy the resources files to a temp folder
+      workbenchServerHome = new File("..");
+      LOG.info("SUBMARINE_WORKBENCH_SERVER_HOME: "
+          + workbenchServerHome.getAbsolutePath());
+      confDir = new File(workbenchServerHome, "conf_" + testClassName);
+      confDir.mkdirs();
+
+      System.setProperty(SubmarineConfiguration.ConfVars.WORKBENCH_WEB_WAR.getVarName(),
+          new File("../workbench-web/dist").getAbsolutePath());
+      System.setProperty(SubmarineConfiguration.ConfVars.SUBMARINE_CONF_DIR.getVarName(),
+          confDir.getAbsolutePath());
+      notebookDir = new File(workbenchServerHome.getAbsolutePath() + "/notebook_" + testClassName);
+      if (cleanData) {
+        FileUtils.deleteDirectory(notebookDir);
+      }
+
+      // some test profile does not build zeppelin-web.
+      // to prevent zeppelin starting up fail, create zeppelin-web/dist directory
+      new File("../zeppelin-web/dist").mkdirs();
+
+      LOG.info("Staring test Workbench server up...");
+
+      executor = Executors.newSingleThreadExecutor();
+      executor.submit(SERVER);
+      long s = System.currentTimeMillis();
+      boolean started = false;
+      while (System.currentTimeMillis() - s < 1000 * 60 * 3) {  // 3 minutes
+        Thread.sleep(2000);
+        started = checkIfServerIsRunning();
+        if (started == true) {
+          break;
+        }
+      }
+      if (started == false) {
+        throw new RuntimeException("Can not start Zeppelin server");
+      }
+      //ZeppelinServer.notebook.setParagraphJobListener(NotebookServer.getInstance());
 
 Review comment:
   Need change to `//SubmarineServer.notebook.setParagraphJobListener(NotebookServer.getInstance());` ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services