Search in sources :

Example 11 with ProcessResult

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());
    }
}
Also used : ProcessResult(io.hops.hopsworks.common.util.ProcessResult) ProcessDescriptor(io.hops.hopsworks.common.util.ProcessDescriptor) IOException(java.io.IOException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 12 with ProcessResult

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);
    }
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) ProcessResult(io.hops.hopsworks.common.util.ProcessResult) ProcessDescriptor(io.hops.hopsworks.common.util.ProcessDescriptor) IOException(java.io.IOException) 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) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 13 with ProcessResult

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);
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) JupyterPaths(io.hops.hopsworks.common.dao.jupyter.config.JupyterPaths) 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)

Example 14 with ProcessResult

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);
    }
}
Also used : ProcessResult(io.hops.hopsworks.common.util.ProcessResult) ProcessDescriptor(io.hops.hopsworks.common.util.ProcessDescriptor) IOException(java.io.IOException) TensorBoardException(io.hops.hopsworks.exceptions.TensorBoardException)

Example 15 with ProcessResult

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;
}
Also used : ProcessResult(io.hops.hopsworks.common.util.ProcessResult) ProcessDescriptor(io.hops.hopsworks.common.util.ProcessDescriptor) IOException(java.io.IOException)

Aggregations

ProcessDescriptor (io.hops.hopsworks.common.util.ProcessDescriptor)24 ProcessResult (io.hops.hopsworks.common.util.ProcessResult)24 IOException (java.io.IOException)22 File (java.io.File)9 TransactionAttribute (javax.ejb.TransactionAttribute)5 ServiceException (io.hops.hopsworks.exceptions.ServiceException)4 ProjectException (io.hops.hopsworks.exceptions.ProjectException)3 ServingException (io.hops.hopsworks.exceptions.ServingException)3 Project (io.hops.hopsworks.persistence.entity.project.Project)3 BufferedWriter (java.io.BufferedWriter)3 FileWriter (java.io.FileWriter)3 Path (java.nio.file.Path)3 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)2 CompressionInfo (io.hops.hopsworks.common.dataset.util.CompressionInfo)2 DatasetException (io.hops.hopsworks.exceptions.DatasetException)2 JobException (io.hops.hopsworks.exceptions.JobException)2 PythonException (io.hops.hopsworks.exceptions.PythonException)2 TensorBoardException (io.hops.hopsworks.exceptions.TensorBoardException)2 FileNotFoundException (java.io.FileNotFoundException)2 URISyntaxException (java.net.URISyntaxException)2