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