use of io.hops.hopsworks.common.util.ProcessResult in project hopsworks by logicalclocks.
the class JupyterManagerImpl method projectCleanup.
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void projectCleanup(Logger logger, Project project) {
String prog = settings.getSudoersDir() + "/jupyter-project-cleanup.sh";
int exitValue;
ProcessDescriptor.Builder pdBuilder = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand(project.getName());
if (!logger.isLoggable(Level.FINE)) {
pdBuilder.ignoreOutErrStreams(true);
}
try {
ProcessResult processResult = osProcessExecutor.execute(pdBuilder.build());
logger.log(Level.FINE, processResult.getStdout());
exitValue = processResult.getExitCode();
} catch (IOException ex) {
logger.log(Level.SEVERE, "Problem cleaning up project: " + project.getName() + ": {0}", ex.toString());
exitValue = -2;
}
if (exitValue != 0) {
logger.log(Level.WARNING, "Problem remove project's jupyter folder: " + project.getName());
}
}
use of io.hops.hopsworks.common.util.ProcessResult in project hopsworks by logicalclocks.
the class LocalHostJupyterProcessMgr method stopJupyterServer.
@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void stopJupyterServer(Project project, Users user, String hdfsUsername, String jupyterHomePath, String cid, Integer port) throws ServiceException {
if (jupyterHomePath == null || cid == null || port == null) {
throw new IllegalArgumentException("Invalid arguments when stopping the Jupyter Server.");
}
// 1. Remove jupyter settings from the DB for this notebook first. If this fails, keep going to kill the notebook
try {
jupyterFacade.remove(hdfsUsername, port);
} catch (Exception e) {
LOGGER.severe("Problem when removing jupyter notebook entry from jupyter_project table: " + jupyterHomePath);
}
// 2. Then kill the jupyter notebook server. If this step isn't
String prog = settings.getSudoersDir() + "/jupyter.sh";
if (jupyterHomePath.isEmpty()) {
jupyterHomePath = "''";
}
int exitValue = 0;
Integer id = 1;
ProcessDescriptor.Builder pdBuilder = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand("kill").addCommand(jupyterHomePath).addCommand(cid).addCommand(hdfsUsername).setWaitTimeout(10L, TimeUnit.SECONDS);
if (!LOGGER.isLoggable(Level.FINE)) {
pdBuilder.ignoreOutErrStreams(true);
}
try {
ProcessResult processResult = osProcessExecutor.execute(pdBuilder.build());
LOGGER.log(Level.FINE, processResult.getStdout());
exitValue = processResult.getExitCode();
} catch (IOException ex) {
throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_STOP_ERROR, Level.SEVERE, "exitValue: " + exitValue, ex.getMessage(), ex);
}
if (exitValue != 0) {
throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_STOP_ERROR, Level.SEVERE, "exitValue: " + exitValue);
}
}
use of io.hops.hopsworks.common.util.ProcessResult 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)).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);
}
use of io.hops.hopsworks.common.util.ProcessResult in project hopsworks by logicalclocks.
the class TensorBoardProcessMgr method removeTensorBoardDirectory.
/**
* Remove TensorBoard directory
* @param tensorBoardDirectoryPath
* @throws IOException
*/
public void removeTensorBoardDirectory(String tensorBoardDirectoryPath) throws TensorBoardException {
// Remove directory
String prog = settings.getSudoersDir() + "/tensorboard.sh";
ProcessDescriptor processDescriptor = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand("cleanup").addCommand(tensorBoardDirectoryPath).ignoreOutErrStreams(true).build();
LOGGER.log(Level.FINE, processDescriptor.toString());
try {
ProcessResult processResult = osProcessExecutor.execute(processDescriptor);
if (!processResult.processExited() || processResult.getExitCode() != 0) {
throw new TensorBoardException(RESTCodes.TensorBoardErrorCode.TENSORBOARD_CLEANUP_ERROR, Level.SEVERE, "Failed to cleanup TensorBoard", "Could not delete TensorBoard directory: " + tensorBoardDirectoryPath);
}
} catch (IOException ex) {
throw new TensorBoardException(RESTCodes.TensorBoardErrorCode.TENSORBOARD_CLEANUP_ERROR, Level.SEVERE, "Failed to cleanup TensorBoard", "Could not delete TensorBoard directory: " + tensorBoardDirectoryPath, ex);
}
}
use of io.hops.hopsworks.common.util.ProcessResult in project hopsworks by logicalclocks.
the class TensorBoardProcessMgr method killTensorBoard.
/**
* Kill the TensorBoard process
* @param cid
* @return
*/
public int killTensorBoard(String cid) {
String prog = settings.getSudoersDir() + "/tensorboard.sh";
int exitValue;
ProcessDescriptor processDescriptor = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand("kill").addCommand(cid).ignoreOutErrStreams(true).build();
LOGGER.log(Level.FINE, processDescriptor.toString());
try {
ProcessResult processResult = osProcessExecutor.execute(processDescriptor);
if (!processResult.processExited()) {
LOGGER.log(Level.SEVERE, "Failed to kill TensorBoard");
}
exitValue = processResult.getExitCode();
} catch (IOException ex) {
exitValue = 2;
LOGGER.log(Level.SEVERE, "Failed to kill TensorBoard", ex);
}
return exitValue;
}
Aggregations