You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by of...@apache.org on 2019/11/19 10:13:52 UTC
[incubator-dlab] branch DLAB-1284 created (now fdb1840)
This is an automated email from the ASF dual-hosted git repository.
ofuks pushed a change to branch DLAB-1284
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git.
at fdb1840 [DLAB-1284, DLAB-1276] Fixed issues with managing the resource of another user
This branch includes the following new commits:
new fdb1840 [DLAB-1284, DLAB-1276] Fixed issues with managing the resource of another user
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@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org
[incubator-dlab] 01/01: [DLAB-1284,
DLAB-1276] Fixed issues with managing the resource of another user
Posted by of...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ofuks pushed a commit to branch DLAB-1284
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
commit fdb1840eff2858f6bf4305bae9801436d8b1f276
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Tue Nov 19 12:13:25 2019 +0200
[DLAB-1284, DLAB-1276] Fixed issues with managing the resource of another user
---
.../backendapi/resources/EnvironmentResource.java | 12 +--
.../backendapi/service/EnvironmentService.java | 15 ++-
.../service/impl/EnvironmentServiceImpl.java | 52 +++------
.../service/impl/ProjectServiceImpl.java | 10 +-
.../resources/EnvironmentResourceTest.java | 61 +++++------
.../backendapi/resources/ProjectResourceTest.java | 2 +-
.../service/impl/EnvironmentServiceImplTest.java | 116 +++------------------
7 files changed, 76 insertions(+), 192 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 313947e..1bd6826 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
@@ -66,7 +66,7 @@ public class EnvironmentResource {
public Response terminateEnv(@Auth UserInfo userInfo,
@NotEmpty String user) {
log.info("User {} is terminating {} environment", userInfo.getName(), user);
- environmentService.terminateEnvironment(user);
+ environmentService.terminateEnvironment(userInfo, user);
return Response.ok().build();
}
@@ -77,7 +77,7 @@ public class EnvironmentResource {
public Response stopEnv(@Auth UserInfo userInfo,
@NotEmpty String user) {
log.info("User {} is stopping {} environment", userInfo.getName(), user);
- environmentService.stopEnvironment(user);
+ environmentService.stopEnvironment(userInfo, user);
return Response.ok().build();
}
@@ -98,7 +98,7 @@ public class EnvironmentResource {
public Response stopNotebook(@Auth UserInfo userInfo, @NotEmpty String user,
@PathParam("exploratoryName") String exploratoryName) {
log.info("Admin {} is stopping notebook {} of user {}", userInfo.getName(), exploratoryName, user);
- environmentService.stopExploratory(user, exploratoryName);
+ environmentService.stopExploratory(userInfo, user, exploratoryName);
return Response.ok().build();
}
@@ -111,7 +111,7 @@ public class EnvironmentResource {
@PathParam("computationalName") String computationalName) {
log.info("Admin {} is stopping computational resource {} affiliated with exploratory {} of user {}",
userInfo.getName(), computationalName, exploratoryName, user);
- environmentService.stopComputational(user, exploratoryName, computationalName);
+ environmentService.stopComputational(userInfo, user, exploratoryName, computationalName);
return Response.ok().build();
}
@@ -122,7 +122,7 @@ public class EnvironmentResource {
public Response terminateNotebook(@Auth UserInfo userInfo, @NotEmpty String user,
@PathParam("exploratoryName") String exploratoryName) {
log.info("Admin {} is terminating notebook {} of user {}", userInfo.getName(), exploratoryName, user);
- environmentService.terminateExploratory(user, exploratoryName);
+ environmentService.terminateExploratory(userInfo, user, exploratoryName);
return Response.ok().build();
}
@@ -135,7 +135,7 @@ public class EnvironmentResource {
@PathParam("computationalName") String computationalName) {
log.info("Admin {} is terminating computational resource {} affiliated with exploratory {} of user {}",
userInfo.getName(), computationalName, exploratoryName, user);
- environmentService.terminateComputational(user, exploratoryName, computationalName);
+ environmentService.terminateComputational(userInfo, user, exploratoryName, computationalName);
return Response.ok().build();
}
}
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 65953cd..91d0ed7 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
@@ -19,6 +19,7 @@
package com.epam.dlab.backendapi.service;
+import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.resources.dto.UserDTO;
import com.epam.dlab.backendapi.resources.dto.UserResourceInfo;
@@ -35,7 +36,7 @@ public interface EnvironmentService {
void stopAll();
- void stopEnvironment(String user);
+ void stopEnvironment(UserInfo userInfo, String user);
void stopEnvironmentWithServiceAccount(String user);
@@ -43,15 +44,13 @@ public interface EnvironmentService {
void stopEdge(String user);
- void stopExploratory(String user, String exploratoryName);
+ void stopExploratory(UserInfo userInfo, String user, String exploratoryName);
- void stopComputational(String user, String exploratoryName, String computationalName);
+ void stopComputational(UserInfo userInfo, String user, String exploratoryName, String computationalName);
- void terminateAll();
+ void terminateEnvironment(UserInfo userInfo, String user);
- void terminateEnvironment(String user);
+ void terminateExploratory(UserInfo userInfo, String user, String exploratoryName);
- void terminateExploratory(String user, String exploratoryName);
-
- void terminateComputational(String user, String exploratoryName, String computationalName);
+ void terminateComputational(UserInfo userInfo, String user, String exploratoryName, String computationalName);
}
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 09428c4..1d70935 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
@@ -113,11 +113,11 @@ public class EnvironmentServiceImpl implements EnvironmentService {
}
@Override
- public void stopEnvironment(String user) {
+ public void stopEnvironment(UserInfo userInfo, String user) {
log.debug("Stopping environment for user {}", user);
checkState(user, "stop");
exploratoryDAO.fetchRunningExploratoryFields(user)
- .forEach(this::stopNotebook);
+ .forEach(e -> stopExploratory(userInfo, user, e.getExploratoryName()));
stopEdge(user);
}
@@ -151,40 +151,36 @@ public class EnvironmentServiceImpl implements EnvironmentService {
}
@Override
- public void stopExploratory(String user, String exploratoryName) {
- stopNotebook(new UserInstanceDTO().withUser(user).withExploratoryName(exploratoryName));
+ public void stopExploratory(UserInfo userInfo, String user, String exploratoryName) {
+ exploratoryService.stop(new UserInfo(user, userInfo.getAccessToken()), exploratoryName);
}
@Override
- public void stopComputational(String user, String exploratoryName, String computationalName) {
- stopDataengine(user, exploratoryName, computationalName);
+ public void stopComputational(UserInfo userInfo, String user, String exploratoryName, String computationalName) {
+ computationalService.stopSparkCluster(new UserInfo(user, userInfo.getAccessToken()),
+ exploratoryName, computationalName);
}
@Override
- public void terminateAll() {
- log.debug("Terminating environment for all users...");
- getUserNames().forEach(this::terminateEnvironment);
- }
-
- @Override
- public void terminateEnvironment(String user) {
+ public void terminateEnvironment(UserInfo userInfo, String user) {
log.debug("Terminating environment for user {}", user);
checkState(user, "terminate");
if (!terminateEdge(user)) {
exploratoryDAO.fetchUserExploratoriesWhereStatusNotIn(user, UserInstanceStatus.TERMINATED,
UserInstanceStatus.FAILED, UserInstanceStatus.TERMINATING)
- .forEach(this::terminateNotebook);
+ .forEach(e -> terminateExploratory(userInfo, user, e.getExploratoryName()));
}
}
@Override
- public void terminateExploratory(String user, String exploratoryName) {
- terminateNotebook(new UserInstanceDTO().withUser(user).withExploratoryName(exploratoryName));
+ public void terminateExploratory(UserInfo userInfo, String user, String exploratoryName) {
+ exploratoryService.terminate(new UserInfo(user, userInfo.getAccessToken()), exploratoryName);
}
@Override
- public void terminateComputational(String user, String exploratoryName, String computationalName) {
- terminateCluster(user, exploratoryName, computationalName);
+ public void terminateComputational(UserInfo userInfo, String user, String exploratoryName, String computationalName) {
+ computationalService.terminateComputational(new UserInfo(user, userInfo.getAccessToken()), exploratoryName,
+ computationalName);
}
private UserDTO toUserDTO(String u, UserDTO.Status status) {
@@ -204,21 +200,11 @@ public class EnvironmentServiceImpl implements EnvironmentService {
}
}
- private void stopNotebook(UserInstanceDTO instance) {
- final UserInfo userInfo = securityService.getUserInfoOffline(instance.getUser());
- exploratoryService.stop(userInfo, instance.getExploratoryName());
- }
-
private void stopNotebookWithServiceAccount(UserInstanceDTO instance) {
final UserInfo userInfo = securityService.getServiceAccountInfo(instance.getUser());
exploratoryService.stop(userInfo, instance.getExploratoryName());
}
- private void stopDataengine(String user, String exploratoryName, String computationalName) {
- final UserInfo userInfo = securityService.getUserInfoOffline(user);
- computationalService.stopSparkCluster(userInfo, exploratoryName, computationalName);
- }
-
private boolean terminateEdge(String user) {
final boolean nodeExists = keyDAO.edgeNodeExist(user);
if (nodeExists) {
@@ -228,16 +214,6 @@ public class EnvironmentServiceImpl implements EnvironmentService {
return nodeExists;
}
- private void terminateNotebook(UserInstanceDTO instance) {
- final UserInfo userInfo = securityService.getUserInfoOffline(instance.getUser());
- exploratoryService.terminate(userInfo, instance.getExploratoryName());
- }
-
- private void terminateCluster(String user, String exploratoryName, String computationalName) {
- final UserInfo userInfo = securityService.getUserInfoOffline(user);
- computationalService.terminateComputational(userInfo, exploratoryName, computationalName);
- }
-
private List<UserResourceInfo> getProjectEnv(ProjectDTO projectDTO, List<UserInstanceDTO> allInstances) {
final Stream<UserResourceInfo> userResources = allInstances.stream()
.filter(instance -> instance.getProject().equals(projectDTO.getName())).map(this::toUserResourceInfo);
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ProjectServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ProjectServiceImpl.java
index ba15773..8b73cb0 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ProjectServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ProjectServiceImpl.java
@@ -149,7 +149,10 @@ public class ProjectServiceImpl implements ProjectService {
public void stopWithResources(UserInfo userInfo, String projectName) {
ProjectDTO project = get(projectName);
checkProjectRelatedResourcesInProgress(projectName, STOP_ACTION);
- exploratoryDAO.fetchRunningExploratoryFieldsForProject(projectName).forEach(this::stopNotebook);
+
+ exploratoryDAO.fetchRunningExploratoryFieldsForProject(projectName).forEach(e ->
+ exploratoryService.stop(new UserInfo(e.getUser(), userInfo.getAccessToken()), e.getExploratoryName()));
+
project.getEndpoints().stream().filter(e -> !Arrays.asList(UserInstanceStatus.TERMINATED,
UserInstanceStatus.TERMINATING).contains(e.getStatus())).
forEach(e -> stop(userInfo, e.getName(), projectName));
@@ -234,11 +237,6 @@ public class ProjectServiceImpl implements ProjectService {
}
}
- private void stopNotebook(UserInstanceDTO instance) {
- final UserInfo userInfo = securityService.getUserInfoOffline(instance.getUser());
- exploratoryService.stop(userInfo, instance.getExploratoryName());
- }
-
private Supplier<ResourceNotFoundException> projectNotFound() {
return () -> new ResourceNotFoundException("Project with passed name not found");
}
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 4d62744..2cc49a2 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
@@ -19,6 +19,7 @@
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;
@@ -125,7 +126,7 @@ public class EnvironmentResourceTest extends TestBase {
@Test
public void terminateEnv() {
- doNothing().when(environmentService).terminateEnvironment(anyString());
+ doNothing().when(environmentService).terminateEnvironment(any(UserInfo.class), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate")
.request()
@@ -135,14 +136,14 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).terminateEnvironment(USER);
+ verify(environmentService).terminateEnvironment(new UserInfo(USER, TOKEN), USER);
verifyNoMoreInteractions(environmentService);
}
@Test
public void terminateEnvWithFailedAuth() throws AuthenticationException {
authFailSetup();
- doNothing().when(environmentService).terminateEnvironment(anyString());
+ doNothing().when(environmentService).terminateEnvironment(any(UserInfo.class), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate")
.request()
@@ -158,7 +159,7 @@ public class EnvironmentResourceTest extends TestBase {
@Test
public void terminateEnvWithResourceConflictException() {
doThrow(new ResourceConflictException("Can not terminate environment because one of the user resources is in" +
- "status CREATING or STARTING")).when(environmentService).terminateEnvironment(anyString());
+ "status CREATING or STARTING")).when(environmentService).terminateEnvironment(any(UserInfo.class), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate")
.request()
@@ -168,13 +169,13 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).terminateEnvironment(USER);
+ verify(environmentService).terminateEnvironment(new UserInfo(USER, TOKEN), USER);
verifyNoMoreInteractions(environmentService);
}
@Test
public void stopEnv() {
- doNothing().when(environmentService).stopEnvironment(anyString());
+ doNothing().when(environmentService).stopEnvironment(any(UserInfo.class), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop")
.request()
@@ -184,14 +185,14 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).stopEnvironment(USER);
+ verify(environmentService).stopEnvironment(new UserInfo(USER, TOKEN), USER);
verifyNoMoreInteractions(environmentService);
}
@Test
public void stopEnvWithFailedAuth() throws AuthenticationException {
authFailSetup();
- doNothing().when(environmentService).stopEnvironment(anyString());
+ doNothing().when(environmentService).stopEnvironment(any(UserInfo.class), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop")
.request()
@@ -207,7 +208,7 @@ public class EnvironmentResourceTest extends TestBase {
@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(anyString());
+ "status CREATING or STARTING")).when(environmentService).stopEnvironment(any(UserInfo.class), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop")
.request()
@@ -217,7 +218,7 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).stopEnvironment(USER);
+ verify(environmentService).stopEnvironment(new UserInfo(USER, TOKEN), USER);
verifyNoMoreInteractions(environmentService);
}
@@ -272,7 +273,7 @@ public class EnvironmentResourceTest extends TestBase {
@Test
public void stopNotebook() {
- doNothing().when(environmentService).stopExploratory(anyString(), anyString());
+ doNothing().when(environmentService).stopExploratory(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop/explName")
.request()
@@ -282,14 +283,14 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).stopExploratory(USER, "explName");
+ verify(environmentService).stopExploratory(new UserInfo(USER, TOKEN), USER, "explName");
verifyNoMoreInteractions(environmentService);
}
@Test
public void stopNotebookWithFailedAuth() throws AuthenticationException {
authFailSetup();
- doNothing().when(environmentService).stopExploratory(anyString(), anyString());
+ doNothing().when(environmentService).stopExploratory(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop/explName")
.request()
@@ -305,7 +306,7 @@ public class EnvironmentResourceTest extends TestBase {
@Test
public void stopNotebookWithResourceConflictException() {
doThrow(new ResourceConflictException("Can not stop notebook because its status is CREATING or STARTING"))
- .when(environmentService).stopExploratory(anyString(), anyString());
+ .when(environmentService).stopExploratory(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop/explName")
.request()
@@ -315,13 +316,13 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).stopExploratory(USER, "explName");
+ verify(environmentService).stopExploratory(new UserInfo(USER, TOKEN), USER, "explName");
verifyNoMoreInteractions(environmentService);
}
@Test
public void stopCluster() {
- doNothing().when(environmentService).stopComputational(anyString(), anyString(), anyString());
+ doNothing().when(environmentService).stopComputational(any(UserInfo.class), anyString(), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop/explName/compName")
.request()
@@ -331,14 +332,14 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).stopComputational(USER, "explName", "compName");
+ verify(environmentService).stopComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
verifyNoMoreInteractions(environmentService);
}
@Test
public void stopClusterWithFailedAuth() throws AuthenticationException {
authFailSetup();
- doNothing().when(environmentService).stopComputational(anyString(), anyString(), anyString());
+ doNothing().when(environmentService).stopComputational(any(UserInfo.class), anyString(), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop/explName/compName")
.request()
@@ -354,7 +355,7 @@ public class EnvironmentResourceTest extends TestBase {
@Test
public void stopClusterWithResourceConflictException() {
doThrow(new ResourceConflictException("Can not stop cluster because its status is CREATING or STARTING"))
- .when(environmentService).stopComputational(anyString(), anyString(), anyString());
+ .when(environmentService).stopComputational(any(UserInfo.class), anyString(), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/stop/explName/compName")
.request()
@@ -364,13 +365,13 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).stopComputational(USER, "explName", "compName");
+ verify(environmentService).stopComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
verifyNoMoreInteractions(environmentService);
}
@Test
public void terminateNotebook() {
- doNothing().when(environmentService).terminateExploratory(anyString(), anyString());
+ doNothing().when(environmentService).terminateExploratory(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate/explName")
.request()
@@ -380,14 +381,14 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).terminateExploratory(USER, "explName");
+ verify(environmentService).terminateExploratory(new UserInfo(USER, TOKEN), USER, "explName");
verifyNoMoreInteractions(environmentService);
}
@Test
public void terminateNotebookWithFailedAuth() throws AuthenticationException {
authFailSetup();
- doNothing().when(environmentService).terminateExploratory(anyString(), anyString());
+ doNothing().when(environmentService).terminateExploratory(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate/explName")
.request()
@@ -403,7 +404,7 @@ public class EnvironmentResourceTest extends TestBase {
@Test
public void terminateNotebookWithResourceConflictException() {
doThrow(new ResourceConflictException("Can not terminate notebook because its status is CREATING or STARTING"))
- .when(environmentService).terminateExploratory(anyString(), anyString());
+ .when(environmentService).terminateExploratory(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate/explName")
.request()
@@ -413,13 +414,13 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).terminateExploratory(USER, "explName");
+ verify(environmentService).terminateExploratory(new UserInfo(USER, TOKEN), USER, "explName");
verifyNoMoreInteractions(environmentService);
}
@Test
public void terminateCluster() {
- doNothing().when(environmentService).terminateComputational(anyString(), anyString(), anyString());
+ doNothing().when(environmentService).terminateComputational(any(UserInfo.class), anyString(), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate/explName/compName")
.request()
@@ -429,14 +430,14 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).terminateComputational(USER, "explName", "compName");
+ verify(environmentService).terminateComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
verifyNoMoreInteractions(environmentService);
}
@Test
public void terminateClusterWithFailedAuth() throws AuthenticationException {
authFailSetup();
- doNothing().when(environmentService).terminateComputational(anyString(), anyString(), anyString());
+ doNothing().when(environmentService).terminateComputational(any(UserInfo.class), anyString(), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate/explName/compName")
.request()
@@ -452,7 +453,7 @@ public class EnvironmentResourceTest extends TestBase {
@Test
public void terminateClusterWithResourceConflictException() {
doThrow(new ResourceConflictException("Can not terminate cluster because its status is CREATING or STARTING"))
- .when(environmentService).terminateComputational(anyString(), anyString(), anyString());
+ .when(environmentService).terminateComputational(any(UserInfo.class), anyString(), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/environment/terminate/explName/compName")
.request()
@@ -462,7 +463,7 @@ public class EnvironmentResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(environmentService).terminateComputational(USER, "explName", "compName");
+ verify(environmentService).terminateComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
verifyNoMoreInteractions(environmentService);
}
}
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ProjectResourceTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ProjectResourceTest.java
index 3f20967..c1df4c7 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ProjectResourceTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ProjectResourceTest.java
@@ -59,7 +59,7 @@ public class ProjectResourceTest extends TestBase {
.post(Entity.json(""));
assertEquals(HttpStatus.SC_ACCEPTED, response.getStatus());
- verify(projectService, times(1)).stopWithResources(any(UserInfo.class), anyString());
+ verify(projectService).stopWithResources(any(UserInfo.class), anyString());
verifyNoMoreInteractions(projectService);
}
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 1df2245..31ce990 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
@@ -150,10 +150,10 @@ public class EnvironmentServiceImplTest {
when(keyDAO.getEdgeStatus(anyString())).thenReturn(RUNNING_STATE);
when(edgeService.stop(any(UserInfo.class))).thenReturn(UUID);
- environmentService.stopEnvironment(USER);
+ environmentService.stopEnvironment(userInfo, USER);
verify(exploratoryDAO).fetchRunningExploratoryFields(USER);
- verify(securityService, times(3)).getUserInfoOffline(USER);
+ verify(securityService).getUserInfoOffline(USER);
verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1));
verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_2));
verify(keyDAO, times(2)).getEdgeStatus(USER);
@@ -172,7 +172,7 @@ public class EnvironmentServiceImplTest {
.thenReturn(getUserInstances());
expectedException.expect(ResourceConflictException.class);
- environmentService.stopEnvironment(USER);
+ environmentService.stopEnvironment(getUserInfo(), USER);
}
@Test
@@ -180,22 +180,20 @@ public class EnvironmentServiceImplTest {
when(keyDAO.getEdgeStatus(anyString())).thenReturn("starting");
expectedException.expect(ResourceConflictException.class);
- environmentService.stopEnvironment(USER);
+ environmentService.stopEnvironment(getUserInfo(), USER);
}
@Test
public void stopEnvironmentWithoutEdge() {
final UserInfo userInfo = getUserInfo();
when(exploratoryDAO.fetchRunningExploratoryFields(anyString())).thenReturn(getUserInstances());
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn(UUID);
when(keyDAO.getEdgeStatus(anyString())).thenReturn(STOPPED_STATE);
when(edgeService.stop(any(UserInfo.class))).thenReturn(UUID);
- environmentService.stopEnvironment(USER);
+ environmentService.stopEnvironment(userInfo, USER);
verify(exploratoryDAO).fetchRunningExploratoryFields(USER);
- verify(securityService, times(2)).getUserInfoOffline(USER);
verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1));
verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_2));
verify(keyDAO, times(2)).getEdgeStatus(USER);
@@ -260,12 +258,10 @@ public class EnvironmentServiceImplTest {
@Test
public void stopExploratory() {
final UserInfo userInfo = getUserInfo();
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn(UUID);
- environmentService.stopExploratory(USER, EXPLORATORY_NAME_1);
+ environmentService.stopExploratory(new UserInfo(USER, TOKEN), USER, EXPLORATORY_NAME_1);
- verify(securityService).getUserInfoOffline(USER);
verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1));
verifyNoMoreInteractions(securityService, exploratoryService);
}
@@ -273,96 +269,16 @@ public class EnvironmentServiceImplTest {
@Test
public void stopComputational() {
final UserInfo userInfo = getUserInfo();
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
doNothing().when(computationalService).stopSparkCluster(any(UserInfo.class), anyString(), anyString());
- environmentService.stopComputational(USER, EXPLORATORY_NAME_1, "compName");
+ environmentService.stopComputational(userInfo, USER, EXPLORATORY_NAME_1, "compName");
- verify(securityService).getUserInfoOffline(USER);
verify(computationalService).stopSparkCluster(refEq(userInfo), eq(EXPLORATORY_NAME_1), eq("compName"));
verifyNoMoreInteractions(securityService, computationalService);
}
@Test
@SuppressWarnings("unchecked")
- public void terminateAll() {
- doReturn(Collections.singleton(USER)).when(envDAO).fetchAllUsers();
- final UserInfo userInfo = getUserInfo();
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusIn(anyString(), any(List.class), anyVararg()))
- .thenReturn(Collections.emptyList());
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
- when(exploratoryService.terminate(any(UserInfo.class), anyString())).thenReturn(UUID);
- when(keyDAO.edgeNodeExist(anyString())).thenReturn(true);
- when(edgeService.terminate(any(UserInfo.class))).thenReturn(UUID);
-
- environmentService.terminateAll();
-
- verify(envDAO).fetchAllUsers();
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusIn(anyString(), any(List.class), anyVararg());
- verify(securityService).getUserInfoOffline(USER);
- verify(keyDAO).edgeNodeExist(USER);
- verify(edgeService).terminate(refEq(userInfo));
- verify(exploratoryService).updateExploratoryStatuses(USER, UserInstanceStatus.TERMINATING);
- verify(keyDAO).getEdgeStatus(userInfo.getName());
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusIn(USER, Arrays.asList(UserInstanceStatus.CREATING,
- UserInstanceStatus.STARTING, UserInstanceStatus.CREATING_IMAGE),
- UserInstanceStatus.CREATING, UserInstanceStatus.STARTING, UserInstanceStatus.CREATING_IMAGE);
- verifyNoMoreInteractions(keyDAO, envDAO, exploratoryDAO, edgeService, exploratoryService);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void terminateAllWithoutEdge() {
- doReturn(Collections.singleton(USER)).when(envDAO).fetchAllUsers();
- final UserInfo userInfo = getUserInfo();
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusIn(anyString(), any(List.class),
- eq(UserInstanceStatus.CREATING), eq(UserInstanceStatus.STARTING))).thenReturn(Collections.emptyList());
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusNotIn(anyString(), eq(UserInstanceStatus.TERMINATED),
- eq(UserInstanceStatus.FAILED), eq(UserInstanceStatus.TERMINATING))).thenReturn(getUserInstances());
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
- when(exploratoryService.terminate(any(UserInfo.class), anyString())).thenReturn(UUID);
- when(keyDAO.edgeNodeExist(anyString())).thenReturn(false);
- when(edgeService.terminate(any(UserInfo.class))).thenReturn(UUID);
-
- environmentService.terminateAll();
-
- verify(envDAO).fetchAllUsers();
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusNotIn(USER, UserInstanceStatus.TERMINATED,
- UserInstanceStatus.FAILED, UserInstanceStatus.TERMINATING);
- verify(securityService, times(2)).getUserInfoOffline(USER);
- verify(exploratoryService).terminate(refEq(userInfo), eq(EXPLORATORY_NAME_1));
- verify(exploratoryService).terminate(refEq(userInfo), eq(EXPLORATORY_NAME_2));
- verify(keyDAO).edgeNodeExist(USER);
- verify(edgeService, never()).terminate(refEq(userInfo));
- verify(keyDAO).getEdgeStatus(USER);
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusIn(USER, Arrays.asList(UserInstanceStatus.CREATING,
- UserInstanceStatus.STARTING, UserInstanceStatus.CREATING_IMAGE),
- UserInstanceStatus.CREATING, UserInstanceStatus.STARTING, UserInstanceStatus.CREATING_IMAGE);
- verifyNoMoreInteractions(keyDAO, envDAO, exploratoryDAO, edgeService, exploratoryService);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void terminateAllWithWrongResourceState() {
- doReturn(Collections.singleton(USER)).when(envDAO).fetchAllUsers();
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusIn(anyString(), any(List.class), anyVararg()))
- .thenReturn(getUserInstances());
- expectedException.expect(ResourceConflictException.class);
-
- environmentService.terminateAll();
- }
-
- @Test
- public void terminateAllWithEdgeStarting() {
- doReturn(Collections.singleton(USER)).when(envDAO).fetchAllUsers();
- when(keyDAO.getEdgeStatus(anyString())).thenReturn("starting");
- expectedException.expect(ResourceConflictException.class);
-
- environmentService.terminateAll();
- }
-
- @Test
- @SuppressWarnings("unchecked")
public void terminateEnvironment() {
final UserInfo userInfo = getUserInfo();
when(exploratoryDAO.fetchUserExploratoriesWhereStatusIn(anyString(), any(List.class), anyVararg()))
@@ -372,7 +288,7 @@ public class EnvironmentServiceImplTest {
when(keyDAO.edgeNodeExist(anyString())).thenReturn(true);
when(edgeService.terminate(any(UserInfo.class))).thenReturn(UUID);
- environmentService.terminateEnvironment(USER);
+ environmentService.terminateEnvironment(userInfo, USER);
verify(exploratoryDAO).fetchUserExploratoriesWhereStatusIn(anyString(), any(List.class), anyVararg());
verify(securityService).getUserInfoOffline(USER);
@@ -394,16 +310,14 @@ public class EnvironmentServiceImplTest {
eq(UserInstanceStatus.CREATING), eq(UserInstanceStatus.STARTING))).thenReturn(Collections.emptyList());
when(exploratoryDAO.fetchUserExploratoriesWhereStatusNotIn(anyString(), eq(UserInstanceStatus.TERMINATED),
eq(UserInstanceStatus.FAILED), eq(UserInstanceStatus.TERMINATING))).thenReturn(getUserInstances());
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
when(exploratoryService.terminate(any(UserInfo.class), anyString())).thenReturn(UUID);
when(keyDAO.edgeNodeExist(anyString())).thenReturn(false);
when(edgeService.terminate(any(UserInfo.class))).thenReturn(UUID);
- environmentService.terminateEnvironment(USER);
+ environmentService.terminateEnvironment(userInfo, USER);
verify(exploratoryDAO).fetchUserExploratoriesWhereStatusNotIn(USER, UserInstanceStatus.TERMINATED,
UserInstanceStatus.FAILED, UserInstanceStatus.TERMINATING);
- verify(securityService, times(2)).getUserInfoOffline(USER);
verify(exploratoryService).terminate(refEq(userInfo), eq(EXPLORATORY_NAME_1));
verify(exploratoryService).terminate(refEq(userInfo), eq(EXPLORATORY_NAME_2));
verify(keyDAO).edgeNodeExist(USER);
@@ -422,7 +336,7 @@ public class EnvironmentServiceImplTest {
.thenReturn(getUserInstances());
expectedException.expect(ResourceConflictException.class);
- environmentService.terminateEnvironment(USER);
+ environmentService.terminateEnvironment(getUserInfo(), USER);
}
@Test
@@ -430,18 +344,16 @@ public class EnvironmentServiceImplTest {
when(keyDAO.getEdgeStatus(anyString())).thenReturn("starting");
expectedException.expect(ResourceConflictException.class);
- environmentService.terminateEnvironment(USER);
+ environmentService.terminateEnvironment(getUserInfo(), USER);
}
@Test
public void terminateExploratory() {
final UserInfo userInfo = getUserInfo();
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
when(exploratoryService.terminate(any(UserInfo.class), anyString())).thenReturn(UUID);
- environmentService.terminateExploratory(USER, EXPLORATORY_NAME_1);
+ environmentService.terminateExploratory(userInfo, USER, EXPLORATORY_NAME_1);
- verify(securityService).getUserInfoOffline(USER);
verify(exploratoryService).terminate(refEq(userInfo), eq(EXPLORATORY_NAME_1));
verifyNoMoreInteractions(securityService, exploratoryService);
}
@@ -449,13 +361,11 @@ public class EnvironmentServiceImplTest {
@Test
public void terminateComputational() {
final UserInfo userInfo = getUserInfo();
- when(securityService.getUserInfoOffline(anyString())).thenReturn(userInfo);
doNothing().when(computationalService)
.terminateComputational(any(UserInfo.class), anyString(), anyString());
- environmentService.terminateComputational(USER, EXPLORATORY_NAME_1, "compName");
+ environmentService.terminateComputational(userInfo, USER, EXPLORATORY_NAME_1, "compName");
- verify(securityService).getUserInfoOffline(USER);
verify(computationalService)
.terminateComputational(refEq(userInfo), eq(EXPLORATORY_NAME_1), eq("compName"));
verifyNoMoreInteractions(securityService, computationalService);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org