Skip to content

Commit

Permalink
[HOPSWORKS-2992] Jupyter update endpoint should update the entire set… (
Browse files Browse the repository at this point in the history
logicalclocks#803)

Co-authored-by: Robin Andersson <[email protected]>
  • Loading branch information
SirOibaf and robzor92 committed Feb 14, 2022
1 parent 246c6e5 commit 636c89b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
15 changes: 15 additions & 0 deletions hopsworks-IT/src/test/ruby/spec/jupyter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@
python_file = json_body[:items].detect { |d| d[:attributes][:name] == "[export model].py" }
expect(python_file).to be_present
end

it "should update the jupyter settings without the need of starting a notebook server" do
get "#{ENV['HOPSWORKS_API']}/project/#{@project[:id]}/jupyter/settings"
expect_status_details(200)
settings = json_body
settings[:jobConfig][:amVCores] = 10
post "#{ENV['HOPSWORKS_API']}/project/#{@project[:id]}/jupyter/update", JSON(settings)
expect_status_details(200)

get "#{ENV['HOPSWORKS_API']}/project/#{@project[:id]}/jupyter/settings"
expect(json_body[:jobConfig][:amVCores]).to be 10

settings[:jobConfig][:amVCores] = 1
post "#{ENV['HOPSWORKS_API']}/project/#{@project[:id]}/jupyter/update", JSON(settings)
end
end

describe "Failure scenarios - python " + version do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private String getHdfsUser(SecurityContext sc) {
@JWTRequired(acceptedTokens={Audience.API}, allowedUserRoles={"HOPS_ADMIN", "HOPS_USER"})
public Response updateNotebookServer(JupyterSettings jupyterSettings, @Context SecurityContext sc) {
Users user = jWTHelper.getUserPrincipal(sc);

jupyterSettingsFacade.update(jupyterSettings);
jupyterController.updateExpirationDate(project, user, jupyterSettings);

return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(jupyterSettings).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,19 @@ public void removeJupyter(Project project) throws ServiceException {
}

public void updateExpirationDate(Project project, Users user, JupyterSettings jupyterSettings) {

//Save the current shutdown level
JupyterSettings js = jupyterSettingsFacade.findByProjectUser(project, user.getEmail());
js.setShutdownLevel(jupyterSettings.getShutdownLevel());
jupyterSettingsFacade.update(js);

//Increase hours on expirationDate
String hdfsUser = hdfsUsersController.getHdfsUserName(project, user);
JupyterProject jupyterProject = jupyterFacade.findByUser(hdfsUser);
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);
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);
}
}

public void versionProgram(Project project, Users user, String sessionKernelId, Path outputPath)
Expand Down

0 comments on commit 636c89b

Please sign in to comment.