This is an automated email from the ASF dual-hosted git repository.

ofuks pushed a commit to branch DLAB-1590
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/DLAB-1590 by this push:
     new e4bcf7c  Admin per project
e4bcf7c is described below

commit e4bcf7cb4eb8ea1775d669f8f922dd4b8a121d1a
Author: Oleh Fuks <[email protected]>
AuthorDate: Wed Mar 25 14:57:43 2020 +0200

    Admin per project
---
 .../backendapi/resources/EnvironmentResource.java  | 18 -----
 .../backendapi/service/EnvironmentService.java     |  2 -
 .../service/impl/EnvironmentServiceImpl.java       | 42 +++++-----
 .../resources/EnvironmentResourceTest.java         | 89 ----------------------
 .../service/impl/EnvironmentServiceImplTest.java   | 47 ------------
 5 files changed, 20 insertions(+), 178 deletions(-)

diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EnvironmentResource.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EnvironmentResource.java
index c92162f..3553ff4 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EnvironmentResource.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EnvironmentResource.java
@@ -49,14 +49,6 @@ public class EnvironmentResource {
        }
 
        @GET
-       @Path("user")
-       @Produces(MediaType.APPLICATION_JSON)
-       public Response getUsersWithActiveEnv(@Auth UserInfo userInfo) {
-               log.debug("User {} requested information about active 
environments", userInfo.getName());
-               return Response.ok(environmentService.getUsers()).build();
-       }
-
-       @GET
        @Path("all")
        @Produces(MediaType.APPLICATION_JSON)
        public Response getAllEnv(@Auth UserInfo userInfo) {
@@ -67,16 +59,6 @@ public class EnvironmentResource {
        @POST
        @Consumes(MediaType.TEXT_PLAIN)
        @Produces(MediaType.APPLICATION_JSON)
-       @Path("stop/{projectName}")
-       public Response stopEnv(@Auth UserInfo userInfo, @NotEmpty String user, 
@PathParam("projectName") String projectName) {
-               log.info("User {} is stopping {} environment", 
userInfo.getName(), user);
-               environmentService.stopEnvironment(userInfo, user, projectName);
-               return Response.ok().build();
-       }
-
-       @POST
-       @Consumes(MediaType.TEXT_PLAIN)
-       @Produces(MediaType.APPLICATION_JSON)
        @Path("stop/{projectName}/{exploratoryName}")
        public Response stopNotebook(@Auth UserInfo userInfo, @NotEmpty String 
user,
                                                                 
@PathParam("projectName") String projectName,
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EnvironmentService.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EnvironmentService.java
index e342f76..c605131 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EnvironmentService.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EnvironmentService.java
@@ -32,8 +32,6 @@ public interface EnvironmentService {
 
        void stopAll();
 
-       void stopEnvironment(UserInfo userInfo, String user, String project);
-
        void stopEnvironmentWithServiceAccount(String user);
 
        void stopProjectEnvironment(String project);
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
index 0bab2d6..8a50de8 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
@@ -55,23 +55,29 @@ import static java.util.stream.Collectors.toList;
 @Singleton
 @Slf4j
 public class EnvironmentServiceImpl implements EnvironmentService {
-
        private static final String ERROR_MSG_FORMAT = "Can not %s environment 
because on of user resource is in status " +
                        "CREATING or STARTING";
+
+       private final EnvDAO envDAO;
+       private final UserSettingsDAO settingsDAO;
+       private final ExploratoryDAO exploratoryDAO;
+       private final ExploratoryService exploratoryService;
+       private final ComputationalService computationalService;
+       private final SecurityService securityService;
+       private final ProjectService projectService;
+
        @Inject
-       private EnvDAO envDAO;
-       @Inject
-       private ExploratoryDAO exploratoryDAO;
-       @Inject
-       private ExploratoryService exploratoryService;
-       @Inject
-       private ComputationalService computationalService;
-       @Inject
-       private SecurityService securityService;
-       @Inject
-       private ProjectService projectService;
-       @Inject
-       private UserSettingsDAO settingsDAO;
+       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;
+       }
 
        @Override
        public List<UserDTO> getUsers() {
@@ -110,14 +116,6 @@ public class EnvironmentServiceImpl implements 
EnvironmentService {
        }
 
        @Override
-       public void stopEnvironment(UserInfo userInfo, String user, String 
project) {
-               log.debug("Stopping environment for user {}", user);
-               checkState(user, "stop");
-               exploratoryDAO.fetchRunningExploratoryFields(user)
-                               .forEach(e -> stopExploratory(userInfo, user, 
project, e.getExploratoryName()));
-       }
-
-       @Override
        public void stopEnvironmentWithServiceAccount(String user) {
                log.debug("Stopping environment for user {} by scheduler", 
user);
                checkState(user, "stop");
diff --git 
a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/EnvironmentResourceTest.java
 
b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/EnvironmentResourceTest.java
index dad779b..5ac537b 100644
--- 
a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/EnvironmentResourceTest.java
+++ 
b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/EnvironmentResourceTest.java
@@ -20,7 +20,6 @@
 package com.epam.dlab.backendapi.resources;
 
 import com.epam.dlab.auth.UserInfo;
-import com.epam.dlab.backendapi.resources.dto.UserDTO;
 import com.epam.dlab.backendapi.service.EnvironmentService;
 import com.epam.dlab.exceptions.ResourceConflictException;
 import io.dropwizard.auth.AuthenticationException;
@@ -31,12 +30,10 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import java.util.Collections;
-import java.util.List;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -64,43 +61,6 @@ public class EnvironmentResourceTest extends TestBase {
        }
 
        @Test
-       public void getUsersWithActiveEnv() {
-               
when(environmentService.getUsers()).thenReturn(Collections.singletonList(new 
UserDTO("activeUser",
-                               null, UserDTO.Status.ACTIVE)));
-               final Response response = resources.getJerseyTest()
-                               .target("/environment/user")
-                               .request()
-                               .header("Authorization", "Bearer " + TOKEN)
-                               .get();
-
-               assertEquals(HttpStatus.SC_OK, response.getStatus());
-               assertEquals(Collections.singletonList(new 
UserDTO("activeUser", null, UserDTO.Status.ACTIVE)),
-                               response.readEntity(new 
GenericType<List<UserDTO>>() {
-                               }));
-               assertEquals(MediaType.APPLICATION_JSON, 
response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
-               verify(environmentService).getUsers();
-               verifyNoMoreInteractions(environmentService);
-       }
-
-       @Test
-       public void getUsersWithActiveEnvWithFailedAuth() throws 
AuthenticationException {
-               authFailSetup();
-               
when(environmentService.getUsers()).thenReturn(Collections.singletonList(new 
UserDTO("activeUser",
-                               null, UserDTO.Status.ACTIVE)));
-               final Response response = resources.getJerseyTest()
-                               .target("/environment/user")
-                               .request()
-                               .header("Authorization", "Bearer " + TOKEN)
-                               .get();
-
-               assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus());
-               assertEquals(MediaType.APPLICATION_JSON, 
response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
-               verifyZeroInteractions(environmentService);
-       }
-
-       @Test
        public void getAllEnv() {
                UserInfo userInfo = getUserInfo();
                
when(environmentService.getAllEnv(userInfo)).thenReturn(Collections.emptyList());
@@ -134,55 +94,6 @@ public class EnvironmentResourceTest extends TestBase {
        }
 
        @Test
-       public void stopEnv() {
-               
doNothing().when(environmentService).stopEnvironment(any(UserInfo.class), 
anyString(), anyString());
-               final Response response = resources.getJerseyTest()
-                               .target("/environment/stop/projectName")
-                               .request()
-                               .header("Authorization", "Bearer " + TOKEN)
-                               .post(Entity.text(USER));
-
-               assertEquals(HttpStatus.SC_OK, response.getStatus());
-               assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
-               verify(environmentService).stopEnvironment(new UserInfo(USER, 
TOKEN), USER, "projectName");
-               verifyNoMoreInteractions(environmentService);
-       }
-
-       @Test
-       public void stopEnvWithFailedAuth() throws AuthenticationException {
-               authFailSetup();
-               
doNothing().when(environmentService).stopEnvironment(any(UserInfo.class), 
anyString(), anyString());
-               final Response response = resources.getJerseyTest()
-                               .target("/environment/stop/projectName")
-                               .request()
-                               .header("Authorization", "Bearer " + TOKEN)
-                               .post(Entity.text(USER));
-
-               assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus());
-               assertEquals(MediaType.APPLICATION_JSON, 
response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
-               verifyZeroInteractions(environmentService);
-       }
-
-       @Test
-       public void stopEnvWithResourceConflictException() {
-               doThrow(new ResourceConflictException("Can not stop environment 
because one of the user resources is in " +
-                               "status CREATING or 
STARTING")).when(environmentService).stopEnvironment(any(UserInfo.class), 
anyString(), anyString());
-               final Response response = resources.getJerseyTest()
-                               .target("/environment/stop/projectName")
-                               .request()
-                               .header("Authorization", "Bearer " + TOKEN)
-                               .post(Entity.text(USER));
-
-               assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, 
response.getStatus());
-               assertEquals(MediaType.APPLICATION_JSON, 
response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
-               verify(environmentService).stopEnvironment(new UserInfo(USER, 
TOKEN), USER, "projectName");
-               verifyNoMoreInteractions(environmentService);
-       }
-
-       @Test
        public void stopNotebook() {
                
doNothing().when(environmentService).stopExploratory(any(UserInfo.class), 
anyString(), anyString(), anyString());
                final Response response = resources.getJerseyTest()
diff --git 
a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImplTest.java
 
b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImplTest.java
index fc1c2a2..460c2f9 100644
--- 
a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImplTest.java
+++ 
b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImplTest.java
@@ -34,7 +34,6 @@ import com.epam.dlab.dto.UserInstanceDTO;
 import com.epam.dlab.dto.UserInstanceStatus;
 import com.epam.dlab.dto.base.edge.EdgeInfo;
 import com.epam.dlab.exceptions.DlabException;
-import com.epam.dlab.exceptions.ResourceConflictException;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -52,7 +51,6 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.anySet;
 import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.anyVararg;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
@@ -126,51 +124,6 @@ public class EnvironmentServiceImplTest {
 
 
        @Test
-       public void stopEnvironment() {
-               final UserInfo userInfo = getUserInfo();
-               
when(exploratoryDAO.fetchRunningExploratoryFields(anyString())).thenReturn(getUserInstances());
-               when(exploratoryService.stop(any(UserInfo.class), anyString(), 
anyString())).thenReturn(UUID);
-
-               environmentService.stopEnvironment(userInfo, USER, 
PROJECT_NAME);
-
-               verify(exploratoryDAO).fetchRunningExploratoryFields(USER);
-               verify(exploratoryService).stop(refEq(userInfo), 
eq(PROJECT_NAME), eq(EXPLORATORY_NAME_1));
-               verify(exploratoryService).stop(refEq(userInfo), 
eq(PROJECT_NAME), eq(EXPLORATORY_NAME_2));
-               
verify(exploratoryDAO).fetchUserExploratoriesWhereStatusIn(USER, 
Arrays.asList(UserInstanceStatus.CREATING,
-                               UserInstanceStatus.STARTING, 
UserInstanceStatus.CREATING_IMAGE),
-                               UserInstanceStatus.CREATING,
-                               UserInstanceStatus.STARTING, 
UserInstanceStatus.CREATING_IMAGE);
-               verifyNoMoreInteractions(exploratoryDAO, exploratoryService);
-       }
-
-       @Test
-       @SuppressWarnings("unchecked")
-       public void stopEnvironmentWithWrongResourceState() {
-               
when(exploratoryDAO.fetchUserExploratoriesWhereStatusIn(anyString(), 
any(List.class), anyVararg()))
-                               .thenReturn(getUserInstances());
-               expectedException.expect(ResourceConflictException.class);
-
-               environmentService.stopEnvironment(getUserInfo(), USER, 
PROJECT_NAME);
-       }
-
-       @Test
-       public void stopEnvironmentWithoutEdge() {
-               final UserInfo userInfo = getUserInfo();
-               
when(exploratoryDAO.fetchRunningExploratoryFields(anyString())).thenReturn(getUserInstances());
-               when(exploratoryService.stop(any(UserInfo.class), anyString(), 
anyString())).thenReturn(UUID);
-
-               environmentService.stopEnvironment(userInfo, USER, 
PROJECT_NAME);
-
-               verify(exploratoryDAO).fetchRunningExploratoryFields(USER);
-               verify(exploratoryService).stop(refEq(userInfo), 
eq(PROJECT_NAME), eq(EXPLORATORY_NAME_1));
-               verify(exploratoryService).stop(refEq(userInfo), 
eq(PROJECT_NAME), eq(EXPLORATORY_NAME_2));
-               
verify(exploratoryDAO).fetchUserExploratoriesWhereStatusIn(USER, 
Arrays.asList(UserInstanceStatus.CREATING,
-                               UserInstanceStatus.STARTING, 
UserInstanceStatus.CREATING_IMAGE),
-                               UserInstanceStatus.CREATING, 
UserInstanceStatus.STARTING, UserInstanceStatus.CREATING_IMAGE);
-               verifyNoMoreInteractions(envDAO, exploratoryDAO, 
exploratoryService);
-       }
-
-       @Test
        public void stopProjectEnvironment() {
                final UserInfo userInfo = getUserInfo();
                final ProjectDTO projectDTO = getProjectDTO();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to