You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datalab.apache.org by dy...@apache.org on 2022/05/18 11:18:40 UTC
[incubator-datalab] branch DATALAB-2785 created (now 3916099d7)
This is an automated email from the ASF dual-hosted git repository.
dyankiv pushed a change to branch DATALAB-2785
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git
at 3916099d7 add support to create user image as admin
This branch includes the following new commits:
new 3916099d7 add support to create user image as admin
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org
[incubator-datalab] 01/01: add support to create user image as admin
Posted by dy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
dyankiv pushed a commit to branch DATALAB-2785
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git
commit 3916099d7d9118afbf611cc0d420d225a880dc0c
Author: Denys Yankiv <de...@gmail.com>
AuthorDate: Wed May 18 14:18:24 2022 +0300
add support to create user image as admin
---
.../backendapi/resources/EnvironmentResource.java | 15 +++++++++++++
.../dto/ExploratoryImageCreateFormAdminDTO.java | 24 ++++++++++++++++++++
.../backendapi/service/EnvironmentService.java | 2 ++
.../service/impl/EnvironmentServiceImpl.java | 26 ++++++++++++++--------
4 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/EnvironmentResource.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/EnvironmentResource.java
index 9b984bb40..84da43971 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/EnvironmentResource.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/EnvironmentResource.java
@@ -20,6 +20,7 @@
package com.epam.datalab.backendapi.resources;
import com.epam.datalab.auth.UserInfo;
+import com.epam.datalab.backendapi.resources.dto.ExploratoryImageCreateFormAdminDTO;
import com.epam.datalab.backendapi.service.EnvironmentService;
import com.google.inject.Inject;
import io.dropwizard.auth.Auth;
@@ -27,6 +28,8 @@ import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.NotEmpty;
import javax.annotation.security.RolesAllowed;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -35,6 +38,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
@Path("environment")
@Slf4j
@@ -119,4 +123,15 @@ public class EnvironmentResource {
environmentService.terminateComputational(userInfo, user, projectName, exploratoryName, computationalName);
return Response.ok().build();
}
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("createImage/{projectName}/{exploratoryName}")
+ public Response createImage(@Auth UserInfo userInfo,
+ @Valid @NotNull ExploratoryImageCreateFormAdminDTO form) {
+ log.info("Admin {} is creating an image of exploratory {} of user {}", userInfo.getName(), form.getNotebookName(), form.getUser());
+ environmentService.createImage(userInfo, form.getUser(), form.getProjectName(), form.getNotebookName(), form.getName(), form.getDescription());
+ return Response.ok().build();
+ }
}
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/ExploratoryImageCreateFormAdminDTO.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/ExploratoryImageCreateFormAdminDTO.java
new file mode 100644
index 000000000..96104fa41
--- /dev/null
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/ExploratoryImageCreateFormAdminDTO.java
@@ -0,0 +1,24 @@
+package com.epam.datalab.backendapi.resources.dto;
+
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.ToString;
+import org.hibernate.validator.constraints.NotBlank;
+
+@Data
+@ToString
+public class ExploratoryImageCreateFormAdminDTO {
+ @NotBlank
+ private String user;
+ @NotBlank
+ @JsonProperty("imageName")
+ private String name;
+ @NotBlank
+ @JsonProperty("exploratory_name")
+ private String notebookName;
+ @NotBlank
+ @JsonProperty("project_name")
+ private String projectName;
+ private final String description;
+}
\ No newline at end of file
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/EnvironmentService.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/EnvironmentService.java
index a4bd017e1..750d16598 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/EnvironmentService.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/EnvironmentService.java
@@ -31,6 +31,8 @@ public interface EnvironmentService {
List<UserResourceInfo> getAllEnv(UserInfo user);
+ void createImage(UserInfo userInfo, String user, String project, String exploratoryName, String imageName, String description);
+
void startExploratory(UserInfo userInfo, String user, String project, String exploratoryName);
void stopAll();
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/EnvironmentServiceImpl.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/EnvironmentServiceImpl.java
index 12867525b..e7506ca55 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/EnvironmentServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/EnvironmentServiceImpl.java
@@ -66,19 +66,21 @@ public class EnvironmentServiceImpl implements EnvironmentService {
private final ComputationalService computationalService;
private final SecurityService securityService;
private final ProjectService projectService;
+ private final ImageExploratoryService imageExploratoryService;
@Inject
public EnvironmentServiceImpl(EnvDAO envDAO, UserSettingsDAO settingsDAO, ExploratoryDAO exploratoryDAO,
ExploratoryService exploratoryService, ComputationalService computationalService,
- SecurityService securityService, ProjectService projectService) {
- this.envDAO = envDAO;
- this.settingsDAO = settingsDAO;
- this.exploratoryDAO = exploratoryDAO;
- this.exploratoryService = exploratoryService;
- this.computationalService = computationalService;
- this.securityService = securityService;
- this.projectService = projectService;
- }
+ SecurityService securityService, ProjectService projectService, ImageExploratoryService imageExploratoryService) {
+ this.envDAO = envDAO;
+ this.settingsDAO = settingsDAO;
+ this.exploratoryDAO = exploratoryDAO;
+ this.exploratoryService = exploratoryService;
+ this.computationalService = computationalService;
+ this.securityService = securityService;
+ this.projectService = projectService;
+ this.imageExploratoryService = imageExploratoryService;
+ }
@Override
public List<UserDTO> getUsers() {
@@ -107,6 +109,12 @@ public class EnvironmentServiceImpl implements EnvironmentService {
.collect(Collectors.toList());
}
+ @ProjectAdmin
+ @Override
+ public void createImage(@User UserInfo userInfo, String user, @Project String project, String exploratoryName, String imageName, String description) {
+ imageExploratoryService.createImage(securityService.getUserInfoOffline(user), project, exploratoryName, imageName, description, null);
+ }
+
@ProjectAdmin
@Override
public void startExploratory(@User UserInfo userInfo, String user, @Project String project, String exploratoryName) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org