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);
}
Aggregations