Search in sources :

Example 6 with JupyterSettings

use of io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings in project hopsworks by logicalclocks.

the class JupyterController method attachJupyterConfigurationToNotebook.

public void attachJupyterConfigurationToNotebook(Users user, String hdfsUsername, Project project, String kernelId) throws ServiceException {
    DistributedFileSystemOps udfso = null;
    try {
        JupyterSettings jupyterSettings = jupyterSettingsFacade.findByProjectUser(project, user.getEmail());
        // When we have support git Datasets remove this if statement
        if (jupyterSettings.isGitBackend()) {
            return;
        }
        udfso = dfs.getDfsOps(hdfsUsername);
        String relativeNotebookPath = getNotebookRelativeFilePath(hdfsUsername, kernelId, udfso);
        JSONObject jupyterSettingsMetadataObj = new JSONObject();
        jupyterSettingsMetadataObj.put(Settings.META_NOTEBOOK_JUPYTER_CONFIG_XATTR_NAME, objectMapper.writeValueAsString(jupyterSettings));
        jupyterSettingsMetadataObj.put(Settings.META_USAGE_TIME, new Date().getTime());
        xAttrsController.addStrXAttr(jupyterSettings.getBaseDir() + "/" + relativeNotebookPath, Settings.META_NOTEBOOK_JUPYTER_CONFIG_XATTR_NAME, jupyterSettingsMetadataObj.toString(), udfso);
    } catch (Exception e) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.ATTACHING_JUPYTER_CONFIG_TO_NOTEBOOK_FAILED, Level.FINE, "Failed to attach jupyter configuration for user: " + user + ", project" + ": " + project + ", " + "kernelId: " + kernelId, e.getMessage(), e);
    } finally {
        dfs.closeDfsClient(udfso);
    }
}
Also used : JSONObject(org.json.JSONObject) ServiceException(io.hops.hopsworks.exceptions.ServiceException) JupyterSettings(io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) Date(java.util.Date) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) IOException(java.io.IOException) ServiceException(io.hops.hopsworks.exceptions.ServiceException)

Example 7 with JupyterSettings

use of io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings in project hopsworks by logicalclocks.

the class JupyterController method shutdown.

public void shutdown(Project project, String hdfsUser, Users user, String secret, String cid, int port, boolean quiet) throws ServiceException {
    // We need to stop the jupyter notebook server with the PID
    // If we can't stop the server, delete the Entity bean anyway
    List<LivyMsg.Session> sessions = livyController.getLivySessionsForProjectUser(project, user);
    int retries = 3;
    while (retries > 0 && livyController.getLivySessionsForProjectUser(project, user).size() > 0) {
        LOGGER.log(Level.SEVERE, "Failed previous attempt to delete livy sessions for project " + project.getName() + " user " + hdfsUser + ", retrying...");
        livyController.deleteAllLivySessions(hdfsUser);
        try {
            Thread.sleep(200);
        } catch (InterruptedException ie) {
            LOGGER.log(Level.SEVERE, "Interrupted while sleeping");
        }
        retries--;
    }
    String jupyterHomePath = jupyterManager.getJupyterHome(hdfsUser, project, secret);
    // This method also removes the corresponding row for the Notebook process in the JupyterProject table.
    try {
        JupyterProject jupyterProject = jupyterFacade.findByUser(hdfsUser);
        JupyterSettings jupyterSettings = jupyterSettingsFacade.findByProjectUser(project, user.getEmail());
        // Do some sanity check before using jupyter settings
        if (jupyterProject != null && jupyterSettings != null) {
            if (jupyterSettings.isGitBackend() && jupyterSettings.getGitConfig().getShutdownAutoPush()) {
                try {
                    jupyterNbVCSController.push(jupyterProject, jupyterSettings, user);
                } catch (ServiceException ex) {
                    if (!quiet) {
                        throw ex;
                    }
                    LOGGER.log(Level.WARNING, "Could not push Git repository, shutting down Jupyter nevertheless", ex);
                }
            }
        }
        jupyterManager.stopJupyterServer(project, user, hdfsUser, jupyterHomePath, cid, port);
    } finally {
        String[] project_user = hdfsUser.split(HdfsUsersController.USER_NAME_DELIMITER);
        DistributedFileSystemOps dfso = dfsService.getDfsOps();
        try {
            String certificatesDir = Paths.get(jupyterHomePath, "certificates").toString();
            HopsUtils.cleanupCertificatesForUserCustomDir(project_user[1], project.getName(), settings.getHdfsTmpCertDir(), certificateMaterializer, certificatesDir, settings);
        } finally {
            if (dfso != null) {
                dfsService.closeDfsClient(dfso);
            }
        }
        FileUtils.deleteQuietly(new File(jupyterHomePath));
        jupyterJWTManager.cleanJWT(cid, port);
        livyController.deleteAllLivySessions(hdfsUser);
    }
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) JupyterSettings(io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject) File(java.io.File)

Aggregations

JupyterSettings (io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings)7 ServiceException (io.hops.hopsworks.exceptions.ServiceException)3 JupyterProject (io.hops.hopsworks.persistence.entity.jupyter.JupyterProject)3 Users (io.hops.hopsworks.persistence.entity.user.Users)3 IOException (java.io.IOException)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)2 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)2 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)2 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)2 Date (java.util.Date)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JWTDecodeException (com.auth0.jwt.exceptions.JWTDecodeException)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)1 NotebookDTO (io.hops.hopsworks.common.jupyter.NotebookDTO)1 RepositoryStatus (io.hops.hopsworks.common.jupyter.RepositoryStatus)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1