Search in sources :

Example 11 with JupyterProject

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

the class JupyterFacade method saveServer.

public JupyterProject saveServer(String host, Project project, String secretConfig, int port, int hdfsUserId, String token, String cid, Date expires, boolean noLimit) {
    JupyterProject jp = new JupyterProject(project, secretConfig, port, hdfsUserId, host, token, cid, expires, noLimit);
    persist(jp);
    return jp;
}
Also used : JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject)

Example 12 with JupyterProject

use of io.hops.hopsworks.persistence.entity.jupyter.JupyterProject 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)

Example 13 with JupyterProject

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

the class JupyterController method updateExpirationDate.

public void updateExpirationDate(Project project, Users user, JupyterSettings jupyterSettings) {
    // Increase hours on expirationDate
    String hdfsUser = hdfsUsersController.getHdfsUserName(project, user);
    JupyterProject jupyterProject = jupyterFacade.findByUser(hdfsUser);
    if (jupyterProject != null) {
        Date expirationDate = jupyterProject.getExpires();
        Calendar cal = Calendar.getInstance();
        cal.setTime(expirationDate);
        cal.add(Calendar.HOUR_OF_DAY, jupyterSettings.getShutdownLevel());
        expirationDate = cal.getTime();
        jupyterProject.setExpires(expirationDate);
        jupyterProject.setNoLimit(jupyterSettings.isNoLimit());
        jupyterFacade.update(jupyterProject);
    }
}
Also used : Calendar(java.util.Calendar) JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject) Date(java.util.Date)

Example 14 with JupyterProject

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

the class JupyterController method removeJupyter.

public void removeJupyter(Project project) throws ServiceException {
    for (JupyterProject jp : project.getJupyterProjectCollection()) {
        HdfsUsers hdfsUser = hdfsUsersFacade.findById(jp.getHdfsUserId());
        String username = hdfsUsersController.getUserName(hdfsUser.getName());
        Users user = userFacade.findByUsername(username);
        shutdown(project, hdfsUser.getName(), user, jp.getSecret(), jp.getCid(), jp.getPort());
    }
    jupyterManager.projectCleanup(project);
}
Also used : JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Users(io.hops.hopsworks.persistence.entity.user.Users) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)

Example 15 with JupyterProject

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

the class LocalHostJupyterProcessMgr method getAllNotebooks.

@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public List<JupyterProject> getAllNotebooks() {
    List<JupyterProject> allNotebooks = jupyterFacade.getAllNotebookServers();
    executeJupyterCommand("list");
    File file = new File(Settings.JUPYTER_PIDS);
    List<String> cidsRunning = new ArrayList<>();
    try {
        Scanner scanner = new Scanner(file);
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            cidsRunning.add(line);
        }
    } catch (FileNotFoundException e) {
        LOGGER.warning("Invalid pids in file: " + Settings.JUPYTER_PIDS);
    }
    List<String> cidsOrphaned = new ArrayList<>();
    cidsOrphaned.addAll(cidsRunning);
    for (String cid : cidsRunning) {
        boolean foundCid = false;
        for (JupyterProject jp : allNotebooks) {
            if (cid == jp.getCid()) {
                foundCid = true;
            }
            if (foundCid) {
                cidsOrphaned.remove(cid);
            }
        }
    }
    for (String cid : cidsOrphaned) {
        JupyterProject jp = new JupyterProject();
        jp.setCid(cid);
        jp.setPort(0);
        jp.setHdfsUserId(-1);
        allNotebooks.add(jp);
    }
    file.deleteOnExit();
    return allNotebooks;
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject) File(java.io.File) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

JupyterProject (io.hops.hopsworks.persistence.entity.jupyter.JupyterProject)17 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)7 ServiceException (io.hops.hopsworks.exceptions.ServiceException)6 Users (io.hops.hopsworks.persistence.entity.user.Users)6 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)4 ProjectException (io.hops.hopsworks.exceptions.ProjectException)4 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)4 IOException (java.io.IOException)4 Date (java.util.Date)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 JupyterSettings (io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings)3 NoResultException (javax.persistence.NoResultException)3 GET (javax.ws.rs.GET)3 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)2 GenericException (io.hops.hopsworks.exceptions.GenericException)2 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)2 File (java.io.File)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2