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