Search in sources :

Example 1 with JupyterPaths

use of io.hops.hopsworks.common.dao.jupyter.config.JupyterPaths in project hopsworks by logicalclocks.

the class LocalHostJupyterProcessMgr method startJupyterServer.

@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public JupyterDTO startJupyterServer(Project project, String secretConfig, String hdfsUser, Users user, JupyterSettings js, String allowOrigin) throws ServiceException, JobException {
    String prog = settings.getSudoersDir() + "/jupyter.sh";
    Integer port = ThreadLocalRandom.current().nextInt(40000, 59999);
    JupyterPaths jp = jupyterConfigFilesGenerator.generateConfiguration(project, secretConfig, hdfsUser, user, js, port, allowOrigin);
    String secretDir = settings.getStagingDir() + Settings.PRIVATE_DIRS + js.getSecret();
    String token = TokenGenerator.generateToken(TOKEN_LENGTH);
    String cid = "";
    // The Jupyter Notebook is running at: http://localhost:8888/?token=c8de56fa4deed24899803e93c227592aef6538f93025fe01
    int maxTries = 5;
    // kill any running servers for this user, clear cached entries
    while (maxTries > 0) {
        try {
            // use pidfile to kill any running servers
            ProcessDescriptor processDescriptor = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand("start").addCommand(jp.getNotebookPath()).addCommand(settings.getHadoopSymbolicLinkDir() + "-" + settings.getHadoopVersion()).addCommand(hdfsUser).addCommand(settings.getAnacondaProjectDir()).addCommand(port.toString()).addCommand(HopsUtils.getJupyterLogName(hdfsUser, port)).addCommand(secretDir).addCommand(jp.getCertificatesDir()).addCommand(hdfsUser).addCommand(token).addCommand(js.getMode().getValue()).addCommand(projectUtils.getFullDockerImageName(project, false)).addCommand(Boolean.toString(js.isGitBackend())).redirectErrorStream(true).setCurrentWorkingDirectory(new File(jp.getNotebookPath())).setWaitTimeout(60L, TimeUnit.SECONDS).build();
            String pidfile = jp.getRunDirPath() + "/jupyter.pid";
            ProcessResult processResult = osProcessExecutor.execute(processDescriptor);
            if (processResult.getExitCode() != 0) {
                String errorMsg = "Could not start Jupyter server. Exit code: " + processResult.getExitCode() + " Error: stdout: " + processResult.getStdout() + " stderr: " + processResult.getStderr();
                LOGGER.log(Level.SEVERE, errorMsg);
                throw new IOException(errorMsg);
            }
            // Read the pid for Jupyter Notebook
            cid = com.google.common.io.Files.readFirstLine(new File(pidfile), Charset.defaultCharset());
            return new JupyterDTO(port, token, cid, secretConfig, jp.getCertificatesDir());
        } catch (Exception ex) {
            LOGGER.log(Level.SEVERE, "Problem executing shell script to start Jupyter server", ex);
            maxTries--;
        }
    }
    String errorMsg = "Failed to start Jupyter";
    throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_START_ERROR, Level.SEVERE, errorMsg, errorMsg + " for project " + project);
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) JupyterPaths(io.hops.hopsworks.common.dao.jupyter.config.JupyterPaths) URIBuilder(org.apache.http.client.utils.URIBuilder) ProcessResult(io.hops.hopsworks.common.util.ProcessResult) ProcessDescriptor(io.hops.hopsworks.common.util.ProcessDescriptor) IOException(java.io.IOException) File(java.io.File) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) JobException(io.hops.hopsworks.exceptions.JobException) JupyterDTO(io.hops.hopsworks.common.dao.jupyter.config.JupyterDTO) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

JupyterDTO (io.hops.hopsworks.common.dao.jupyter.config.JupyterDTO)1 JupyterPaths (io.hops.hopsworks.common.dao.jupyter.config.JupyterPaths)1 ProcessDescriptor (io.hops.hopsworks.common.util.ProcessDescriptor)1 ProcessResult (io.hops.hopsworks.common.util.ProcessResult)1 JobException (io.hops.hopsworks.exceptions.JobException)1 ServiceException (io.hops.hopsworks.exceptions.ServiceException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 TimeoutException (java.util.concurrent.TimeoutException)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1