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 2020/02/17 11:39:01 UTC
[incubator-dlab] 01/01: [DLAB-1541] Added project name as a unique
part of the exploratory
This is an automated email from the ASF dual-hosted git repository.
ofuks pushed a commit to branch DLAB-1541
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
commit 01927e5aa4f38121ff7195b7a3b3433ecd69f613
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Mon Feb 17 13:38:16 2020 +0200
[DLAB-1541] Added project name as a unique part of the exploratory
---
.../java/com/epam/dlab/dto/StatusEnvBaseDTO.java | 14 +
.../handlers/ComputationalCallbackHandler.java | 5 +-
.../handlers/ExploratoryCallbackHandler.java | 8 +-
.../resources/base/ExploratoryService.java | 2 +-
.../core/commands/CommandExecutorMockTest.java | 2 +-
.../epam/dlab/backendapi/dao/ComputationalDAO.java | 182 ++--
.../java/com/epam/dlab/backendapi/dao/EnvDAO.java | 74 +-
.../epam/dlab/backendapi/dao/ExploratoryDAO.java | 158 +---
.../dlab/backendapi/dao/ExploratoryLibDAO.java | 60 +-
.../com/epam/dlab/backendapi/dao/IndexCreator.java | 7 +-
.../epam/dlab/backendapi/dao/SchedulerJobDAO.java | 36 +-
.../backendapi/resources/EnvironmentResource.java | 64 +-
.../backendapi/resources/ExploratoryResource.java | 29 +-
.../resources/ImageExploratoryResource.java | 18 +-
.../resources/LibExploratoryResource.java | 31 +-
.../backendapi/resources/SchedulerJobResource.java | 31 +-
.../resources/aws/ComputationalResourceAws.java | 29 +-
.../azure/ComputationalResourceAzure.java | 28 +-
.../callback/CheckInactivityCallback.java | 5 +-
.../resources/callback/ComputationalCallback.java | 15 +-
.../callback/EnvironmentStatusCallback.java | 4 +-
.../resources/callback/ExploratoryCallback.java | 26 +-
.../dto/ExploratoryImageCreateFormDTO.java | 16 +-
.../resources/dto/LibInstallFormDTO.java | 3 +
.../resources/dto/SearchLibsFormDTO.java | 4 +
.../resources/gcp/ComputationalResourceGcp.java | 28 +-
.../backendapi/service/ComputationalService.java | 18 +-
.../backendapi/service/EnvironmentService.java | 11 -
.../backendapi/service/ExploratoryService.java | 26 +-
.../service/ImageExploratoryService.java | 10 +-
.../dlab/backendapi/service/InactivityService.java | 8 +-
.../dlab/backendapi/service/LibraryService.java | 10 +-
.../backendapi/service/SchedulerJobService.java | 106 +--
.../service/impl/ComputationalServiceImpl.java | 88 +-
.../service/impl/EnvironmentServiceImpl.java | 32 +-
.../service/impl/ExploratoryServiceImpl.java | 114 +--
.../service/impl/ImageExploratoryServiceImpl.java | 10 +-
.../service/impl/InactivityServiceImpl.java | 4 +-
.../service/impl/LibraryServiceImpl.java | 50 +-
.../service/impl/ProjectServiceImpl.java | 15 +-
.../service/impl/ReuploadKeyServiceImpl.java | 66 +-
.../service/impl/SchedulerJobServiceImpl.java | 81 +-
.../resources/EnvironmentResourceTest.java | 256 +-----
.../resources/ExploratoryResourceTest.java | 57 +-
.../resources/ImageExploratoryResourceTest.java | 25 +-
.../resources/LibExploratoryResourceTest.java | 602 +++++++------
.../resources/SchedulerJobResourceTest.java | 383 ++++----
.../service/impl/ComputationalServiceImplTest.java | 993 +++++++++++----------
.../service/impl/EnvironmentServiceImplTest.java | 124 +--
.../service/impl/ExploratoryServiceImplTest.java | 585 ++++++------
.../impl/ImageExploratoryServiceImplTest.java | 61 +-
.../service/impl/LibraryServiceImplTest.java | 464 +++++-----
.../service/impl/ReuploadKeyServiceImplTest.java | 49 +-
.../service/impl/SchedulerJobServiceImplTest.java | 250 +++---
54 files changed, 2482 insertions(+), 2895 deletions(-)
diff --git a/services/dlab-model/src/main/java/com/epam/dlab/dto/StatusEnvBaseDTO.java b/services/dlab-model/src/main/java/com/epam/dlab/dto/StatusEnvBaseDTO.java
index 65fb838..16d36be 100644
--- a/services/dlab-model/src/main/java/com/epam/dlab/dto/StatusEnvBaseDTO.java
+++ b/services/dlab-model/src/main/java/com/epam/dlab/dto/StatusEnvBaseDTO.java
@@ -30,6 +30,7 @@ public abstract class StatusEnvBaseDTO<T extends StatusEnvBaseDTO<?>> extends St
private String instanceId;
@JsonProperty("exploratory_name")
private String exploratoryName;
+ private String project;
@JsonProperty("exploratory_id")
private String exploratoryId;
@JsonProperty("exploratory_template_name")
@@ -61,6 +62,19 @@ public abstract class StatusEnvBaseDTO<T extends StatusEnvBaseDTO<?>> extends St
return self;
}
+ public String getProject() {
+ return project;
+ }
+
+ public void setProject(String project) {
+ this.project = project;
+ }
+
+ public T withProject(String project) {
+ setProject(project);
+ return self;
+ }
+
public String getExploratoryId() {
return exploratoryId;
}
diff --git a/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ComputationalCallbackHandler.java b/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ComputationalCallbackHandler.java
index 8ccf260..877cc5a 100644
--- a/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ComputationalCallbackHandler.java
+++ b/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ComputationalCallbackHandler.java
@@ -96,8 +96,9 @@ public class ComputationalCallbackHandler extends ResourceCallbackHandler<Comput
@Override
protected ComputationalStatusDTO getBaseStatusDTO(UserInstanceStatus status) {
return super.getBaseStatusDTO(status)
- .withExploratoryName(dto.getExploratoryName())
- .withComputationalName(dto.getComputationalName());
+ .withExploratoryName(dto.getExploratoryName())
+ .withComputationalName(dto.getComputationalName())
+ .withProject(dto.getProject());
}
private String instanceId(JsonNode jsonNode) {
diff --git a/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ExploratoryCallbackHandler.java b/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ExploratoryCallbackHandler.java
index 62746e8..047ebf9 100644
--- a/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ExploratoryCallbackHandler.java
+++ b/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/core/response/handlers/ExploratoryCallbackHandler.java
@@ -50,14 +50,16 @@ public class ExploratoryCallbackHandler extends ResourceCallbackHandler<Explorat
@JsonProperty
private final String exploratoryName;
+ private final String project;
@JsonCreator
public ExploratoryCallbackHandler(@JacksonInject RESTService selfService,
@JsonProperty("action") DockerAction action,
@JsonProperty("uuid") String uuid, @JsonProperty("user") String user,
- @JsonProperty("exploratoryName") String exploratoryName) {
+ String project, @JsonProperty("exploratoryName") String exploratoryName) {
super(selfService, user, uuid, action);
this.exploratoryName = exploratoryName;
+ this.project = project;
}
@Override
@@ -99,6 +101,8 @@ public class ExploratoryCallbackHandler extends ResourceCallbackHandler<Explorat
@Override
protected ExploratoryStatusDTO getBaseStatusDTO(UserInstanceStatus status) {
- return super.getBaseStatusDTO(status).withExploratoryName(exploratoryName);
+ return super.getBaseStatusDTO(status)
+ .withExploratoryName(exploratoryName)
+ .withProject(project);
}
}
diff --git a/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/resources/base/ExploratoryService.java b/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/resources/base/ExploratoryService.java
index e4d9ecf..b15b342 100644
--- a/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/resources/base/ExploratoryService.java
+++ b/services/provisioning-service/src/main/java/com/epam/dlab/backendapi/resources/base/ExploratoryService.java
@@ -70,7 +70,7 @@ public class ExploratoryService extends DockerService implements DockerCommands
private FileHandlerCallback getFileHandlerCallback(DockerAction action, String uuid, ExploratoryBaseDTO<?> dto) {
return new ExploratoryCallbackHandler(selfService, action, uuid, dto.getCloudSettings().getIamUser(),
- dto.getExploratoryName());
+ dto.getProject(), dto.getExploratoryName());
}
private String nameContainer(String user, DockerAction action, String name) {
diff --git a/services/provisioning-service/src/test/java/com/epam/dlab/backendapi/core/commands/CommandExecutorMockTest.java b/services/provisioning-service/src/test/java/com/epam/dlab/backendapi/core/commands/CommandExecutorMockTest.java
index bf92609..a065248 100644
--- a/services/provisioning-service/src/test/java/com/epam/dlab/backendapi/core/commands/CommandExecutorMockTest.java
+++ b/services/provisioning-service/src/test/java/com/epam/dlab/backendapi/core/commands/CommandExecutorMockTest.java
@@ -70,7 +70,7 @@ public class CommandExecutorMockTest {
RESTServiceMock selfService = new RESTServiceMock();
ExploratoryCallbackHandler handler = new ExploratoryCallbackHandler(selfService, action,
- getRequestId(exec), getEdgeUserName(exec), getExploratoryName(exec));
+ getRequestId(exec), getEdgeUserName(exec), "", getExploratoryName(exec));
handler.handle(exec.getResponseFileName(), Files.readAllBytes(Paths.get(exec.getResponseFileName())));
try {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java
index 311158a..683f8fc 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ComputationalDAO.java
@@ -21,7 +21,11 @@ package com.epam.dlab.backendapi.dao;
import com.epam.dlab.backendapi.util.DateRemoverUtil;
-import com.epam.dlab.dto.*;
+import com.epam.dlab.dto.ResourceURL;
+import com.epam.dlab.dto.SchedulerJobDTO;
+import com.epam.dlab.dto.StatusEnvBaseDTO;
+import com.epam.dlab.dto.UserInstanceDTO;
+import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.aws.computational.ClusterConfig;
import com.epam.dlab.dto.base.DataEngineType;
import com.epam.dlab.dto.computational.ComputationalStatusDTO;
@@ -36,15 +40,30 @@ import org.bson.conversions.Bson;
import java.time.LocalDateTime;
import java.time.ZoneId;
-import java.util.*;
-
-import static com.epam.dlab.backendapi.dao.ExploratoryDAO.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.COMPUTATIONAL_RESOURCES;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.UPTIME;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.exploratoryCondition;
import static com.epam.dlab.backendapi.dao.MongoCollections.USER_INSTANCES;
import static com.epam.dlab.backendapi.dao.SchedulerJobDAO.SCHEDULER_DATA;
import static com.epam.dlab.dto.UserInstanceStatus.TERMINATED;
-import static com.mongodb.client.model.Filters.*;
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.in;
+import static com.mongodb.client.model.Filters.ne;
+import static com.mongodb.client.model.Filters.not;
import static com.mongodb.client.model.Projections.elemMatch;
-import static com.mongodb.client.model.Projections.*;
+import static com.mongodb.client.model.Projections.excludeId;
+import static com.mongodb.client.model.Projections.fields;
+import static com.mongodb.client.model.Projections.include;
import static com.mongodb.client.model.Updates.push;
import static com.mongodb.client.model.Updates.set;
import static java.util.stream.Collectors.toList;
@@ -70,8 +89,8 @@ public class ComputationalDAO extends BaseDAO {
return COMPUTATIONAL_RESOURCES + FIELD_SET_DELIMETER + fieldName;
}
- private static Bson computationalCondition(String user, String exploratoryName, String compName) {
- return and(eq(USER, user), eq(EXPLORATORY_NAME, exploratoryName),
+ private static Bson computationalCondition(String user, String project, String exploratoryName, String compName) {
+ return and(eq(USER, user), eq(PROJECT, project), eq(EXPLORATORY_NAME, exploratoryName),
eq(COMPUTATIONAL_RESOURCES + "." + COMPUTATIONAL_NAME, compName));
}
@@ -80,12 +99,14 @@ public class ComputationalDAO extends BaseDAO {
*
* @param user user name.
* @param exploratoryName name of exploratory.
+ * @param project name of project
* @param computationalDTO object of computational resource.
* @return <b>true</b> if operation was successful, otherwise <b>false</b>.
*/
- public boolean addComputational(String user, String exploratoryName, UserComputationalResource computationalDTO) {
+ public boolean addComputational(String user, String exploratoryName, String project,
+ UserComputationalResource computationalDTO) {
final UpdateResult updateResult = updateOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName),
+ and(exploratoryCondition(user, exploratoryName, project),
not(elemMatch(COMPUTATIONAL_RESOURCES,
eq(COMPUTATIONAL_NAME, computationalDTO.getComputationalName())))),
push(COMPUTATIONAL_RESOURCES, convertToBson(computationalDTO)));
@@ -96,14 +117,15 @@ public class ComputationalDAO extends BaseDAO {
* Finds and returns the of computational resource.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName the name of exploratory.
* @param computationalName name of computational resource.
* @throws DlabException if exception occurs
*/
- public UserComputationalResource fetchComputationalFields(String user, String exploratoryName,
+ public UserComputationalResource fetchComputationalFields(String user, String project, String exploratoryName,
String computationalName) {
Optional<UserInstanceDTO> opt = findOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName),
+ and(exploratoryCondition(user, exploratoryName, project),
Filters.elemMatch(COMPUTATIONAL_RESOURCES, eq(COMPUTATIONAL_NAME, computationalName))),
fields(include(COMPUTATIONAL_RESOURCES + ".$"), excludeId()),
UserInstanceDTO.class);
@@ -114,10 +136,10 @@ public class ComputationalDAO extends BaseDAO {
"exploratory name " + exploratoryName + " not found."));
}
- public List<UserComputationalResource> findComputationalResourcesWithStatus(String user, String exploratoryName,
+ public List<UserComputationalResource> findComputationalResourcesWithStatus(String user, String project, String exploratoryName,
UserInstanceStatus status) {
final UserInstanceDTO userInstanceDTO = findOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName),
+ and(exploratoryCondition(user, exploratoryName, project),
elemMatch(COMPUTATIONAL_RESOURCES, eq(STATUS, status.toString()))),
fields(include(COMPUTATIONAL_RESOURCES), excludeId()),
UserInstanceDTO.class)
@@ -139,7 +161,7 @@ public class ComputationalDAO extends BaseDAO {
try {
Document values = new Document(computationalFieldFilter(STATUS), dto.getStatus());
return updateOne(USER_INSTANCES,
- and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
+ and(exploratoryCondition(dto.getUser(), dto.getExploratoryName(), dto.getProject()),
elemMatch(COMPUTATIONAL_RESOURCES,
and(eq(COMPUTATIONAL_NAME, dto.getComputationalName()),
not(eq(STATUS, TERMINATED.toString()))))),
@@ -162,7 +184,7 @@ public class ComputationalDAO extends BaseDAO {
UpdateResult result;
do {
result = updateOne(USER_INSTANCES,
- and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
+ and(exploratoryCondition(dto.getUser(), dto.getExploratoryName(), dto.getProject()),
elemMatch(COMPUTATIONAL_RESOURCES,
and(not(eq(STATUS, TERMINATED.toString())),
not(eq(STATUS, dto.getStatus()))))),
@@ -174,80 +196,51 @@ public class ComputationalDAO extends BaseDAO {
return count;
}
- public void updateComputationalStatusesForExploratory(String user, String exploratoryName,
+ public void updateComputationalStatusesForExploratory(String user, String project, String exploratoryName,
UserInstanceStatus dataengineStatus,
UserInstanceStatus dataengineServiceStatus,
UserInstanceStatus... excludedStatuses) {
- updateComputationalResource(user, exploratoryName, dataengineStatus, DataEngineType.SPARK_STANDALONE,
- excludedStatuses);
- updateComputationalResource(user, exploratoryName, dataengineServiceStatus, DataEngineType.CLOUD_SERVICE,
- excludedStatuses);
-
- }
-
- /**
- * Updates status for all corresponding computational resources in Mongo database.
- *
- * @param newStatus new status for computational resources.
- * @param user user name.
- * @param exploratoryStatuses exploratory's status list.
- * @param computationalTypes type list of computational resource (may contain 'dataengine' and/or
- * 'dataengine-service').
- * @param oldComputationalStatuses old statuses of computational resources.
- */
-
- public void updateStatusForComputationalResources(UserInstanceStatus newStatus, String user,
- List<UserInstanceStatus> exploratoryStatuses,
- List<DataEngineType> computationalTypes,
- UserInstanceStatus... oldComputationalStatuses) {
-
- List<String> exploratoryNames = stream(find(USER_INSTANCES,
- and(eq(USER, user), in(STATUS, statusList(exploratoryStatuses))),
- fields(include(EXPLORATORY_NAME)))).map(d -> d.getString(EXPLORATORY_NAME))
- .collect(toList());
-
- exploratoryNames.forEach(explName ->
- getComputationalResourcesWhereStatusIn(user, computationalTypes, explName, oldComputationalStatuses)
- .forEach(compName -> updateComputationalField(user, explName, compName,
- STATUS, newStatus.toString()))
- );
+ updateComputationalResource(user, project, exploratoryName, dataengineStatus,
+ DataEngineType.SPARK_STANDALONE, excludedStatuses);
+ updateComputationalResource(user, project, exploratoryName, dataengineServiceStatus,
+ DataEngineType.CLOUD_SERVICE, excludedStatuses);
}
/**
* Updates the status for single computational resource in Mongo database.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName exploratory's name.
* @param computationalName name of computational resource.
* @param newStatus new status of computational resource.
*/
- public void updateStatusForComputationalResource(String user, String exploratoryName,
- String computationalName,
- UserInstanceStatus newStatus) {
- updateComputationalField(user, exploratoryName, computationalName, STATUS, newStatus.toString());
+ public void updateStatusForComputationalResource(String user, String project, String exploratoryName,
+ String computationalName, UserInstanceStatus newStatus) {
+ updateComputationalField(user, project, exploratoryName, computationalName, STATUS, newStatus.toString());
}
- private void updateComputationalResource(String user, String exploratoryName,
+ private void updateComputationalResource(String user, String project, String exploratoryName,
UserInstanceStatus dataengineServiceStatus, DataEngineType cloudService,
UserInstanceStatus... excludedStatuses) {
UpdateResult result;
do {
result = updateMany(USER_INSTANCES,
- computationalFilter(user, exploratoryName, dataengineServiceStatus.toString(),
- DataEngineType.getDockerImageName(cloudService), excludedStatuses),
+ computationalFilter(user, project, exploratoryName,
+ dataengineServiceStatus.toString(), DataEngineType.getDockerImageName(cloudService), excludedStatuses),
new Document(SET,
new Document(computationalFieldFilter(STATUS), dataengineServiceStatus.toString())));
} while (result.getModifiedCount() > 0);
}
- private Bson computationalFilter(String user, String exploratoryName, String computationalStatus, String
- computationalImage, UserInstanceStatus[] excludedStatuses) {
+ private Bson computationalFilter(String user, String project, String exploratoryName, String computationalStatus,
+ String computationalImage, UserInstanceStatus[] excludedStatuses) {
final String[] statuses = Arrays.stream(excludedStatuses)
.map(UserInstanceStatus::toString)
.toArray(String[]::new);
- return and(exploratoryCondition(user, exploratoryName),
+ return and(exploratoryCondition(user, exploratoryName, project),
elemMatch(COMPUTATIONAL_RESOURCES, and(eq(IMAGE, computationalImage),
not(in(STATUS, statuses)),
not(eq(STATUS, computationalStatus)))));
@@ -286,7 +279,7 @@ public class ComputationalDAO extends BaseDAO {
values.append(computationalFieldFilter(CONFIG),
dto.getConfig().stream().map(this::convertToBson).collect(toList()));
}
- return updateOne(USER_INSTANCES, and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
+ return updateOne(USER_INSTANCES, and(exploratoryCondition(dto.getUser(), dto.getExploratoryName(), dto.getProject()),
elemMatch(COMPUTATIONAL_RESOURCES,
and(eq(COMPUTATIONAL_NAME, dto.getComputationalName()),
not(eq(STATUS, TERMINATED.toString()))))),
@@ -309,49 +302,19 @@ public class ComputationalDAO extends BaseDAO {
return map;
}
-
- /**
- * Updates the requirement for reuploading key for all corresponding computational resources in Mongo database.
- *
- * @param user user name.
- * @param exploratoryStatuses exploratory's status list.
- * @param computationalTypes type list of computational resource (may contain 'dataengine' and/or
- * 'dataengine-service').
- * @param reuploadKeyRequired true/false.
- * @param computationalStatuses statuses of computational resource.
- */
-
- public void updateReuploadKeyFlagForComputationalResources(String user,
- List<UserInstanceStatus> exploratoryStatuses,
- List<DataEngineType> computationalTypes,
- boolean reuploadKeyRequired,
- UserInstanceStatus... computationalStatuses) {
-
- List<String> exploratoryNames = stream(find(USER_INSTANCES,
- and(eq(USER, user), in(STATUS, statusList(exploratoryStatuses))),
- fields(include(EXPLORATORY_NAME)))).map(d -> d.getString(EXPLORATORY_NAME))
- .collect(toList());
-
- exploratoryNames.forEach(explName ->
- getComputationalResourcesWhereStatusIn(user, computationalTypes, explName, computationalStatuses)
- .forEach(compName -> updateComputationalField(user, explName, compName,
- REUPLOAD_KEY_REQUIRED, reuploadKeyRequired))
- );
- }
-
/**
* Updates the requirement for reuploading key for single computational resource in Mongo database.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName exploratory's name.
* @param computationalName name of computational resource.
* @param reuploadKeyRequired true/false.
*/
- public void updateReuploadKeyFlagForComputationalResource(String user, String exploratoryName,
- String computationalName, boolean
- reuploadKeyRequired) {
- updateComputationalField(user, exploratoryName, computationalName, REUPLOAD_KEY_REQUIRED, reuploadKeyRequired);
+ public void updateReuploadKeyFlagForComputationalResource(String user, String project, String exploratoryName,
+ String computationalName, boolean reuploadKeyRequired) {
+ updateComputationalField(user, project, exploratoryName, computationalName, REUPLOAD_KEY_REQUIRED, reuploadKeyRequired);
}
/**
@@ -359,6 +322,7 @@ public class ComputationalDAO extends BaseDAO {
* have predefined type.
*
* @param user user name.
+ * @param project project name
* @param computationalTypes type list of computational resource which may contain 'dataengine' and/or
* 'dataengine-service'.
* @param exploratoryName name of exploratory.
@@ -367,10 +331,11 @@ public class ComputationalDAO extends BaseDAO {
*/
@SuppressWarnings("unchecked")
- public List<String> getComputationalResourcesWhereStatusIn(String user, List<DataEngineType> computationalTypes,
+ public List<String> getComputationalResourcesWhereStatusIn(String user, String project,
+ List<DataEngineType> computationalTypes,
String exploratoryName,
UserInstanceStatus... computationalStatuses) {
- return stream((List<Document>) find(USER_INSTANCES, and(eq(USER, user), eq(EXPLORATORY_NAME, exploratoryName)),
+ return stream((List<Document>) find(USER_INSTANCES, exploratoryCondition(user, exploratoryName, project),
fields(include(COMPUTATIONAL_RESOURCES))).first().get(COMPUTATIONAL_RESOURCES))
.filter(doc ->
statusList(computationalStatuses).contains(doc.getString(STATUS)) &&
@@ -379,9 +344,9 @@ public class ComputationalDAO extends BaseDAO {
}
@SuppressWarnings("unchecked")
- public List<ClusterConfig> getClusterConfig(String user, String exploratoryName, String computationalName) {
+ public List<ClusterConfig> getClusterConfig(String user, String project, String exploratoryName, String computationalName) {
return findOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName),
+ and(exploratoryCondition(user, exploratoryName, project),
Filters.elemMatch(COMPUTATIONAL_RESOURCES, and(eq(COMPUTATIONAL_NAME, computationalName),
notNull(CONFIG)))),
fields(include(COMPUTATIONAL_RESOURCES + ".$"), excludeId())
@@ -396,41 +361,42 @@ public class ComputationalDAO extends BaseDAO {
* Updates computational resource's field.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName name of exploratory.
* @param computationalName name of computational resource.
* @param fieldName computational field's name for updating.
* @param fieldValue computational field's value for updating.
*/
- private <T> UpdateResult updateComputationalField(String user, String exploratoryName, String computationalName,
+ private <T> UpdateResult updateComputationalField(String user, String project, String exploratoryName, String computationalName,
String fieldName, T fieldValue) {
return updateOne(USER_INSTANCES,
- computationalCondition(user, exploratoryName, computationalName),
+ computationalCondition(user, project, exploratoryName, computationalName),
set(computationalFieldFilter(fieldName), fieldValue));
}
- public void updateSchedulerSyncFlag(String user, String exploratoryName, boolean syncFlag) {
+ public void updateSchedulerSyncFlag(String user, String project, String exploratoryName, boolean syncFlag) {
final String syncStartField = SCHEDULER_DATA + ".sync_start_required";
UpdateResult result;
do {
- result = updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName),
+ result = updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName, project),
elemMatch(COMPUTATIONAL_RESOURCES, and(ne(SCHEDULER_DATA, null), ne(syncStartField, syncFlag)))),
set(computationalFieldFilter(syncStartField), syncFlag));
} while (result.getModifiedCount() != 0);
}
- public UpdateResult updateSchedulerDataForComputationalResource(String user, String exploratoryName,
+ public UpdateResult updateSchedulerDataForComputationalResource(String user, String project, String exploratoryName,
String computationalName, SchedulerJobDTO dto) {
- return updateComputationalField(user, exploratoryName, computationalName, SCHEDULER_DATA,
- Objects.isNull(dto) ? null : convertToBson(dto));
+ return updateComputationalField(user, project, exploratoryName, computationalName,
+ SCHEDULER_DATA, Objects.isNull(dto) ? null : convertToBson(dto));
}
- public void updateLastActivity(String user, String exploratoryName,
+ public void updateLastActivity(String user, String project, String exploratoryName,
String computationalName, LocalDateTime lastActivity) {
updateOne(USER_INSTANCES,
- computationalCondition(user, exploratoryName, computationalName),
+ computationalCondition(user, project, exploratoryName, computationalName),
set(computationalFieldFilter(COMPUTATIONAL_LAST_ACTIVITY),
Date.from(lastActivity.atZone(ZoneId.systemDefault()).toInstant())));
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EnvDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EnvDAO.java
index 0e85908..ebacc51 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EnvDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EnvDAO.java
@@ -40,18 +40,39 @@ import org.bson.conversions.Bson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
-import static com.epam.dlab.backendapi.dao.ExploratoryDAO.*;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.COMPUTATIONAL_RESOURCES;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.EXPLORATORY_NAME;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.exploratoryCondition;
import static com.epam.dlab.backendapi.dao.MongoCollections.USER_EDGE;
import static com.epam.dlab.backendapi.dao.MongoCollections.USER_INSTANCES;
-import static com.epam.dlab.dto.UserInstanceStatus.*;
-import static com.mongodb.client.model.Filters.*;
+import static com.epam.dlab.dto.UserInstanceStatus.CONFIGURING;
+import static com.epam.dlab.dto.UserInstanceStatus.CREATING;
+import static com.epam.dlab.dto.UserInstanceStatus.FAILED;
+import static com.epam.dlab.dto.UserInstanceStatus.RUNNING;
+import static com.epam.dlab.dto.UserInstanceStatus.STARTING;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPED;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPING;
+import static com.epam.dlab.dto.UserInstanceStatus.TERMINATED;
+import static com.epam.dlab.dto.UserInstanceStatus.TERMINATING;
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.in;
+import static com.mongodb.client.model.Filters.not;
+import static com.mongodb.client.model.Filters.or;
import static com.mongodb.client.model.Projections.elemMatch;
-import static com.mongodb.client.model.Projections.*;
+import static com.mongodb.client.model.Projections.excludeId;
+import static com.mongodb.client.model.Projections.fields;
+import static com.mongodb.client.model.Projections.include;
import static java.util.Objects.nonNull;
/**
@@ -159,17 +180,18 @@ public class EnvDAO extends BaseDAO {
/**
* Updates the status of exploratory and computational for user.
*
- * @param user the name of user.
- * @param list the status of node.
+ * @param user the name of user.
+ * @param project name of project
+ * @param list the status of node.
*/
- public void updateEnvStatus(String user, EnvResourceList list) {
+ public void updateEnvStatus(String user, String project, EnvResourceList list) {
if (list != null && notEmpty(list.getHostList())) {
updateEdgeStatus(user, list.getHostList());
if (!list.getHostList().isEmpty()) {
stream(find(USER_INSTANCES, eq(USER, user),
fields(INCLUDE_EXP_UPDATE_FIELDS, excludeId())))
.filter(this::instanceIdPresent)
- .forEach(exp -> updateUserResourceStatuses(user, list, exp));
+ .forEach(exp -> updateUserResourceStatuses(user, project, list, exp));
}
}
}
@@ -195,26 +217,25 @@ public class EnvDAO extends BaseDAO {
}
@SuppressWarnings("unchecked")
- private void updateUserResourceStatuses(String user, EnvResourceList list, Document exp) {
+ private void updateUserResourceStatuses(String user, String project, EnvResourceList list, Document exp) {
final String exploratoryName = exp.getString(EXPLORATORY_NAME);
getEnvResourceAndRemove(list.getHostList(), exp.getString(INSTANCE_ID))
- .ifPresent(resource -> updateExploratoryStatus(user, exploratoryName, exp.getString(STATUS),
- resource.getStatus()));
+ .ifPresent(resource -> updateExploratoryStatus(user, project, exploratoryName,
+ exp.getString(STATUS), resource.getStatus()));
(getComputationalResources(exp))
.stream()
.filter(this::instanceIdPresent)
- .forEach(comp -> updateComputational(user, list, exploratoryName, comp));
+ .forEach(comp -> updateComputational(user, project, list, exploratoryName, comp));
}
- private void updateComputational(String user, EnvResourceList list, String exploratoryName, Document comp) {
+ private void updateComputational(String user, String project, EnvResourceList list, String exploratoryName, Document comp) {
final List<EnvResource> listToCheck = DataEngineType.CLOUD_SERVICE ==
DataEngineType.fromDockerImageName(comp.getString(IMAGE)) ?
list.getClusterList() : list.getHostList();
getEnvResourceAndRemove(listToCheck, comp.getString(INSTANCE_ID))
- .ifPresent(resource -> updateComputationalStatus(user, exploratoryName,
- comp.getString(ComputationalDAO.COMPUTATIONAL_NAME), comp.getString(STATUS), resource
- .getStatus()));
+ .ifPresent(resource -> updateComputationalStatus(user, project, exploratoryName,
+ comp.getString(ComputationalDAO.COMPUTATIONAL_NAME), comp.getString(STATUS), resource.getStatus()));
}
private boolean instanceIdPresent(Document d) {
@@ -339,11 +360,12 @@ public class EnvDAO extends BaseDAO {
* Update the status of exploratory if it needed.
*
* @param user the user name
+ * @param project project name
* @param exploratoryName the name of exploratory
* @param oldStatus old status
* @param newStatus new status
*/
- private void updateExploratoryStatus(String user, String exploratoryName,
+ private void updateExploratoryStatus(String user, String project, String exploratoryName,
String oldStatus, String newStatus) {
LOGGER.trace("Update exploratory status for user {} with exploratory {} from {} to {}", user, exploratoryName,
oldStatus, newStatus);
@@ -356,7 +378,7 @@ public class EnvDAO extends BaseDAO {
LOGGER.debug("Exploratory status for user {} with exploratory {} will be updated from {} to {}", user,
exploratoryName, oldStatus, status);
updateOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
Updates.set(STATUS, status.toString()));
}
}
@@ -399,12 +421,13 @@ public class EnvDAO extends BaseDAO {
* Update the status of exploratory if it needed.
*
* @param user the user name.
+ * @param project project name
* @param exploratoryName the name of exploratory.
* @param computationalName the name of computational.
* @param oldStatus old status.
* @param newStatus new status.
*/
- private void updateComputationalStatus(String user, String exploratoryName, String computationalName,
+ private void updateComputationalStatus(String user, String project, String exploratoryName, String computationalName,
String oldStatus, String newStatus) {
LOGGER.trace("Update computational status for user {} with exploratory {} and computational {} from {} to {}",
user, exploratoryName, computationalName, oldStatus, newStatus);
@@ -420,12 +443,12 @@ public class EnvDAO extends BaseDAO {
"from {} to {}",
user, exploratoryName, computationalName, oldStatus, status);
if (status == UserInstanceStatus.TERMINATED &&
- terminateComputationalSpot(user, exploratoryName, computationalName)) {
+ terminateComputationalSpot(user, project, exploratoryName, computationalName)) {
return;
}
Document values = new Document(COMPUTATIONAL_STATUS_FILTER, status.toString());
updateOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName),
+ and(exploratoryCondition(user, exploratoryName, project),
elemMatch(COMPUTATIONAL_RESOURCES,
and(eq(ComputationalDAO.COMPUTATIONAL_NAME, computationalName))
)
@@ -438,15 +461,16 @@ public class EnvDAO extends BaseDAO {
* Terminate EMR if it is spot.
*
* @param user the user name.
+ * @param project name of project
* @param exploratoryName the name of exploratory.
* @param computationalName the name of computational.
* @return <b>true</b> if computational is spot and should be terminated by docker, otherwise <b>false</b>.
*/
- private boolean terminateComputationalSpot(String user, String exploratoryName, String computationalName) {
+ private boolean terminateComputationalSpot(String user, String project, String exploratoryName, String computationalName) {
LOGGER.trace("Check computatation is spot for user {} with exploratory {} and computational {}", user,
exploratoryName, computationalName);
Document doc = findOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
and(elemMatch(COMPUTATIONAL_RESOURCES,
and(eq(ComputationalDAO.COMPUTATIONAL_NAME, computationalName),
eq(COMPUTATIONAL_SPOT, true),
@@ -471,7 +495,7 @@ public class EnvDAO extends BaseDAO {
ComputationalResourceAws computational = new ComputationalResourceAws();
SelfServiceApplication.getInjector().injectMembers(computational);
UserInfo ui = new UserInfo(user, accessToken);
- computational.terminate(ui, exploratoryName, computationalName);
+ computational.terminate(ui, project, exploratoryName, computationalName);
} catch (Exception e) {
// Cannot terminate EMR, just update status to terminated
LOGGER.warn("Can't terminate computational for user {} with exploratory {} and computational {}. {}",
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java
index 160ccce..6b14599 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryDAO.java
@@ -61,7 +61,6 @@ import static com.mongodb.client.model.Projections.fields;
import static com.mongodb.client.model.Projections.include;
import static com.mongodb.client.model.Updates.set;
import static java.util.stream.Collectors.toList;
-import static org.apache.commons.lang3.StringUtils.EMPTY;
/**
* DAO for user exploratory.
@@ -91,22 +90,18 @@ public class ExploratoryDAO extends BaseDAO {
log.info("{} is initialized", getClass().getSimpleName());
}
- static Bson exploratoryCondition(String user, String exploratoryName) {
- return and(eq(USER, user), eq(EXPLORATORY_NAME, exploratoryName));
+ static Bson exploratoryCondition(String user, String exploratoryName, String project) {
+ return and(eq(USER, user), eq(PROJECT, project), eq(EXPLORATORY_NAME, exploratoryName));
}
- private Bson exploratoryStatusCondition(String user, UserInstanceStatus... exploratoryStatuses) {
- return and(eq(USER, user), in(STATUS, statusList(exploratoryStatuses)));
- }
-
- private static Bson runningExploratoryCondition(String user, String exploratoryName) {
- return and(eq(USER, user),
+ private static Bson runningExploratoryCondition(String user, String exploratoryName, String project) {
+ return and(eq(USER, user), eq(PROJECT, project),
and(eq(EXPLORATORY_NAME, exploratoryName), eq(STATUS, UserInstanceStatus.RUNNING.toString())));
}
- static Bson runningExploratoryAndComputationalCondition(String user, String exploratoryName, String
- computationalName) {
- return and(eq(USER, user),
+ static Bson runningExploratoryAndComputationalCondition(String user, String project, String exploratoryName,
+ String computationalName) {
+ return and(eq(USER, user), eq(PROJECT, project),
and(eq(EXPLORATORY_NAME, exploratoryName), eq(STATUS, UserInstanceStatus.RUNNING.toString()),
eq(COMPUTATIONAL_RESOURCES + "." + COMPUTATIONAL_NAME, computationalName),
eq(COMPUTATIONAL_RESOURCES + "." + STATUS, UserInstanceStatus.RUNNING.toString())));
@@ -125,20 +120,6 @@ public class ExploratoryDAO extends BaseDAO {
}
/**
- * Finds and returns the unique id for exploratory.
- *
- * @param user user name.
- * @param exploratoryName the name of exploratory.
- */
- public String fetchExploratoryId(String user, String exploratoryName) {
- return findOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
- fields(include(EXPLORATORY_ID), excludeId()))
- .orElse(new Document())
- .getOrDefault(EXPLORATORY_ID, EMPTY).toString();
- }
-
- /**
* Finds and returns the info of all user's running notebooks.
*
* @param user user name.
@@ -156,24 +137,6 @@ public class ExploratoryDAO extends BaseDAO {
}
/**
- * Finds and returns the info of all user's notebooks whose status is present among predefined ones.
- *
- * @param user user name.
- * @param computationalFieldsRequired true/false.
- * @param statuses array of statuses.
- */
- public List<UserInstanceDTO> fetchUserExploratoriesWhereStatusIn(String user, boolean computationalFieldsRequired,
- UserInstanceStatus... statuses) {
- final List<String> statusList = statusList(statuses);
- return getUserInstances(
- and(
- eq(USER, user),
- in(STATUS, statusList)
- ),
- computationalFieldsRequired);
- }
-
- /**
* Finds and returns the info of all user's notebooks whose status or status of affiliated computational resource
* is present among predefined ones.
*
@@ -224,22 +187,6 @@ public class ExploratoryDAO extends BaseDAO {
false);
}
- /**
- * Finds and returns the info of all user's notebooks whose status is absent among predefined ones.
- *
- * @param user user name.
- * @param statuses array of statuses.
- */
- public List<UserInstanceDTO> fetchUserExploratoriesWhereStatusNotIn(String user, UserInstanceStatus... statuses) {
- final List<String> statusList = statusList(statuses);
- return getUserInstances(
- and(
- eq(USER, user),
- not(in(STATUS, statusList))
- ),
- false);
- }
-
public List<UserInstanceDTO> fetchProjectExploratoriesWhereStatusNotIn(String project, String endpoint,
UserInstanceStatus... statuses) {
final List<String> statusList = statusList(statuses);
@@ -295,35 +242,25 @@ public class ExploratoryDAO extends BaseDAO {
* Finds and returns the info of exploratory (without info about computational resources).
*
* @param user user name.
+ * @param project project name
* @param exploratoryName the name of exploratory.
*/
- public UserInstanceDTO fetchExploratoryFields(String user, String exploratoryName) {
- return getExploratory(user, exploratoryName, false).orElseThrow(() ->
+ public UserInstanceDTO fetchExploratoryFields(String user, String project, String exploratoryName) {
+ return getExploratory(user, project, exploratoryName, false).orElseThrow(() ->
new ResourceNotFoundException(String.format(EXPLORATORY_NOT_FOUND_MSG, user, exploratoryName)));
}
- public UserInstanceDTO fetchExploratoryFields(String user, String exploratoryName,
- boolean includeComputationalResources) {
- return getExploratory(user, exploratoryName, includeComputationalResources).orElseThrow(() ->
+ public UserInstanceDTO fetchExploratoryFields(String user, String project, String exploratoryName, boolean includeCompResources) {
+ return getExploratory(user, project, exploratoryName, includeCompResources).orElseThrow(() ->
new ResourceNotFoundException(String.format(EXPLORATORY_NOT_FOUND_MSG, user, exploratoryName)));
}
- /**
- * Checks if exploratory exists.
- *
- * @param user user name.
- * @param exploratoryName the name of exploratory.
- */
- public boolean isExploratoryExist(String user, String exploratoryName) {
- return getExploratory(user, exploratoryName, false).isPresent();
- }
-
- private Optional<UserInstanceDTO> getExploratory(String user, String exploratoryName,
+ private Optional<UserInstanceDTO> getExploratory(String user, String project, String exploratoryName,
boolean includeCompResources) {
return findOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
includeCompResources ? null : fields(exclude(COMPUTATIONAL_RESOURCES)),
UserInstanceDTO.class);
}
@@ -332,12 +269,13 @@ public class ExploratoryDAO extends BaseDAO {
* Finds and returns the info of running exploratory with running cluster.
*
* @param user user name.
+ * @param project name of project
* @param exploratoryName name of exploratory.
* @param computationalName name of cluster
*/
- public UserInstanceDTO fetchExploratoryFields(String user, String exploratoryName, String computationalName) {
+ public UserInstanceDTO fetchExploratoryFields(String user, String project, String exploratoryName, String computationalName) {
return findOne(USER_INSTANCES,
- runningExploratoryAndComputationalCondition(user, exploratoryName, computationalName),
+ runningExploratoryAndComputationalCondition(user, project, exploratoryName, computationalName),
UserInstanceDTO.class)
.orElseThrow(() -> new DlabException(String.format("Running notebook %s with running cluster %s not " +
"found for user %s",
@@ -348,10 +286,11 @@ public class ExploratoryDAO extends BaseDAO {
* Finds and returns the info of running exploratory.
*
* @param user user name.
+ * @param project project
* @param exploratoryName name of exploratory.
*/
- public UserInstanceDTO fetchRunningExploratoryFields(String user, String exploratoryName) {
- return findOne(USER_INSTANCES, runningExploratoryCondition(user, exploratoryName),
+ public UserInstanceDTO fetchRunningExploratoryFields(String user, String project, String exploratoryName) {
+ return findOne(USER_INSTANCES, runningExploratoryCondition(user, exploratoryName, project),
fields(exclude(COMPUTATIONAL_RESOURCES)), UserInstanceDTO.class)
.orElseThrow(() -> new DlabException(
String.format("Running exploratory instance for user %s with name %s not found.",
@@ -375,34 +314,22 @@ public class ExploratoryDAO extends BaseDAO {
*/
public UpdateResult updateExploratoryStatus(StatusEnvBaseDTO<?> dto) {
return updateOne(USER_INSTANCES,
- exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
+ exploratoryCondition(dto.getUser(), dto.getExploratoryName(), dto.getProject()),
set(STATUS, dto.getStatus()));
}
/**
- * Updates the status for all user's corresponding exploratories in Mongo database.
- *
- * @param newExploratoryStatus new status for exploratories.
- * @param user user name.
- * @param oldExploratoryStatuses old statuses of exploratories.
- */
- public void updateStatusForExploratories(UserInstanceStatus newExploratoryStatus, String user,
- UserInstanceStatus... oldExploratoryStatuses) {
- updateMany(USER_INSTANCES, exploratoryStatusCondition(user, oldExploratoryStatuses),
- set(STATUS, newExploratoryStatus.toString()));
- }
-
- /**
* Updates status for single exploratory in Mongo database.
*
* @param user user.
+ * @param project project name
* @param exploratoryName name of exploratory.
* @param newStatus new status of exploratory.
* @return The result of an update operation.
*/
- public UpdateResult updateStatusForExploratory(String user, String exploratoryName, UserInstanceStatus newStatus) {
+ public UpdateResult updateStatusForExploratory(String user, String project, String exploratoryName, UserInstanceStatus newStatus) {
return updateOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
set(STATUS, newStatus.toString()));
}
@@ -410,40 +337,29 @@ public class ExploratoryDAO extends BaseDAO {
* Updates the scheduler's data for exploratory in Mongo database.
*
* @param user user.
+ * @param project name of project
* @param exploratoryName name of exploratory.
* @param dto object of scheduler data.
* @return The result of an update operation.
*/
- public UpdateResult updateSchedulerDataForUserAndExploratory(String user, String exploratoryName,
+ public UpdateResult updateSchedulerDataForUserAndExploratory(String user, String project, String exploratoryName,
SchedulerJobDTO dto) {
return updateOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
set(SCHEDULER_DATA, Objects.isNull(dto) ? null : convertToBson(dto)));
}
/**
- * Updates the requirement for reuploading key for all user's corresponding exploratories in Mongo database.
- *
- * @param user user name.
- * @param reuploadKeyRequired true/false.
- * @param exploratoryStatuses statuses of exploratory.
- */
- public void updateReuploadKeyForExploratories(String user, boolean reuploadKeyRequired,
- UserInstanceStatus... exploratoryStatuses) {
- updateMany(USER_INSTANCES, exploratoryStatusCondition(user, exploratoryStatuses),
- set(REUPLOAD_KEY_REQUIRED, reuploadKeyRequired));
- }
-
- /**
* Updates the requirement for reuploading key for single exploratory in Mongo database.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName exploratory's name
* @param reuploadKeyRequired true/false.
*/
- public void updateReuploadKeyForExploratory(String user, String exploratoryName, boolean reuploadKeyRequired) {
+ public void updateReuploadKeyForExploratory(String user, String project, String exploratoryName, boolean reuploadKeyRequired) {
updateOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
set(REUPLOAD_KEY_REQUIRED, reuploadKeyRequired));
}
@@ -481,7 +397,7 @@ public class ExploratoryDAO extends BaseDAO {
}
).collect(Collectors.toList()));
} else if (dto.getPrivateIp() != null) {
- UserInstanceDTO inst = fetchExploratoryFields(dto.getUser(), dto.getExploratoryName());
+ UserInstanceDTO inst = fetchExploratoryFields(dto.getUser(), dto.getProject(), dto.getExploratoryName());
if (!inst.getPrivateIp().equals(dto.getPrivateIp()) && inst.getResourceUrl() != null) {
values.append(EXPLORATORY_URL, inst.getResourceUrl().stream()
.map(url -> replaceIp(dto.getPrivateIp(), inst, url))
@@ -502,13 +418,13 @@ public class ExploratoryDAO extends BaseDAO {
values.append(CLUSTER_CONFIG, dto.getConfig().stream().map(this::convertToBson).collect(toList()));
}
return updateOne(USER_INSTANCES,
- exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
+ exploratoryCondition(dto.getUser(), dto.getExploratoryName(), dto.getProject()),
new Document(SET, values));
}
- public void updateExploratoryIp(String user, String ip, String exploratoryName) {
+ public void updateExploratoryIp(String user, String project, String ip, String exploratoryName) {
- UserInstanceDTO inst = fetchExploratoryFields(user, exploratoryName);
+ UserInstanceDTO inst = fetchExploratoryFields(user, project, exploratoryName);
if (!inst.getPrivateIp().equals(ip)) {
Document values = new Document();
values.append(EXPLORATORY_PRIVATE_IP, ip);
@@ -519,15 +435,15 @@ public class ExploratoryDAO extends BaseDAO {
}
updateOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
new Document(SET, values));
}
}
@SuppressWarnings("unchecked")
- public List<ClusterConfig> getClusterConfig(String user, String exploratoryName) {
- return findOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), notNull(CLUSTER_CONFIG)),
+ public List<ClusterConfig> getClusterConfig(String user, String project, String exploratoryName) {
+ return findOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName, project), notNull(CLUSTER_CONFIG)),
fields(include(CLUSTER_CONFIG), excludeId()))
.map(d -> convertFromDocument((List<Document>) d.get(CLUSTER_CONFIG),
new TypeReference<List<ClusterConfig>>() {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryLibDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryLibDAO.java
index ebdd028..bcec258 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryLibDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/ExploratoryLibDAO.java
@@ -38,11 +38,16 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static com.epam.dlab.backendapi.dao.ExploratoryDAO.*;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.COMPUTATIONAL_RESOURCES;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.exploratoryCondition;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.runningExploratoryAndComputationalCondition;
import static com.epam.dlab.backendapi.dao.MongoCollections.USER_INSTANCES;
import static com.mongodb.client.model.Filters.and;
import static com.mongodb.client.model.Filters.eq;
-import static com.mongodb.client.model.Projections.*;
+import static com.mongodb.client.model.Projections.elemMatch;
+import static com.mongodb.client.model.Projections.excludeId;
+import static com.mongodb.client.model.Projections.fields;
+import static com.mongodb.client.model.Projections.include;
import static com.mongodb.client.model.Updates.push;
/**
@@ -98,17 +103,17 @@ public class ExploratoryLibDAO extends BaseDAO {
return COMPUTATIONAL_LIBS + "." + computational + FIELD_SET_DELIMETER + fieldName;
}
- private Document findLibraries(String user, String exploratoryName, Bson include) {
+ private Document findLibraries(String user, String project, String exploratoryName, Bson include) {
Optional<Document> opt = findOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
fields(excludeId(), include));
return opt.orElseGet(Document::new);
}
- public List<Library> getLibraries(String user, String exploratoryName) {
- final Document libsDocument = findAllLibraries(user, exploratoryName);
+ public List<Library> getLibraries(String user, String project, String exploratoryName) {
+ final Document libsDocument = findAllLibraries(user, project, exploratoryName);
return Stream
.concat(
libraryStream(libsDocument, exploratoryName, EXPLORATORY_LIBS, ResourceType.EXPLORATORY),
@@ -116,24 +121,23 @@ public class ExploratoryLibDAO extends BaseDAO {
.collect(Collectors.toList());
}
- public Document findAllLibraries(String user, String exploratoryName) {
- return findLibraries(user, exploratoryName, include(EXPLORATORY_LIBS, COMPUTATIONAL_LIBS,
+ public Document findAllLibraries(String user, String project, String exploratoryName) {
+ return findLibraries(user, project, exploratoryName, include(EXPLORATORY_LIBS, COMPUTATIONAL_LIBS,
COMPUTATIONAL_RESOURCES));
}
- public Document findExploratoryLibraries(String user, String exploratoryName) {
- return findLibraries(user, exploratoryName, include(EXPLORATORY_LIBS));
+ public Document findExploratoryLibraries(String user, String project, String exploratoryName) {
+ return findLibraries(user, project, exploratoryName, include(EXPLORATORY_LIBS));
}
- public Document findComputationalLibraries(String user, String exploratoryName, String computationalName) {
- return findLibraries(user, exploratoryName, include(COMPUTATIONAL_LIBS + "." + computationalName));
+ public Document findComputationalLibraries(String user, String project, String exploratoryName, String computationalName) {
+ return findLibraries(user, project, exploratoryName, include(COMPUTATIONAL_LIBS + "." + computationalName));
}
@SuppressWarnings("unchecked")
- public Library getLibrary(String user, String exploratoryName,
- String libraryGroup, String libraryName) {
+ public Library getLibrary(String user, String project, String exploratoryName, String libraryGroup, String libraryName) {
Optional<Document> userInstance = findOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName),
+ and(exploratoryCondition(user, exploratoryName, project),
elemMatch(EXPLORATORY_LIBS,
and(eq(LIB_GROUP, libraryGroup), eq(LIB_NAME, libraryName))
)),
@@ -153,10 +157,10 @@ public class ExploratoryLibDAO extends BaseDAO {
}
@SuppressWarnings("unchecked")
- public Library getLibrary(String user, String exploratoryName, String computationalName,
+ public Library getLibrary(String user, String project, String exploratoryName, String computationalName,
String libraryGroup, String libraryName) {
Optional<Document> libraryStatus = findOne(USER_INSTANCES,
- and(runningExploratoryAndComputationalCondition(user, exploratoryName, computationalName),
+ and(runningExploratoryAndComputationalCondition(user, project, exploratoryName, computationalName),
libraryConditionComputational(computationalName, libraryGroup, libraryName)
),
@@ -184,18 +188,19 @@ public class ExploratoryLibDAO extends BaseDAO {
* Add the user's library for exploratory into database.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName name of exploratory.
* @param library library.
* @return <b>true</b> if operation was successful, otherwise <b>false</b>.
*/
- public boolean addLibrary(String user, String exploratoryName, LibInstallDTO library, boolean reinstall) {
+ public boolean addLibrary(String user, String project, String exploratoryName, LibInstallDTO library, boolean reinstall) {
Optional<Document> opt = findOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName),
+ and(exploratoryCondition(user, exploratoryName, project),
elemMatch(EXPLORATORY_LIBS,
and(eq(LIB_GROUP, library.getGroup()), eq(LIB_NAME, library.getName())))));
if (!opt.isPresent()) {
updateOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
push(EXPLORATORY_LIBS, convertToBson(library)));
return true;
} else {
@@ -205,7 +210,7 @@ public class ExploratoryLibDAO extends BaseDAO {
values.append(libraryFieldFilter(LIB_ERROR_MESSAGE), null);
}
- updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName),
+ updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName, project),
elemMatch(EXPLORATORY_LIBS,
and(eq(LIB_GROUP, library.getGroup()), eq(LIB_NAME, library.getName())))),
new Document(SET, values));
@@ -217,22 +222,23 @@ public class ExploratoryLibDAO extends BaseDAO {
* Add the user's library for exploratory into database.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName name of exploratory.
* @param computationalName name of computational.
* @param library library.
* @return <b>true</b> if operation was successful, otherwise <b>false</b>.
*/
- public boolean addLibrary(String user, String exploratoryName, String computationalName,
+ public boolean addLibrary(String user, String project, String exploratoryName, String computationalName,
LibInstallDTO library, boolean reinstall) {
Optional<Document> opt = findOne(USER_INSTANCES,
- and(runningExploratoryAndComputationalCondition(user, exploratoryName, computationalName),
+ and(runningExploratoryAndComputationalCondition(user, project, exploratoryName, computationalName),
eq(COMPUTATIONAL_LIBS + "." + computationalName + "." + LIB_GROUP, library.getGroup()),
eq(COMPUTATIONAL_LIBS + "." + computationalName + "." + LIB_NAME, library.getName())));
if (!opt.isPresent()) {
updateOne(USER_INSTANCES,
- runningExploratoryAndComputationalCondition(user, exploratoryName, computationalName),
+ runningExploratoryAndComputationalCondition(user, project, exploratoryName, computationalName),
push(COMPUTATIONAL_LIBS + "." + computationalName, convertToBson(library)));
return true;
} else {
@@ -243,7 +249,7 @@ public class ExploratoryLibDAO extends BaseDAO {
}
updateOne(USER_INSTANCES, and(
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
eq(COMPUTATIONAL_LIBS + "." + computationalName + "." + LIB_GROUP, library.getGroup()),
eq(COMPUTATIONAL_LIBS + "." + computationalName + "." + LIB_NAME, library.getName())),
@@ -276,7 +282,7 @@ public class ExploratoryLibDAO extends BaseDAO {
Document values = updateLibraryFields(lib, dto.getUptime());
updateOne(USER_INSTANCES,
- and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
+ and(exploratoryCondition(dto.getUser(), dto.getExploratoryName(), dto.getProject()),
libraryConditionExploratory(lib.getGroup(), lib.getName())),
new Document(SET, values));
} catch (Exception e) {
@@ -292,7 +298,7 @@ public class ExploratoryLibDAO extends BaseDAO {
Document values = updateComputationalLibraryFields(dto.getComputationalName(), lib, dto.getUptime());
updateOne(USER_INSTANCES,
- and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
+ and(exploratoryCondition(dto.getUser(), dto.getExploratoryName(), dto.getProject()),
elemMatch(COMPUTATIONAL_LIBS + "." + dto.getComputationalName(),
libCondition(lib.getGroup(), lib.getName()))),
new Document(SET, values));
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java
index 3d3fb36..f6e8bb6 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/IndexCreator.java
@@ -19,8 +19,8 @@
package com.epam.dlab.backendapi.dao;
-import com.mongodb.BasicDBObject;
import com.mongodb.client.model.IndexOptions;
+import com.mongodb.client.model.Indexes;
import io.dropwizard.lifecycle.Managed;
import static com.epam.dlab.backendapi.dao.ExploratoryDAO.EXPLORATORY_NAME;
@@ -28,12 +28,11 @@ import static com.epam.dlab.backendapi.dao.MongoCollections.USER_INSTANCES;
/** Creates the indexes for mongo collections. */
public class IndexCreator extends BaseDAO implements Managed {
+ private static final String PROJECT_FIELD = "project";
@Override
public void start() {
mongoService.getCollection(USER_INSTANCES)
- .createIndex(new BasicDBObject(USER, 1)
- .append(EXPLORATORY_NAME, 2),
- new IndexOptions().unique(true));
+ .createIndex(Indexes.ascending(USER, EXPLORATORY_NAME, PROJECT_FIELD), new IndexOptions().unique(true));
// TODO: Make refactoring and append indexes for other mongo collections
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SchedulerJobDAO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SchedulerJobDAO.java
index 2fbb299..bfb79c9 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SchedulerJobDAO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SchedulerJobDAO.java
@@ -31,19 +31,35 @@ import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.bson.conversions.Bson;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.epam.dlab.backendapi.dao.ComputationalDAO.COMPUTATIONAL_NAME;
-import static com.epam.dlab.backendapi.dao.ComputationalDAO.PROJECT;
import static com.epam.dlab.backendapi.dao.ComputationalDAO.IMAGE;
-import static com.epam.dlab.backendapi.dao.ExploratoryDAO.*;
+import static com.epam.dlab.backendapi.dao.ComputationalDAO.PROJECT;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.COMPUTATIONAL_RESOURCES;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.EXPLORATORY_NAME;
+import static com.epam.dlab.backendapi.dao.ExploratoryDAO.exploratoryCondition;
import static com.epam.dlab.backendapi.dao.MongoCollections.USER_INSTANCES;
import static com.epam.dlab.dto.base.DataEngineType.fromDockerImageName;
-import static com.mongodb.client.model.Filters.*;
-import static com.mongodb.client.model.Projections.*;
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.exists;
+import static com.mongodb.client.model.Filters.in;
+import static com.mongodb.client.model.Filters.lte;
+import static com.mongodb.client.model.Filters.ne;
+import static com.mongodb.client.model.Filters.or;
+import static com.mongodb.client.model.Projections.excludeId;
+import static com.mongodb.client.model.Projections.fields;
+import static com.mongodb.client.model.Projections.include;
import static java.util.stream.Collectors.toList;
/**
@@ -78,12 +94,13 @@ public class SchedulerJobDAO extends BaseDAO {
* Finds and returns the info of user's single scheduler job by exploratory name.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName the name of exploratory.
* @return scheduler job data.
*/
- public Optional<SchedulerJobDTO> fetchSingleSchedulerJobByUserAndExploratory(String user, String exploratoryName) {
+ public Optional<SchedulerJobDTO> fetchSingleSchedulerJobByUserAndExploratory(String user, String project, String exploratoryName) {
return findOne(USER_INSTANCES,
- and(exploratoryCondition(user, exploratoryName), schedulerNotNullCondition()),
+ and(exploratoryCondition(user, exploratoryName, project), schedulerNotNullCondition()),
fields(include(SCHEDULER_DATA), excludeId()))
.map(d -> convertFromDocument((Document) d.get(SCHEDULER_DATA), SchedulerJobDTO.class));
}
@@ -92,16 +109,17 @@ public class SchedulerJobDAO extends BaseDAO {
* Finds and returns the info of user's single scheduler job for computational resource.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName the name of exploratory.
* @param computationalName the name of computational resource.
* @return scheduler job data.
*/
@SuppressWarnings("unchecked")
- public Optional<SchedulerJobDTO> fetchSingleSchedulerJobForCluster(String user, String exploratoryName,
+ public Optional<SchedulerJobDTO> fetchSingleSchedulerJobForCluster(String user, String project, String exploratoryName,
String computationalName) {
return findOne(USER_INSTANCES,
- exploratoryCondition(user, exploratoryName),
+ exploratoryCondition(user, exploratoryName, project),
fields(include(COMPUTATIONAL_RESOURCES), excludeId()))
.map(d -> (List<Document>) d.get(COMPUTATIONAL_RESOURCES))
.map(list -> list.stream().filter(d -> d.getString(COMPUTATIONAL_NAME).equals(computationalName))
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 f227f3f..879b527 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
@@ -24,10 +24,11 @@ import com.epam.dlab.backendapi.service.EnvironmentService;
import com.google.inject.Inject;
import io.dropwizard.auth.Auth;
import lombok.extern.slf4j.Slf4j;
-import org.hibernate.validator.constraints.NotEmpty;
import javax.annotation.security.RolesAllowed;
-import javax.ws.rs.*;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -58,63 +59,4 @@ public class EnvironmentResource {
log.debug("Admin {} requested information about all user's environment", userInfo.getName());
return Response.ok(environmentService.getAllEnv()).build();
}
-
- @POST
- @Consumes(MediaType.TEXT_PLAIN)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("stop")
- public Response stopEnv(@Auth UserInfo userInfo,
- @NotEmpty String user) {
- log.info("User {} is stopping {} environment", userInfo.getName(), user);
- environmentService.stopEnvironment(userInfo, user);
- return Response.ok().build();
- }
-
- @POST
- @Consumes(MediaType.TEXT_PLAIN)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("stop/{exploratoryName}")
- 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(userInfo, user, exploratoryName);
- return Response.ok().build();
- }
-
- @POST
- @Consumes(MediaType.TEXT_PLAIN)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("stop/{exploratoryName}/{computationalName}")
- public Response stopCluster(@Auth UserInfo userInfo, @NotEmpty String user,
- @PathParam("exploratoryName") String exploratoryName,
- @PathParam("computationalName") String computationalName) {
- log.info("Admin {} is stopping computational resource {} affiliated with exploratory {} of user {}",
- userInfo.getName(), computationalName, exploratoryName, user);
- environmentService.stopComputational(userInfo, user, exploratoryName, computationalName);
- return Response.ok().build();
- }
-
- @POST
- @Consumes(MediaType.TEXT_PLAIN)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("terminate/{exploratoryName}")
- 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(userInfo, user, exploratoryName);
- return Response.ok().build();
- }
-
- @POST
- @Consumes(MediaType.TEXT_PLAIN)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("terminate/{exploratoryName}/{computationalName}")
- public Response terminateCluster(@Auth UserInfo userInfo, @NotEmpty String user,
- @PathParam("exploratoryName") String exploratoryName,
- @PathParam("computationalName") String computationalName) {
- log.info("Admin {} is terminating computational resource {} affiliated with exploratory {} of user {}",
- userInfo.getName(), computationalName, exploratoryName, user);
- environmentService.terminateComputational(userInfo, user, exploratoryName, computationalName);
- return Response.ok().build();
- }
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java
index cb2c7d2..7b29af1 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java
@@ -37,7 +37,14 @@ import lombok.extern.slf4j.Slf4j;
import javax.annotation.security.RolesAllowed;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@@ -109,11 +116,12 @@ public class ExploratoryResource implements ExploratoryAPI {
* @return Invocation response as JSON string.
*/
@DELETE
- @Path("/{name}/stop")
+ @Path("/{project}/{name}/stop")
public String stop(@Auth UserInfo userInfo,
+ @PathParam("project") String project,
@PathParam("name") String name) {
log.debug("Stopping exploratory environment {} for user {}", name, userInfo.getName());
- return exploratoryService.stop(userInfo, name);
+ return exploratoryService.stop(userInfo, project, name);
}
/**
@@ -124,29 +132,32 @@ public class ExploratoryResource implements ExploratoryAPI {
* @return Invocation response as JSON string.
*/
@DELETE
- @Path("/{name}/terminate")
+ @Path("/{project}/{name}/terminate")
public String terminate(@Auth UserInfo userInfo,
+ @PathParam("project") String project,
@PathParam("name") String name) {
log.debug("Terminating exploratory environment {} for user {}", name, userInfo.getName());
- return exploratoryService.terminate(userInfo, name);
+ return exploratoryService.terminate(userInfo, project, name);
}
@PUT
- @Path("/{name}/reconfigure")
+ @Path("/{project}/{name}/reconfigure")
public Response reconfigureSpark(@Auth UserInfo userInfo,
+ @PathParam("project") String project,
@PathParam("name") String name,
List<ClusterConfig> config) {
log.debug("Updating exploratory {} spark cluster for user {}", name, userInfo.getName());
- exploratoryService.updateClusterConfig(userInfo, name, config);
+ exploratoryService.updateClusterConfig(userInfo, project, name, config);
return Response.ok().build();
}
@GET
- @Path("/{name}/cluster/config")
+ @Path("/{project}/{name}/cluster/config")
public Response getClusterConfig(@Auth UserInfo userInfo,
+ @PathParam("project") String project,
@PathParam("name") String name) {
log.debug("Getting exploratory {} spark cluster configuration for user {}", name, userInfo.getName());
- return Response.ok(exploratoryService.getClusterConfig(userInfo, name)).build();
+ return Response.ok(exploratoryService.getClusterConfig(userInfo, project, name)).build();
}
private Exploratory getExploratory(ExploratoryCreateFormDTO formDTO) {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ImageExploratoryResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ImageExploratoryResource.java
index a39a468..f913e2b 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ImageExploratoryResource.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ImageExploratoryResource.java
@@ -30,8 +30,18 @@ import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
-import javax.ws.rs.*;
-import javax.ws.rs.core.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.List;
@@ -58,8 +68,8 @@ public class ImageExploratoryResource {
@Valid @NotNull ExploratoryImageCreateFormDTO formDTO,
@Context UriInfo uriInfo) {
log.debug("Creating an image {} for user {}", formDTO, ui.getName());
- String uuid = imageExploratoryService.createImage(ui, formDTO.getNotebookName(), formDTO.getName(), formDTO
- .getDescription());
+ String uuid = imageExploratoryService.createImage(ui, formDTO.getProjectName(), formDTO.getNotebookName(),
+ formDTO.getName(), formDTO.getDescription());
requestId.put(ui.getName(), uuid);
final URI imageUri = UriBuilder.fromUri(uriInfo.getRequestUri())
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/LibExploratoryResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/LibExploratoryResource.java
index 64ede19..841ed73 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/LibExploratoryResource.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/LibExploratoryResource.java
@@ -41,7 +41,12 @@ import org.hibernate.validator.constraints.NotBlank;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@@ -81,6 +86,7 @@ public class LibExploratoryResource {
@GET
@Path("/lib_groups")
public Iterable<String> getLibGroupList(@Auth UserInfo userInfo,
+ @QueryParam("project_name") @NotBlank String projectName,
@QueryParam("exploratory_name") @NotBlank String exploratoryName,
@QueryParam("computational_name") String computationalName) {
@@ -88,11 +94,11 @@ public class LibExploratoryResource {
exploratoryName, computationalName);
try {
if (StringUtils.isEmpty(computationalName)) {
- UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(),
+ UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), projectName,
exploratoryName);
return ExploratoryLibCache.getCache().getLibGroupList(userInfo, userInstance);
} else {
- UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(),
+ UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), projectName,
exploratoryName, computationalName);
userInstance.setResources(userInstance.getResources().stream()
@@ -120,13 +126,14 @@ public class LibExploratoryResource {
@GET
@Path("/lib_list")
public List<Document> getLibList(@Auth UserInfo userInfo,
+ @QueryParam("project_name") @NotBlank String projectName,
@QueryParam("exploratory_name") @NotBlank String exploratoryName,
@QueryParam("computational_name") String computationalName) {
log.debug("Loading list of libraries for user {} and exploratory {} and computational {}", userInfo.getName(),
exploratoryName, computationalName);
try {
- return libraryService.getLibs(userInfo.getName(), exploratoryName, computationalName);
+ return libraryService.getLibs(userInfo.getName(), projectName, exploratoryName, computationalName);
} catch (Exception t) {
log.error("Cannot load installed libraries for user {} and exploratory {} an", userInfo.getName(),
@@ -147,14 +154,14 @@ public class LibExploratoryResource {
*/
@GET
@Path("/lib_list/formatted")
-
public List<LibInfoRecord> getLibListFormatted(@Auth UserInfo userInfo,
+ @QueryParam("project_name") @NotBlank String projectName,
@QueryParam("exploratory_name") @NotBlank String exploratoryName) {
log.debug("Loading formatted list of libraries for user {} and exploratory {}", userInfo.getName(),
exploratoryName);
try {
- return libraryService.getLibInfo(userInfo.getName(), exploratoryName);
+ return libraryService.getLibInfo(userInfo.getName(), projectName, exploratoryName);
} catch (Exception t) {
log.error("Cannot load list of libraries for user {} and exploratory {}", userInfo.getName(),
exploratoryName, t);
@@ -175,15 +182,16 @@ public class LibExploratoryResource {
public Response libInstall(@Auth UserInfo userInfo,
@Valid @NotNull LibInstallFormDTO formDTO) {
log.debug("Installing libs to environment {} for user {}", formDTO, userInfo.getName());
+ String project = formDTO.getProject();
final String exploratoryName = formDTO.getNotebookName();
final List<LibInstallDTO> libs = formDTO.getLibs();
final String computationalName = formDTO.getComputationalName();
String uuid = StringUtils.isEmpty(computationalName) ?
- libraryService.installExploratoryLibs(userInfo, exploratoryName, libs) :
- libraryService.installComputationalLibs(userInfo, exploratoryName, computationalName, libs);
+ libraryService.installExploratoryLibs(userInfo, project, exploratoryName, libs) :
+ libraryService.installComputationalLibs(userInfo, project, exploratoryName, computationalName, libs);
return Response.ok(uuid)
.build();
- }
+ }
/**
* Returns the list of available libraries for exploratory basing on search conditions provided in @formDTO.
@@ -203,7 +211,7 @@ public class LibExploratoryResource {
if (StringUtils.isNotEmpty(formDTO.getComputationalName())) {
- userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(),
+ userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), formDTO.getProjectName(),
formDTO.getNotebookName(), formDTO.getComputationalName());
userInstance.setResources(userInstance.getResources().stream()
@@ -211,7 +219,8 @@ public class LibExploratoryResource {
.collect(Collectors.toList()));
} else {
- userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), formDTO.getNotebookName());
+ userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), formDTO.getProjectName(),
+ formDTO.getNotebookName());
}
return ExploratoryLibCache.getCache().getLibList(userInfo, userInstance, formDTO.getGroup(), formDTO
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/SchedulerJobResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/SchedulerJobResource.java
index c4f9ee4..dd8f82f 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/SchedulerJobResource.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/SchedulerJobResource.java
@@ -28,7 +28,14 @@ import com.google.inject.Inject;
import io.dropwizard.auth.Auth;
import lombok.extern.slf4j.Slf4j;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -56,12 +63,13 @@ public class SchedulerJobResource {
* @return response
*/
@POST
- @Path("/{exploratoryName}")
+ @Path("/{projectName}/{exploratoryName}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateExploratoryScheduler(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@SchedulerJobDTOValid SchedulerJobDTO dto) {
- schedulerJobService.updateExploratorySchedulerData(userInfo.getName(), exploratoryName, dto);
+ schedulerJobService.updateExploratorySchedulerData(userInfo.getName(), projectName, exploratoryName, dto);
return Response.ok().build();
}
@@ -92,16 +100,17 @@ public class SchedulerJobResource {
* @return response
*/
@POST
- @Path("/{exploratoryName}/{computationalName}")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateComputationalScheduler(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName,
@SchedulerJobDTOValid SchedulerJobDTO dto) {
- schedulerJobService.updateComputationalSchedulerData(userInfo.getName(), exploratoryName,
+ schedulerJobService.updateComputationalSchedulerData(userInfo.getName(), projectName, exploratoryName,
computationalName, dto);
return Response.ok().build();
- }
+ }
/**
* Updates computational resource <code>computationalName<code/> affiliated with exploratory
@@ -132,13 +141,14 @@ public class SchedulerJobResource {
* @return scheduler job data
*/
@GET
- @Path("/{exploratoryName}")
+ @Path("/{projectName}/{exploratoryName}")
@Produces(MediaType.APPLICATION_JSON)
public Response fetchSchedulerJobForUserAndExploratory(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName) {
log.debug("Loading scheduler job for user {} and exploratory {}...", userInfo.getName(), exploratoryName);
final SchedulerJobDTO schedulerJob =
- schedulerJobService.fetchSchedulerJobForUserAndExploratory(userInfo.getName(), exploratoryName);
+ schedulerJobService.fetchSchedulerJobForUserAndExploratory(userInfo.getName(), projectName, exploratoryName);
return Response.ok(schedulerJob).build();
}
@@ -152,15 +162,16 @@ public class SchedulerJobResource {
* @return scheduler job data
*/
@GET
- @Path("/{exploratoryName}/{computationalName}")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}")
@Produces(MediaType.APPLICATION_JSON)
public Response fetchSchedulerJobForComputationalResource(@Auth UserInfo userInfo,
@PathParam("exploratoryName") String exploratoryName,
+ @PathParam("projectName") String projectName,
@PathParam("computationalName") String computationalName) {
log.debug("Loading scheduler job for user {}, exploratory {} and computational resource {}...",
userInfo.getName(), exploratoryName, computationalName);
final SchedulerJobDTO schedulerJob = schedulerJobService
- .fetchSchedulerJobForComputationalResource(userInfo.getName(), exploratoryName, computationalName);
+ .fetchSchedulerJobForComputationalResource(userInfo.getName(), projectName, exploratoryName, computationalName);
return Response.ok(schedulerJob).build();
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/aws/ComputationalResourceAws.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/aws/ComputationalResourceAws.java
index d2ed15d..c324f60 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/aws/ComputationalResourceAws.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/aws/ComputationalResourceAws.java
@@ -34,13 +34,18 @@ import com.epam.dlab.exceptions.DlabException;
import com.epam.dlab.rest.contracts.ComputationalAPI;
import com.google.inject.Inject;
import io.dropwizard.auth.Auth;
-import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@@ -133,13 +138,14 @@ public class ComputationalResourceAws implements ComputationalAPI {
* @return 200 OK if operation is successfully triggered
*/
@DELETE
- @Path("/{exploratoryName}/{computationalName}/terminate")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}/terminate")
public Response terminate(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
log.debug("Terminating computational resource {} for user {}", computationalName, userInfo.getName());
- computationalService.terminateComputational(userInfo, exploratoryName, computationalName);
+ computationalService.terminateComputational(userInfo, projectName, exploratoryName, computationalName);
return Response.ok().build();
}
@@ -155,14 +161,15 @@ public class ComputationalResourceAws implements ComputationalAPI {
@DELETE
@Path("/{project}/{exploratoryName}/{computationalName}/stop")
public Response stop(@Auth UserInfo userInfo,
+ @PathParam("project") String project,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
log.debug("Stopping computational resource {} for user {}", computationalName, userInfo.getName());
- computationalService.stopSparkCluster(userInfo, exploratoryName, computationalName);
+ computationalService.stopSparkCluster(userInfo, project, exploratoryName, computationalName);
return Response.ok().build();
- }
+ }
/**
* Sends request to provisioning service for starting the computational resource for user.
@@ -186,22 +193,24 @@ public class ComputationalResourceAws implements ComputationalAPI {
}
@PUT
- @Path("dataengine/{exploratoryName}/{computationalName}/config")
+ @Path("dataengine/{projectName}/{exploratoryName}/{computationalName}/config")
public Response updateDataEngineConfig(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName,
@Valid @NotNull List<ClusterConfig> config) {
- computationalService.updateSparkClusterConfig(userInfo, exploratoryName, computationalName, config);
+ computationalService.updateSparkClusterConfig(userInfo, projectName, exploratoryName, computationalName, config);
return Response.ok().build();
}
@GET
- @Path("{exploratoryName}/{computationalName}/config")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}/config")
public Response getClusterConfig(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
- return Response.ok(computationalService.getClusterConfig(userInfo, exploratoryName, computationalName)).build();
+ return Response.ok(computationalService.getClusterConfig(userInfo, projectName, exploratoryName, computationalName)).build();
}
private void validate(SparkStandaloneClusterCreateForm form) {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/azure/ComputationalResourceAzure.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/azure/ComputationalResourceAzure.java
index 1ba09d8..56db8ff 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/azure/ComputationalResourceAzure.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/azure/ComputationalResourceAzure.java
@@ -40,7 +40,13 @@ import lombok.extern.slf4j.Slf4j;
import javax.annotation.security.RolesAllowed;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@@ -105,14 +111,15 @@ public class ComputationalResourceAzure {
* @return 200 OK if operation is successfully triggered
*/
@DELETE
- @Path("/{exploratoryName}/{computationalName}/terminate")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}/terminate")
public Response terminate(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
log.debug("Terminating computational resource {} for user {}", computationalName, userInfo.getName());
- computationalService.terminateComputational(userInfo, exploratoryName, computationalName);
+ computationalService.terminateComputational(userInfo, projectName, exploratoryName, computationalName);
return Response.ok().build();
}
@@ -127,12 +134,13 @@ public class ComputationalResourceAzure {
*/
@DELETE
@Path("/{project}/{exploratoryName}/{computationalName}/stop")
- public Response stop( @Auth UserInfo userInfo,
+ public Response stop(@Auth UserInfo userInfo,
+ @PathParam("project") String project,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
log.debug("Stopping computational resource {} for user {}", computationalName, userInfo.getName());
- computationalService.stopSparkCluster(userInfo, exploratoryName, computationalName);
+ computationalService.stopSparkCluster(userInfo, project, exploratoryName, computationalName);
return Response.ok().build();
}
@@ -159,21 +167,23 @@ public class ComputationalResourceAzure {
}
@PUT
- @Path("dataengine/{exploratoryName}/{computationalName}/config")
+ @Path("dataengine/{projectName}/{exploratoryName}/{computationalName}/config")
public Response updateDataEngineConfig(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName,
@Valid @NotNull List<ClusterConfig> config) {
- computationalService.updateSparkClusterConfig(userInfo, exploratoryName, computationalName, config);
+ computationalService.updateSparkClusterConfig(userInfo, projectName, exploratoryName, computationalName, config);
return Response.ok().build();
}
@GET
- @Path("{exploratoryName}/{computationalName}/config")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}/config")
public Response getClusterConfig(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
- return Response.ok(computationalService.getClusterConfig(userInfo, exploratoryName, computationalName)).build();
+ return Response.ok(computationalService.getClusterConfig(userInfo, projectName, exploratoryName, computationalName)).build();
}
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/CheckInactivityCallback.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/CheckInactivityCallback.java
index 111bcfa..abf4c6d 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/CheckInactivityCallback.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/CheckInactivityCallback.java
@@ -58,9 +58,8 @@ public class CheckInactivityCallback {
@Path("computational")
public Response updateComputationalLastActivity(CheckInactivityStatusDTO dto) {
requestId.checkAndRemove(dto.getRequestId());
- inactivityService.updateLastActivityForComputational(new UserInfo(dto.getUser(), null),
- dto.getExploratoryName(),
- dto.getComputationalName(), toLocalDateTime(dto.getLastActivityUnixTime()));
+ inactivityService.updateLastActivityForComputational(new UserInfo(dto.getUser(), null), null,
+ dto.getExploratoryName(), dto.getComputationalName(), toLocalDateTime(dto.getLastActivityUnixTime()));
return Response.ok().build();
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ComputationalCallback.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ComputationalCallback.java
index 04ca8fb..b60f34c 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ComputationalCallback.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ComputationalCallback.java
@@ -19,7 +19,6 @@
package com.epam.dlab.backendapi.resources.callback;
-import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.dao.ComputationalDAO;
import com.epam.dlab.backendapi.domain.RequestId;
import com.epam.dlab.backendapi.service.ComputationalService;
@@ -29,7 +28,6 @@ import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.computational.ComputationalStatusDTO;
import com.epam.dlab.dto.computational.UserComputationalResource;
import com.epam.dlab.exceptions.DlabException;
-import com.epam.dlab.model.ResourceData;
import com.epam.dlab.rest.contracts.ApiCallbacks;
import com.google.inject.Inject;
import lombok.extern.slf4j.Slf4j;
@@ -42,8 +40,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Date;
-import static com.epam.dlab.dto.UserInstanceStatus.RUNNING;
-
@Path("/infrastructure_provision/computational_resources")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -75,11 +71,12 @@ public class ComputationalCallback {
String uuid = dto.getRequestId();
requestId.checkAndRemove(uuid);
- UserComputationalResource compResource = computationalService.getComputationalResource(dto.getUser(),
- dto.getExploratoryName(), dto.getComputationalName()).orElseThrow(() ->
- new DlabException("Computational resource " + dto.getComputationalName() +
- " of exploratory environment " + dto.getExploratoryName() + " for user " + dto.getUser() +
- " doesn't exist"));
+ UserComputationalResource compResource = computationalService.getComputationalResource(dto.getUser(), dto.getProject(),
+ dto.getExploratoryName(), dto.getComputationalName())
+ .orElseThrow(() ->
+ new DlabException("Computational resource " + dto.getComputationalName() +
+ " of exploratory environment " + dto.getExploratoryName() + " for user " + dto.getUser() +
+ " doesn't exist"));
log.debug("Current status for computational resource {} of exploratory environment {} for user {} is {}",
dto.getComputationalName(), dto.getExploratoryName(), dto.getUser(),
compResource.getStatus());
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/EnvironmentStatusCallback.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/EnvironmentStatusCallback.java
index 618fb04..d4c059e 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/EnvironmentStatusCallback.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/EnvironmentStatusCallback.java
@@ -20,14 +20,12 @@
package com.epam.dlab.backendapi.resources.callback;
import com.epam.dlab.backendapi.dao.EnvDAO;
-import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.domain.RequestId;
import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.status.EnvStatusDTO;
import com.epam.dlab.exceptions.DlabException;
import com.epam.dlab.rest.contracts.ApiCallbacks;
import com.google.inject.Inject;
-import io.dropwizard.auth.Auth;
import lombok.extern.slf4j.Slf4j;
import javax.ws.rs.Consumes;
@@ -63,7 +61,7 @@ public class EnvironmentStatusCallback {
if (UserInstanceStatus.FAILED == UserInstanceStatus.of(dto.getStatus())) {
log.warn("Request for the status of resources for user {} fails: {}", dto.getUser(), dto.getErrorMessage());
} else {
- envDAO.updateEnvStatus(dto.getUser(), dto.getResourceList());
+ envDAO.updateEnvStatus(dto.getUser(), null, dto.getResourceList());
}
} catch (DlabException e) {
log.warn("Could not update status of resources for user {}: {}", dto.getUser(), e.getLocalizedMessage(), e);
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ExploratoryCallback.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ExploratoryCallback.java
index 8e11c0b..c275a18 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ExploratoryCallback.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/callback/ExploratoryCallback.java
@@ -41,7 +41,11 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Date;
-import static com.epam.dlab.dto.UserInstanceStatus.*;
+import static com.epam.dlab.dto.UserInstanceStatus.FAILED;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPED;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPING;
+import static com.epam.dlab.dto.UserInstanceStatus.TERMINATED;
+import static com.epam.dlab.dto.UserInstanceStatus.TERMINATING;
@Path("/infrastructure_provision/exploratory_environment")
@@ -78,7 +82,7 @@ public class ExploratoryCallback {
dto.getExploratoryName(), dto.getUser(), dto.getStatus());
requestId.checkAndRemove(dto.getRequestId());
- UserInstanceDTO instance = exploratoryService.getUserInstance(dto.getUser(), dto.getExploratoryName())
+ UserInstanceDTO instance = exploratoryService.getUserInstance(dto.getUser(), dto.getProject(), dto.getExploratoryName())
.orElseThrow(() -> new DlabException(String.format(USER_INSTANCE_NOT_EXIST_MSG,
dto.getExploratoryName(), dto.getUser())));
@@ -89,15 +93,15 @@ public class ExploratoryCallback {
try {
exploratoryDAO.updateExploratoryFields(dto.withLastActivity(new Date()));
if (currentStatus == TERMINATING) {
- updateComputationalStatuses(dto.getUser(), dto.getExploratoryName(),
+ updateComputationalStatuses(dto.getUser(), dto.getProject(), dto.getExploratoryName(),
UserInstanceStatus.of(dto.getStatus()));
} else if (currentStatus == STOPPING) {
- updateComputationalStatuses(dto.getUser(), dto.getExploratoryName(),
+ updateComputationalStatuses(dto.getUser(), dto.getProject(), dto.getExploratoryName(),
UserInstanceStatus.of(dto.getStatus()), TERMINATED, FAILED, TERMINATED, STOPPED);
}
} catch (DlabException e) {
- log.error("Could not update status for exploratory environment {} for user {} to {}",
- dto.getExploratoryName(), dto.getUser(), dto.getStatus(), e);
+ log.error("Could not update status for exploratory environment {} in project {} for user {} to {}",
+ dto.getExploratoryName(), dto.getProject(), dto.getUser(), dto.getStatus(), e);
throw new DlabException("Could not update status for exploratory environment " + dto.getExploratoryName() +
" for user " + dto.getUser() + " to " + dto.getStatus() + ": " + e.getLocalizedMessage(), e);
}
@@ -109,23 +113,25 @@ public class ExploratoryCallback {
* Updates the computational status of exploratory environment.
*
* @param user user name
+ * @param project project name
* @param exploratoryName name of exploratory environment.
* @param status status for exploratory environment.
*/
- private void updateComputationalStatuses(String user, String exploratoryName, UserInstanceStatus status) {
+ private void updateComputationalStatuses(String user, String project, String exploratoryName, UserInstanceStatus status) {
log.debug("updating status for all computational resources of {} for user {}: {}", exploratoryName, user,
status);
computationalDAO.updateComputationalStatusesForExploratory(new ExploratoryStatusDTO()
.withUser(user)
.withExploratoryName(exploratoryName)
+ .withProject(project)
.withStatus(status));
}
- private void updateComputationalStatuses(String user, String exploratoryName, UserInstanceStatus
+ private void updateComputationalStatuses(String user, String project, String exploratoryName, UserInstanceStatus
dataEngineStatus, UserInstanceStatus dataEngineServiceStatus, UserInstanceStatus... excludedStatuses) {
log.debug("updating status for all computational resources of {} for user {}: DataEngine {}, " +
"dataengine-service {}", exploratoryName, user, dataEngineStatus, dataEngineServiceStatus);
- computationalDAO.updateComputationalStatusesForExploratory(user, exploratoryName, dataEngineStatus,
- dataEngineServiceStatus, excludedStatuses);
+ computationalDAO.updateComputationalStatusesForExploratory(user, project, exploratoryName,
+ dataEngineStatus, dataEngineServiceStatus, excludedStatuses);
}
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryImageCreateFormDTO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryImageCreateFormDTO.java
index 9c3eb30..14193f2 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryImageCreateFormDTO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryImageCreateFormDTO.java
@@ -27,11 +27,13 @@ import org.hibernate.validator.constraints.NotBlank;
@Data
@ToString
public class ExploratoryImageCreateFormDTO {
-
- @NotBlank
- @JsonProperty("exploratory_name")
- private String notebookName;
- @NotBlank
- private final String name;
- private final String description;
+ @NotBlank
+ private final String name;
+ @NotBlank
+ @JsonProperty("exploratory_name")
+ private String notebookName;
+ @NotBlank
+ @JsonProperty("project_name")
+ private String projectName;
+ private final String description;
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/LibInstallFormDTO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/LibInstallFormDTO.java
index 1a3b8a8..c2b8d1a 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/LibInstallFormDTO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/LibInstallFormDTO.java
@@ -39,6 +39,9 @@ public class LibInstallFormDTO {
@JsonProperty("computational_name")
private String computationalName;
+ @JsonProperty("project_name")
+ private String project;
+
@NotEmpty
@JsonProperty
private List<LibInstallDTO> libs;
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/SearchLibsFormDTO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/SearchLibsFormDTO.java
index f817c4e..ff6edb6 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/SearchLibsFormDTO.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/SearchLibsFormDTO.java
@@ -30,6 +30,10 @@ public class SearchLibsFormDTO {
private String notebookName;
@NotBlank
+ @JsonProperty("project_name")
+ private String projectName;
+
+ @NotBlank
@JsonProperty
private String group;
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/gcp/ComputationalResourceGcp.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/gcp/ComputationalResourceGcp.java
index 43fca4a..36636a6 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/gcp/ComputationalResourceGcp.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/gcp/ComputationalResourceGcp.java
@@ -39,7 +39,13 @@ import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@@ -134,13 +140,14 @@ public class ComputationalResourceGcp implements ComputationalAPI {
* @return 200 OK if operation is successfully triggered
*/
@DELETE
- @Path("/{exploratoryName}/{computationalName}/terminate")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}/terminate")
public Response terminate(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
log.debug("Terminating computational resource {} for user {}", computationalName, userInfo.getName());
- computationalService.terminateComputational(userInfo, exploratoryName, computationalName);
+ computationalService.terminateComputational(userInfo, projectName, exploratoryName, computationalName);
return Response.ok().build();
}
@@ -156,14 +163,15 @@ public class ComputationalResourceGcp implements ComputationalAPI {
@DELETE
@Path("/{project}/{exploratoryName}/{computationalName}/stop")
public Response stop(@Auth UserInfo userInfo,
+ @PathParam("project") String project,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
log.debug("Stopping computational resource {} for user {}", computationalName, userInfo.getName());
- computationalService.stopSparkCluster(userInfo, exploratoryName, computationalName);
+ computationalService.stopSparkCluster(userInfo, project, exploratoryName, computationalName);
return Response.ok().build();
- }
+ }
/**
* Sends request to provisioning service for starting the computational resource for user.
@@ -187,22 +195,24 @@ public class ComputationalResourceGcp implements ComputationalAPI {
}
@PUT
- @Path("dataengine/{exploratoryName}/{computationalName}/config")
+ @Path("dataengine/{projectName}/{exploratoryName}/{computationalName}/config")
public Response updateDataEngineConfig(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName,
@Valid @NotNull List<ClusterConfig> config) {
- computationalService.updateSparkClusterConfig(userInfo, exploratoryName, computationalName, config);
+ computationalService.updateSparkClusterConfig(userInfo, projectName, exploratoryName, computationalName, config);
return Response.ok().build();
}
@GET
- @Path("{exploratoryName}/{computationalName}/config")
+ @Path("/{projectName}/{exploratoryName}/{computationalName}/config")
public Response getClusterConfig(@Auth UserInfo userInfo,
+ @PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName) {
- return Response.ok(computationalService.getClusterConfig(userInfo, exploratoryName, computationalName)).build();
+ return Response.ok(computationalService.getClusterConfig(userInfo, projectName, exploratoryName, computationalName)).build();
}
private void validate(@Auth UserInfo userInfo, GcpComputationalCreateForm formDTO) {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ComputationalService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ComputationalService.java
index 217e18e..f686b59 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ComputationalService.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ComputationalService.java
@@ -22,9 +22,7 @@ package com.epam.dlab.backendapi.service;
import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.resources.dto.ComputationalCreateFormDTO;
import com.epam.dlab.backendapi.resources.dto.SparkStandaloneClusterCreateForm;
-import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.aws.computational.ClusterConfig;
-import com.epam.dlab.dto.base.DataEngineType;
import com.epam.dlab.dto.computational.UserComputationalResource;
import java.util.List;
@@ -46,29 +44,25 @@ public interface ComputationalService {
* Asynchronously triggers termination of computational resources
*
* @param userInfo user info of authenticated user
+ * @param project project name
* @param exploratoryName name of exploratory where to terminate computational resources with
* <code>computationalName</code>
* @param computationalName computational name
*/
- void terminateComputational(UserInfo userInfo, String exploratoryName, String computationalName);
+ void terminateComputational(UserInfo userInfo, String project, String exploratoryName, String computationalName);
boolean createDataEngineService(UserInfo userInfo, ComputationalCreateFormDTO formDTO, UserComputationalResource
computationalResource, String project);
- void stopSparkCluster(UserInfo userInfo, String exploratoryName, String computationalName);
+ void stopSparkCluster(UserInfo userInfo, String project, String exploratoryName, String computationalName);
void startSparkCluster(UserInfo userInfo, String exploratoryName, String computationalName, String project);
- void updateSparkClusterConfig(UserInfo userInfo, String exploratoryName, String computationalName,
+ void updateSparkClusterConfig(UserInfo userInfo, String project, String exploratoryName, String computationalName,
List<ClusterConfig> config);
- void updateComputationalsReuploadKeyFlag(String user, List<UserInstanceStatus> exploratoryStatuses,
- List<DataEngineType> computationalTypes,
- boolean reuploadKeyRequired,
- UserInstanceStatus... computationalStatuses);
-
- Optional<UserComputationalResource> getComputationalResource(String user, String exploratoryName,
+ Optional<UserComputationalResource> getComputationalResource(String user, String project, String exploratoryName,
String computationalName);
- List<ClusterConfig> getClusterConfig(UserInfo userInfo, String exploratoryName, String computationalName);
+ List<ClusterConfig> getClusterConfig(UserInfo userInfo, String project, String exploratoryName, String computationalName);
}
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 5ef7cae..de4dcb3 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,7 +19,6 @@
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;
@@ -36,17 +35,7 @@ public interface EnvironmentService {
void stopAll();
- void stopEnvironment(UserInfo userInfo, String user);
-
void stopEnvironmentWithServiceAccount(String user);
void stopProjectEnvironment(String project);
-
- void stopExploratory(UserInfo userInfo, String user, String exploratoryName);
-
- void stopComputational(UserInfo userInfo, String user, String exploratoryName, String computationalName);
-
- void terminateExploratory(UserInfo userInfo, String user, String exploratoryName);
-
- void terminateComputational(UserInfo userInfo, String user, String exploratoryName, String computationalName);
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ExploratoryService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ExploratoryService.java
index 4348819..2b93a8e 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ExploratoryService.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ExploratoryService.java
@@ -32,29 +32,21 @@ import java.util.Optional;
public interface ExploratoryService {
- String start(UserInfo userInfo, String exploratoryName, String project);
+ String start(UserInfo userInfo, String exploratoryName, String project);
- String stop(UserInfo userInfo, String exploratoryName);
+ String stop(UserInfo userInfo, String project, String exploratoryName);
- String terminate(UserInfo userInfo, String exploratoryName);
+ String terminate(UserInfo userInfo, String project, String exploratoryName);
- String create(UserInfo userInfo, Exploratory exploratory, String project);
+ String create(UserInfo userInfo, Exploratory exploratory, String project);
- void updateExploratoryStatuses(String user, UserInstanceStatus status);
+ void updateProjectExploratoryStatuses(String project, String endpoint, UserInstanceStatus status);
- void updateProjectExploratoryStatuses(String project, String endpoint, UserInstanceStatus status);
+ void updateClusterConfig(UserInfo userInfo, String project, String exploratoryName, List<ClusterConfig> config);
- void updateExploratoriesReuploadKeyFlag(String user, boolean reuploadKeyRequired,
- UserInstanceStatus... exploratoryStatuses);
+ Optional<UserInstanceDTO> getUserInstance(String user, String project, String exploratoryName);
- List<UserInstanceDTO> getInstancesWithStatuses(String user, UserInstanceStatus exploratoryStatus,
- UserInstanceStatus computationalStatus);
+ List<ClusterConfig> getClusterConfig(UserInfo user, String project, String exploratoryName);
- void updateClusterConfig(UserInfo userInfo, String exploratoryName, List<ClusterConfig> config);
-
- Optional<UserInstanceDTO> getUserInstance(String user, String exploratoryName);
-
- List<ClusterConfig> getClusterConfig(UserInfo user, String exploratoryName);
-
- ExploratoryCreatePopUp getUserInstances(UserInfo user);
+ ExploratoryCreatePopUp getUserInstances(UserInfo user);
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ImageExploratoryService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ImageExploratoryService.java
index 5091c97..604bdcf 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ImageExploratoryService.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/ImageExploratoryService.java
@@ -27,13 +27,13 @@ import java.util.List;
public interface ImageExploratoryService {
- String createImage(UserInfo user, String exploratoryName, String imageName, String imageDescription);
+ String createImage(UserInfo user, String project, String exploratoryName, String imageName, String imageDescription);
- void finishImageCreate(Image image, String exploratoryName, String newNotebookIp);
+ void finishImageCreate(Image image, String exploratoryName, String newNotebookIp);
- List<ImageInfoRecord> getNotFailedImages(String user, String dockerImage, String project, String endpoint);
+ List<ImageInfoRecord> getNotFailedImages(String user, String dockerImage, String project, String endpoint);
- ImageInfoRecord getImage(String user, String name, String project, String endpoint);
+ ImageInfoRecord getImage(String user, String name, String project, String endpoint);
- List<ImageInfoRecord> getImagesForProject(String project);
+ List<ImageInfoRecord> getImagesForProject(String project);
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/InactivityService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/InactivityService.java
index 7b5cd44..038a7b6 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/InactivityService.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/InactivityService.java
@@ -24,10 +24,10 @@ import java.time.LocalDateTime;
public interface InactivityService {
- void updateRunningResourcesLastActivity();
+ void updateRunningResourcesLastActivity();
- void updateLastActivityForExploratory(UserInfo userInfo, String exploratoryName, LocalDateTime lastActivity);
+ void updateLastActivityForExploratory(UserInfo userInfo, String exploratoryName, LocalDateTime lastActivity);
- void updateLastActivityForComputational(UserInfo userInfo, String exploratoryName,
- String computationalName, LocalDateTime lastActivity);
+ void updateLastActivityForComputational(UserInfo userInfo, String project, String exploratoryName,
+ String computationalName, LocalDateTime lastActivity);
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/LibraryService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/LibraryService.java
index 5b98293..bdd22f1 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/LibraryService.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/LibraryService.java
@@ -27,12 +27,12 @@ import org.bson.Document;
import java.util.List;
public interface LibraryService {
- List<Document> getLibs(String user, String exploratoryName, String computationalName);
+ List<Document> getLibs(String user, String project, String exploratoryName, String computationalName);
- List<LibInfoRecord> getLibInfo(String user, String exploratoryName);
+ List<LibInfoRecord> getLibInfo(String user, String project, String exploratoryName);
- String installComputationalLibs(UserInfo userInfo, String exploratoryName, String computationalName,
- List<LibInstallDTO> libs);
+ String installComputationalLibs(UserInfo userInfo, String project, String exploratoryName, String computationalName,
+ List<LibInstallDTO> libs);
- String installExploratoryLibs(UserInfo userInfo, String exploratoryName, List<LibInstallDTO> libs);
+ String installExploratoryLibs(UserInfo userInfo, String project, String exploratoryName, List<LibInstallDTO> libs);
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SchedulerJobService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SchedulerJobService.java
index 1059db0..7702601 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SchedulerJobService.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SchedulerJobService.java
@@ -25,57 +25,61 @@ import com.epam.dlab.model.scheduler.SchedulerJobData;
import java.util.List;
public interface SchedulerJobService {
- /**
- * Pulls out scheduler job data for user <code>user<code/> and his exploratory <code>exploratoryName<code/>
- *
- * @param user user's name
- * @param exploratoryName name of exploratory resource
- * @return dto object
- */
- SchedulerJobDTO fetchSchedulerJobForUserAndExploratory(String user, String exploratoryName);
-
- /**
- * Pulls out scheduler job data for computational resource <code>computationalName<code/> affiliated with
- * user <code>user<code/> and his exploratory <code>exploratoryName<code/>
- *
- * @param user user's name
- * @param exploratoryName name of exploratory resource
- * @param computationalName name of computational resource
- * @return dto object
- */
- SchedulerJobDTO fetchSchedulerJobForComputationalResource(String user, String exploratoryName,
- String computationalName);
-
- /**
- * Updates scheduler job data for user <code>user<code/> and his exploratory <code>exploratoryName<code/>
- *
- * @param user user's name
- * @param exploratoryName name of exploratory resource
- * @param dto scheduler job data
- */
- void updateExploratorySchedulerData(String user, String exploratoryName, SchedulerJobDTO dto);
-
- /**
- * Updates scheduler job data for computational resource <code>computationalName<code/> affiliated with
- * user <code>user<code/> and his exploratory <code>exploratoryName<code/>
- *
- * @param user user's name
- * @param exploratoryName name of exploratory resource
- * @param computationalName name of computational resource
- * @param dto scheduler job data
- */
- void updateComputationalSchedulerData(String user, String exploratoryName,
- String computationalName, SchedulerJobDTO dto);
-
- void stopComputationalByScheduler();
-
- void stopExploratoryByScheduler();
-
- void startExploratoryByScheduler();
-
- void startComputationalByScheduler();
-
- void terminateExploratoryByScheduler();
+ /**
+ * Pulls out scheduler job data for user <code>user<code/> and his exploratory <code>exploratoryName<code/>
+ *
+ * @param user user's name
+ * @param project project name
+ * @param exploratoryName name of exploratory resource
+ * @return dto object
+ */
+ SchedulerJobDTO fetchSchedulerJobForUserAndExploratory(String user, String project, String exploratoryName);
+
+ /**
+ * Pulls out scheduler job data for computational resource <code>computationalName<code/> affiliated with
+ * user <code>user<code/> and his exploratory <code>exploratoryName<code/>
+ *
+ * @param user user's name
+ * @param project project name
+ * @param exploratoryName name of exploratory resource
+ * @param computationalName name of computational resource
+ * @return dto object
+ */
+ SchedulerJobDTO fetchSchedulerJobForComputationalResource(String user, String project, String exploratoryName,
+ String computationalName);
+
+ /**
+ * Updates scheduler job data for user <code>user<code/> and his exploratory <code>exploratoryName<code/>
+ *
+ * @param user user's name
+ * @param project project name
+ * @param exploratoryName name of exploratory resource
+ * @param dto scheduler job data
+ */
+ void updateExploratorySchedulerData(String user, String project, String exploratoryName, SchedulerJobDTO dto);
+
+ /**
+ * Updates scheduler job data for computational resource <code>computationalName<code/> affiliated with
+ * user <code>user<code/> and his exploratory <code>exploratoryName<code/>
+ *
+ * @param user user's name
+ * @param project project name
+ * @param exploratoryName name of exploratory resource
+ * @param computationalName name of computational resource
+ * @param dto scheduler job data
+ */
+ void updateComputationalSchedulerData(String user, String project, String exploratoryName,
+ String computationalName, SchedulerJobDTO dto);
+
+ void stopComputationalByScheduler();
+
+ void stopExploratoryByScheduler();
+
+ void startExploratoryByScheduler();
+
+ void startComputationalByScheduler();
+
+ void terminateExploratoryByScheduler();
void terminateComputationalByScheduler();
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImpl.java
index 52decf8..ca48eae 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImpl.java
@@ -41,7 +41,11 @@ import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.aws.computational.ClusterConfig;
import com.epam.dlab.dto.base.DataEngineType;
import com.epam.dlab.dto.base.computational.ComputationalBase;
-import com.epam.dlab.dto.computational.*;
+import com.epam.dlab.dto.computational.ComputationalClusterConfigDTO;
+import com.epam.dlab.dto.computational.ComputationalStatusDTO;
+import com.epam.dlab.dto.computational.ComputationalTerminateDTO;
+import com.epam.dlab.dto.computational.SparkStandaloneClusterResource;
+import com.epam.dlab.dto.computational.UserComputationalResource;
import com.epam.dlab.exceptions.DlabException;
import com.epam.dlab.exceptions.ResourceNotFoundException;
import com.epam.dlab.rest.client.RESTService;
@@ -56,7 +60,12 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
-import static com.epam.dlab.dto.UserInstanceStatus.*;
+import static com.epam.dlab.dto.UserInstanceStatus.CREATING;
+import static com.epam.dlab.dto.UserInstanceStatus.FAILED;
+import static com.epam.dlab.dto.UserInstanceStatus.RECONFIGURING;
+import static com.epam.dlab.dto.UserInstanceStatus.STARTING;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPING;
+import static com.epam.dlab.dto.UserInstanceStatus.TERMINATING;
import static com.epam.dlab.dto.base.DataEngineType.CLOUD_SERVICE;
import static com.epam.dlab.dto.base.DataEngineType.SPARK_STANDALONE;
import static com.epam.dlab.rest.contracts.ComputationalAPI.COMPUTATIONAL_CREATE_CLOUD_SPECIFIC;
@@ -103,11 +112,11 @@ public class ComputationalServiceImpl implements ComputationalService {
final ProjectDTO projectDTO = projectService.get(project);
final UserInstanceDTO instance =
- exploratoryDAO.fetchExploratoryFields(userInfo.getName(), form.getNotebookName());
+ exploratoryDAO.fetchExploratoryFields(userInfo.getName(), project, form.getNotebookName());
final SparkStandaloneClusterResource compResource = createInitialComputationalResource(form);
compResource.setTags(tagService.getResourceTags(userInfo, instance.getEndpoint(), project,
form.getCustomTag()));
- if (computationalDAO.addComputational(userInfo.getName(), form.getNotebookName(), compResource)) {
+ if (computationalDAO.addComputational(userInfo.getName(), form.getNotebookName(), project, compResource)) {
try {
EndpointDTO endpointDTO = endpointService.get(instance.getEndpoint());
ComputationalBase<?> dto = requestBuilder.newComputationalCreate(userInfo, projectDTO, instance, form, endpointDTO);
@@ -119,7 +128,7 @@ public class ComputationalServiceImpl implements ComputationalService {
return true;
} catch (RuntimeException e) {
try {
- updateComputationalStatus(userInfo.getName(), form.getNotebookName(), form.getName(), FAILED);
+ updateComputationalStatus(userInfo.getName(), project, form.getNotebookName(), form.getName(), FAILED);
} catch (DlabException d) {
log.error(COULD_NOT_UPDATE_THE_STATUS_MSG_FORMAT, form.getName(), userInfo.getName(), d);
}
@@ -133,15 +142,15 @@ public class ComputationalServiceImpl implements ComputationalService {
}
@Override
- public void terminateComputational(UserInfo userInfo, String exploratoryName, String computationalName) {
+ public void terminateComputational(UserInfo userInfo, String project, String exploratoryName, String computationalName) {
try {
- updateComputationalStatus(userInfo.getName(), exploratoryName, computationalName, TERMINATING);
+ updateComputationalStatus(userInfo.getName(), project, exploratoryName, computationalName, TERMINATING);
- final UserInstanceDTO userInstanceDTO = exploratoryDAO.fetchExploratoryFields(userInfo.getName(),
+ final UserInstanceDTO userInstanceDTO = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), project,
exploratoryName);
- UserComputationalResource compResource = computationalDAO.fetchComputationalFields(userInfo
- .getName(), exploratoryName, computationalName);
+ UserComputationalResource compResource = computationalDAO.fetchComputationalFields(userInfo.getName(), project,
+ exploratoryName, computationalName);
final DataEngineType dataEngineType = compResource.getDataEngineType();
EndpointDTO endpointDTO = endpointService.get(userInstanceDTO.getEndpoint());
@@ -156,7 +165,7 @@ public class ComputationalServiceImpl implements ComputationalService {
} catch (RuntimeException re) {
try {
- updateComputationalStatus(userInfo.getName(), exploratoryName, computationalName, FAILED);
+ updateComputationalStatus(userInfo.getName(), project, exploratoryName, computationalName, FAILED);
} catch (DlabException e) {
log.error(COULD_NOT_UPDATE_THE_STATUS_MSG_FORMAT, computationalName, userInfo.getName(), e);
}
@@ -171,12 +180,12 @@ public class ComputationalServiceImpl implements ComputationalService {
UserComputationalResource computationalResource, @Project String project) {
final ProjectDTO projectDTO = projectService.get(project);
- final UserInstanceDTO instance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), formDTO
+ final UserInstanceDTO instance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), project, formDTO
.getNotebookName());
final Map<String, String> tags = tagService.getResourceTags(userInfo, instance.getEndpoint(), project,
formDTO.getCustomTag());
computationalResource.setTags(tags);
- boolean isAdded = computationalDAO.addComputational(userInfo.getName(), formDTO.getNotebookName(),
+ boolean isAdded = computationalDAO.addComputational(userInfo.getName(), formDTO.getNotebookName(), project,
computationalResource);
if (isAdded) {
@@ -191,8 +200,8 @@ public class ComputationalServiceImpl implements ComputationalService {
return true;
} catch (Exception t) {
try {
- updateComputationalStatus(userInfo.getName(), formDTO.getNotebookName(), formDTO.getName(),
- FAILED);
+ updateComputationalStatus(userInfo.getName(), project, formDTO.getNotebookName(),
+ formDTO.getName(), FAILED);
} catch (DlabException e) {
log.error(COULD_NOT_UPDATE_THE_STATUS_MSG_FORMAT, formDTO.getName(), userInfo.getName(), e);
}
@@ -206,12 +215,12 @@ public class ComputationalServiceImpl implements ComputationalService {
}
@Override
- public void stopSparkCluster(UserInfo userInfo, String expName, String compName) {
- final UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), expName, true);
+ public void stopSparkCluster(UserInfo userInfo, String project, String expName, String compName) {
+ final UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), project, expName, true);
final UserInstanceStatus requiredStatus = UserInstanceStatus.RUNNING;
if (computationalWithStatusResourceExist(compName, userInstance, requiredStatus)) {
log.debug("{} spark cluster {} for userInstance {}", STOPPING.toString(), compName, expName);
- updateComputationalStatus(userInfo.getName(), expName, compName, STOPPING);
+ updateComputationalStatus(userInfo.getName(), project, expName, compName, STOPPING);
EndpointDTO endpointDTO = endpointService.get(userInstance.getEndpoint());
final String uuid =
provisioningService.post(endpointDTO.getUrl() + ComputationalAPI.COMPUTATIONAL_STOP_SPARK,
@@ -230,11 +239,11 @@ public class ComputationalServiceImpl implements ComputationalService {
@Override
public void startSparkCluster(UserInfo userInfo, String expName, String compName, @Project String project) {
final UserInstanceDTO userInstance =
- exploratoryDAO.fetchExploratoryFields(userInfo.getName(), expName, true);
+ exploratoryDAO.fetchExploratoryFields(userInfo.getName(), project, expName, true);
final UserInstanceStatus requiredStatus = UserInstanceStatus.STOPPED;
if (computationalWithStatusResourceExist(compName, userInstance, requiredStatus)) {
log.debug("{} spark cluster {} for userInstance {}", STARTING.toString(), compName, expName);
- updateComputationalStatus(userInfo.getName(), expName, compName, STARTING);
+ updateComputationalStatus(userInfo.getName(), project, expName, compName, STARTING);
EndpointDTO endpointDTO = endpointService.get(userInstance.getEndpoint());
final String uuid =
provisioningService.post(endpointDTO.getUrl() + ComputationalAPI.COMPUTATIONAL_START_SPARK,
@@ -249,12 +258,12 @@ public class ComputationalServiceImpl implements ComputationalService {
}
@Override
- public void updateSparkClusterConfig(UserInfo userInfo, String exploratoryName, String computationalName,
+ public void updateSparkClusterConfig(UserInfo userInfo, String project, String exploratoryName, String computationalName,
List<ClusterConfig> config) {
final String userName = userInfo.getName();
final String token = userInfo.getAccessToken();
final UserInstanceDTO userInstanceDTO = exploratoryDAO
- .fetchExploratoryFields(userName, exploratoryName, true);
+ .fetchExploratoryFields(userName, project, exploratoryName, true);
final UserComputationalResource compResource = userInstanceDTO
.getResources()
.stream()
@@ -269,6 +278,7 @@ public class ComputationalServiceImpl implements ComputationalService {
provisioningService.post(endpointDTO.getUrl() + ComputationalAPI.COMPUTATIONAL_RECONFIGURE_SPARK,
token, clusterConfigDto, String.class);
computationalDAO.updateComputationalFields(new ComputationalStatusDTO()
+ .withProject(userInstanceDTO.getProject())
.withComputationalName(computationalName)
.withExploratoryName(exploratoryName)
.withConfig(config)
@@ -279,37 +289,19 @@ public class ComputationalServiceImpl implements ComputationalService {
}
/**
- * Updates parameter 'reuploadKeyRequired' for corresponding user's computational resources with allowable statuses
- * which are affiliated with exploratories with theirs allowable statuses.
- *
- * @param user user.
- * @param exploratoryStatuses allowable exploratories' statuses.
- * @param computationalTypes type list of computational resource.
- * @param reuploadKeyRequired true/false.
- * @param computationalStatuses allowable statuses for computational resources.
- */
- @Override
- public void updateComputationalsReuploadKeyFlag(String user, List<UserInstanceStatus> exploratoryStatuses,
- List<DataEngineType> computationalTypes,
- boolean reuploadKeyRequired,
- UserInstanceStatus... computationalStatuses) {
- computationalDAO.updateReuploadKeyFlagForComputationalResources(user, exploratoryStatuses, computationalTypes,
- reuploadKeyRequired, computationalStatuses);
- }
-
- /**
* Returns computational resource's data by name for user's exploratory.
*
- * @param user user.
+ * @param user user
+ * @param project name of project
* @param exploratoryName name of exploratory.
* @param computationalName name of computational resource.
* @return corresponding computational resource's data or empty data if resource doesn't exist.
*/
@Override
- public Optional<UserComputationalResource> getComputationalResource(String user, String exploratoryName,
+ public Optional<UserComputationalResource> getComputationalResource(String user, String project, String exploratoryName,
String computationalName) {
try {
- return Optional.of(computationalDAO.fetchComputationalFields(user, exploratoryName, computationalName));
+ return Optional.of(computationalDAO.fetchComputationalFields(user, project, exploratoryName, computationalName));
} catch (DlabException e) {
log.warn("Computational resource {} affiliated with exploratory {} for user {} not found.",
computationalName, exploratoryName, user);
@@ -318,22 +310,24 @@ public class ComputationalServiceImpl implements ComputationalService {
}
@Override
- public List<ClusterConfig> getClusterConfig(UserInfo userInfo, String exploratoryName, String computationalName) {
- return computationalDAO.getClusterConfig(userInfo.getName(), exploratoryName, computationalName);
+ public List<ClusterConfig> getClusterConfig(UserInfo userInfo, String project, String exploratoryName, String computationalName) {
+ return computationalDAO.getClusterConfig(userInfo.getName(), project, exploratoryName, computationalName);
}
/**
* Updates the status of computational resource in database.
*
* @param user user name.
+ * @param project project name
* @param exploratoryName name of exploratory.
* @param computationalName name of computational resource.
* @param status status
*/
- private void updateComputationalStatus(String user, String exploratoryName, String computationalName,
+ private void updateComputationalStatus(String user, String project, String exploratoryName, String computationalName,
UserInstanceStatus status) {
ComputationalStatusDTO computationalStatus = new ComputationalStatusDTO()
.withUser(user)
+ .withProject(project)
.withExploratoryName(exploratoryName)
.withComputationalName(computationalName)
.withStatus(status);
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 808f8ae..18a354b 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
@@ -112,14 +112,6 @@ public class EnvironmentServiceImpl implements EnvironmentService {
}
@Override
- public void stopEnvironment(UserInfo userInfo, String user) {
- log.debug("Stopping environment for user {}", user);
- checkState(user, "stop");
- exploratoryDAO.fetchRunningExploratoryFields(user)
- .forEach(e -> stopExploratory(userInfo, user, e.getExploratoryName()));
- }
-
- @Override
public void stopEnvironmentWithServiceAccount(String user) {
log.debug("Stopping environment for user {} by scheduler", user);
checkState(user, "stop");
@@ -140,28 +132,6 @@ public class EnvironmentServiceImpl implements EnvironmentService {
endpoint.getName(), project));
}
- @Override
- public void stopExploratory(UserInfo userInfo, String user, String exploratoryName) {
- exploratoryService.stop(new UserInfo(user, userInfo.getAccessToken()), exploratoryName);
- }
-
- @Override
- public void stopComputational(UserInfo userInfo, String user, String exploratoryName, String computationalName) {
- computationalService.stopSparkCluster(new UserInfo(user, userInfo.getAccessToken()),
- exploratoryName, computationalName);
- }
-
- @Override
- public void terminateExploratory(UserInfo userInfo, String user, String exploratoryName) {
- exploratoryService.terminate(new UserInfo(user, userInfo.getAccessToken()), exploratoryName);
- }
-
- @Override
- 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) {
return new UserDTO(u, settingsDAO.getAllowedBudget(u).orElse(null), status);
}
@@ -181,7 +151,7 @@ public class EnvironmentServiceImpl implements EnvironmentService {
private void stopNotebookWithServiceAccount(UserInstanceDTO instance) {
final UserInfo userInfo = securityService.getServiceAccountInfo(instance.getUser());
- exploratoryService.stop(userInfo, instance.getExploratoryName());
+ exploratoryService.stop(userInfo, instance.getProject(), instance.getExploratoryName());
}
private List<UserResourceInfo> getProjectEnv(ProjectDTO projectDTO, List<UserInstanceDTO> allInstances) {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImpl.java
index 17b8967..a4d45cb 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImpl.java
@@ -105,17 +105,17 @@ public class ExploratoryServiceImpl implements ExploratoryService {
@BudgetLimited
@Override
public String start(UserInfo userInfo, String exploratoryName, @Project String project) {
- return action(userInfo, exploratoryName, EXPLORATORY_START, STARTING);
+ return action(userInfo, project, exploratoryName, EXPLORATORY_START, STARTING);
}
@Override
- public String stop(UserInfo userInfo, String exploratoryName) {
- return action(userInfo, exploratoryName, EXPLORATORY_STOP, STOPPING);
+ public String stop(UserInfo userInfo, String project, String exploratoryName) {
+ return action(userInfo, project, exploratoryName, EXPLORATORY_STOP, STOPPING);
}
@Override
- public String terminate(UserInfo userInfo, String exploratoryName) {
- return action(userInfo, exploratoryName, EXPLORATORY_TERMINATE, TERMINATING);
+ public String terminate(UserInfo userInfo, String project, String exploratoryName) {
+ return action(userInfo, project, exploratoryName, EXPLORATORY_TERMINATE, TERMINATING);
}
@BudgetLimited
@@ -142,7 +142,7 @@ public class ExploratoryServiceImpl implements ExploratoryService {
log.error("Could not update the status of exploratory environment {} with name {} for user {}",
exploratory.getDockerImage(), exploratory.getName(), userInfo.getName(), t);
if (isAdded) {
- updateExploratoryStatusSilent(userInfo.getName(), exploratory.getName(), FAILED);
+ updateExploratoryStatusSilent(userInfo.getName(), project, exploratory.getName(), FAILED);
}
throw new DlabException("Could not create exploratory environment " + exploratory.getName() + " for user "
+ userInfo.getName() + ": " + Optional.ofNullable(t.getCause()).map(Throwable::getMessage).orElse(t.getMessage()), t);
@@ -150,53 +150,16 @@ public class ExploratoryServiceImpl implements ExploratoryService {
}
@Override
- public void updateExploratoryStatuses(String user, UserInstanceStatus status) {
- exploratoryDAO.fetchUserExploratoriesWhereStatusNotIn(user, TERMINATED, FAILED)
- .forEach(ui -> updateExploratoryStatus(ui.getExploratoryName(), status, user));
- }
-
- @Override
public void updateProjectExploratoryStatuses(String project, String endpoint, UserInstanceStatus status) {
exploratoryDAO.fetchProjectExploratoriesWhereStatusNotIn(project, endpoint, TERMINATED, FAILED)
- .forEach(ui -> updateExploratoryStatus(ui.getExploratoryName(), status, ui.getUser()));
- }
-
- /**
- * Updates parameter 'reuploadKeyRequired' for corresponding user's exploratories with allowable statuses.
- *
- * @param user user.
- * @param reuploadKeyRequired true/false.
- * @param exploratoryStatuses allowable exploratories' statuses.
- */
- @Override
- public void updateExploratoriesReuploadKeyFlag(String user, boolean reuploadKeyRequired,
- UserInstanceStatus... exploratoryStatuses) {
- exploratoryDAO.updateReuploadKeyForExploratories(user, reuploadKeyRequired, exploratoryStatuses);
- }
-
- /**
- * Returns list of user's exploratories and corresponding computational resources where both of them have
- * predefined statuses.
- *
- * @param user user.
- * @param exploratoryStatus status for exploratory environment.
- * @param computationalStatus status for computational resource affiliated with the exploratory.
- * @return list with user instances.
- */
- @Override
- public List<UserInstanceDTO> getInstancesWithStatuses(String user, UserInstanceStatus exploratoryStatus,
- UserInstanceStatus computationalStatus) {
- return getExploratoriesWithStatus(user, exploratoryStatus).stream()
- .map(e -> e.withResources(computationalResourcesWithStatus(e, computationalStatus)))
- .collect(Collectors.toList());
+ .forEach(ui -> updateExploratoryStatus(project, ui.getExploratoryName(), status, ui.getUser()));
}
@Override
- public void updateClusterConfig(UserInfo userInfo, String exploratoryName, List<ClusterConfig> config) {
+ public void updateClusterConfig(UserInfo userInfo, String project, String exploratoryName, List<ClusterConfig> config) {
final String userName = userInfo.getName();
final String token = userInfo.getAccessToken();
- final UserInstanceDTO userInstanceDTO = exploratoryDAO.fetchRunningExploratoryFields(userName,
- exploratoryName);
+ final UserInstanceDTO userInstanceDTO = exploratoryDAO.fetchRunningExploratoryFields(userName, project, exploratoryName);
EndpointDTO endpointDTO = endpointService.get(userInstanceDTO.getEndpoint());
final ExploratoryReconfigureSparkClusterActionDTO updateClusterConfigDTO =
requestBuilder.newClusterConfigUpdate(userInfo, userInstanceDTO, config, endpointDTO);
@@ -206,6 +169,7 @@ public class ExploratoryServiceImpl implements ExploratoryService {
requestId.put(userName, uuid);
exploratoryDAO.updateExploratoryFields(new ExploratoryStatusDTO()
.withUser(userName)
+ .withProject(project)
.withExploratoryName(exploratoryName)
.withConfig(config)
.withStatus(UserInstanceStatus.RECONFIGURING.toString()));
@@ -215,13 +179,14 @@ public class ExploratoryServiceImpl implements ExploratoryService {
* Returns user instance's data by it's name.
*
* @param user user.
+ * @param project
* @param exploratoryName name of exploratory.
* @return corresponding user instance's data or empty data if resource doesn't exist.
*/
@Override
- public Optional<UserInstanceDTO> getUserInstance(String user, String exploratoryName) {
+ public Optional<UserInstanceDTO> getUserInstance(String user, String project, String exploratoryName) {
try {
- return Optional.of(exploratoryDAO.fetchExploratoryFields(user, exploratoryName));
+ return Optional.of(exploratoryDAO.fetchExploratoryFields(user, project, exploratoryName));
} catch (DlabException e) {
log.warn("User instance with exploratory name {} for user {} not found.", exploratoryName, user);
}
@@ -229,8 +194,8 @@ public class ExploratoryServiceImpl implements ExploratoryService {
}
@Override
- public List<ClusterConfig> getClusterConfig(UserInfo user, String exploratoryName) {
- return exploratoryDAO.getClusterConfig(user.getName(), exploratoryName);
+ public List<ClusterConfig> getClusterConfig(UserInfo user, String project, String exploratoryName) {
+ return exploratoryDAO.getClusterConfig(user.getName(), project, exploratoryName);
}
@Override
@@ -256,30 +221,20 @@ public class ExploratoryServiceImpl implements ExploratoryService {
}
/**
- * Returns list of user's exploratories with predefined status.
- *
- * @param user user.
- * @param status status for exploratory environment.
- * @return list of user's instances.
- */
- private List<UserInstanceDTO> getExploratoriesWithStatus(String user, UserInstanceStatus status) {
- return exploratoryDAO.fetchUserExploratoriesWhereStatusIn(user, true, status);
- }
-
- /**
* Sends the post request to the provisioning service and update the status of exploratory environment.
*
* @param userInfo user info.
+ * @param project name of project
* @param exploratoryName name of exploratory environment.
* @param action action for exploratory environment.
* @param status status for exploratory environment.
* @return Invocation request as JSON string.
*/
- private String action(UserInfo userInfo, String exploratoryName, String action, UserInstanceStatus status) {
+ private String action(UserInfo userInfo, String project, String exploratoryName, String action, UserInstanceStatus status) {
try {
- updateExploratoryStatus(exploratoryName, status, userInfo.getName());
+ updateExploratoryStatus(project, exploratoryName, status, userInfo.getName());
- UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), exploratoryName);
+ UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(userInfo.getName(), project, exploratoryName);
EndpointDTO endpointDTO = endpointService.get(userInstance.getEndpoint());
final String uuid =
provisioningService.post(endpointDTO.getUrl() + action, userInfo.getAccessToken(),
@@ -289,7 +244,7 @@ public class ExploratoryServiceImpl implements ExploratoryService {
} catch (Exception t) {
log.error("Could not {} exploratory environment {} for user {}",
StringUtils.substringAfter(action, "/"), exploratoryName, userInfo.getName(), t);
- updateExploratoryStatusSilent(userInfo.getName(), exploratoryName, FAILED);
+ updateExploratoryStatusSilent(userInfo.getName(), project, exploratoryName, FAILED);
final String errorMsg = String.format("Could not %s exploratory environment %s: %s",
StringUtils.substringAfter(action, "/"), exploratoryName,
Optional.ofNullable(t.getCause()).map(Throwable::getMessage).orElse(t.getMessage()));
@@ -297,15 +252,15 @@ public class ExploratoryServiceImpl implements ExploratoryService {
}
}
- private void updateExploratoryStatus(String exploratoryName, UserInstanceStatus status, String user) {
- updateExploratoryStatus(user, exploratoryName, status);
+ private void updateExploratoryStatus(String project, String exploratoryName, UserInstanceStatus status, String user) {
+ updateExploratoryStatus(user, project, exploratoryName, status);
if (status == STOPPING) {
- updateComputationalStatuses(user, exploratoryName, STOPPING, TERMINATING, FAILED, TERMINATED, STOPPED);
+ updateComputationalStatuses(user, project, exploratoryName, STOPPING, TERMINATING, FAILED, TERMINATED, STOPPED);
} else if (status == TERMINATING) {
- updateComputationalStatuses(user, exploratoryName, TERMINATING, TERMINATING, TERMINATED, FAILED);
+ updateComputationalStatuses(user, project, exploratoryName, TERMINATING, TERMINATING, TERMINATED, FAILED);
} else if (status == TERMINATED) {
- updateComputationalStatuses(user, exploratoryName, TERMINATED, TERMINATED, TERMINATED, FAILED);
+ updateComputationalStatuses(user, project, exploratoryName, TERMINATED, TERMINATED, TERMINATED, FAILED);
}
}
@@ -327,11 +282,12 @@ public class ExploratoryServiceImpl implements ExploratoryService {
* Updates the status of exploratory environment.
*
* @param user user name
+ * @param project project name
* @param exploratoryName name of exploratory environment.
* @param status status for exploratory environment.
*/
- private void updateExploratoryStatus(String user, String exploratoryName, UserInstanceStatus status) {
- StatusEnvBaseDTO<?> exploratoryStatus = createStatusDTO(user, exploratoryName, status);
+ private void updateExploratoryStatus(String user, String project, String exploratoryName, UserInstanceStatus status) {
+ StatusEnvBaseDTO<?> exploratoryStatus = createStatusDTO(user, project, exploratoryName, status);
exploratoryDAO.updateExploratoryStatus(exploratoryStatus);
}
@@ -339,34 +295,36 @@ public class ExploratoryServiceImpl implements ExploratoryService {
* Updates the status of exploratory environment without exceptions. If exception occurred then logging it.
*
* @param user user name
+ * @param project project name
* @param exploratoryName name of exploratory environment.
* @param status status for exploratory environment.
*/
- private void updateExploratoryStatusSilent(String user, String exploratoryName, UserInstanceStatus status) {
+ private void updateExploratoryStatusSilent(String user, String project, String exploratoryName, UserInstanceStatus status) {
try {
- updateExploratoryStatus(user, exploratoryName, status);
+ updateExploratoryStatus(user, project, exploratoryName, status);
} catch (DlabException e) {
log.error("Could not update the status of exploratory environment {} for user {} to {}",
exploratoryName, user, status, e);
}
}
- private void updateComputationalStatuses(String user, String exploratoryName, UserInstanceStatus
+ private void updateComputationalStatuses(String user, String project, String exploratoryName, UserInstanceStatus
dataEngineStatus, UserInstanceStatus dataEngineServiceStatus, UserInstanceStatus... excludedStatuses) {
log.debug("updating status for all computational resources of {} for user {}: DataEngine {}, " +
"dataengine-service {}", exploratoryName, user, dataEngineStatus, dataEngineServiceStatus);
- computationalDAO.updateComputationalStatusesForExploratory(user, exploratoryName, dataEngineStatus,
- dataEngineServiceStatus, excludedStatuses);
+ computationalDAO.updateComputationalStatusesForExploratory(user, project, exploratoryName,
+ dataEngineStatus, dataEngineServiceStatus, excludedStatuses);
}
/**
* Instantiates and returns the descriptor of exploratory environment status.
*
* @param user user name
+ * @param project
* @param exploratoryName name of exploratory environment.
* @param status status for exploratory environment.
*/
- private StatusEnvBaseDTO<?> createStatusDTO(String user, String exploratoryName, UserInstanceStatus status) {
+ private StatusEnvBaseDTO<?> createStatusDTO(String user, String project, String exploratoryName, UserInstanceStatus status) {
return new ExploratoryStatusDTO()
.withUser(user)
.withExploratoryName(exploratoryName)
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImpl.java
index bd00f38..85ce534 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImpl.java
@@ -73,15 +73,15 @@ public class ImageExploratoryServiceImpl implements ImageExploratoryService {
private EndpointService endpointService;
@Override
- public String createImage(UserInfo user, String exploratoryName, String imageName, String imageDescription) {
+ public String createImage(UserInfo user, String project, String exploratoryName, String imageName, String imageDescription) {
- UserInstanceDTO userInstance = exploratoryDAO.fetchRunningExploratoryFields(user.getName(), exploratoryName);
+ UserInstanceDTO userInstance = exploratoryDAO.fetchRunningExploratoryFields(user.getName(), project, exploratoryName);
if (imageExploratoryDao.exist(imageName, userInstance.getProject())) {
log.error(String.format(IMAGE_EXISTS_MSG, imageName, userInstance.getProject()));
throw new ResourceAlreadyExistException(String.format(IMAGE_EXISTS_MSG, imageName, userInstance.getProject()));
}
- final List<Library> libraries = libDAO.getLibraries(user.getName(), exploratoryName);
+ final List<Library> libraries = libDAO.getLibraries(user.getName(), project, exploratoryName);
imageExploratoryDao.save(Image.builder()
.name(imageName)
@@ -98,6 +98,7 @@ public class ImageExploratoryServiceImpl implements ImageExploratoryService {
exploratoryDAO.updateExploratoryStatus(new ExploratoryStatusDTO()
.withUser(user.getName())
+ .withProject(project)
.withExploratoryName(exploratoryName)
.withStatus(UserInstanceStatus.CREATING_IMAGE));
@@ -113,13 +114,14 @@ public class ImageExploratoryServiceImpl implements ImageExploratoryService {
exploratoryName, image.getUser());
exploratoryDAO.updateExploratoryStatus(new ExploratoryStatusDTO()
.withUser(image.getUser())
+ .withProject(image.getProject())
.withExploratoryName(exploratoryName)
.withStatus(UserInstanceStatus.RUNNING));
imageExploratoryDao.updateImageFields(image);
if (newNotebookIp != null) {
log.debug("Changing exploratory ip with name {} for user {} to {}", exploratoryName, image.getUser(),
newNotebookIp);
- exploratoryDAO.updateExploratoryIp(image.getUser(), newNotebookIp, exploratoryName);
+ exploratoryDAO.updateExploratoryIp(image.getUser(), image.getProject(), newNotebookIp, exploratoryName);
}
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/InactivityServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/InactivityServiceImpl.java
index 1d3230f..dd370dd 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/InactivityServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/InactivityServiceImpl.java
@@ -75,9 +75,9 @@ public class InactivityServiceImpl implements InactivityService {
}
@Override
- public void updateLastActivityForComputational(UserInfo userInfo, String exploratoryName,
+ public void updateLastActivityForComputational(UserInfo userInfo, String project, String exploratoryName,
String computationalName, LocalDateTime lastActivity) {
- computationalDAO.updateLastActivity(userInfo.getName(), exploratoryName, computationalName, lastActivity);
+ computationalDAO.updateLastActivity(userInfo.getName(), project, exploratoryName, computationalName, lastActivity);
}
private void updateLastActivity(UserInstanceDTO ui) {
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImpl.java
index 3d65a15..3fbb170 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImpl.java
@@ -50,7 +50,13 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.TreeMap;
import java.util.stream.Collectors;
@Slf4j
@@ -80,13 +86,13 @@ public class LibraryServiceImpl implements LibraryService {
@Override
@SuppressWarnings("unchecked")
- public List<Document> getLibs(String user, String exploratoryName, String computationalName) {
+ public List<Document> getLibs(String user, String project, String exploratoryName, String computationalName) {
if (StringUtils.isEmpty(computationalName)) {
- return (List<Document>) libraryDAO.findExploratoryLibraries(user, exploratoryName)
+ return (List<Document>) libraryDAO.findExploratoryLibraries(user, project, exploratoryName)
.getOrDefault(ExploratoryLibDAO.EXPLORATORY_LIBS, new ArrayList<>());
} else {
- Document document = (Document) libraryDAO.findComputationalLibraries(user, exploratoryName,
- computationalName)
+ Document document = (Document) libraryDAO.findComputationalLibraries(user, project,
+ exploratoryName, computationalName)
.getOrDefault(ExploratoryLibDAO.COMPUTATIONAL_LIBS, new Document());
return (List<Document>) document.getOrDefault(computationalName, new ArrayList<>());
@@ -95,8 +101,8 @@ public class LibraryServiceImpl implements LibraryService {
@Override
@SuppressWarnings("unchecked")
- public List<LibInfoRecord> getLibInfo(String user, String exploratoryName) {
- Document document = libraryDAO.findAllLibraries(user, exploratoryName);
+ public List<LibInfoRecord> getLibInfo(String user, String project, String exploratoryName) {
+ Document document = libraryDAO.findAllLibraries(user, project, exploratoryName);
Map<LibKey, List<LibraryStatus>> model = new TreeMap<>(Comparator.comparing(LibKey::getName)
.thenComparing(LibKey::getVersion)
@@ -124,52 +130,52 @@ public class LibraryServiceImpl implements LibraryService {
}
@Override
- public String installComputationalLibs(UserInfo ui, String expName, String compName,
+ public String installComputationalLibs(UserInfo ui, String project, String expName, String compName,
List<LibInstallDTO> libs) {
- final UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(ui.getName(), expName, compName);
+ final UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(ui.getName(), project, expName, compName);
EndpointDTO endpointDTO = endpointService.get(userInstance.getEndpoint());
final String uuid =
provisioningService.post(endpointDTO.getUrl() + ComputationalAPI.COMPUTATIONAL_LIB_INSTALL,
ui.getAccessToken(),
- toComputationalLibraryInstallDto(ui, expName, compName, libs, userInstance, endpointDTO),
+ toComputationalLibraryInstallDto(ui, project, expName, compName, libs, userInstance, endpointDTO),
String.class);
requestId.put(ui.getName(), uuid);
return uuid;
}
@Override
- public String installExploratoryLibs(UserInfo ui, String expName, List<LibInstallDTO> libs) {
- final UserInstanceDTO userInstance = exploratoryDAO.fetchRunningExploratoryFields(ui.getName(), expName);
+ public String installExploratoryLibs(UserInfo ui, String project, String expName, List<LibInstallDTO> libs) {
+ final UserInstanceDTO userInstance = exploratoryDAO.fetchRunningExploratoryFields(ui.getName(), project, expName);
EndpointDTO endpointDTO = endpointService.get(userInstance.getEndpoint());
final String uuid =
provisioningService.post(endpointDTO.getUrl() + ExploratoryAPI.EXPLORATORY_LIB_INSTALL,
- ui.getAccessToken(), toExploratoryLibraryInstallDto(ui, expName, libs, userInstance, endpointDTO),
+ ui.getAccessToken(), toExploratoryLibraryInstallDto(ui, project, expName, libs, userInstance, endpointDTO),
String.class);
requestId.put(ui.getName(), uuid);
return uuid;
}
- private LibraryInstallDTO toExploratoryLibraryInstallDto(UserInfo userInfo, String exploratoryName,
+ private LibraryInstallDTO toExploratoryLibraryInstallDto(UserInfo userInfo, String project, String exploratoryName,
List<LibInstallDTO> libs, UserInstanceDTO userInstance, EndpointDTO endpointDTO) {
final List<LibInstallDTO> libsToInstall = libs.stream()
- .map(lib -> toLibInstallDto(lib, libraryDAO.getLibrary(userInfo.getName(), exploratoryName,
+ .map(lib -> toLibInstallDto(lib, libraryDAO.getLibrary(userInfo.getName(), project, exploratoryName,
lib.getGroup(), lib.getName())))
- .peek(l -> libraryDAO.addLibrary(userInfo.getName(), exploratoryName, l, l.isOverride()))
+ .peek(l -> libraryDAO.addLibrary(userInfo.getName(), project, exploratoryName, l, l.isOverride()))
.collect(Collectors.toList());
return requestBuilder.newLibInstall(userInfo, userInstance, endpointDTO, libsToInstall);
}
- private LibraryInstallDTO toComputationalLibraryInstallDto(UserInfo userInfo, String expName, String compName,
- List<LibInstallDTO> libs,
+ private LibraryInstallDTO toComputationalLibraryInstallDto(UserInfo userInfo, String project, String expName,
+ String compName, List<LibInstallDTO> libs,
UserInstanceDTO userInstance, EndpointDTO endpointDTO) {
final UserComputationalResource computationalResource = getComputationalResource(compName, userInstance);
final List<LibInstallDTO> libsToInstall = libs.stream()
- .map(lib -> toLibInstallDto(lib, libraryDAO.getLibrary(userInfo.getName(), expName,
- compName, lib.getGroup(), lib.getName())))
- .peek(l -> libraryDAO.addLibrary(userInfo.getName(), expName, compName, l,
- l.isOverride()))
+ .map(lib -> toLibInstallDto(lib, libraryDAO.getLibrary(userInfo.getName(), project,
+ expName, compName, lib.getGroup(), lib.getName())))
+ .peek(l -> libraryDAO.addLibrary(userInfo.getName(), project, expName, compName,
+ l, l.isOverride()))
.collect(Collectors.toList());
return requestBuilder.newLibInstall(userInfo, userInstance, computationalResource, libsToInstall, endpointDTO);
}
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 5355dee..92e7e42 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
@@ -6,7 +6,12 @@ import com.epam.dlab.backendapi.annotation.Project;
import com.epam.dlab.backendapi.dao.ExploratoryDAO;
import com.epam.dlab.backendapi.dao.ProjectDAO;
import com.epam.dlab.backendapi.dao.UserGroupDao;
-import com.epam.dlab.backendapi.domain.*;
+import com.epam.dlab.backendapi.domain.EndpointDTO;
+import com.epam.dlab.backendapi.domain.ProjectDTO;
+import com.epam.dlab.backendapi.domain.ProjectEndpointDTO;
+import com.epam.dlab.backendapi.domain.ProjectManagingDTO;
+import com.epam.dlab.backendapi.domain.RequestId;
+import com.epam.dlab.backendapi.domain.UpdateProjectDTO;
import com.epam.dlab.backendapi.service.EndpointService;
import com.epam.dlab.backendapi.service.ExploratoryService;
import com.epam.dlab.backendapi.service.ProjectService;
@@ -21,7 +26,11 @@ import com.google.inject.Inject;
import com.google.inject.name.Named;
import lombok.extern.slf4j.Slf4j;
-import java.util.*;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -160,7 +169,7 @@ public class ProjectServiceImpl implements ProjectService {
checkProjectRelatedResourcesInProgress(projectName, endpoints, STOP_ACTION);
exploratoryDAO.fetchRunningExploratoryFieldsForProject(projectName).forEach(e ->
- exploratoryService.stop(new UserInfo(e.getUser(), userInfo.getAccessToken()), e.getExploratoryName()));
+ exploratoryService.stop(new UserInfo(e.getUser(), userInfo.getAccessToken()), projectName, e.getExploratoryName()));
endpoints.stream().filter(e -> !Arrays.asList(UserInstanceStatus.TERMINATED,
UserInstanceStatus.TERMINATING, UserInstanceStatus.STOPPED).contains(e.getStatus()))
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImpl.java
index 0efe7f6..e75d9df 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImpl.java
@@ -19,7 +19,6 @@
package com.epam.dlab.backendapi.service.impl;
-import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.dao.ComputationalDAO;
import com.epam.dlab.backendapi.dao.ExploratoryDAO;
import com.epam.dlab.backendapi.domain.RequestId;
@@ -27,11 +26,8 @@ import com.epam.dlab.backendapi.service.ExploratoryService;
import com.epam.dlab.backendapi.service.ReuploadKeyService;
import com.epam.dlab.backendapi.util.RequestBuilder;
import com.epam.dlab.dto.UserInstanceStatus;
-import com.epam.dlab.dto.base.DataEngineType;
-import com.epam.dlab.dto.reuploadkey.ReuploadKeyDTO;
import com.epam.dlab.dto.reuploadkey.ReuploadKeyStatus;
import com.epam.dlab.dto.reuploadkey.ReuploadKeyStatusDTO;
-import com.epam.dlab.exceptions.DlabException;
import com.epam.dlab.model.ResourceData;
import com.epam.dlab.model.ResourceType;
import com.epam.dlab.rest.client.RESTService;
@@ -39,16 +35,9 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.UUID;
import static com.epam.dlab.constants.ServiceConsts.PROVISIONING_SERVICE_NAME;
-import static com.epam.dlab.dto.UserInstanceStatus.REUPLOADING_KEY;
import static com.epam.dlab.dto.UserInstanceStatus.RUNNING;
-import static com.epam.dlab.rest.contracts.KeyAPI.REUPLOAD_KEY;
@Singleton
@Slf4j
@@ -75,34 +64,33 @@ public class ReuploadKeyServiceImpl implements ReuploadKeyService {
@Override
public void updateResourceData(ReuploadKeyStatusDTO dto) {
- String user = dto.getUser();
- ResourceData resource = dto.getReuploadKeyCallbackDTO().getResource();
- log.debug("Updating resource {} to status RUNNING...", resource.toString());
- updateResourceStatus(user, resource, RUNNING);
- if (dto.getReuploadKeyStatus() == ReuploadKeyStatus.COMPLETED) {
- log.debug(REUPLOAD_KEY_UPDATE_MSG, resource.toString());
- updateResourceReuploadKeyFlag(user, resource, false);
- } else {
- log.error(REUPLOAD_KEY_ERROR_MSG, resource.toString());
- }
- }
+ String user = dto.getUser();
+ ResourceData resource = dto.getReuploadKeyCallbackDTO().getResource();
+ log.debug("Updating resource {} to status RUNNING...", resource.toString());
+ updateResourceStatus(user, null, resource, RUNNING);
+ if (dto.getReuploadKeyStatus() == ReuploadKeyStatus.COMPLETED) {
+ log.debug(REUPLOAD_KEY_UPDATE_MSG, resource.toString());
+ updateResourceReuploadKeyFlag(user, null, resource, false);
+ } else {
+ log.error(REUPLOAD_KEY_ERROR_MSG, resource.toString());
+ }
+ }
- private void updateResourceStatus(String user, ResourceData resourceData, UserInstanceStatus newStatus) {
- if (resourceData.getResourceType() == ResourceType.EXPLORATORY) {
- exploratoryDAO.updateStatusForExploratory(user, resourceData.getExploratoryName(), newStatus);
- } else if (resourceData.getResourceType() == ResourceType.COMPUTATIONAL) {
- computationalDAO.updateStatusForComputationalResource(user, resourceData.getExploratoryName(),
- resourceData.getComputationalName(), newStatus);
- }
- }
+ private void updateResourceStatus(String user, String project, ResourceData resourceData, UserInstanceStatus newStatus) {
+ if (resourceData.getResourceType() == ResourceType.EXPLORATORY) {
+ exploratoryDAO.updateStatusForExploratory(user, project, resourceData.getExploratoryName(), newStatus);
+ } else if (resourceData.getResourceType() == ResourceType.COMPUTATIONAL) {
+ computationalDAO.updateStatusForComputationalResource(user, project,
+ resourceData.getExploratoryName(), resourceData.getComputationalName(), newStatus);
+ }
+ }
- private void updateResourceReuploadKeyFlag(String user, ResourceData resourceData, boolean reuploadKeyRequired) {
- if (resourceData.getResourceType() == ResourceType.EXPLORATORY) {
- exploratoryDAO.updateReuploadKeyForExploratory(user, resourceData.getExploratoryName(),
- reuploadKeyRequired);
- } else if (resourceData.getResourceType() == ResourceType.COMPUTATIONAL) {
- computationalDAO.updateReuploadKeyFlagForComputationalResource(user, resourceData.getExploratoryName(),
- resourceData.getComputationalName(), reuploadKeyRequired);
- }
- }
+ private void updateResourceReuploadKeyFlag(String user, String project, ResourceData resourceData, boolean reuploadKeyRequired) {
+ if (resourceData.getResourceType() == ResourceType.EXPLORATORY) {
+ exploratoryDAO.updateReuploadKeyForExploratory(user, project, resourceData.getExploratoryName(), reuploadKeyRequired);
+ } else if (resourceData.getResourceType() == ResourceType.COMPUTATIONAL) {
+ computationalDAO.updateReuploadKeyFlagForComputationalResource(user, project,
+ resourceData.getExploratoryName(), resourceData.getComputationalName(), reuploadKeyRequired);
+ }
+ }
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImpl.java
index e84908e..cb7b1c1 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImpl.java
@@ -44,7 +44,12 @@ import com.google.inject.name.Named;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import java.time.*;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
@@ -55,7 +60,13 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.epam.dlab.constants.ServiceConsts.PROVISIONING_SERVICE_NAME;
-import static com.epam.dlab.dto.UserInstanceStatus.*;
+import static com.epam.dlab.dto.UserInstanceStatus.CONFIGURING;
+import static com.epam.dlab.dto.UserInstanceStatus.CREATING;
+import static com.epam.dlab.dto.UserInstanceStatus.RUNNING;
+import static com.epam.dlab.dto.UserInstanceStatus.STARTING;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPED;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPING;
+import static com.epam.dlab.dto.UserInstanceStatus.TERMINATING;
import static com.epam.dlab.dto.base.DataEngineType.getDockerImageName;
import static java.time.ZoneId.systemDefault;
import static java.util.Collections.singletonList;
@@ -98,44 +109,44 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
private RESTService provisioningService;
@Override
- public SchedulerJobDTO fetchSchedulerJobForUserAndExploratory(String user, String exploratoryName) {
- return schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(user, exploratoryName)
+ public SchedulerJobDTO fetchSchedulerJobForUserAndExploratory(String user, String project, String exploratoryName) {
+ return schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(user, project, exploratoryName)
.orElseThrow(() -> new ResourceNotFoundException(String.format(SCHEDULER_NOT_FOUND_MSG, user,
exploratoryName)));
}
@Override
- public SchedulerJobDTO fetchSchedulerJobForComputationalResource(String user, String exploratoryName,
+ public SchedulerJobDTO fetchSchedulerJobForComputationalResource(String user, String project, String exploratoryName,
String computationalName) {
- return schedulerJobDAO.fetchSingleSchedulerJobForCluster(user, exploratoryName, computationalName)
+ return schedulerJobDAO.fetchSingleSchedulerJobForCluster(user, project, exploratoryName, computationalName)
.orElseThrow(() -> new ResourceNotFoundException(String.format(SCHEDULER_NOT_FOUND_MSG, user,
exploratoryName) + " with computational resource " + computationalName));
}
@Override
- public void updateExploratorySchedulerData(String user, String exploratoryName, SchedulerJobDTO dto) {
- validateExploratoryStatus(user, exploratoryName);
+ public void updateExploratorySchedulerData(String user, String project, String exploratoryName, SchedulerJobDTO dto) {
+ validateExploratoryStatus(user, project, exploratoryName);
populateDefaultSchedulerValues(dto);
log.debug("Updating exploratory {} for user {} with new scheduler job data: {}...", exploratoryName, user,
dto);
- exploratoryDAO.updateSchedulerDataForUserAndExploratory(user, exploratoryName, dto);
+ exploratoryDAO.updateSchedulerDataForUserAndExploratory(user, project, exploratoryName, dto);
if (!dto.inactivityScheduler() && dto.isSyncStartRequired()) {
- shareSchedulerJobDataToSparkClusters(user, exploratoryName, dto);
+ shareSchedulerJobDataToSparkClusters(user, project, exploratoryName, dto);
} else if (!dto.inactivityScheduler()) {
- computationalDAO.updateSchedulerSyncFlag(user, exploratoryName, dto.isSyncStartRequired());
+ computationalDAO.updateSchedulerSyncFlag(user, project, exploratoryName, dto.isSyncStartRequired());
}
}
@Override
- public void updateComputationalSchedulerData(String user, String exploratoryName, String computationalName,
+ public void updateComputationalSchedulerData(String user, String project, String exploratoryName, String computationalName,
SchedulerJobDTO dto) {
- validateExploratoryStatus(user, exploratoryName);
- validateComputationalStatus(user, exploratoryName, computationalName);
+ validateExploratoryStatus(user, project, exploratoryName);
+ validateComputationalStatus(user, project, exploratoryName, computationalName);
populateDefaultSchedulerValues(dto);
log.debug("Updating computational resource {} affiliated with exploratory {} for user {} with new scheduler " +
"job data {}...", computationalName, exploratoryName, user, dto);
- computationalDAO.updateSchedulerDataForComputationalResource(user, exploratoryName, computationalName, dto);
+ computationalDAO.updateSchedulerDataForComputationalResource(user, project, exploratoryName, computationalName, dto);
}
@Override
@@ -203,11 +214,12 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
}
private void stopComputational(SchedulerJobData job) {
+ final String project = job.getProject();
final String expName = job.getExploratoryName();
final String compName = job.getComputationalName();
final String user = job.getUser();
log.debug("Stopping exploratory {} computational {} for user {} by scheduler", expName, compName, user);
- computationalService.stopSparkCluster(securityService.getServiceAccountInfo(user), expName, compName);
+ computationalService.stopSparkCluster(securityService.getServiceAccountInfo(user), project, expName, compName);
}
private void terminateComputational(SchedulerJobData job) {
@@ -216,14 +228,15 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
final String compName = job.getComputationalName();
final UserInfo userInfo = securityService.getServiceAccountInfo(user);
log.debug("Terminating exploratory {} computational {} for user {} by scheduler", expName, compName, user);
- computationalService.terminateComputational(userInfo, expName, compName);
+ computationalService.terminateComputational(userInfo, job.getProject(), expName, compName);
}
private void stopExploratory(SchedulerJobData job) {
final String expName = job.getExploratoryName();
final String user = job.getUser();
+ final String project = job.getProject();
log.debug("Stopping exploratory {} for user {} by scheduler", expName, user);
- exploratoryService.stop(securityService.getServiceAccountInfo(user), expName);
+ exploratoryService.stop(securityService.getServiceAccountInfo(user), project, expName);
}
private List<SchedulerJobData> getExploratorySchedulersForTerminating(OffsetDateTime now) {
@@ -250,7 +263,7 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
log.trace("Starting computational for exploratory {} for user {} by scheduler", exploratoryName, user);
final DataEngineType sparkCluster = DataEngineType.SPARK_STANDALONE;
final List<UserComputationalResource> compToBeStarted =
- computationalDAO.findComputationalResourcesWithStatus(user, exploratoryName, STOPPED);
+ computationalDAO.findComputationalResourcesWithStatus(user, project, exploratoryName, STOPPED);
compToBeStarted
.stream()
@@ -261,9 +274,10 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
private void terminateExploratory(SchedulerJobData job) {
final String user = job.getUser();
+ final String project = job.getProject();
final String expName = job.getExploratoryName();
log.debug("Terminating exploratory {} for user {} by scheduler", expName, user);
- exploratoryService.terminate(securityService.getUserInfoOffline(user), expName);
+ exploratoryService.terminate(securityService.getUserInfoOffline(user), project, expName);
}
private void startSpark(String user, String expName, String compName, String project) {
@@ -282,19 +296,20 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
* performed automatically with notebook stopping since Spark resources have such feature).
*
* @param user user's name
+ * @param project project name
* @param exploratoryName name of exploratory resource
* @param dto scheduler job data.
*/
- private void shareSchedulerJobDataToSparkClusters(String user, String exploratoryName, SchedulerJobDTO dto) {
- List<String> correspondingSparkClusters = computationalDAO.getComputationalResourcesWhereStatusIn(user,
- singletonList(DataEngineType.SPARK_STANDALONE), exploratoryName,
- STARTING, RUNNING, STOPPING, STOPPED);
+ private void shareSchedulerJobDataToSparkClusters(String user, String project, String exploratoryName, SchedulerJobDTO dto) {
+ List<String> correspondingSparkClusters = computationalDAO.getComputationalResourcesWhereStatusIn(user, project,
+ singletonList(DataEngineType.SPARK_STANDALONE),
+ exploratoryName, STARTING, RUNNING, STOPPING, STOPPED);
SchedulerJobDTO dtoWithoutStopData = getSchedulerJobWithoutStopData(dto);
for (String sparkName : correspondingSparkClusters) {
log.debug("Updating computational resource {} affiliated with exploratory {} for user {} with new " +
"scheduler job data {}...", sparkName, exploratoryName, user, dtoWithoutStopData);
- computationalDAO.updateSchedulerDataForComputationalResource(user, exploratoryName, sparkName,
- dtoWithoutStopData);
+ computationalDAO.updateSchedulerDataForComputationalResource(user, project, exploratoryName,
+ sparkName, dtoWithoutStopData);
}
}
@@ -367,10 +382,11 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
}
private boolean computationalInactivityExceed(SchedulerJobData schedulerJobData, SchedulerJobDTO schedulerData) {
+ final String projectName = schedulerJobData.getProject();
final String explName = schedulerJobData.getExploratoryName();
final String compName = schedulerJobData.getComputationalName();
final String user = schedulerJobData.getUser();
- final UserComputationalResource c = computationalDAO.fetchComputationalFields(user, explName, compName);
+ final UserComputationalResource c = computationalDAO.fetchComputationalFields(user, projectName, explName, compName);
final Long maxInactivity = schedulerData.getMaxInactivity();
return inactivityCondition(maxInactivity, c.getStatus(), c.getLastActivity());
}
@@ -381,9 +397,10 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
}
private boolean exploratoryInactivityExceed(SchedulerJobData schedulerJobData, SchedulerJobDTO schedulerData) {
+ final String project = schedulerJobData.getProject();
final String expName = schedulerJobData.getExploratoryName();
final String user = schedulerJobData.getUser();
- final UserInstanceDTO userInstanceDTO = exploratoryDAO.fetchExploratoryFields(user, expName, true);
+ final UserInstanceDTO userInstanceDTO = exploratoryDAO.fetchExploratoryFields(user, project, expName, true);
final boolean canBeStopped = userInstanceDTO.getResources()
.stream()
.map(UserComputationalResource::getStatus)
@@ -409,14 +426,14 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
}
}
- private void validateExploratoryStatus(String user, String exploratoryName) {
- final UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(user, exploratoryName);
+ private void validateExploratoryStatus(String user, String project, String exploratoryName) {
+ final UserInstanceDTO userInstance = exploratoryDAO.fetchExploratoryFields(user, project, exploratoryName);
validateResourceStatus(userInstance.getStatus());
}
- private void validateComputationalStatus(String user, String exploratoryName, String computationalName) {
+ private void validateComputationalStatus(String user, String project, String exploratoryName, String computationalName) {
final UserComputationalResource computationalResource =
- computationalDAO.fetchComputationalFields(user, exploratoryName, computationalName);
+ computationalDAO.fetchComputationalFields(user, project, exploratoryName, computationalName);
final String computationalStatus = computationalResource.getStatus();
validateResourceStatus(computationalStatus);
}
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 a8b01fa..8df0856 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,10 +19,8 @@
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;
import io.dropwizard.testing.junit.ResourceTestRule;
import org.apache.http.HttpStatus;
@@ -30,7 +28,6 @@ import org.junit.Before;
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;
@@ -39,9 +36,11 @@ import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class EnvironmentResourceTest extends TestBase {
@@ -123,249 +122,4 @@ public class EnvironmentResourceTest extends TestBase {
verifyZeroInteractions(environmentService);
}
-
- @Test
- public void stopEnv() {
- doNothing().when(environmentService).stopEnvironment(any(UserInfo.class), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop")
- .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);
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void stopEnvWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- doNothing().when(environmentService).stopEnvironment(any(UserInfo.class), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop")
- .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());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop")
- .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);
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void stopNotebook() {
- doNothing().when(environmentService).stopExploratory(any(UserInfo.class), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop/explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.text(USER));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(environmentService).stopExploratory(new UserInfo(USER, TOKEN), USER, "explName");
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void stopNotebookWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- doNothing().when(environmentService).stopExploratory(any(UserInfo.class), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop/explName")
- .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 stopNotebookWithResourceConflictException() {
- doThrow(new ResourceConflictException("Can not stop notebook because its status is CREATING or STARTING"))
- .when(environmentService).stopExploratory(any(UserInfo.class), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop/explName")
- .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).stopExploratory(new UserInfo(USER, TOKEN), USER, "explName");
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void stopCluster() {
- doNothing().when(environmentService).stopComputational(any(UserInfo.class), anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.text(USER));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(environmentService).stopComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void stopClusterWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- doNothing().when(environmentService).stopComputational(any(UserInfo.class), anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop/explName/compName")
- .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 stopClusterWithResourceConflictException() {
- doThrow(new ResourceConflictException("Can not stop cluster because its status is CREATING or STARTING"))
- .when(environmentService).stopComputational(any(UserInfo.class), anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/stop/explName/compName")
- .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).stopComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void terminateNotebook() {
- doNothing().when(environmentService).terminateExploratory(any(UserInfo.class), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/terminate/explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.text(USER));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(environmentService).terminateExploratory(new UserInfo(USER, TOKEN), USER, "explName");
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void terminateNotebookWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- doNothing().when(environmentService).terminateExploratory(any(UserInfo.class), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/terminate/explName")
- .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 terminateNotebookWithResourceConflictException() {
- doThrow(new ResourceConflictException("Can not terminate notebook because its status is CREATING or STARTING"))
- .when(environmentService).terminateExploratory(any(UserInfo.class), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/terminate/explName")
- .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).terminateExploratory(new UserInfo(USER, TOKEN), USER, "explName");
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void terminateCluster() {
- doNothing().when(environmentService).terminateComputational(any(UserInfo.class), anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/terminate/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.text(USER));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(environmentService).terminateComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
- verifyNoMoreInteractions(environmentService);
- }
-
- @Test
- public void terminateClusterWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- doNothing().when(environmentService).terminateComputational(any(UserInfo.class), anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/terminate/explName/compName")
- .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 terminateClusterWithResourceConflictException() {
- doThrow(new ResourceConflictException("Can not terminate cluster because its status is CREATING or STARTING"))
- .when(environmentService).terminateComputational(any(UserInfo.class), anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/environment/terminate/explName/compName")
- .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).terminateComputational(new UserInfo(USER, TOKEN), USER, "explName", "compName");
- verifyNoMoreInteractions(environmentService);
- }
}
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java
index f6f4692..bccfa8b 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java
@@ -47,7 +47,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.refEq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class ExploratoryResourceTest extends TestBase {
@@ -154,9 +161,9 @@ public class ExploratoryResourceTest extends TestBase {
@Test
public void stop() {
- when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn("someUuid");
+ when(exploratoryService.stop(any(UserInfo.class), anyString(), anyString())).thenReturn("someUuid");
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/stop")
+ .target("/infrastructure_provision/exploratory_environment/project/someName/stop")
.request()
.header("Authorization", "Bearer " + TOKEN)
.delete();
@@ -165,16 +172,16 @@ public class ExploratoryResourceTest extends TestBase {
assertEquals("someUuid", response.readEntity(String.class));
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(exploratoryService).stop(getUserInfo(), "someName");
+ verify(exploratoryService).stop(getUserInfo(), "project", "someName");
verifyNoMoreInteractions(exploratoryService);
}
@Test
public void stopWithFailedAuth() throws AuthenticationException {
authFailSetup();
- when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn("someUuid");
+ when(exploratoryService.stop(any(UserInfo.class), anyString(), anyString())).thenReturn("someUuid");
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/stop")
+ .target("/infrastructure_provision/exploratory_environment/project/someName/stop")
.request()
.header("Authorization", "Bearer " + TOKEN)
.delete();
@@ -183,16 +190,16 @@ public class ExploratoryResourceTest extends TestBase {
assertEquals("someUuid", response.readEntity(String.class));
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(exploratoryService).stop(getUserInfo(), "someName");
+ verify(exploratoryService).stop(getUserInfo(), "project", "someName");
verifyNoMoreInteractions(exploratoryService);
}
@Test
public void stopWithException() {
doThrow(new DlabException("Could not stop exploratory environment"))
- .when(exploratoryService).stop(any(UserInfo.class), anyString());
+ .when(exploratoryService).stop(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/stop")
+ .target("/infrastructure_provision/exploratory_environment/project/someName/stop")
.request()
.header("Authorization", "Bearer " + TOKEN)
.delete();
@@ -204,15 +211,15 @@ public class ExploratoryResourceTest extends TestBase {
assertTrue(actualJson.contains(expectedJson));
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(exploratoryService).stop(getUserInfo(), "someName");
+ verify(exploratoryService).stop(getUserInfo(), "project", "someName");
verifyNoMoreInteractions(exploratoryService);
}
@Test
public void terminate() {
- when(exploratoryService.terminate(any(UserInfo.class), anyString())).thenReturn("someUuid");
+ when(exploratoryService.terminate(any(UserInfo.class), anyString(), anyString())).thenReturn("someUuid");
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/terminate")
+ .target("/infrastructure_provision/exploratory_environment/project/someName/terminate")
.request()
.header("Authorization", "Bearer " + TOKEN)
.delete();
@@ -221,16 +228,16 @@ public class ExploratoryResourceTest extends TestBase {
assertEquals("someUuid", response.readEntity(String.class));
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(exploratoryService).terminate(getUserInfo(), "someName");
+ verify(exploratoryService).terminate(getUserInfo(), "project", "someName");
verifyNoMoreInteractions(exploratoryService);
}
@Test
public void terminateWithFailedAuth() throws AuthenticationException {
authFailSetup();
- when(exploratoryService.terminate(any(UserInfo.class), anyString())).thenReturn("someUuid");
+ when(exploratoryService.terminate(any(UserInfo.class), anyString(), anyString())).thenReturn("someUuid");
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/terminate")
+ .target("/infrastructure_provision/exploratory_environment/project/someName/terminate")
.request()
.header("Authorization", "Bearer " + TOKEN)
.delete();
@@ -239,16 +246,16 @@ public class ExploratoryResourceTest extends TestBase {
assertEquals("someUuid", response.readEntity(String.class));
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(exploratoryService).terminate(getUserInfo(), "someName");
+ verify(exploratoryService).terminate(getUserInfo(), "project", "someName");
verifyNoMoreInteractions(exploratoryService);
}
@Test
public void terminateWithException() {
doThrow(new DlabException("Could not terminate exploratory environment"))
- .when(exploratoryService).terminate(any(UserInfo.class), anyString());
+ .when(exploratoryService).terminate(any(UserInfo.class), anyString(), anyString());
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/terminate")
+ .target("/infrastructure_provision/exploratory_environment/project/someName/terminate")
.request()
.header("Authorization", "Bearer " + TOKEN)
.delete();
@@ -260,22 +267,22 @@ public class ExploratoryResourceTest extends TestBase {
assertTrue(actualJson.contains(expectedJson));
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(exploratoryService).terminate(getUserInfo(), "someName");
+ verify(exploratoryService).terminate(getUserInfo(), "project", "someName");
verifyNoMoreInteractions(exploratoryService);
}
@Test
public void updateSparkConfig() {
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/reconfigure")
+ .target("/infrastructure_provision/exploratory_environment/someProject/someName/reconfigure")
.request()
.header("Authorization", "Bearer " + TOKEN)
.put(Entity.json(Collections.singletonList(new ClusterConfig())));
assertEquals(HttpStatus.SC_OK, response.getStatus());
- verify(exploratoryService).updateClusterConfig(refEq(getUserInfo()), eq("someName"),
- eq(Collections.singletonList(new ClusterConfig())));
+ verify(exploratoryService).updateClusterConfig(refEq(getUserInfo()), eq("someProject"),
+ eq("someName"), eq(Collections.singletonList(new ClusterConfig())));
verifyNoMoreInteractions(exploratoryService);
}
@@ -283,9 +290,9 @@ public class ExploratoryResourceTest extends TestBase {
public void getSparkConfig() {
final ClusterConfig config = new ClusterConfig();
config.setClassification("test");
- when(exploratoryService.getClusterConfig(any(UserInfo.class), anyString())).thenReturn(Collections.singletonList(config));
+ when(exploratoryService.getClusterConfig(any(UserInfo.class), anyString(), anyString())).thenReturn(Collections.singletonList(config));
final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/someName/cluster/config")
+ .target("/infrastructure_provision/exploratory_environment/someProject/someName/cluster/config")
.request()
.header("Authorization", "Bearer " + TOKEN)
.get();
@@ -296,7 +303,7 @@ public class ExploratoryResourceTest extends TestBase {
assertEquals(1, clusterConfigs.size());
assertEquals("test", clusterConfigs.get(0).getClassification());
- verify(exploratoryService).getClusterConfig(refEq(getUserInfo()), eq("someName"));
+ verify(exploratoryService).getClusterConfig(refEq(getUserInfo()), eq("someProject"), eq("someName"));
verifyNoMoreInteractions(exploratoryService);
}
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ImageExploratoryResourceTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ImageExploratoryResourceTest.java
index 2a7e4c0..38c0e46 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ImageExploratoryResourceTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ImageExploratoryResourceTest.java
@@ -45,10 +45,16 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class ImageExploratoryResourceTest extends TestBase {
-
+ private static final String PROJECT = "projectName";
private ImageExploratoryService imageExploratoryService = mock(ImageExploratoryService.class);
private RequestId requestId = mock(RequestId.class);
@@ -63,7 +69,7 @@ public class ImageExploratoryResourceTest extends TestBase {
@Test
public void createImage() {
- when(imageExploratoryService.createImage(any(UserInfo.class), anyString(), anyString(), anyString()))
+ when(imageExploratoryService.createImage(any(UserInfo.class), anyString(), anyString(), anyString(), anyString()))
.thenReturn("someUuid");
when(requestId.put(anyString(), anyString())).thenReturn("someUuid");
final Response response = resources.getJerseyTest()
@@ -75,7 +81,7 @@ public class ImageExploratoryResourceTest extends TestBase {
assertEquals(HttpStatus.SC_ACCEPTED, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(imageExploratoryService).createImage(getUserInfo(), "someNotebookName",
+ verify(imageExploratoryService).createImage(getUserInfo(), PROJECT, "someNotebookName",
"someImageName", "someDescription");
verify(requestId).put(USER.toLowerCase(), "someUuid");
verifyNoMoreInteractions(imageExploratoryService, requestId);
@@ -84,7 +90,7 @@ public class ImageExploratoryResourceTest extends TestBase {
@Test
public void createImageWithFailedAuth() throws AuthenticationException {
authFailSetup();
- when(imageExploratoryService.createImage(any(UserInfo.class), anyString(), anyString(), anyString()))
+ when(imageExploratoryService.createImage(any(UserInfo.class), anyString(), anyString(), anyString(), anyString()))
.thenReturn("someUuid");
when(requestId.put(anyString(), anyString())).thenReturn("someUuid");
final Response response = resources.getJerseyTest()
@@ -96,8 +102,7 @@ public class ImageExploratoryResourceTest extends TestBase {
assertEquals(HttpStatus.SC_ACCEPTED, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(imageExploratoryService).createImage(getUserInfo(), "someNotebookName",
- "someImageName", "someDescription");
+ verify(imageExploratoryService).createImage(getUserInfo(), PROJECT, "someNotebookName", "someImageName", "someDescription");
verify(requestId).put(USER.toLowerCase(), "someUuid");
verifyNoMoreInteractions(imageExploratoryService, requestId);
}
@@ -105,7 +110,7 @@ public class ImageExploratoryResourceTest extends TestBase {
@Test
public void createImageWithException() {
doThrow(new ResourceAlreadyExistException("Image with name is already exist"))
- .when(imageExploratoryService).createImage(any(UserInfo.class), anyString(), anyString(), anyString());
+ .when(imageExploratoryService).createImage(any(UserInfo.class), anyString(), anyString(), anyString(), anyString());
final Response response = resources.getJerseyTest()
.target("/infrastructure_provision/exploratory_environment/image")
.request()
@@ -115,8 +120,7 @@ public class ImageExploratoryResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(imageExploratoryService).createImage(getUserInfo(), "someNotebookName",
- "someImageName", "someDescription");
+ verify(imageExploratoryService).createImage(getUserInfo(), PROJECT, "someNotebookName", "someImageName", "someDescription");
verifyNoMoreInteractions(imageExploratoryService);
verifyZeroInteractions(requestId);
}
@@ -263,6 +267,7 @@ public class ImageExploratoryResourceTest extends TestBase {
private ExploratoryImageCreateFormDTO getExploratoryImageCreateFormDTO() {
ExploratoryImageCreateFormDTO eicfDto = new ExploratoryImageCreateFormDTO("someImageName", "someDescription");
eicfDto.setNotebookName("someNotebookName");
+ eicfDto.setProjectName(PROJECT);
return eicfDto;
}
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/LibExploratoryResourceTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/LibExploratoryResourceTest.java
index 50f6763..c7f5ced 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/LibExploratoryResourceTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/LibExploratoryResourceTest.java
@@ -22,7 +22,12 @@ package com.epam.dlab.backendapi.resources;
import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.dao.ExploratoryDAO;
import com.epam.dlab.backendapi.domain.RequestId;
-import com.epam.dlab.backendapi.resources.dto.*;
+import com.epam.dlab.backendapi.resources.dto.LibInfoRecord;
+import com.epam.dlab.backendapi.resources.dto.LibInstallFormDTO;
+import com.epam.dlab.backendapi.resources.dto.LibKey;
+import com.epam.dlab.backendapi.resources.dto.LibraryDTO;
+import com.epam.dlab.backendapi.resources.dto.LibraryStatus;
+import com.epam.dlab.backendapi.resources.dto.SearchLibsFormDTO;
import com.epam.dlab.backendapi.service.ExternalLibraryService;
import com.epam.dlab.backendapi.service.LibraryService;
import com.epam.dlab.dto.UserInstanceDTO;
@@ -50,331 +55,355 @@ import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.anyListOf;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.refEq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class LibExploratoryResourceTest extends TestBase {
- private static final String LIB_GROUP = "group";
- private static final String LIB_NAME = "name";
- private static final String LIB_VERSION = "version";
- private static final String EXPLORATORY_NAME = "explName";
- private static final String COMPUTATIONAL_NAME = "compName";
- private static final String UUID = "uid";
- private ExploratoryDAO exploratoryDAO = mock(ExploratoryDAO.class);
- private LibraryService libraryService = mock(LibraryService.class);
- private RESTService provisioningService = mock(RESTService.class);
- private ExternalLibraryService externalLibraryService = mock(ExternalLibraryService.class);
- private RequestId requestId = mock(RequestId.class);
-
- @Rule
- public final ResourceTestRule resources = getResourceTestRuleInstance(
- new LibExploratoryResource(exploratoryDAO, libraryService, externalLibraryService));
-
- @Before
- public void setup() throws AuthenticationException {
- authSetup();
- }
-
- @Test
- public void getLibGroupListWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn
- (getUserInstanceDto());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_groups")
- .queryParam("exploratory_name", "explName")
- .queryParam("computational_name", "compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "explName", "compName");
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ private static final String LIB_GROUP = "group";
+ private static final String LIB_NAME = "name";
+ private static final String LIB_VERSION = "version";
+ private static final String EXPLORATORY_NAME = "explName";
+ private static final String PROJECT = "projectName";
+ private static final String COMPUTATIONAL_NAME = "compName";
+ private static final String UUID = "uid";
+ private ExploratoryDAO exploratoryDAO = mock(ExploratoryDAO.class);
+ private LibraryService libraryService = mock(LibraryService.class);
+ private RESTService provisioningService = mock(RESTService.class);
+ private ExternalLibraryService externalLibraryService = mock(ExternalLibraryService.class);
+ private RequestId requestId = mock(RequestId.class);
+
+ @Rule
+ public final ResourceTestRule resources = getResourceTestRuleInstance(
+ new LibExploratoryResource(exploratoryDAO, libraryService, externalLibraryService));
+
+ @Before
+ public void setup() throws AuthenticationException {
+ authSetup();
+ }
+
+ @Test
+ public void getLibGroupListWithFailedAuth() throws AuthenticationException {
+ authFailSetup();
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getUserInstanceDto());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_groups")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("project_name", "projectName")
+ .queryParam("computational_name", "compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "projectName", "explName", "compName");
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getLibGroupListWithException() {
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn
- (getUserInstanceDto());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_groups")
- .queryParam("exploratory_name", "explName")
- .queryParam("computational_name", "compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "explName", "compName");
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString())).thenReturn
+ (getUserInstanceDto());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_groups")
+ .queryParam("project_name", "projectName")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("computational_name", "compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "projectName", "explName", "compName");
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getLibGroupListWithoutComputationalWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(getUserInstanceDto());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_groups")
- .queryParam("exploratory_name", "explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ authFailSetup();
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_groups")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("project_name", "projectName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getLibGroupListWithoutComputationalWithException() {
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(getUserInstanceDto());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_groups")
- .queryParam("exploratory_name", "explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_groups")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("project_name", "projectName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getLibList() {
- when(libraryService.getLibs(anyString(), anyString(), anyString())).thenReturn(getDocuments());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_list")
- .queryParam("exploratory_name", "explName")
- .queryParam("computational_name", "compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(getDocuments(), response.readEntity(new GenericType<List<Document>>() {
- }));
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(libraryService).getLibs(USER.toLowerCase(), "explName", "compName");
- verifyNoMoreInteractions(libraryService);
- }
+ when(libraryService.getLibs(anyString(), anyString(), anyString(), anyString())).thenReturn(getDocuments());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_list")
+ .queryParam("project_name", "projectName")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("computational_name", "compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(getDocuments(), response.readEntity(new GenericType<List<Document>>() {
+ }));
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(libraryService).getLibs(USER.toLowerCase(), "projectName", "explName", "compName");
+ verifyNoMoreInteractions(libraryService);
+ }
@Test
public void getLibListWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- when(libraryService.getLibs(anyString(), anyString(), anyString())).thenReturn(getDocuments());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_list")
- .queryParam("exploratory_name", "explName")
- .queryParam("computational_name", "compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(getDocuments(), response.readEntity(new GenericType<List<Document>>() {
- }));
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(libraryService).getLibs(USER.toLowerCase(), "explName", "compName");
- verifyNoMoreInteractions(libraryService);
- }
+ authFailSetup();
+ when(libraryService.getLibs(anyString(), anyString(), anyString(), anyString())).thenReturn(getDocuments());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_list")
+ .queryParam("project_name", "projectName")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("computational_name", "compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(getDocuments(), response.readEntity(new GenericType<List<Document>>() {
+ }));
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(libraryService).getLibs(USER.toLowerCase(), "projectName", "explName", "compName");
+ verifyNoMoreInteractions(libraryService);
+ }
@Test
public void getLibListWithException() {
- doThrow(new DlabException("Cannot load installed libraries"))
- .when(libraryService).getLibs(anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_list")
- .queryParam("exploratory_name", "explName")
- .queryParam("computational_name", "compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(libraryService).getLibs(USER.toLowerCase(), "explName", "compName");
- verifyNoMoreInteractions(libraryService);
- }
+ doThrow(new DlabException("Cannot load installed libraries"))
+ .when(libraryService).getLibs(anyString(), anyString(), anyString(), anyString());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_list")
+ .queryParam("project_name", "projectName")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("computational_name", "compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(libraryService).getLibs(USER.toLowerCase(), "projectName", "explName", "compName");
+ verifyNoMoreInteractions(libraryService);
+ }
@Test
public void getLibListFormatted() {
- when(libraryService.getLibInfo(anyString(), anyString())).thenReturn(getLibInfoRecords());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_list/formatted")
- .queryParam("exploratory_name", "explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(libraryService).getLibInfo(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(libraryService);
- }
+ when(libraryService.getLibInfo(anyString(), anyString(), anyString())).thenReturn(getLibInfoRecords());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_list/formatted")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("project_name", "projectName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(libraryService).getLibInfo(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(libraryService);
+ }
@Test
public void getLibListFormattedWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- when(libraryService.getLibInfo(anyString(), anyString())).thenReturn(getLibInfoRecords());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_list/formatted")
- .queryParam("exploratory_name", "explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(libraryService).getLibInfo(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(libraryService);
- }
+ authFailSetup();
+ when(libraryService.getLibInfo(anyString(), anyString(), anyString())).thenReturn(getLibInfoRecords());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_list/formatted")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("project_name", "projectName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(libraryService).getLibInfo(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(libraryService);
+ }
@Test
public void getLibListFormattedWithException() {
- doThrow(new DlabException("Cannot load formatted list of installed libraries"))
- .when(libraryService).getLibInfo(anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_list/formatted")
- .queryParam("exploratory_name", "explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(libraryService).getLibInfo(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(libraryService);
- }
+ doThrow(new DlabException("Cannot load formatted list of installed libraries"))
+ .when(libraryService).getLibInfo(anyString(), anyString(), anyString());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_list/formatted")
+ .queryParam("exploratory_name", "explName")
+ .queryParam("project_name", "projectName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(libraryService).getLibInfo(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(libraryService);
+ }
@Test
public void libInstall() {
- when(libraryService.installComputationalLibs(any(UserInfo.class), anyString(), anyString(),
- anyListOf(LibInstallDTO.class))).thenReturn(UUID);
- LibInstallFormDTO libInstallFormDTO = new LibInstallFormDTO();
- libInstallFormDTO.setComputationalName(COMPUTATIONAL_NAME);
- libInstallFormDTO.setNotebookName(EXPLORATORY_NAME);
- libInstallFormDTO.setLibs(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION)));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_install")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(libInstallFormDTO));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- assertEquals(UUID, response.readEntity(String.class));
-
- verify(libraryService).installComputationalLibs(refEq(getUserInfo()), eq(EXPLORATORY_NAME),
- eq(COMPUTATIONAL_NAME), eq(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION))));
- verifyNoMoreInteractions(libraryService);
- verifyZeroInteractions(provisioningService, requestId);
- }
+ when(libraryService.installComputationalLibs(any(UserInfo.class), anyString(), anyString(),
+ anyString(), anyListOf(LibInstallDTO.class))).thenReturn(UUID);
+ LibInstallFormDTO libInstallFormDTO = new LibInstallFormDTO();
+ libInstallFormDTO.setComputationalName(COMPUTATIONAL_NAME);
+ libInstallFormDTO.setNotebookName(EXPLORATORY_NAME);
+ libInstallFormDTO.setProject(PROJECT);
+ libInstallFormDTO.setLibs(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION)));
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_install")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(libInstallFormDTO));
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+ assertEquals(UUID, response.readEntity(String.class));
+
+ verify(libraryService).installComputationalLibs(refEq(getUserInfo()), eq(PROJECT),
+ eq(EXPLORATORY_NAME), eq(COMPUTATIONAL_NAME), eq(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION))));
+ verifyNoMoreInteractions(libraryService);
+ verifyZeroInteractions(provisioningService, requestId);
+ }
@Test
public void libInstallWithoutComputational() {
- when(libraryService.installExploratoryLibs(any(UserInfo.class), anyString(), anyListOf(LibInstallDTO.class))).thenReturn(UUID);
- LibInstallFormDTO libInstallFormDTO = new LibInstallFormDTO();
- libInstallFormDTO.setNotebookName(EXPLORATORY_NAME);
- libInstallFormDTO.setLibs(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION)));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/lib_install")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(libInstallFormDTO));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- assertEquals(UUID, response.readEntity(String.class));
-
- verify(libraryService).installExploratoryLibs(refEq(getUserInfo()), eq(EXPLORATORY_NAME),
- eq(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION))));
- verifyNoMoreInteractions(libraryService);
- verifyZeroInteractions(provisioningService, requestId);
- }
+ when(libraryService.installExploratoryLibs(any(UserInfo.class), anyString(), anyString(), anyListOf(LibInstallDTO.class))).thenReturn(UUID);
+ LibInstallFormDTO libInstallFormDTO = new LibInstallFormDTO();
+ libInstallFormDTO.setNotebookName(EXPLORATORY_NAME);
+ libInstallFormDTO.setLibs(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION)));
+ libInstallFormDTO.setProject(PROJECT);
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/lib_install")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(libInstallFormDTO));
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+ assertEquals(UUID, response.readEntity(String.class));
+
+ verify(libraryService).installExploratoryLibs(refEq(getUserInfo()), eq(PROJECT),
+ eq(EXPLORATORY_NAME), eq(singletonList(new LibInstallDTO(LIB_GROUP, LIB_NAME, LIB_VERSION))));
+ verifyNoMoreInteractions(libraryService);
+ verifyZeroInteractions(provisioningService, requestId);
+ }
@Test
public void getLibraryListWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString()))
- .thenReturn(getUserInstanceDto());
- SearchLibsFormDTO searchLibsFormDTO = new SearchLibsFormDTO();
- searchLibsFormDTO.setComputationalName("compName");
- searchLibsFormDTO.setNotebookName("explName");
- searchLibsFormDTO.setGroup("someGroup");
- searchLibsFormDTO.setStartWith("someText");
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/search/lib_list")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(searchLibsFormDTO));
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "explName", "compName");
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ authFailSetup();
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getUserInstanceDto());
+ SearchLibsFormDTO searchLibsFormDTO = new SearchLibsFormDTO();
+ searchLibsFormDTO.setComputationalName("compName");
+ searchLibsFormDTO.setNotebookName("explName");
+ searchLibsFormDTO.setGroup("someGroup");
+ searchLibsFormDTO.setStartWith("someText");
+ searchLibsFormDTO.setProjectName("projectName");
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/search/lib_list")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(searchLibsFormDTO));
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "projectName", "explName", "compName");
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getLibraryListWithException() {
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString()))
- .thenReturn(getUserInstanceDto());
- SearchLibsFormDTO searchLibsFormDTO = new SearchLibsFormDTO();
- searchLibsFormDTO.setComputationalName("compName");
- searchLibsFormDTO.setNotebookName("explName");
- searchLibsFormDTO.setGroup("someGroup");
- searchLibsFormDTO.setStartWith("someText");
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/search/lib_list")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(searchLibsFormDTO));
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "explName", "compName");
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getUserInstanceDto());
+ SearchLibsFormDTO searchLibsFormDTO = new SearchLibsFormDTO();
+ searchLibsFormDTO.setComputationalName("compName");
+ searchLibsFormDTO.setNotebookName("explName");
+ searchLibsFormDTO.setGroup("someGroup");
+ searchLibsFormDTO.setStartWith("someText");
+ searchLibsFormDTO.setProjectName("projectName");
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/search/lib_list")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(searchLibsFormDTO));
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "projectName", "explName", "compName");
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getLibraryListWithoutComputationalWithException() {
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString()))
- .thenReturn(getUserInstanceDto());
- SearchLibsFormDTO searchLibsFormDTO = new SearchLibsFormDTO();
- searchLibsFormDTO.setComputationalName("");
- searchLibsFormDTO.setNotebookName("explName");
- searchLibsFormDTO.setGroup("someGroup");
- searchLibsFormDTO.setStartWith("someText");
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/search/lib_list")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(searchLibsFormDTO));
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString()))
+ .thenReturn(getUserInstanceDto());
+ SearchLibsFormDTO searchLibsFormDTO = new SearchLibsFormDTO();
+ searchLibsFormDTO.setComputationalName("");
+ searchLibsFormDTO.setNotebookName("explName");
+ searchLibsFormDTO.setGroup("someGroup");
+ searchLibsFormDTO.setStartWith("someText");
+ searchLibsFormDTO.setProjectName("projectName");
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/search/lib_list")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(searchLibsFormDTO));
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getMavenArtifact() {
@@ -422,11 +451,14 @@ public class LibExploratoryResourceTest extends TestBase {
}
private UserInstanceDTO getUserInstanceDto() {
- UserComputationalResource ucResource = new UserComputationalResource();
- ucResource.setComputationalName("compName");
- return new UserInstanceDTO().withUser(USER).withExploratoryName("explName")
- .withResources(singletonList(ucResource));
- }
+ UserComputationalResource ucResource = new UserComputationalResource();
+ ucResource.setComputationalName("compName");
+ return new UserInstanceDTO()
+ .withUser(USER)
+ .withExploratoryName("explName")
+ .withProject(PROJECT)
+ .withResources(singletonList(ucResource));
+ }
private List<Document> getDocuments() {
return singletonList(new Document());
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/SchedulerJobResourceTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/SchedulerJobResourceTest.java
index 08e601e..c763238 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/SchedulerJobResourceTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/SchedulerJobResourceTest.java
@@ -36,7 +36,12 @@ 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.time.*;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collections;
@@ -46,7 +51,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
public class SchedulerJobResourceTest extends TestBase {
@@ -63,228 +74,228 @@ public class SchedulerJobResourceTest extends TestBase {
@Test
public void updateExploratoryScheduler() {
- doNothing().when(schedulerJobService)
- .updateExploratorySchedulerData(anyString(), anyString(), any(SchedulerJobDTO.class));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(getSchedulerJobDTO()));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(),
- "explName", getSchedulerJobDTO());
- verifyNoMoreInteractions(schedulerJobService);
- }
+ doNothing().when(schedulerJobService)
+ .updateExploratorySchedulerData(anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(getSchedulerJobDTO()));
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(), "projectName",
+ "explName", getSchedulerJobDTO());
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void updateExploratorySchedulerWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- doNothing().when(schedulerJobService)
- .updateExploratorySchedulerData(anyString(), anyString(), any(SchedulerJobDTO.class));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName")
- .request()
- .header("Authorization", String.join(" ", "Bearer", TOKEN))
- .post(Entity.json(getSchedulerJobDTO()));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(),
- "explName", getSchedulerJobDTO());
- verifyNoMoreInteractions(schedulerJobService);
- }
+ authFailSetup();
+ doNothing().when(schedulerJobService)
+ .updateExploratorySchedulerData(anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
+ .request()
+ .header("Authorization", String.join(" ", "Bearer", TOKEN))
+ .post(Entity.json(getSchedulerJobDTO()));
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(), "projectName",
+ "explName", getSchedulerJobDTO());
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void updateExploratorySchedulerWithException() {
- doThrow(new ResourceInappropriateStateException("Can't create/update scheduler for user instance with status"))
- .when(schedulerJobService).updateExploratorySchedulerData(anyString(), anyString(),
- any(SchedulerJobDTO.class));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(getSchedulerJobDTO()));
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(), "explName",
- getSchedulerJobDTO());
- verifyNoMoreInteractions(schedulerJobService);
- }
+ doThrow(new ResourceInappropriateStateException("Can't create/update scheduler for user instance with status"))
+ .when(schedulerJobService).updateExploratorySchedulerData(anyString(), anyString(), anyString(),
+ any(SchedulerJobDTO.class));
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(getSchedulerJobDTO()));
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(), "projectName",
+ "explName", getSchedulerJobDTO());
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void upsertComputationalScheduler() {
- doNothing().when(schedulerJobService)
- .updateComputationalSchedulerData(anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(getSchedulerJobDTO()));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "explName",
- "compName", getSchedulerJobDTO());
- verifyNoMoreInteractions(schedulerJobService);
- }
+ doNothing().when(schedulerJobService)
+ .updateComputationalSchedulerData(anyString(), anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(getSchedulerJobDTO()));
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "projectName",
+ "explName", "compName", getSchedulerJobDTO());
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void upsertComputationalSchedulerWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- doNothing().when(schedulerJobService)
- .updateComputationalSchedulerData(anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(getSchedulerJobDTO()));
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "explName",
- "compName", getSchedulerJobDTO());
- verifyNoMoreInteractions(schedulerJobService);
- }
+ authFailSetup();
+ doNothing().when(schedulerJobService)
+ .updateComputationalSchedulerData(anyString(), anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(getSchedulerJobDTO()));
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "projectName",
+ "explName", "compName", getSchedulerJobDTO());
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void upsertComputationalSchedulerWithException() {
- doThrow(new ResourceInappropriateStateException("Can't create/update scheduler for user instance with status"))
- .when(schedulerJobService).updateComputationalSchedulerData(anyString(), anyString(), anyString(),
- any(SchedulerJobDTO.class));
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .post(Entity.json(getSchedulerJobDTO()));
-
- assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "explName",
- "compName", getSchedulerJobDTO());
- verifyNoMoreInteractions(schedulerJobService);
- }
+ doThrow(new ResourceInappropriateStateException("Can't create/update scheduler for user instance with status"))
+ .when(schedulerJobService).updateComputationalSchedulerData(anyString(), anyString(), anyString(),
+ anyString(), any(SchedulerJobDTO.class));
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .post(Entity.json(getSchedulerJobDTO()));
+
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "projectName",
+ "explName", "compName", getSchedulerJobDTO());
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void fetchSchedulerJobForUserAndExploratory() {
- when(schedulerJobService.fetchSchedulerJobForUserAndExploratory(anyString(), anyString()))
- .thenReturn(getSchedulerJobDTO());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).fetchSchedulerJobForUserAndExploratory(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(schedulerJobService);
- }
+ when(schedulerJobService.fetchSchedulerJobForUserAndExploratory(anyString(), anyString(), anyString()))
+ .thenReturn(getSchedulerJobDTO());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).fetchSchedulerJobForUserAndExploratory(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void fetchSchedulerJobForUserAndExploratoryWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- when(schedulerJobService.fetchSchedulerJobForUserAndExploratory(anyString(), anyString()))
- .thenReturn(getSchedulerJobDTO());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
+ authFailSetup();
+ when(schedulerJobService.fetchSchedulerJobForUserAndExploratory(anyString(), anyString(), anyString()))
+ .thenReturn(getSchedulerJobDTO());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).fetchSchedulerJobForUserAndExploratory(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(schedulerJobService);
- }
+ verify(schedulerJobService).fetchSchedulerJobForUserAndExploratory(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void fetchSchedulerJobForUserAndExploratoryWithException() {
- doThrow(new ResourceNotFoundException("Scheduler job data not found for user with exploratory"))
- .when(schedulerJobService).fetchSchedulerJobForUserAndExploratory(anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
+ doThrow(new ResourceNotFoundException("Scheduler job data not found for user with exploratory"))
+ .when(schedulerJobService).fetchSchedulerJobForUserAndExploratory(anyString(), anyString(), anyString());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
- assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+ assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).fetchSchedulerJobForUserAndExploratory(USER.toLowerCase(), "explName");
- verifyNoMoreInteractions(schedulerJobService);
- }
+ verify(schedulerJobService).fetchSchedulerJobForUserAndExploratory(USER.toLowerCase(), "projectName", "explName");
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void fetchSchedulerJobForComputationalResource() {
- when(schedulerJobService.fetchSchedulerJobForComputationalResource(anyString(), anyString(), anyString()))
- .thenReturn(getSchedulerJobDTO());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).fetchSchedulerJobForComputationalResource(USER.toLowerCase(),
- "explName", "compName");
- verifyNoMoreInteractions(schedulerJobService);
- }
+ when(schedulerJobService.fetchSchedulerJobForComputationalResource(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getSchedulerJobDTO());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).fetchSchedulerJobForComputationalResource(USER.toLowerCase(), "projectName",
+ "explName", "compName");
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void fetchSchedulerJobForComputationalResourceWithFailedAuth() throws AuthenticationException {
- authFailSetup();
- when(schedulerJobService.fetchSchedulerJobForComputationalResource(anyString(), anyString(), anyString()))
- .thenReturn(getSchedulerJobDTO());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_OK, response.getStatus());
- assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).fetchSchedulerJobForComputationalResource(USER.toLowerCase(),
- "explName", "compName");
- verifyNoMoreInteractions(schedulerJobService);
- }
+ authFailSetup();
+ when(schedulerJobService.fetchSchedulerJobForComputationalResource(anyString(), anyString(), anyString(), anyString()))
+ .thenReturn(getSchedulerJobDTO());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertEquals(getSchedulerJobDTO(), response.readEntity(SchedulerJobDTO.class));
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).fetchSchedulerJobForComputationalResource(USER.toLowerCase(), "projectName",
+ "explName", "compName");
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void fetchSchedulerJobForComputationalResourceWithException() {
- doThrow(new ResourceNotFoundException("Scheduler job data not found for user with exploratory with " +
- "computational resource")).when(schedulerJobService)
- .fetchSchedulerJobForComputationalResource(anyString(), anyString(), anyString());
- final Response response = resources.getJerseyTest()
- .target("/infrastructure_provision/exploratory_environment/scheduler/explName/compName")
- .request()
- .header("Authorization", "Bearer " + TOKEN)
- .get();
-
- assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
- assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
-
- verify(schedulerJobService).fetchSchedulerJobForComputationalResource(USER.toLowerCase(),
- "explName", "compName");
- verifyNoMoreInteractions(schedulerJobService);
- }
+ doThrow(new ResourceNotFoundException("Scheduler job data not found for user with exploratory with " +
+ "computational resource")).when(schedulerJobService)
+ .fetchSchedulerJobForComputationalResource(anyString(), anyString(), anyString(), anyString());
+ final Response response = resources.getJerseyTest()
+ .target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
+ .request()
+ .header("Authorization", "Bearer " + TOKEN)
+ .get();
+
+ assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
+ assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ verify(schedulerJobService).fetchSchedulerJobForComputationalResource(USER.toLowerCase(), "projectName",
+ "explName", "compName");
+ verifyNoMoreInteractions(schedulerJobService);
+ }
@Test
public void testGetActiveSchedulers() {
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImplTest.java
index 8331235..74fc7f0 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ComputationalServiceImplTest.java
@@ -38,10 +38,15 @@ import com.epam.dlab.dto.SchedulerJobDTO;
import com.epam.dlab.dto.UserInstanceDTO;
import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.aws.computational.ClusterConfig;
-import com.epam.dlab.dto.base.DataEngineType;
import com.epam.dlab.dto.base.computational.ComputationalBase;
import com.epam.dlab.dto.base.edge.EdgeInfo;
-import com.epam.dlab.dto.computational.*;
+import com.epam.dlab.dto.computational.ComputationalClusterConfigDTO;
+import com.epam.dlab.dto.computational.ComputationalStartDTO;
+import com.epam.dlab.dto.computational.ComputationalStatusDTO;
+import com.epam.dlab.dto.computational.ComputationalStopDTO;
+import com.epam.dlab.dto.computational.ComputationalTerminateDTO;
+import com.epam.dlab.dto.computational.SparkStandaloneClusterResource;
+import com.epam.dlab.dto.computational.UserComputationalResource;
import com.epam.dlab.exceptions.DlabException;
import com.epam.dlab.exceptions.ResourceNotFoundException;
import com.epam.dlab.rest.client.RESTService;
@@ -62,42 +67,60 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import static com.epam.dlab.dto.UserInstanceStatus.*;
+import static com.epam.dlab.dto.UserInstanceStatus.CREATING;
+import static com.epam.dlab.dto.UserInstanceStatus.RUNNING;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPED;
import static java.util.Collections.singletonList;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
+import static org.mockito.Mockito.anyListOf;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.refEq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ComputationalServiceImplTest {
- private static final long MAX_INACTIVITY = 10L;
- private static final String DOCKER_DLAB_DATAENGINE = "docker.dlab-dataengine";
- private static final String DOCKER_DLAB_DATAENGINE_SERVICE = "docker.dlab-dataengine-service";
- private static final String COMP_ID = "compId";
- private final String USER = "test";
- private final String TOKEN = "token";
- private final String EXPLORATORY_NAME = "expName";
- private final String COMP_NAME = "compName";
- private final String UUID = "1234-56789765-4321";
- private final LocalDateTime LAST_ACTIVITY = LocalDateTime.now().minusMinutes(MAX_INACTIVITY);
-
- private UserInfo userInfo;
- private List<ComputationalCreateFormDTO> formList;
- private UserInstanceDTO userInstance;
- private ComputationalStatusDTO computationalStatusDTOWithStatusTerminating;
- private ComputationalStatusDTO computationalStatusDTOWithStatusFailed;
- private ComputationalStatusDTO computationalStatusDTOWithStatusStopping;
- private ComputationalStatusDTO computationalStatusDTOWithStatusStarting;
- private SparkStandaloneClusterResource sparkClusterResource;
- private UserComputationalResource ucResource;
-
- @Mock
- private ProjectService projectService;
- @Mock
- private ExploratoryDAO exploratoryDAO;
- @Mock
- private ComputationalDAO computationalDAO;
+ private static final long MAX_INACTIVITY = 10L;
+ private static final String DOCKER_DLAB_DATAENGINE = "docker.dlab-dataengine";
+ private static final String DOCKER_DLAB_DATAENGINE_SERVICE = "docker.dlab-dataengine-service";
+ private static final String COMP_ID = "compId";
+ private final String USER = "test";
+ private final String TOKEN = "token";
+ private final String EXPLORATORY_NAME = "expName";
+ private final String PROJECT = "project";
+ private final String COMP_NAME = "compName";
+ private final String UUID = "1234-56789765-4321";
+ private final LocalDateTime LAST_ACTIVITY = LocalDateTime.now().minusMinutes(MAX_INACTIVITY);
+
+ private UserInfo userInfo;
+ private List<ComputationalCreateFormDTO> formList;
+ private UserInstanceDTO userInstance;
+ private ComputationalStatusDTO computationalStatusDTOWithStatusTerminating;
+ private ComputationalStatusDTO computationalStatusDTOWithStatusFailed;
+ private ComputationalStatusDTO computationalStatusDTOWithStatusStopping;
+ private ComputationalStatusDTO computationalStatusDTOWithStatusStarting;
+ private SparkStandaloneClusterResource sparkClusterResource;
+ private UserComputationalResource ucResource;
+
+ @Mock
+ private ProjectService projectService;
+ @Mock
+ private ExploratoryDAO exploratoryDAO;
+ @Mock
+ private ComputationalDAO computationalDAO;
@Mock
private RESTService provisioningService;
@Mock
@@ -132,149 +155,148 @@ public class ComputationalServiceImplTest {
@Test
public void createSparkCluster() {
- ProjectDTO projectDTO = getProjectDTO();
- when(projectService.get(anyString())).thenReturn(projectDTO);
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(computationalDAO.addComputational(anyString(), anyString(),
- any(SparkStandaloneClusterResource.class))).thenReturn(true);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
-
- ComputationalBase compBaseMocked = mock(ComputationalBase.class);
- when(requestBuilder.newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
- any(UserInstanceDTO.class), any(SparkStandaloneClusterCreateForm.class), any(EndpointDTO.class)))
- .thenReturn(compBaseMocked);
- when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any())).thenReturn(UUID);
- when(requestId.put(anyString(), anyString())).thenReturn(UUID);
-
- SparkStandaloneClusterCreateForm sparkClusterCreateForm = (SparkStandaloneClusterCreateForm) formList.get(0);
- boolean creationResult =
- computationalService.createSparkCluster(userInfo, sparkClusterCreateForm, "");
- assertTrue(creationResult);
-
- verify(projectService).get("");
- verify(computationalDAO)
- .addComputational(eq(USER), eq(EXPLORATORY_NAME), refEq(sparkClusterResource));
-
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(requestBuilder).newComputationalCreate(
- refEq(userInfo), refEq(projectDTO), refEq(userInstance), refEq(sparkClusterCreateForm), refEq(endpointDTO()));
-
- verify(provisioningService)
- .post(endpointDTO().getUrl() + ComputationalAPI.COMPUTATIONAL_CREATE_SPARK, TOKEN, compBaseMocked,
- String.class);
-
- verify(requestId).put(USER, UUID);
- verifyNoMoreInteractions(projectService, configuration, computationalDAO, requestBuilder, provisioningService, requestId);
- }
- @Test
- public void createSparkClusterWhenResourceAlreadyExists() {
- when(computationalDAO.addComputational(anyString(), anyString(),
- any(SparkStandaloneClusterResource.class))).thenReturn(false);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
-
-
- boolean creationResult =
- computationalService.createSparkCluster(userInfo, (SparkStandaloneClusterCreateForm) formList.get(0),
- "");
- assertFalse(creationResult);
-
- verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), refEq(sparkClusterResource));
- verifyNoMoreInteractions(configuration, computationalDAO);
- }
+ ProjectDTO projectDTO = getProjectDTO();
+ when(projectService.get(anyString())).thenReturn(projectDTO);
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(computationalDAO.addComputational(anyString(), anyString(), anyString(),
+ any(SparkStandaloneClusterResource.class))).thenReturn(true);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+
+ ComputationalBase compBaseMocked = mock(ComputationalBase.class);
+ when(requestBuilder.newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
+ any(UserInstanceDTO.class), any(SparkStandaloneClusterCreateForm.class), any(EndpointDTO.class)))
+ .thenReturn(compBaseMocked);
+ when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any())).thenReturn(UUID);
+ when(requestId.put(anyString(), anyString())).thenReturn(UUID);
+
+ SparkStandaloneClusterCreateForm sparkClusterCreateForm = (SparkStandaloneClusterCreateForm) formList.get(0);
+ boolean creationResult =
+ computationalService.createSparkCluster(userInfo, sparkClusterCreateForm, PROJECT);
+ assertTrue(creationResult);
+
+ verify(projectService).get(PROJECT);
+ verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), eq(PROJECT), refEq(sparkClusterResource));
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(requestBuilder).newComputationalCreate(
+ refEq(userInfo), refEq(projectDTO), refEq(userInstance), refEq(sparkClusterCreateForm), refEq(endpointDTO()));
+
+ verify(provisioningService)
+ .post(endpointDTO().getUrl() + ComputationalAPI.COMPUTATIONAL_CREATE_SPARK, TOKEN, compBaseMocked,
+ String.class);
+
+ verify(requestId).put(USER, UUID);
+ verifyNoMoreInteractions(projectService, configuration, computationalDAO, requestBuilder, provisioningService, requestId);
+ }
+
+ @Test
+ public void createSparkClusterWhenResourceAlreadyExists() {
+ when(computationalDAO.addComputational(anyString(), anyString(), anyString(),
+ any(SparkStandaloneClusterResource.class))).thenReturn(false);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+
+
+ boolean creationResult = computationalService.createSparkCluster(userInfo, (SparkStandaloneClusterCreateForm) formList.get(0),
+ PROJECT);
+ assertFalse(creationResult);
+
+ verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), eq(PROJECT), refEq(sparkClusterResource));
+ verifyNoMoreInteractions(configuration, computationalDAO);
+ }
@Test
public void createSparkClusterWhenMethodFetchExploratoryFieldsThrowsException() {
- when(computationalDAO.addComputational(anyString(), anyString(),
- any(SparkStandaloneClusterResource.class))).thenReturn(true);
- doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
- .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString());
-
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
-
- SparkStandaloneClusterCreateForm sparkClusterCreateForm = (SparkStandaloneClusterCreateForm) formList.get(0);
- try {
- computationalService.createSparkCluster(userInfo, sparkClusterCreateForm, "");
- } catch (ResourceNotFoundException e) {
- assertEquals("Exploratory for user with name not found", e.getMessage());
- }
-
- verify(computationalDAO, never()).addComputational(USER, EXPLORATORY_NAME, sparkClusterResource);
- verify(computationalDAO, never()).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed,
- "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(configuration, computationalDAO, exploratoryDAO);
- }
+ when(computationalDAO.addComputational(anyString(), anyString(), anyString(),
+ any(SparkStandaloneClusterResource.class))).thenReturn(true);
+ doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
+ .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
+
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+
+ SparkStandaloneClusterCreateForm sparkClusterCreateForm = (SparkStandaloneClusterCreateForm) formList.get(0);
+ try {
+ computationalService.createSparkCluster(userInfo, sparkClusterCreateForm, PROJECT);
+ } catch (ResourceNotFoundException e) {
+ assertEquals("Exploratory for user with name not found", e.getMessage());
+ }
+
+ verify(computationalDAO, never()).addComputational(USER, EXPLORATORY_NAME, PROJECT, sparkClusterResource);
+ verify(computationalDAO, never()).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed,
+ "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(configuration, computationalDAO, exploratoryDAO);
+ }
@Test
public void createSparkClusterWhenMethodNewComputationalCreateThrowsException() {
- ProjectDTO projectDTO = getProjectDTO();
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(projectService.get(anyString())).thenReturn(projectDTO);
- when(computationalDAO.addComputational(anyString(), anyString(),
- any(SparkStandaloneClusterResource.class))).thenReturn(true);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
-
- doThrow(new DlabException("Cannot create instance of resource class "))
- .when(requestBuilder).newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
- any(UserInstanceDTO.class), any(SparkStandaloneClusterCreateForm.class), any(EndpointDTO.class));
-
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
-
- SparkStandaloneClusterCreateForm sparkClusterCreateForm = (SparkStandaloneClusterCreateForm) formList.get(0);
- try {
- computationalService.createSparkCluster(userInfo, sparkClusterCreateForm, "");
- } catch (DlabException e) {
- assertEquals("Cannot create instance of resource class ", e.getMessage());
- }
- verify(projectService).get("");
- verify(computationalDAO).addComputational(USER, EXPLORATORY_NAME, sparkClusterResource);
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(requestBuilder).newComputationalCreate(userInfo, projectDTO, userInstance, sparkClusterCreateForm, endpointDTO());
- verifyNoMoreInteractions(projectService, configuration, computationalDAO, exploratoryDAO, requestBuilder);
- }
+ ProjectDTO projectDTO = getProjectDTO();
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(projectService.get(anyString())).thenReturn(projectDTO);
+ when(computationalDAO.addComputational(anyString(), anyString(), anyString(),
+ any(SparkStandaloneClusterResource.class))).thenReturn(true);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+
+ doThrow(new DlabException("Cannot create instance of resource class "))
+ .when(requestBuilder).newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
+ any(UserInstanceDTO.class), any(SparkStandaloneClusterCreateForm.class), any(EndpointDTO.class));
+
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+
+ SparkStandaloneClusterCreateForm sparkClusterCreateForm = (SparkStandaloneClusterCreateForm) formList.get(0);
+ try {
+ computationalService.createSparkCluster(userInfo, sparkClusterCreateForm, PROJECT);
+ } catch (DlabException e) {
+ assertEquals("Cannot create instance of resource class ", e.getMessage());
+ }
+ verify(projectService).get(PROJECT);
+ verify(computationalDAO).addComputational(USER, EXPLORATORY_NAME, PROJECT, sparkClusterResource);
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(requestBuilder).newComputationalCreate(userInfo, projectDTO, userInstance, sparkClusterCreateForm, endpointDTO());
+ verifyNoMoreInteractions(projectService, configuration, computationalDAO, exploratoryDAO, requestBuilder);
+ }
@Test
public void terminateComputationalEnvironment() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
- String explId = "explId";
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+ String explId = "explId";
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
- String compId = "compId";
- UserComputationalResource ucResource = new UserComputationalResource();
- ucResource.setComputationalName(COMP_NAME);
- ucResource.setImageName("dataengine-service");
- ucResource.setComputationalId(compId);
- when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString())).thenReturn(ucResource);
+ String compId = "compId";
+ UserComputationalResource ucResource = new UserComputationalResource();
+ ucResource.setComputationalName(COMP_NAME);
+ ucResource.setImageName("dataengine-service");
+ ucResource.setComputationalId(compId);
+ when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString())).thenReturn(ucResource);
- ComputationalTerminateDTO ctDto = new ComputationalTerminateDTO();
- ctDto.setComputationalName(COMP_NAME);
- ctDto.setExploratoryName(EXPLORATORY_NAME);
- when(requestBuilder.newComputationalTerminate(any(UserInfo.class), any(UserInstanceDTO.class),
- any(UserComputationalResource.class), any(EndpointDTO.class))).thenReturn(ctDto);
+ ComputationalTerminateDTO ctDto = new ComputationalTerminateDTO();
+ ctDto.setComputationalName(COMP_NAME);
+ ctDto.setExploratoryName(EXPLORATORY_NAME);
+ when(requestBuilder.newComputationalTerminate(any(UserInfo.class), any(UserInstanceDTO.class),
+ any(UserComputationalResource.class), any(EndpointDTO.class))).thenReturn(ctDto);
- when(provisioningService.post(anyString(), anyString(), any(ComputationalTerminateDTO.class), any()))
- .thenReturn(UUID);
- when(requestId.put(anyString(), anyString())).thenReturn(UUID);
+ when(provisioningService.post(anyString(), anyString(), any(ComputationalTerminateDTO.class), any()))
+ .thenReturn(UUID);
+ when(requestId.put(anyString(), anyString())).thenReturn(UUID);
- computationalService.terminateComputational(userInfo, EXPLORATORY_NAME, COMP_NAME);
+ computationalService.terminateComputational(userInfo, PROJECT, EXPLORATORY_NAME, COMP_NAME);
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusTerminating, "self"));
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMP_NAME);
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusTerminating, "self"));
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMP_NAME);
- verify(requestBuilder).newComputationalTerminate(userInfo, userInstance, ucResource, endpointDTO());
+ verify(requestBuilder).newComputationalTerminate(userInfo, userInstance, ucResource, endpointDTO());
- verify(provisioningService).post(endpointDTO().getUrl() + ComputationalAPI.COMPUTATIONAL_TERMINATE_CLOUD_SPECIFIC, TOKEN, ctDto,
- String.class);
+ verify(provisioningService).post(endpointDTO().getUrl() + ComputationalAPI.COMPUTATIONAL_TERMINATE_CLOUD_SPECIFIC, TOKEN, ctDto,
+ String.class);
- verify(requestId).put(USER, UUID);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder, provisioningService, requestId);
- }
+ verify(requestId).put(USER, UUID);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder, provisioningService, requestId);
+ }
@Test
public void terminateComputationalEnvironmentWhenMethodUpdateComputationalStatusThrowsException() {
@@ -285,11 +307,11 @@ public class ComputationalServiceImplTest {
when(computationalDAO.updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self")))
.thenReturn(mock(UpdateResult.class));
- try {
- computationalService.terminateComputational(userInfo, EXPLORATORY_NAME, COMP_NAME);
- } catch (DlabException e) {
- assertEquals("Could not update computational resource status", e.getMessage());
- }
+ try {
+ computationalService.terminateComputational(userInfo, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ } catch (DlabException e) {
+ assertEquals("Could not update computational resource status", e.getMessage());
+ }
verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusTerminating, "self"));
verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
@@ -298,400 +320,384 @@ public class ComputationalServiceImplTest {
@Test
public void terminateComputationalEnvironmentWhenMethodFetchComputationalFieldsThrowsException() {
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
- String explId = "explId";
- when(exploratoryDAO.fetchExploratoryId(anyString(), anyString())).thenReturn(explId);
-
- doThrow(new DlabException("Computational resource for user with exploratory name not found."))
- .when(computationalDAO).fetchComputationalFields(anyString(), anyString(), anyString());
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
-
- try {
- computationalService.terminateComputational(userInfo, EXPLORATORY_NAME, COMP_NAME);
- } catch (DlabException e) {
- assertEquals("Computational resource for user with exploratory name not found.", e.getMessage());
- }
-
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusTerminating, "self"));
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMP_NAME);
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(computationalDAO, exploratoryDAO);
- }
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+
+ doThrow(new DlabException("Computational resource for user with exploratory name not found."))
+ .when(computationalDAO).fetchComputationalFields(anyString(), anyString(), anyString(), anyString());
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+
+ try {
+ computationalService.terminateComputational(userInfo, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ } catch (DlabException e) {
+ assertEquals("Computational resource for user with exploratory name not found.", e.getMessage());
+ }
+
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusTerminating, "self"));
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(computationalDAO, exploratoryDAO);
+ }
@Test
public void terminateComputationalEnvironmentWhenMethodNewComputationalTerminateThrowsException() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
- String compId = "compId";
- UserComputationalResource ucResource = new UserComputationalResource();
- ucResource.setComputationalName(COMP_NAME);
- ucResource.setImageName("dataengine-service");
- ucResource.setComputationalId(compId);
- when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString())).thenReturn(ucResource);
+ String compId = "compId";
+ UserComputationalResource ucResource = new UserComputationalResource();
+ ucResource.setComputationalName(COMP_NAME);
+ ucResource.setImageName("dataengine-service");
+ ucResource.setComputationalId(compId);
+ when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString())).thenReturn(ucResource);
- doThrow(new DlabException("Cannot create instance of resource class "))
- .when(requestBuilder).newComputationalTerminate(any(UserInfo.class), any(UserInstanceDTO.class),
- any(UserComputationalResource.class), any(EndpointDTO.class));
+ doThrow(new DlabException("Cannot create instance of resource class "))
+ .when(requestBuilder).newComputationalTerminate(any(UserInfo.class), any(UserInstanceDTO.class),
+ any(UserComputationalResource.class), any(EndpointDTO.class));
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
- try {
- computationalService.terminateComputational(userInfo, EXPLORATORY_NAME, COMP_NAME);
- } catch (DlabException e) {
- assertEquals("Cannot create instance of resource class ", e.getMessage());
- }
+ try {
+ computationalService.terminateComputational(userInfo, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ } catch (DlabException e) {
+ assertEquals("Cannot create instance of resource class ", e.getMessage());
+ }
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusTerminating, "self"));
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMP_NAME);
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusTerminating, "self"));
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMP_NAME);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
- verify(requestBuilder).newComputationalTerminate(userInfo, userInstance, ucResource, endpointDTO());
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
- verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder);
- }
+ verify(requestBuilder).newComputationalTerminate(userInfo, userInstance, ucResource, endpointDTO());
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
+ verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder);
+ }
@Test
public void createDataEngineService() {
- ProjectDTO projectDTO = getProjectDTO();
- when(projectService.get(anyString())).thenReturn(projectDTO);
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(computationalDAO.addComputational(anyString(), anyString(), any(UserComputationalResource.class)))
- .thenReturn(true);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ ProjectDTO projectDTO = getProjectDTO();
+ when(projectService.get(anyString())).thenReturn(projectDTO);
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(computationalDAO.addComputational(anyString(), anyString(), anyString(), any(UserComputationalResource.class)))
+ .thenReturn(true);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
- ComputationalBase compBaseMocked = mock(ComputationalBase.class);
- when(requestBuilder.newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
- any(UserInstanceDTO.class), any(ComputationalCreateFormDTO.class), any(EndpointDTO.class)))
- .thenReturn(compBaseMocked);
+ ComputationalBase compBaseMocked = mock(ComputationalBase.class);
+ when(requestBuilder.newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
+ any(UserInstanceDTO.class), any(ComputationalCreateFormDTO.class), any(EndpointDTO.class)))
+ .thenReturn(compBaseMocked);
- when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any())).thenReturn(UUID);
- when(requestId.put(anyString(), anyString())).thenReturn(UUID);
+ when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any())).thenReturn(UUID);
+ when(requestId.put(anyString(), anyString())).thenReturn(UUID);
- boolean creationResult =
- computationalService.createDataEngineService(userInfo, formList.get(1), ucResource, "");
- assertTrue(creationResult);
+ boolean creationResult =
+ computationalService.createDataEngineService(userInfo, formList.get(1), ucResource, PROJECT);
+ assertTrue(creationResult);
- verify(projectService).get("");
+ verify(projectService).get(PROJECT);
- verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), refEq(ucResource));
+ verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), eq(PROJECT), refEq(ucResource));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
- verify(requestBuilder).newComputationalCreate(
- refEq(userInfo), refEq(projectDTO), refEq(userInstance), any(ComputationalCreateFormDTO.class), refEq(endpointDTO()));
+ verify(requestBuilder).newComputationalCreate(
+ refEq(userInfo), refEq(projectDTO), refEq(userInstance), any(ComputationalCreateFormDTO.class), refEq(endpointDTO()));
- verify(provisioningService)
- .post(endpointDTO().getUrl() + ComputationalAPI.COMPUTATIONAL_CREATE_CLOUD_SPECIFIC, TOKEN,
- compBaseMocked, String.class);
+ verify(provisioningService)
+ .post(endpointDTO().getUrl() + ComputationalAPI.COMPUTATIONAL_CREATE_CLOUD_SPECIFIC, TOKEN,
+ compBaseMocked, String.class);
- verify(requestId).put(USER, UUID);
- verifyNoMoreInteractions(projectService, computationalDAO, exploratoryDAO, requestBuilder, provisioningService, requestId);
- }
+ verify(requestId).put(USER, UUID);
+ verifyNoMoreInteractions(projectService, computationalDAO, exploratoryDAO, requestBuilder, provisioningService, requestId);
+ }
@Test
public void createDataEngineServiceWhenComputationalResourceNotAdded() {
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(computationalDAO.addComputational(anyString(), anyString(), any(UserComputationalResource.class)))
- .thenReturn(false);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(computationalDAO.addComputational(anyString(), anyString(), any(), any(UserComputationalResource.class)))
+ .thenReturn(false);
- boolean creationResult = computationalService.createDataEngineService(userInfo, formList.get(1), ucResource,
- "");
- assertFalse(creationResult);
+ boolean creationResult = computationalService.createDataEngineService(userInfo, formList.get(1), ucResource,
+ PROJECT);
+ assertFalse(creationResult);
- verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), refEq(ucResource));
- verifyNoMoreInteractions(computationalDAO);
- }
+ verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), eq(PROJECT), refEq(ucResource));
+ verifyNoMoreInteractions(computationalDAO);
+ }
@Test
public void createDataEngineServiceWhenMethodFetchExploratoryFieldsThrowsException() {
- when(computationalDAO.addComputational(anyString(), anyString(), any(UserComputationalResource.class)))
- .thenReturn(true);
- doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
- .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString());
+ when(computationalDAO.addComputational(anyString(), anyString(), anyString(), any(UserComputationalResource.class)))
+ .thenReturn(true);
+ doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
+ .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
- try {
- computationalService.createDataEngineService(userInfo, formList.get(1), ucResource, "");
- } catch (DlabException e) {
- assertEquals("Exploratory for user with name not found", e.getMessage());
- }
+ try {
+ computationalService.createDataEngineService(userInfo, formList.get(1), ucResource, PROJECT);
+ } catch (DlabException e) {
+ assertEquals("Exploratory for user with name not found", e.getMessage());
+ }
- verify(computationalDAO, never())
- .addComputational(eq(USER), eq(EXPLORATORY_NAME), refEq(ucResource));
+ verify(computationalDAO, never())
+ .addComputational(eq(USER), eq(EXPLORATORY_NAME), eq(PROJECT), refEq(ucResource));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
- verify(computationalDAO, never()).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed,
- "self"));
- verifyNoMoreInteractions(computationalDAO, exploratoryDAO);
- }
+ verify(computationalDAO, never()).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed,
+ "self"));
+ verifyNoMoreInteractions(computationalDAO, exploratoryDAO);
+ }
@Test
public void createDataEngineServiceWhenMethodNewComputationalCreateThrowsException() {
- ProjectDTO projectDTO = getProjectDTO();
- when(projectService.get(anyString())).thenReturn(projectDTO);
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(computationalDAO.addComputational(anyString(), anyString(), any(UserComputationalResource.class)))
- .thenReturn(true);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
-
- doThrow(new DlabException("Cannot create instance of resource class "))
- .when(requestBuilder).newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
- any(UserInstanceDTO.class), any(ComputationalCreateFormDTO.class), any(EndpointDTO.class));
-
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
-
- ComputationalCreateFormDTO computationalCreateFormDTO = formList.get(1);
- try {
- computationalService.createDataEngineService(userInfo, computationalCreateFormDTO, ucResource, "");
- } catch (DlabException e) {
- assertEquals("Could not send request for creation the computational resource compName: " +
- "Cannot create instance of resource class ", e.getMessage());
- }
-
- verify(projectService).get("");
- verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), refEq(ucResource));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(requestBuilder).newComputationalCreate(
- refEq(userInfo), refEq(projectDTO), refEq(userInstance), refEq(computationalCreateFormDTO), refEq(endpointDTO()));
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
-
- verifyNoMoreInteractions(projectService, computationalDAO, exploratoryDAO, requestBuilder);
- }
+ ProjectDTO projectDTO = getProjectDTO();
+ when(projectService.get(anyString())).thenReturn(projectDTO);
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(computationalDAO.addComputational(anyString(), anyString(), any(), any(UserComputationalResource.class)))
+ .thenReturn(true);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+
+ doThrow(new DlabException("Cannot create instance of resource class "))
+ .when(requestBuilder).newComputationalCreate(any(UserInfo.class), any(ProjectDTO.class),
+ any(UserInstanceDTO.class), any(ComputationalCreateFormDTO.class), any(EndpointDTO.class));
+
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+
+ ComputationalCreateFormDTO computationalCreateFormDTO = formList.get(1);
+ try {
+ computationalService.createDataEngineService(userInfo, computationalCreateFormDTO, ucResource, PROJECT);
+ } catch (DlabException e) {
+ assertEquals("Could not send request for creation the computational resource compName: " +
+ "Cannot create instance of resource class ", e.getMessage());
+ }
+
+ verify(projectService).get(PROJECT);
+ verify(computationalDAO).addComputational(eq(USER), eq(EXPLORATORY_NAME), eq(PROJECT), refEq(ucResource));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(requestBuilder).newComputationalCreate(
+ refEq(userInfo), refEq(projectDTO), refEq(userInstance), refEq(computationalCreateFormDTO), refEq(endpointDTO()));
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusFailed, "self"));
+
+ verifyNoMoreInteractions(projectService, computationalDAO, exploratoryDAO, requestBuilder);
+ }
@Test
public void stopSparkCluster() {
- final UserInstanceDTO exploratory = getUserInstanceDto();
- exploratory.setResources(singletonList(getUserComputationalResource(RUNNING, DOCKER_DLAB_DATAENGINE)));
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyBoolean())).thenReturn(exploratory);
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
-
- ComputationalStopDTO computationalStopDTO = new ComputationalStopDTO();
- when(requestBuilder.newComputationalStop(any(UserInfo.class), any(UserInstanceDTO.class), anyString(),
- any(EndpointDTO.class))).thenReturn(computationalStopDTO);
- when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any()))
- .thenReturn("someUuid");
- when(requestId.put(anyString(), anyString())).thenReturn("someUuid");
-
- computationalService.stopSparkCluster(userInfo, EXPLORATORY_NAME, COMP_NAME);
-
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusStopping, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, true);
- verify(requestBuilder).newComputationalStop(refEq(userInfo), refEq(exploratory), eq(COMP_NAME), refEq(endpointDTO()));
- verify(provisioningService)
- .post(eq(endpointDTO().getUrl() + "computational/stop/spark"), eq(TOKEN), refEq(computationalStopDTO),
- eq(String.class));
- verify(requestId).put(USER, "someUuid");
- verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder,
- provisioningService, requestId);
- }
+ final UserInstanceDTO exploratory = getUserInstanceDto();
+ exploratory.setResources(singletonList(getUserComputationalResource(RUNNING, DOCKER_DLAB_DATAENGINE)));
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(exploratory);
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+
+ ComputationalStopDTO computationalStopDTO = new ComputationalStopDTO();
+ when(requestBuilder.newComputationalStop(any(UserInfo.class), any(UserInstanceDTO.class), anyString(),
+ any(EndpointDTO.class))).thenReturn(computationalStopDTO);
+ when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any()))
+ .thenReturn("someUuid");
+ when(requestId.put(anyString(), anyString())).thenReturn("someUuid");
+
+ computationalService.stopSparkCluster(userInfo, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusStopping, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, true);
+ verify(requestBuilder).newComputationalStop(refEq(userInfo), refEq(exploratory), eq(COMP_NAME), refEq(endpointDTO()));
+ verify(provisioningService)
+ .post(eq(endpointDTO().getUrl() + "computational/stop/spark"), eq(TOKEN), refEq(computationalStopDTO),
+ eq(String.class));
+ verify(requestId).put(USER, "someUuid");
+ verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder,
+ provisioningService, requestId);
+ }
@Test
public void stopSparkClusterWhenDataengineTypeIsAnother() {
- final UserInstanceDTO exploratory = getUserInstanceDto();
- exploratory.setResources(singletonList(getUserComputationalResource(RUNNING, DOCKER_DLAB_DATAENGINE_SERVICE)));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyBoolean())).thenReturn(exploratory);
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("There is no running dataengine compName for exploratory expName");
+ final UserInstanceDTO exploratory = getUserInstanceDto();
+ exploratory.setResources(singletonList(getUserComputationalResource(RUNNING, DOCKER_DLAB_DATAENGINE_SERVICE)));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(exploratory);
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("There is no running dataengine compName for exploratory expName");
- computationalService.stopSparkCluster(userInfo, EXPLORATORY_NAME, COMP_NAME);
- }
+ computationalService.stopSparkCluster(userInfo, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ }
@Test
public void startSparkCluster() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- final UserInstanceDTO exploratory = getUserInstanceDto();
- exploratory.setResources(singletonList(getUserComputationalResource(STOPPED, DOCKER_DLAB_DATAENGINE)));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyBoolean())).thenReturn(exploratory);
- when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
- .thenReturn(mock(UpdateResult.class));
-
- ComputationalStartDTO computationalStartDTO = new ComputationalStartDTO();
- when(requestBuilder.newComputationalStart(any(UserInfo.class), any(UserInstanceDTO.class), anyString(),
- any(EndpointDTO.class))).thenReturn(computationalStartDTO);
- when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any()))
- .thenReturn("someUuid");
- when(requestId.put(anyString(), anyString())).thenReturn("someUuid");
-
- computationalService.startSparkCluster(userInfo, EXPLORATORY_NAME, COMP_NAME, "");
-
- verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusStarting, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, true);
- verify(requestBuilder).newComputationalStart(refEq(userInfo), refEq(exploratory), eq(COMP_NAME), refEq(endpointDTO()));
- verify(provisioningService)
- .post(eq(endpointDTO().getUrl() + "computational/start/spark"), eq(TOKEN),
- refEq(computationalStartDTO),
- eq(String.class));
- verify(requestId).put(USER, "someUuid");
- verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder,
- provisioningService, requestId);
- }
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ final UserInstanceDTO exploratory = getUserInstanceDto();
+ exploratory.setResources(singletonList(getUserComputationalResource(STOPPED, DOCKER_DLAB_DATAENGINE)));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(exploratory);
+ when(computationalDAO.updateComputationalStatus(any(ComputationalStatusDTO.class)))
+ .thenReturn(mock(UpdateResult.class));
+
+ ComputationalStartDTO computationalStartDTO = new ComputationalStartDTO();
+ when(requestBuilder.newComputationalStart(any(UserInfo.class), any(UserInstanceDTO.class), anyString(),
+ any(EndpointDTO.class))).thenReturn(computationalStartDTO);
+ when(provisioningService.post(anyString(), anyString(), any(ComputationalBase.class), any()))
+ .thenReturn("someUuid");
+ when(requestId.put(anyString(), anyString())).thenReturn("someUuid");
+
+ computationalService.startSparkCluster(userInfo, EXPLORATORY_NAME, COMP_NAME, PROJECT);
+
+ verify(computationalDAO).updateComputationalStatus(refEq(computationalStatusDTOWithStatusStarting, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, true);
+ verify(requestBuilder).newComputationalStart(refEq(userInfo), refEq(exploratory), eq(COMP_NAME), refEq(endpointDTO()));
+ verify(provisioningService)
+ .post(eq(endpointDTO().getUrl() + "computational/start/spark"), eq(TOKEN),
+ refEq(computationalStartDTO),
+ eq(String.class));
+ verify(requestId).put(USER, "someUuid");
+ verifyNoMoreInteractions(computationalDAO, exploratoryDAO, requestBuilder,
+ provisioningService, requestId);
+ }
@Test
public void startSparkClusterWhenDataengineStatusIsRunning() {
- final UserInstanceDTO userInstanceDto = getUserInstanceDto();
- userInstanceDto.setResources(singletonList(getUserComputationalResource(RUNNING,
- DOCKER_DLAB_DATAENGINE_SERVICE)));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("There is no stopped dataengine compName for exploratory expName");
-
- computationalService.startSparkCluster(userInfo, EXPLORATORY_NAME, COMP_NAME, "");
- }
+ final UserInstanceDTO userInstanceDto = getUserInstanceDto();
+ userInstanceDto.setResources(singletonList(getUserComputationalResource(RUNNING,
+ DOCKER_DLAB_DATAENGINE_SERVICE)));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
- @Test
- @SuppressWarnings("unchecked")
- public void updateComputationalsReuploadKeyFlag() {
- doNothing().when(computationalDAO).updateReuploadKeyFlagForComputationalResources(anyString(), any(List.class),
- any(List.class), anyBoolean(), anyVararg());
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("There is no stopped dataengine compName for exploratory expName");
- computationalService.updateComputationalsReuploadKeyFlag(USER, singletonList(RUNNING),
- singletonList(DataEngineType.SPARK_STANDALONE), true, RUNNING);
-
- verify(computationalDAO).updateReuploadKeyFlagForComputationalResources(USER, singletonList
- (RUNNING),
- singletonList(DataEngineType.SPARK_STANDALONE), true, RUNNING);
- verifyNoMoreInteractions(computationalDAO);
- }
+ computationalService.startSparkCluster(userInfo, EXPLORATORY_NAME, COMP_NAME, PROJECT);
+ }
@Test
public void getComputationalResource() {
- when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString())).thenReturn(ucResource);
+ when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString())).thenReturn(ucResource);
- Optional<UserComputationalResource> expectedResource = Optional.of(ucResource);
- Optional<UserComputationalResource> actualResource =
- computationalService.getComputationalResource(USER, EXPLORATORY_NAME, COMP_NAME);
- assertEquals(expectedResource, actualResource);
+ Optional<UserComputationalResource> expectedResource = Optional.of(ucResource);
+ Optional<UserComputationalResource> actualResource =
+ computationalService.getComputationalResource(USER, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ assertEquals(expectedResource, actualResource);
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMP_NAME);
- verifyNoMoreInteractions(computationalDAO);
- }
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ verifyNoMoreInteractions(computationalDAO);
+ }
@Test
public void getComputationalResourceWithException() {
- doThrow(new DlabException("Computational resource not found"))
- .when(computationalDAO).fetchComputationalFields(anyString(), anyString(), anyString());
+ doThrow(new DlabException("Computational resource not found"))
+ .when(computationalDAO).fetchComputationalFields(anyString(), anyString(), anyString(), anyString());
- Optional<UserComputationalResource> expectedResource = Optional.empty();
- Optional<UserComputationalResource> actualResource =
- computationalService.getComputationalResource(USER, EXPLORATORY_NAME, COMP_NAME);
- assertEquals(expectedResource, actualResource);
+ Optional<UserComputationalResource> expectedResource = Optional.empty();
+ Optional<UserComputationalResource> actualResource =
+ computationalService.getComputationalResource(USER, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ assertEquals(expectedResource, actualResource);
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMP_NAME);
- verifyNoMoreInteractions(computationalDAO);
- }
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ verifyNoMoreInteractions(computationalDAO);
+ }
@Test
public void testUpdateSparkClusterConfig() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- final ComputationalClusterConfigDTO clusterConfigDTO = new ComputationalClusterConfigDTO();
- final UserInstanceDTO userInstanceDto = getUserInstanceDto();
- final List<ClusterConfig> config = Collections.singletonList(new ClusterConfig());
- userInstanceDto.setResources(Collections.singletonList(getUserComputationalResource(RUNNING, COMP_NAME)));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
- when(requestBuilder.newClusterConfigUpdate(any(UserInfo.class), any(UserInstanceDTO.class),
- any(UserComputationalResource.class), anyListOf(ClusterConfig.class), any(EndpointDTO.class)))
- .thenReturn(clusterConfigDTO);
- when(provisioningService.post(anyString(), anyString(), any(ComputationalClusterConfigDTO.class), any()))
- .thenReturn("someUuid");
- computationalService.updateSparkClusterConfig(getUserInfo(), EXPLORATORY_NAME, COMP_NAME,
- config);
-
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, true);
- verify(requestBuilder).newClusterConfigUpdate(refEq(getUserInfo()), refEq(userInstanceDto),
- refEq(getUserComputationalResource(RUNNING, COMP_NAME)),
- eq(Collections.singletonList(new ClusterConfig())), eq(endpointDTO()));
- verify(requestId).put(USER, "someUuid");
- verify(computationalDAO).updateComputationalFields(refEq(new ComputationalStatusDTO()
- .withConfig(config)
- .withUser(USER)
- .withExploratoryName(EXPLORATORY_NAME)
- .withComputationalName(COMP_NAME)
- .withStatus(UserInstanceStatus.RECONFIGURING.toString()), "self"));
- verify(provisioningService).post(eq(endpointDTO().getUrl() + "computational/spark/reconfigure"),
- eq(getUserInfo().getAccessToken()),
- refEq(new ComputationalClusterConfigDTO()), eq(String.class));
-
- }
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ final ComputationalClusterConfigDTO clusterConfigDTO = new ComputationalClusterConfigDTO();
+ final UserInstanceDTO userInstanceDto = getUserInstanceDto();
+ final List<ClusterConfig> config = Collections.singletonList(new ClusterConfig());
+ userInstanceDto.setResources(Collections.singletonList(getUserComputationalResource(RUNNING, COMP_NAME)));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
+ when(requestBuilder.newClusterConfigUpdate(any(UserInfo.class), any(UserInstanceDTO.class),
+ any(UserComputationalResource.class), anyListOf(ClusterConfig.class), any(EndpointDTO.class)))
+ .thenReturn(clusterConfigDTO);
+ when(provisioningService.post(anyString(), anyString(), any(ComputationalClusterConfigDTO.class), any()))
+ .thenReturn("someUuid");
+ computationalService.updateSparkClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME,
+ COMP_NAME, config);
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, true);
+ verify(requestBuilder).newClusterConfigUpdate(refEq(getUserInfo()), refEq(userInstanceDto),
+ refEq(getUserComputationalResource(RUNNING, COMP_NAME)),
+ eq(Collections.singletonList(new ClusterConfig())), eq(endpointDTO()));
+ verify(requestId).put(USER, "someUuid");
+ verify(computationalDAO).updateComputationalFields(refEq(new ComputationalStatusDTO()
+ .withProject(PROJECT)
+ .withConfig(config)
+ .withUser(USER)
+ .withExploratoryName(EXPLORATORY_NAME)
+ .withComputationalName(COMP_NAME)
+ .withStatus(UserInstanceStatus.RECONFIGURING.toString()), "self"));
+ verify(provisioningService).post(eq(endpointDTO().getUrl() + "computational/spark/reconfigure"),
+ eq(getUserInfo().getAccessToken()),
+ refEq(new ComputationalClusterConfigDTO()), eq(String.class));
+
+ }
@Test
public void testUpdateSparkClusterConfigWhenClusterIsNotRunning() {
- final UserInstanceDTO userInstanceDto = getUserInstanceDto();
- final List<ClusterConfig> config = Collections.singletonList(new ClusterConfig());
- userInstanceDto.setResources(Collections.singletonList(getUserComputationalResource(STOPPED, COMP_NAME)));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
- try {
- computationalService.updateSparkClusterConfig(getUserInfo(), EXPLORATORY_NAME, COMP_NAME,
- config);
- } catch (ResourceNotFoundException e) {
- assertEquals("Running computational resource with name compName for exploratory expName not found",
- e.getMessage());
- }
-
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, true);
- verifyNoMoreInteractions(exploratoryDAO);
- verifyZeroInteractions(provisioningService, requestBuilder, requestId);
-
- }
+ final UserInstanceDTO userInstanceDto = getUserInstanceDto();
+ final List<ClusterConfig> config = Collections.singletonList(new ClusterConfig());
+ userInstanceDto.setResources(Collections.singletonList(getUserComputationalResource(STOPPED, COMP_NAME)));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
+ try {
+ computationalService.updateSparkClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME,
+ COMP_NAME, config);
+ } catch (ResourceNotFoundException e) {
+ assertEquals("Running computational resource with name compName for exploratory expName not found",
+ e.getMessage());
+ }
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, true);
+ verifyNoMoreInteractions(exploratoryDAO);
+ verifyZeroInteractions(provisioningService, requestBuilder, requestId);
+
+ }
@Test
public void testUpdateSparkClusterConfigWhenClusterIsNotFound() {
- final UserInstanceDTO userInstanceDto = getUserInstanceDto();
- final List<ClusterConfig> config = Collections.singletonList(new ClusterConfig());
- userInstanceDto.setResources(Collections.singletonList(getUserComputationalResource(STOPPED, COMP_NAME)));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
- try {
- computationalService.updateSparkClusterConfig(getUserInfo(), EXPLORATORY_NAME, COMP_NAME + "X",
- config);
- } catch (ResourceNotFoundException e) {
- assertEquals("Running computational resource with name compNameX for exploratory expName not found",
- e.getMessage());
- }
-
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, true);
- verifyNoMoreInteractions(exploratoryDAO);
- verifyZeroInteractions(provisioningService, requestBuilder, requestId);
-
- }
+ final UserInstanceDTO userInstanceDto = getUserInstanceDto();
+ final List<ClusterConfig> config = Collections.singletonList(new ClusterConfig());
+ userInstanceDto.setResources(Collections.singletonList(getUserComputationalResource(STOPPED, COMP_NAME)));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyBoolean())).thenReturn(userInstanceDto);
+ try {
+ computationalService.updateSparkClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME,
+ COMP_NAME + "X", config);
+ } catch (ResourceNotFoundException e) {
+ assertEquals("Running computational resource with name compNameX for exploratory expName not found",
+ e.getMessage());
+ }
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, true);
+ verifyNoMoreInteractions(exploratoryDAO);
+ verifyZeroInteractions(provisioningService, requestBuilder, requestId);
+
+ }
@Test
public void testGetClusterConfig() {
- when(computationalDAO.getClusterConfig(anyString(), anyString(), anyString())).thenReturn(Collections.singletonList(getClusterConfig()));
+ when(computationalDAO.getClusterConfig(anyString(), anyString(), anyString(), anyString())).thenReturn(Collections.singletonList(getClusterConfig()));
- final List<ClusterConfig> clusterConfig = computationalService.getClusterConfig(getUserInfo(),
- EXPLORATORY_NAME, COMP_NAME);
- final ClusterConfig config = clusterConfig.get(0);
+ final List<ClusterConfig> clusterConfig = computationalService.getClusterConfig(getUserInfo(), PROJECT,
+ EXPLORATORY_NAME, COMP_NAME);
+ final ClusterConfig config = clusterConfig.get(0);
- assertEquals(1, clusterConfig.size());
- assertEquals("test", config.getClassification());
- assertNull(config.getConfigurations());
- assertNull(config.getProperties());
- }
+ assertEquals(1, clusterConfig.size());
+ assertEquals("test", config.getClassification());
+ assertNull(config.getConfigurations());
+ assertNull(config.getProperties());
+ }
@Test
public void testGetClusterConfigWithException() {
- when(computationalDAO.getClusterConfig(anyString(), anyString(), anyString())).thenThrow(new RuntimeException(
- "Exception"));
+ when(computationalDAO.getClusterConfig(anyString(), anyString(), anyString(), anyString())).thenThrow(new RuntimeException(
+ "Exception"));
- expectedException.expectMessage("Exception");
- expectedException.expect(RuntimeException.class);
- computationalService.getClusterConfig(getUserInfo(), EXPLORATORY_NAME, COMP_NAME);
- }
+ expectedException.expectMessage("Exception");
+ expectedException.expect(RuntimeException.class);
+ computationalService.getClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME, COMP_NAME);
+ }
private ClusterConfig getClusterConfig() {
final ClusterConfig config = new ClusterConfig();
@@ -705,26 +711,29 @@ public class ComputationalServiceImplTest {
private UserInstanceDTO getUserInstanceDto() {
return new UserInstanceDTO().withUser(USER).withExploratoryName(EXPLORATORY_NAME)
- .withExploratoryId("explId")
+ .withExploratoryId("explId")
+ .withProject(PROJECT)
.withTags(Collections.emptyMap());
}
private List<ComputationalCreateFormDTO> getFormList() {
- SparkStandaloneClusterCreateForm sparkClusterForm = new SparkStandaloneClusterCreateForm();
- sparkClusterForm.setNotebookName(EXPLORATORY_NAME);
- sparkClusterForm.setName(COMP_NAME);
- sparkClusterForm.setDataEngineInstanceCount(String.valueOf(2));
- sparkClusterForm.setImage("dataengine");
- ComputationalCreateFormDTO desClusterForm = new ComputationalCreateFormDTO();
- desClusterForm.setNotebookName(EXPLORATORY_NAME);
- desClusterForm.setName(COMP_NAME);
-
- return Arrays.asList(sparkClusterForm, desClusterForm);
- }
+ SparkStandaloneClusterCreateForm sparkClusterForm = new SparkStandaloneClusterCreateForm();
+ sparkClusterForm.setNotebookName(EXPLORATORY_NAME);
+ sparkClusterForm.setName(COMP_NAME);
+ sparkClusterForm.setProject(PROJECT);
+ sparkClusterForm.setDataEngineInstanceCount(String.valueOf(2));
+ sparkClusterForm.setImage("dataengine");
+ ComputationalCreateFormDTO desClusterForm = new ComputationalCreateFormDTO();
+ desClusterForm.setNotebookName(EXPLORATORY_NAME);
+ desClusterForm.setName(COMP_NAME);
+
+ return Arrays.asList(sparkClusterForm, desClusterForm);
+ }
private ComputationalStatusDTO getComputationalStatusDTOWithStatus(String status) {
return new ComputationalStatusDTO()
- .withUser(USER)
+ .withUser(USER)
+ .withProject(PROJECT)
.withExploratoryName(EXPLORATORY_NAME)
.withComputationalName(COMP_NAME)
.withStatus(UserInstanceStatus.of(status));
@@ -762,8 +771,8 @@ public class ComputationalServiceImplTest {
}
private ProjectDTO getProjectDTO() {
- return new ProjectDTO("project", Collections.emptySet(), "", "", null,
- singletonList(new ProjectEndpointDTO("endpoint", UserInstanceStatus.RUNNING,
- new EdgeInfo())), true);
- }
+ return new ProjectDTO(PROJECT, Collections.emptySet(), "", "", null,
+ singletonList(new ProjectEndpointDTO("endpoint", UserInstanceStatus.RUNNING,
+ new EdgeInfo())), true);
+ }
}
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 5396ca8..536454e 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;
@@ -43,11 +42,26 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anySet;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.refEq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class EnvironmentServiceImplTest {
@@ -57,8 +71,6 @@ public class EnvironmentServiceImplTest {
private static final String EXPLORATORY_NAME_2 = "expName2";
private static final String TOKEN = "token";
private static final String UUID = "213-12312-321";
- private static final String RUNNING_STATE = "running";
- private static final String STOPPED_STATE = "stopped";
private static final String PROJECT_NAME = "projectName";
private static final String ENDPOINT_NAME = "endpointName";
private static final String ADMIN = "admin";
@@ -134,67 +146,21 @@ public class EnvironmentServiceImplTest {
environmentService.getUserNames();
}
-
- @Test
- public void stopEnvironment() {
- final UserInfo userInfo = getUserInfo();
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString())).thenReturn(getUserInstances());
- when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn(UUID);
-
- environmentService.stopEnvironment(userInfo, USER);
-
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER);
- verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1));
- verify(exploratoryService).stop(refEq(userInfo), 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);
- }
-
- @Test
- public void stopEnvironmentWithoutEdge() {
- final UserInfo userInfo = getUserInfo();
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString())).thenReturn(getUserInstances());
- when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn(UUID);
-
- environmentService.stopEnvironment(userInfo, USER);
-
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER);
- verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1));
- verify(exploratoryService).stop(refEq(userInfo), 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();
when(exploratoryDAO.fetchRunningExploratoryFieldsForProject(anyString())).thenReturn(getUserInstances());
when(securityService.getServiceAccountInfo(anyString())).thenReturn(userInfo);
- when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn(UUID);
+ when(exploratoryService.stop(any(UserInfo.class), anyString(), anyString())).thenReturn(UUID);
when(projectService.get(anyString())).thenReturn(projectDTO);
doNothing().when(projectService).stop(any(UserInfo.class), anyString(), anyString());
environmentService.stopProjectEnvironment(PROJECT_NAME);
verify(exploratoryDAO).fetchRunningExploratoryFieldsForProject(PROJECT_NAME);
- verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1));
- verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_2));
+ 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(securityService, times(2)).getServiceAccountInfo(USER);
verify(securityService).getServiceAccountInfo(ADMIN);
verify(projectService).get(eq(PROJECT_NAME));
@@ -205,60 +171,14 @@ public class EnvironmentServiceImplTest {
verifyNoMoreInteractions(exploratoryDAO, exploratoryService, securityService, projectService);
}
- @Test
- public void stopExploratory() {
- final UserInfo userInfo = getUserInfo();
- when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn(UUID);
-
- environmentService.stopExploratory(new UserInfo(USER, TOKEN), USER, EXPLORATORY_NAME_1);
-
- verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1));
- verifyNoMoreInteractions(securityService, exploratoryService);
- }
-
- @Test
- public void stopComputational() {
- final UserInfo userInfo = getUserInfo();
- doNothing().when(computationalService).stopSparkCluster(any(UserInfo.class), anyString(), anyString());
-
- environmentService.stopComputational(userInfo, USER, EXPLORATORY_NAME_1, "compName");
-
- verify(computationalService).stopSparkCluster(refEq(userInfo), eq(EXPLORATORY_NAME_1), eq("compName"));
- verifyNoMoreInteractions(securityService, computationalService);
- }
-
- @Test
- public void terminateExploratory() {
- final UserInfo userInfo = getUserInfo();
- when(exploratoryService.terminate(any(UserInfo.class), anyString())).thenReturn(UUID);
-
- environmentService.terminateExploratory(userInfo, USER, EXPLORATORY_NAME_1);
-
- verify(exploratoryService).terminate(refEq(userInfo), eq(EXPLORATORY_NAME_1));
- verifyNoMoreInteractions(securityService, exploratoryService);
- }
-
- @Test
- public void terminateComputational() {
- final UserInfo userInfo = getUserInfo();
- doNothing().when(computationalService)
- .terminateComputational(any(UserInfo.class), anyString(), anyString());
-
- environmentService.terminateComputational(userInfo, USER, EXPLORATORY_NAME_1, "compName");
-
- verify(computationalService)
- .terminateComputational(refEq(userInfo), eq(EXPLORATORY_NAME_1), eq("compName"));
- verifyNoMoreInteractions(securityService, computationalService);
- }
-
private UserInfo getUserInfo() {
return new UserInfo(USER, TOKEN);
}
private List<UserInstanceDTO> getUserInstances() {
return Arrays.asList(
- new UserInstanceDTO().withExploratoryName(EXPLORATORY_NAME_1).withUser(USER).withProject("prj"),
- new UserInstanceDTO().withExploratoryName(EXPLORATORY_NAME_2).withUser(USER).withProject("prj"));
+ new UserInstanceDTO().withExploratoryName(EXPLORATORY_NAME_1).withUser(USER).withProject(PROJECT_NAME),
+ new UserInstanceDTO().withExploratoryName(EXPLORATORY_NAME_2).withUser(USER).withProject(PROJECT_NAME));
}
private ProjectDTO getProjectDTO() {
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImplTest.java
index e7d718d..c641667 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ExploratoryServiceImplTest.java
@@ -66,7 +66,6 @@ import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyListOf;
import static org.mockito.Mockito.anyMapOf;
import static org.mockito.Mockito.anyString;
@@ -85,26 +84,27 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ExploratoryServiceImplTest {
- private final String USER = "test";
- private final String TOKEN = "token";
- private final String EXPLORATORY_NAME = "expName";
- private final String UUID = "1234-56789765-4321";
- private static final String ENDPOINT_NAME = "endpointName";
-
-
- private UserInfo userInfo;
- private UserInstanceDTO userInstance;
- private StatusEnvBaseDTO statusEnvBaseDTO;
-
- @Mock
- private ProjectService projectService;
- @Mock
- private ExploratoryDAO exploratoryDAO;
- @Mock
- private ComputationalDAO computationalDAO;
- @Mock
- private GitCredsDAO gitCredsDAO;
- @Mock
+ private final String USER = "test";
+ private final String TOKEN = "token";
+ private final String PROJECT = "project";
+ private final String EXPLORATORY_NAME = "expName";
+ private final String UUID = "1234-56789765-4321";
+ private static final String ENDPOINT_NAME = "endpointName";
+
+
+ private UserInfo userInfo;
+ private UserInstanceDTO userInstance;
+ private StatusEnvBaseDTO statusEnvBaseDTO;
+
+ @Mock
+ private ProjectService projectService;
+ @Mock
+ private ExploratoryDAO exploratoryDAO;
+ @Mock
+ private ComputationalDAO computationalDAO;
+ @Mock
+ private GitCredsDAO gitCredsDAO;
+ @Mock
private RESTService provisioningService;
@Mock
private RequestBuilder requestBuilder;
@@ -129,162 +129,162 @@ public class ExploratoryServiceImplTest {
@Test
public void start() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
- ExploratoryGitCredsDTO egcDtoMock = mock(ExploratoryGitCredsDTO.class);
- when(gitCredsDAO.findGitCreds(anyString())).thenReturn(egcDtoMock);
+ ExploratoryGitCredsDTO egcDtoMock = mock(ExploratoryGitCredsDTO.class);
+ when(gitCredsDAO.findGitCreds(anyString())).thenReturn(egcDtoMock);
- ExploratoryActionDTO egcuDto = new ExploratoryGitCredsUpdateDTO();
- egcuDto.withExploratoryName(EXPLORATORY_NAME);
- when(requestBuilder.newExploratoryStart(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
- any(ExploratoryGitCredsDTO.class))).thenReturn(egcuDto);
+ ExploratoryActionDTO egcuDto = new ExploratoryGitCredsUpdateDTO();
+ egcuDto.withExploratoryName(EXPLORATORY_NAME);
+ when(requestBuilder.newExploratoryStart(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
+ any(ExploratoryGitCredsDTO.class))).thenReturn(egcuDto);
- String exploratoryStart = "exploratory/start";
- when(provisioningService.post(anyString(), anyString(), any(ExploratoryActionDTO.class), any()))
- .thenReturn(UUID);
- when(requestId.put(anyString(), anyString())).thenReturn(UUID);
+ String exploratoryStart = "exploratory/start";
+ when(provisioningService.post(anyString(), anyString(), any(ExploratoryActionDTO.class), any()))
+ .thenReturn(UUID);
+ when(requestId.put(anyString(), anyString())).thenReturn(UUID);
- String uuid = exploratoryService.start(userInfo, EXPLORATORY_NAME, "project");
- assertNotNull(uuid);
- assertEquals(UUID, uuid);
+ String uuid = exploratoryService.start(userInfo, EXPLORATORY_NAME, "project");
+ assertNotNull(uuid);
+ assertEquals(UUID, uuid);
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("starting");
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("starting");
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(provisioningService).post(endpointDTO().getUrl() + exploratoryStart, TOKEN, egcuDto, String.class);
- verify(requestId).put(USER, UUID);
- verifyNoMoreInteractions(exploratoryDAO, provisioningService, requestId);
- }
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(provisioningService).post(endpointDTO().getUrl() + exploratoryStart, TOKEN, egcuDto, String.class);
+ verify(requestId).put(USER, UUID);
+ verifyNoMoreInteractions(exploratoryDAO, provisioningService, requestId);
+ }
@Test
public void startWhenMethodFetchExploratoryFieldsThrowsException() {
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
- doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
- .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString());
- try {
- exploratoryService.start(userInfo, EXPLORATORY_NAME, "project");
- } catch (DlabException e) {
- assertEquals("Could not start exploratory environment expName: Exploratory for user with " +
- "name not found", e.getMessage());
- }
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("starting");
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("failed");
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
+ doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
+ .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
+ try {
+ exploratoryService.start(userInfo, EXPLORATORY_NAME, PROJECT);
+ } catch (DlabException e) {
+ assertEquals("Could not start exploratory environment expName: Exploratory for user with " +
+ "name not found", e.getMessage());
+ }
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("starting");
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("failed");
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void stop() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
- when(computationalDAO.updateComputationalStatusesForExploratory(any(StatusEnvBaseDTO.class))).thenReturn(1);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
-
- ExploratoryActionDTO eaDto = new ExploratoryActionDTO();
- eaDto.withExploratoryName(EXPLORATORY_NAME);
- when(requestBuilder.newExploratoryStop(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class)))
- .thenReturn(eaDto);
-
- String exploratoryStop = "exploratory/stop";
- when(provisioningService.post(anyString(), anyString(), any(ExploratoryActionDTO.class), any())).thenReturn
- (UUID);
- when(requestId.put(anyString(), anyString())).thenReturn(UUID);
-
- String uuid = exploratoryService.stop(userInfo, EXPLORATORY_NAME);
- assertNotNull(uuid);
- assertEquals(UUID, uuid);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("stopping");
-
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(provisioningService).post(endpointDTO().getUrl() + exploratoryStop, TOKEN, eaDto, String.class);
- verify(computationalDAO).updateComputationalStatusesForExploratory(userInfo.getName(), EXPLORATORY_NAME,
- UserInstanceStatus.STOPPING, UserInstanceStatus.TERMINATING, UserInstanceStatus.FAILED,
- UserInstanceStatus.TERMINATED, UserInstanceStatus.STOPPED);
- verify(requestId).put(USER, UUID);
- verifyNoMoreInteractions(exploratoryDAO, provisioningService, requestId);
- }
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
+ when(computationalDAO.updateComputationalStatusesForExploratory(any(StatusEnvBaseDTO.class))).thenReturn(1);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+
+ ExploratoryActionDTO eaDto = new ExploratoryActionDTO();
+ eaDto.withExploratoryName(EXPLORATORY_NAME);
+ when(requestBuilder.newExploratoryStop(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class)))
+ .thenReturn(eaDto);
+
+ String exploratoryStop = "exploratory/stop";
+ when(provisioningService.post(anyString(), anyString(), any(ExploratoryActionDTO.class), any())).thenReturn
+ (UUID);
+ when(requestId.put(anyString(), anyString())).thenReturn(UUID);
+
+ String uuid = exploratoryService.stop(userInfo, PROJECT, EXPLORATORY_NAME);
+ assertNotNull(uuid);
+ assertEquals(UUID, uuid);
+
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("stopping");
+
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(provisioningService).post(endpointDTO().getUrl() + exploratoryStop, TOKEN, eaDto, String.class);
+ verify(computationalDAO).updateComputationalStatusesForExploratory(userInfo.getName(), PROJECT,
+ EXPLORATORY_NAME, UserInstanceStatus.STOPPING, UserInstanceStatus.TERMINATING,
+ UserInstanceStatus.FAILED, UserInstanceStatus.TERMINATED, UserInstanceStatus.STOPPED);
+ verify(requestId).put(USER, UUID);
+ verifyNoMoreInteractions(exploratoryDAO, provisioningService, requestId);
+ }
@Test
public void stopWhenMethodFetchExploratoryFieldsThrowsException() {
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
- doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
- .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString());
- try {
- exploratoryService.stop(userInfo, EXPLORATORY_NAME);
- } catch (DlabException e) {
- assertEquals("Could not stop exploratory environment expName: Exploratory for user with " +
- "name not found", e.getMessage());
- }
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("stopping");
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("failed");
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
+ doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
+ .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
+ try {
+ exploratoryService.stop(userInfo, PROJECT, EXPLORATORY_NAME);
+ } catch (DlabException e) {
+ assertEquals("Could not stop exploratory environment expName: Exploratory for user with " +
+ "name not found", e.getMessage());
+ }
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("stopping");
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("failed");
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void terminate() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
- when(computationalDAO.updateComputationalStatusesForExploratory(any(StatusEnvBaseDTO.class))).thenReturn(1);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
-
- ExploratoryActionDTO eaDto = new ExploratoryActionDTO();
- eaDto.withExploratoryName(EXPLORATORY_NAME);
- when(requestBuilder.newExploratoryStop(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class)))
- .thenReturn(eaDto);
-
- String exploratoryTerminate = "exploratory/terminate";
- when(provisioningService.post(anyString(), anyString(), any(ExploratoryActionDTO.class), any())).thenReturn
- (UUID);
- when(requestId.put(anyString(), anyString())).thenReturn(UUID);
-
- String uuid = exploratoryService.terminate(userInfo, EXPLORATORY_NAME);
- assertNotNull(uuid);
- assertEquals(UUID, uuid);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("terminating");
-
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(computationalDAO).updateComputationalStatusesForExploratory(USER, EXPLORATORY_NAME, UserInstanceStatus
- .TERMINATING, UserInstanceStatus.TERMINATING, UserInstanceStatus.TERMINATED,
- UserInstanceStatus.FAILED);
- verify(requestBuilder).newExploratoryStop(userInfo, userInstance, endpointDTO());
- verify(provisioningService).post(endpointDTO().getUrl() + exploratoryTerminate, TOKEN, eaDto, String.class);
- verify(requestId).put(USER, UUID);
- verifyNoMoreInteractions(exploratoryDAO, computationalDAO, requestBuilder, provisioningService, requestId);
- }
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
+ when(computationalDAO.updateComputationalStatusesForExploratory(any(StatusEnvBaseDTO.class))).thenReturn(1);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+
+ ExploratoryActionDTO eaDto = new ExploratoryActionDTO();
+ eaDto.withExploratoryName(EXPLORATORY_NAME);
+ when(requestBuilder.newExploratoryStop(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class)))
+ .thenReturn(eaDto);
+
+ String exploratoryTerminate = "exploratory/terminate";
+ when(provisioningService.post(anyString(), anyString(), any(ExploratoryActionDTO.class), any())).thenReturn
+ (UUID);
+ when(requestId.put(anyString(), anyString())).thenReturn(UUID);
+
+ String uuid = exploratoryService.terminate(userInfo, PROJECT, EXPLORATORY_NAME);
+ assertNotNull(uuid);
+ assertEquals(UUID, uuid);
+
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("terminating");
+
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(computationalDAO).updateComputationalStatusesForExploratory(USER, PROJECT, EXPLORATORY_NAME,
+ UserInstanceStatus.TERMINATING, UserInstanceStatus.TERMINATING, UserInstanceStatus.TERMINATED,
+ UserInstanceStatus.FAILED);
+ verify(requestBuilder).newExploratoryStop(userInfo, userInstance, endpointDTO());
+ verify(provisioningService).post(endpointDTO().getUrl() + exploratoryTerminate, TOKEN, eaDto, String.class);
+ verify(requestId).put(USER, UUID);
+ verifyNoMoreInteractions(exploratoryDAO, computationalDAO, requestBuilder, provisioningService, requestId);
+ }
@Test
public void terminateWhenMethodFetchExploratoryFieldsThrowsException() {
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
- doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
- .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString());
- try {
- exploratoryService.terminate(userInfo, EXPLORATORY_NAME);
- } catch (DlabException e) {
- assertEquals("Could not terminate exploratory environment expName: Exploratory for user " +
- "with name not found", e.getMessage());
- }
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("terminating");
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("failed");
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
+ doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
+ .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
+ try {
+ exploratoryService.terminate(userInfo, PROJECT, EXPLORATORY_NAME);
+ } catch (DlabException e) {
+ assertEquals("Could not terminate exploratory environment expName: Exploratory for user " +
+ "with name not found", e.getMessage());
+ }
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("terminating");
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("failed");
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void create() {
@@ -389,202 +389,116 @@ public class ExploratoryServiceImplTest {
}
@Test
- public void updateExploratoryStatusesWithRunningStatus() {
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusNotIn(anyString(), anyVararg()))
- .thenReturn(singletonList(userInstance));
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class)))
- .thenReturn(mock(UpdateResult.class));
-
- exploratoryService.updateExploratoryStatuses(USER, UserInstanceStatus.RUNNING);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("running");
-
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusNotIn(USER,
- UserInstanceStatus.TERMINATED, UserInstanceStatus.FAILED);
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verifyNoMoreInteractions(exploratoryDAO);
- }
-
- @Test
- public void updateExploratoryStatusesWithStoppingStatus() {
- userInstance.setStatus("stopping");
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusNotIn(anyString(), anyVararg()))
- .thenReturn(singletonList(userInstance));
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class)))
- .thenReturn(mock(UpdateResult.class));
- doNothing().when(computationalDAO).updateComputationalStatusesForExploratory(anyString(), anyString(),
- any(UserInstanceStatus.class), any(UserInstanceStatus.class));
-
- exploratoryService.updateExploratoryStatuses(USER, UserInstanceStatus.STOPPING);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("stopping");
-
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusNotIn(USER,
- UserInstanceStatus.TERMINATED, UserInstanceStatus.FAILED);
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(computationalDAO).updateComputationalStatusesForExploratory(USER, EXPLORATORY_NAME,
- UserInstanceStatus.STOPPING, UserInstanceStatus.TERMINATING, UserInstanceStatus.FAILED,
- UserInstanceStatus.TERMINATED, UserInstanceStatus.STOPPED);
- verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
- }
-
- @Test
- public void updateExploratoryStatusesWithTerminatingStatus() {
- userInstance.setStatus("terminating");
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusNotIn(anyString(), anyVararg()))
- .thenReturn(singletonList(userInstance));
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class)))
- .thenReturn(mock(UpdateResult.class));
- when(computationalDAO.updateComputationalStatusesForExploratory(any(StatusEnvBaseDTO.class)))
- .thenReturn(10);
-
- exploratoryService.updateExploratoryStatuses(USER, UserInstanceStatus.TERMINATING);
-
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("terminating");
-
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusNotIn(USER,
- UserInstanceStatus.TERMINATED, UserInstanceStatus.FAILED);
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(computationalDAO).updateComputationalStatusesForExploratory(USER, EXPLORATORY_NAME, UserInstanceStatus
- .TERMINATING, UserInstanceStatus.TERMINATING, UserInstanceStatus.TERMINATED, UserInstanceStatus
- .FAILED);
- verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
- }
-
- @Test
public void updateProjectExploratoryStatuses() {
- when(exploratoryDAO.fetchProjectExploratoriesWhereStatusNotIn(anyString(), anyString(), anyVararg()))
- .thenReturn(singletonList(userInstance));
- when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
- doNothing().when(computationalDAO).updateComputationalStatusesForExploratory(anyString(), anyString(),
- any(UserInstanceStatus.class), any(UserInstanceStatus.class), anyVararg());
-
- exploratoryService.updateProjectExploratoryStatuses("project", "endpoint",
- UserInstanceStatus.TERMINATED);
- statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("terminated");
-
- verify(exploratoryDAO).fetchProjectExploratoriesWhereStatusNotIn("project", "endpoint",
- UserInstanceStatus.TERMINATED, UserInstanceStatus.FAILED);
- verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
- verify(computationalDAO).updateComputationalStatusesForExploratory(USER, EXPLORATORY_NAME,
- UserInstanceStatus.TERMINATED, UserInstanceStatus.TERMINATED, UserInstanceStatus.TERMINATED,
- UserInstanceStatus.FAILED);
-
- verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
- }
-
- @Test
- public void updateUserExploratoriesReuploadKeyFlag() {
- doNothing().when(exploratoryDAO).updateReuploadKeyForExploratories(anyString(), anyBoolean(),
- any(UserInstanceStatus.class));
-
- exploratoryService.updateExploratoriesReuploadKeyFlag(USER, true, UserInstanceStatus.RUNNING);
-
- verify(exploratoryDAO).updateReuploadKeyForExploratories(USER, true, UserInstanceStatus.RUNNING);
- verifyNoMoreInteractions(exploratoryDAO);
- }
-
- @Test
- public void getInstancesWithStatuses() {
- when(exploratoryDAO.fetchUserExploratoriesWhereStatusIn(anyString(), anyBoolean(), anyVararg()))
- .thenReturn(singletonList(userInstance));
- exploratoryService.getInstancesWithStatuses(USER, UserInstanceStatus.RUNNING, UserInstanceStatus.RUNNING);
-
- verify(exploratoryDAO).fetchUserExploratoriesWhereStatusIn(USER, true, UserInstanceStatus.RUNNING);
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ when(exploratoryDAO.fetchProjectExploratoriesWhereStatusNotIn(anyString(), anyString(), anyVararg()))
+ .thenReturn(singletonList(userInstance));
+ when(exploratoryDAO.updateExploratoryStatus(any(StatusEnvBaseDTO.class))).thenReturn(mock(UpdateResult.class));
+ doNothing().when(computationalDAO).updateComputationalStatusesForExploratory(anyString(), anyString(),
+ anyString(), any(UserInstanceStatus.class), any(UserInstanceStatus.class), anyVararg());
+
+ exploratoryService.updateProjectExploratoryStatuses("project", "endpoint",
+ UserInstanceStatus.TERMINATED);
+ statusEnvBaseDTO = getStatusEnvBaseDTOWithStatus("terminated");
+
+ verify(exploratoryDAO).fetchProjectExploratoriesWhereStatusNotIn("project", "endpoint",
+ UserInstanceStatus.TERMINATED, UserInstanceStatus.FAILED);
+ verify(exploratoryDAO).updateExploratoryStatus(refEq(statusEnvBaseDTO, "self"));
+ verify(computationalDAO).updateComputationalStatusesForExploratory(USER, PROJECT,
+ EXPLORATORY_NAME, UserInstanceStatus.TERMINATED, UserInstanceStatus.TERMINATED,
+ UserInstanceStatus.TERMINATED, UserInstanceStatus.FAILED);
+
+ verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
+ }
@Test
public void getUserInstance() {
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
- Optional<UserInstanceDTO> expectedInstance = Optional.of(userInstance);
- Optional<UserInstanceDTO> actualInstance = exploratoryService.getUserInstance(USER, EXPLORATORY_NAME);
- assertEquals(expectedInstance, actualInstance);
+ Optional<UserInstanceDTO> expectedInstance = Optional.of(userInstance);
+ Optional<UserInstanceDTO> actualInstance = exploratoryService.getUserInstance(USER, PROJECT, EXPLORATORY_NAME);
+ assertEquals(expectedInstance, actualInstance);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void getUserInstanceWithException() {
- doThrow(new ResourceNotFoundException("Exploratory for user not found"))
- .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString());
+ doThrow(new ResourceNotFoundException("Exploratory for user not found"))
+ .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
- Optional<UserInstanceDTO> expectedInstance = Optional.empty();
- Optional<UserInstanceDTO> actualInstance = exploratoryService.getUserInstance(USER, EXPLORATORY_NAME);
- assertEquals(expectedInstance, actualInstance);
+ Optional<UserInstanceDTO> expectedInstance = Optional.empty();
+ Optional<UserInstanceDTO> actualInstance = exploratoryService.getUserInstance(USER, PROJECT, EXPLORATORY_NAME);
+ assertEquals(expectedInstance, actualInstance);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void testUpdateExploratoryClusterConfig() {
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(requestBuilder.newClusterConfigUpdate(any(UserInfo.class), any(UserInstanceDTO.class),
- anyListOf(ClusterConfig.class), any(EndpointDTO.class))).thenReturn(new ExploratoryReconfigureSparkClusterActionDTO());
- when(provisioningService.post(anyString(), anyString(), any(ExploratoryReconfigureSparkClusterActionDTO.class)
- , any())).thenReturn(UUID);
-
- exploratoryService.updateClusterConfig(getUserInfo(), EXPLORATORY_NAME, singletonList(new ClusterConfig()));
-
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
- verify(requestBuilder).newClusterConfigUpdate(refEq(getUserInfo()), refEq(getUserInstanceDto()),
- refEq(singletonList(new ClusterConfig())), refEq(endpointDTO()));
- verify(requestId).put(USER, UUID);
- verify(provisioningService).post(eq(endpointDTO().getUrl() + "exploratory/reconfigure_spark"), eq(TOKEN),
- refEq(new ExploratoryReconfigureSparkClusterActionDTO(), "self"), eq(String.class));
- verify(exploratoryDAO).updateExploratoryFields(refEq(new ExploratoryStatusDTO()
- .withUser(USER)
- .withConfig(singletonList(new ClusterConfig()))
- .withStatus(UserInstanceStatus.RECONFIGURING.toString())
- .withExploratoryName(EXPLORATORY_NAME), "self"));
- verifyNoMoreInteractions(requestBuilder, requestId, exploratoryDAO, provisioningService);
- }
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(requestBuilder.newClusterConfigUpdate(any(UserInfo.class), any(UserInstanceDTO.class),
+ anyListOf(ClusterConfig.class), any(EndpointDTO.class))).thenReturn(new ExploratoryReconfigureSparkClusterActionDTO());
+ when(provisioningService.post(anyString(), anyString(), any(ExploratoryReconfigureSparkClusterActionDTO.class)
+ , any())).thenReturn(UUID);
+
+ exploratoryService.updateClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME, singletonList(new ClusterConfig()));
+
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(requestBuilder).newClusterConfigUpdate(refEq(getUserInfo()), refEq(getUserInstanceDto()),
+ refEq(singletonList(new ClusterConfig())), refEq(endpointDTO()));
+ verify(requestId).put(USER, UUID);
+ verify(provisioningService).post(eq(endpointDTO().getUrl() + "exploratory/reconfigure_spark"), eq(TOKEN),
+ refEq(new ExploratoryReconfigureSparkClusterActionDTO(), "self"), eq(String.class));
+ verify(exploratoryDAO).updateExploratoryFields(refEq(new ExploratoryStatusDTO()
+ .withUser(USER)
+ .withProject(PROJECT)
+ .withConfig(singletonList(new ClusterConfig()))
+ .withStatus(UserInstanceStatus.RECONFIGURING.toString())
+ .withExploratoryName(EXPLORATORY_NAME), "self"));
+ verifyNoMoreInteractions(requestBuilder, requestId, exploratoryDAO, provisioningService);
+ }
@Test
public void testUpdateExploratoryClusterConfigWhenNotRunning() {
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenThrow(new ResourceNotFoundException("EXCEPTION"));
-
- try {
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenThrow(new ResourceNotFoundException("EXCEPTION"));
- exploratoryService.updateClusterConfig(getUserInfo(), EXPLORATORY_NAME,
- singletonList(new ClusterConfig()));
- } catch (ResourceNotFoundException e) {
- assertEquals("EXCEPTION", e.getMessage());
- }
+ try {
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(exploratoryDAO);
- verifyZeroInteractions(requestBuilder, requestId, provisioningService);
+ exploratoryService.updateClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME,
+ singletonList(new ClusterConfig()));
+ } catch (ResourceNotFoundException e) {
+ assertEquals("EXCEPTION", e.getMessage());
+ }
- }
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(exploratoryDAO);
+ verifyZeroInteractions(requestBuilder, requestId, provisioningService);
+ }
@Test
public void testGetClusterConfig() {
+ when(exploratoryDAO.getClusterConfig(anyString(), anyString(), anyString())).thenReturn(Collections.singletonList(getClusterConfig()));
+ final List<ClusterConfig> clusterConfig = exploratoryService.getClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME);
- when(exploratoryDAO.getClusterConfig(anyString(), anyString())).thenReturn(Collections.singletonList(getClusterConfig()));
- final List<ClusterConfig> clusterConfig = exploratoryService.getClusterConfig(getUserInfo(), EXPLORATORY_NAME);
+ assertEquals(1, clusterConfig.size());
+ assertEquals("classification", clusterConfig.get(0).getClassification());
- assertEquals(1, clusterConfig.size());
- assertEquals("classification", clusterConfig.get(0).getClassification());
-
- verify(exploratoryDAO).getClusterConfig(getUserInfo().getName(), EXPLORATORY_NAME);
- verifyNoMoreInteractions(exploratoryDAO);
- }
+ verify(exploratoryDAO).getClusterConfig(getUserInfo().getName(), PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(exploratoryDAO);
+ }
@Test
public void testGetClusterConfigWithException() {
+ when(exploratoryDAO.getClusterConfig(anyString(), anyString(), anyString())).thenThrow(new RuntimeException("Exception"));
- when(exploratoryDAO.getClusterConfig(anyString(), anyString())).thenThrow(new RuntimeException("Exception"));
-
- expectedException.expect(RuntimeException.class);
- expectedException.expectMessage("Exception");
- exploratoryService.getClusterConfig(getUserInfo(), EXPLORATORY_NAME);
- }
+ expectedException.expect(RuntimeException.class);
+ expectedException.expectMessage("Exception");
+ exploratoryService.getClusterConfig(getUserInfo(), PROJECT, EXPLORATORY_NAME);
+ }
private ClusterConfig getClusterConfig() {
final ClusterConfig config = new ClusterConfig();
@@ -597,18 +511,21 @@ public class ExploratoryServiceImplTest {
}
private UserInstanceDTO getUserInstanceDto() {
- UserComputationalResource compResource = new UserComputationalResource();
- compResource.setImageName("YYYY.dataengine");
- compResource.setComputationalName("compName");
- compResource.setStatus("stopped");
- compResource.setComputationalId("compId");
- return new UserInstanceDTO().withUser(USER).withExploratoryName(EXPLORATORY_NAME).withStatus("running")
- .withResources(singletonList(compResource))
- .withTags(Collections.emptyMap())
- .withProject("project")
- .withEndpoint("test")
- .withCloudProvider(CloudProvider.AWS.toString());
- }
+ UserComputationalResource compResource = new UserComputationalResource();
+ compResource.setImageName("YYYY.dataengine");
+ compResource.setComputationalName("compName");
+ compResource.setStatus("stopped");
+ compResource.setComputationalId("compId");
+ return new UserInstanceDTO()
+ .withUser(USER)
+ .withExploratoryName(EXPLORATORY_NAME)
+ .withStatus("running")
+ .withResources(singletonList(compResource))
+ .withTags(Collections.emptyMap())
+ .withProject(PROJECT)
+ .withEndpoint("test")
+ .withCloudProvider(CloudProvider.AWS.toString());
+ }
private StatusEnvBaseDTO getStatusEnvBaseDTOWithStatus(String status) {
return new ExploratoryStatusDTO()
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImplTest.java
index 7509971..57d0284 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ImageExploratoryServiceImplTest.java
@@ -56,7 +56,16 @@ import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.anyVararg;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ImageExploratoryServiceImplTest {
@@ -98,10 +107,10 @@ public class ImageExploratoryServiceImplTest {
@Test
public void createImage() {
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
when(imageExploratoryDao.exist(anyString(), anyString())).thenReturn(false);
- when(libDAO.getLibraries(anyString(), anyString())).thenReturn(Collections.singletonList(getLibrary()));
+ when(libDAO.getLibraries(anyString(), anyString(), anyString())).thenReturn(Collections.singletonList(getLibrary()));
doNothing().when(imageExploratoryDao).save(any(Image.class));
when(exploratoryDAO.updateExploratoryStatus(any(ExploratoryStatusDTO.class)))
.thenReturn(mock(UpdateResult.class));
@@ -115,16 +124,16 @@ public class ImageExploratoryServiceImplTest {
.thenReturn(expectedUuid);
String imageName = "someImageName", imageDescription = "someDescription";
- String actualUuid = imageExploratoryService.createImage(userInfo, EXPLORATORY_NAME, imageName,
- imageDescription);
+ String actualUuid = imageExploratoryService.createImage(userInfo, PROJECT, EXPLORATORY_NAME,
+ imageName, imageDescription);
assertNotNull(actualUuid);
assertEquals(expectedUuid, actualUuid);
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
verify(exploratoryDAO).updateExploratoryStatus(any(ExploratoryStatusDTO.class));
verify(imageExploratoryDao).exist(imageName, PROJECT);
verify(imageExploratoryDao).save(any(Image.class));
- verify(libDAO).getLibraries(USER, EXPLORATORY_NAME);
+ verify(libDAO).getLibraries(USER, PROJECT, EXPLORATORY_NAME);
verify(requestBuilder).newExploratoryImageCreate(userInfo, userInstance, imageName, endpointDTO());
verify(endpointService).get(anyString());
verify(provisioningService).post(endpointDTO().getUrl() + "exploratory/image", TOKEN, eiDto, String.class);
@@ -134,37 +143,37 @@ public class ImageExploratoryServiceImplTest {
@Test
public void createImageWhenMethodFetchRunningExploratoryFieldsThrowsException() {
doThrow(new DlabException("Running exploratory instance for user with name not found."))
- .when(exploratoryDAO).fetchRunningExploratoryFields(anyString(), anyString());
+ .when(exploratoryDAO).fetchRunningExploratoryFields(anyString(), anyString(), anyString());
String imageName = "someImageName", imageDescription = "someDescription";
try {
- imageExploratoryService.createImage(userInfo, EXPLORATORY_NAME, imageName, imageDescription);
+ imageExploratoryService.createImage(userInfo, PROJECT, EXPLORATORY_NAME, imageName, imageDescription);
} catch (DlabException e) {
assertEquals("Running exploratory instance for user with name not found.", e.getMessage());
}
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
verifyNoMoreInteractions(exploratoryDAO);
}
@Test
public void createImageWhenResourceAlreadyExists() {
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
when(imageExploratoryDao.exist(anyString(), anyString())).thenReturn(true);
expectedException.expect(ResourceAlreadyExistException.class);
expectedException.expectMessage("Image with name someImageName is already exist");
String imageName = "someImageName", imageDescription = "someDescription";
- imageExploratoryService.createImage(userInfo, EXPLORATORY_NAME, imageName, imageDescription);
+ imageExploratoryService.createImage(userInfo, PROJECT, EXPLORATORY_NAME, imageName, imageDescription);
}
@Test
public void createImageWhenMethodNewExploratoryImageCreateThrowsException() {
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
when(imageExploratoryDao.exist(anyString(), anyString())).thenReturn(false);
- when(libDAO.getLibraries(anyString(), anyString())).thenReturn(Collections.singletonList(getLibrary()));
+ when(libDAO.getLibraries(anyString(), anyString(), anyString())).thenReturn(Collections.singletonList(getLibrary()));
doNothing().when(imageExploratoryDao).save(any(Image.class));
when(exploratoryDAO.updateExploratoryStatus(any(ExploratoryStatusDTO.class)))
.thenReturn(mock(UpdateResult.class));
@@ -174,16 +183,16 @@ public class ImageExploratoryServiceImplTest {
String imageName = "someImageName", imageDescription = "someDescription";
try {
- imageExploratoryService.createImage(userInfo, EXPLORATORY_NAME, imageName, imageDescription);
+ imageExploratoryService.createImage(userInfo, PROJECT, EXPLORATORY_NAME, imageName, imageDescription);
} catch (DlabException e) {
assertEquals("Cannot create instance of resource class", e.getMessage());
}
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
verify(exploratoryDAO).updateExploratoryStatus(any(ExploratoryStatusDTO.class));
verify(imageExploratoryDao).exist(imageName, PROJECT);
verify(imageExploratoryDao).save(any(Image.class));
- verify(libDAO).getLibraries(USER, EXPLORATORY_NAME);
+ verify(libDAO).getLibraries(USER, PROJECT, EXPLORATORY_NAME);
verify(requestBuilder).newExploratoryImageCreate(userInfo, userInstance, imageName, endpointDTO());
verify(endpointService).get(anyString());
verifyNoMoreInteractions(exploratoryDAO, imageExploratoryDao, libDAO, requestBuilder, endpointService);
@@ -194,13 +203,13 @@ public class ImageExploratoryServiceImplTest {
when(exploratoryDAO.updateExploratoryStatus(any(ExploratoryStatusDTO.class)))
.thenReturn(mock(UpdateResult.class));
doNothing().when(imageExploratoryDao).updateImageFields(any(Image.class));
- doNothing().when(exploratoryDAO).updateExploratoryIp(anyString(), anyString(), anyString());
+ doNothing().when(exploratoryDAO).updateExploratoryIp(anyString(), anyString(), anyString(), anyString());
String notebookIp = "someIp";
imageExploratoryService.finishImageCreate(image, EXPLORATORY_NAME, notebookIp);
verify(exploratoryDAO).updateExploratoryStatus(any(ExploratoryStatusDTO.class));
- verify(exploratoryDAO).updateExploratoryIp(USER, notebookIp, EXPLORATORY_NAME);
+ verify(exploratoryDAO).updateExploratoryIp(USER, PROJECT, notebookIp, EXPLORATORY_NAME);
verify(imageExploratoryDao).updateImageFields(image);
verifyNoMoreInteractions(exploratoryDAO, imageExploratoryDao);
}
@@ -211,7 +220,7 @@ public class ImageExploratoryServiceImplTest {
.thenReturn(mock(UpdateResult.class));
doNothing().when(imageExploratoryDao).updateImageFields(any(Image.class));
doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
- .when(exploratoryDAO).updateExploratoryIp(anyString(), anyString(), anyString());
+ .when(exploratoryDAO).updateExploratoryIp(anyString(), anyString(), anyString(), anyString());
String notebookIp = "someIp";
try {
@@ -221,7 +230,7 @@ public class ImageExploratoryServiceImplTest {
}
verify(exploratoryDAO).updateExploratoryStatus(any(ExploratoryStatusDTO.class));
- verify(exploratoryDAO).updateExploratoryIp(USER, notebookIp, EXPLORATORY_NAME);
+ verify(exploratoryDAO).updateExploratoryIp(USER, PROJECT, notebookIp, EXPLORATORY_NAME);
verify(imageExploratoryDao).updateImageFields(image);
verifyNoMoreInteractions(exploratoryDAO, imageExploratoryDao);
}
@@ -235,7 +244,7 @@ public class ImageExploratoryServiceImplTest {
imageExploratoryService.finishImageCreate(image, EXPLORATORY_NAME, null);
verify(exploratoryDAO).updateExploratoryStatus(any(ExploratoryStatusDTO.class));
- verify(exploratoryDAO, never()).updateExploratoryIp(USER, null, EXPLORATORY_NAME);
+ verify(exploratoryDAO, never()).updateExploratoryIp(USER, PROJECT, null, EXPLORATORY_NAME);
verify(imageExploratoryDao).updateImageFields(image);
verifyNoMoreInteractions(exploratoryDAO, imageExploratoryDao);
}
@@ -301,6 +310,7 @@ public class ImageExploratoryServiceImplTest {
.description("someDescription")
.status(ImageStatus.CREATING)
.user(USER)
+ .project(PROJECT)
.libraries(Collections.singletonList(getLibrary()))
.computationalLibraries(Collections.emptyMap())
.dockerImage("someImageName")
@@ -313,8 +323,11 @@ public class ImageExploratoryServiceImplTest {
}
private UserInstanceDTO getUserInstanceDto() {
- return new UserInstanceDTO().withUser(USER).withExploratoryName(EXPLORATORY_NAME)
- .withExploratoryId("explId").withProject(PROJECT);
+ return new UserInstanceDTO()
+ .withUser(USER)
+ .withExploratoryName(EXPLORATORY_NAME)
+ .withExploratoryId("explId")
+ .withProject(PROJECT);
}
private UserInfo getUserInfo() {
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImplTest.java
index bc3ecbf..3677929 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/LibraryServiceImplTest.java
@@ -56,38 +56,46 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyListOf;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.refEq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class LibraryServiceImplTest {
- private static final String LIB_NAME = "name";
- private static final String LIB_GROUP = "group";
- private static final String LIB_VERSION = "version";
- private static final String UUID = "id";
- private final String USER = "test";
- private final String EXPLORATORY_NAME = "explName";
- private final String COMPUTATIONAL_NAME = "compName";
-
- private LibInstallDTO liDto;
- private List<LibInstallDTO> libs;
- private LibInstallFormDTO libInstallFormDTO;
- private LibraryInstallDTO libraryInstallDto;
-
- @Mock
- private ExploratoryDAO exploratoryDAO;
- @Mock
- private ExploratoryLibDAO libraryDAO;
- @Mock
- private RequestBuilder requestBuilder;
- @Mock
- private RequestId requestId;
- @Mock
- private RESTService provisioningService;
- @Mock
- private EndpointService endpointService;
-
- @Rule
+ private static final String LIB_NAME = "name";
+ private static final String LIB_GROUP = "group";
+ private static final String LIB_VERSION = "version";
+ private static final String UUID = "id";
+ private final String USER = "test";
+ private final String EXPLORATORY_NAME = "explName";
+ private final String PROJECT = "projectName";
+ private final String COMPUTATIONAL_NAME = "compName";
+
+ private LibInstallDTO liDto;
+ private List<LibInstallDTO> libs;
+ private LibInstallFormDTO libInstallFormDTO;
+ private LibraryInstallDTO libraryInstallDto;
+
+ @Mock
+ private ExploratoryDAO exploratoryDAO;
+ @Mock
+ private ExploratoryLibDAO libraryDAO;
+ @Mock
+ private RequestBuilder requestBuilder;
+ @Mock
+ private RequestId requestId;
+ @Mock
+ private RESTService provisioningService;
+ @Mock
+ private EndpointService endpointService;
+
+ @Rule
public ExpectedException expectedException = ExpectedException.none();
@InjectMocks
@@ -100,243 +108,245 @@ public class LibraryServiceImplTest {
@Test
public void testGetLibs() {
- Document document = new Document();
- when(libraryDAO.findExploratoryLibraries(anyString(), anyString())).thenReturn(document);
+ Document document = new Document();
+ when(libraryDAO.findExploratoryLibraries(anyString(), anyString(), anyString())).thenReturn(document);
- List<Document> expectedList = new ArrayList<>();
- List<Document> actualList = libraryService.getLibs(USER, EXPLORATORY_NAME, "");
- assertNotNull(actualList);
- assertEquals(expectedList, actualList);
+ List<Document> expectedList = new ArrayList<>();
+ List<Document> actualList = libraryService.getLibs(USER, PROJECT, EXPLORATORY_NAME, "");
+ assertNotNull(actualList);
+ assertEquals(expectedList, actualList);
- verify(libraryDAO).findExploratoryLibraries(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(libraryDAO);
- }
+ verify(libraryDAO).findExploratoryLibraries(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(libraryDAO);
+ }
@Test
public void getLibInfo() {
- Document document = new Document();
- when(libraryDAO.findAllLibraries(anyString(), anyString())).thenReturn(document);
+ Document document = new Document();
+ when(libraryDAO.findAllLibraries(anyString(), anyString(), anyString())).thenReturn(document);
- List<LibInfoRecord> expectedList = new ArrayList<>();
- List<LibInfoRecord> actualList = libraryService.getLibInfo(USER, EXPLORATORY_NAME);
- assertNotNull(actualList);
- assertEquals(expectedList, actualList);
+ List<LibInfoRecord> expectedList = new ArrayList<>();
+ List<LibInfoRecord> actualList = libraryService.getLibInfo(USER, PROJECT, EXPLORATORY_NAME);
+ assertNotNull(actualList);
+ assertEquals(expectedList, actualList);
- verify(libraryDAO).findAllLibraries(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(libraryDAO);
- }
+ verify(libraryDAO).findAllLibraries(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(libraryDAO);
+ }
@Test
public void getLibInfoWhenListsOfExploratoryAndComputationalLibsAreNotEmpty() {
- when(libraryDAO.findAllLibraries(anyString(), anyString()))
- .thenReturn(getDocumentWithExploratoryAndComputationalLibs());
+ when(libraryDAO.findAllLibraries(anyString(), anyString(), anyString()))
+ .thenReturn(getDocumentWithExploratoryAndComputationalLibs());
- List<LibInfoRecord> expectedList = getLibInfoRecordList();
- List<LibInfoRecord> actualList = libraryService.getLibInfo(USER, EXPLORATORY_NAME);
- assertNotNull(actualList);
- assertEquals(expectedList, actualList);
+ List<LibInfoRecord> expectedList = getLibInfoRecordList();
+ List<LibInfoRecord> actualList = libraryService.getLibInfo(USER, PROJECT, EXPLORATORY_NAME);
+ assertNotNull(actualList);
+ assertEquals(expectedList, actualList);
- verify(libraryDAO).findAllLibraries(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(libraryDAO);
- }
+ verify(libraryDAO).findAllLibraries(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(libraryDAO);
+ }
@Test
public void installComputationalLibsWithoutOverride() {
- final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
- final List<LibInstallDTO> libsToInstall = getLibs("installing");
- libraryInstallDTO.setLibs(libsToInstall);
- final UserInfo user = getUser();
-
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
- when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
- any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class))).thenReturn(libraryInstallDTO);
-
-
- final String uuid = libraryService.installComputationalLibs(user, EXPLORATORY_NAME, COMPUTATIONAL_NAME,
- getLibs(null));
-
- assertEquals(UUID, uuid);
-
- verify(libraryDAO).getLibrary(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME, LIB_GROUP, LIB_NAME);
- verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()),
- refEq(getUserComputationalResourceWithName(COMPUTATIONAL_NAME)), eq(libsToInstall), refEq(endpointDTO()));
- verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/computational/lib_install"), eq(user.getAccessToken()),
- refEq(libraryInstallDTO), eq(String.class));
- verify(libraryDAO).addLibrary(eq(USER), eq(EXPLORATORY_NAME), eq(COMPUTATIONAL_NAME),
- refEq(libsToInstall.get(0)), eq(false));
- verify(requestId).put(user.getName(), UUID);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
- verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
- }
+ final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
+ final List<LibInstallDTO> libsToInstall = getLibs("installing");
+ libraryInstallDTO.setLibs(libsToInstall);
+ final UserInfo user = getUser();
+
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
+ when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
+ any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class))).thenReturn(libraryInstallDTO);
+
+
+ final String uuid = libraryService.installComputationalLibs(user, PROJECT, EXPLORATORY_NAME,
+ COMPUTATIONAL_NAME, getLibs(null));
+
+ assertEquals(UUID, uuid);
+
+ verify(libraryDAO).getLibrary(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, LIB_GROUP, LIB_NAME);
+ verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()),
+ refEq(getUserComputationalResourceWithName(COMPUTATIONAL_NAME)), eq(libsToInstall), refEq(endpointDTO()));
+ verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/computational/lib_install"), eq(user.getAccessToken()),
+ refEq(libraryInstallDTO), eq(String.class));
+ verify(libraryDAO).addLibrary(eq(USER), eq(PROJECT), eq(EXPLORATORY_NAME),
+ eq(COMPUTATIONAL_NAME), refEq(libsToInstall.get(0)), eq(false));
+ verify(requestId).put(user.getName(), UUID);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
+ }
@Test
public void installComputationalLibsWhenComputationalNotFound() {
- final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
- final List<LibInstallDTO> libsToInstall = getLibs("installing");
- libraryInstallDTO.setLibs(libsToInstall);
- final UserInfo user = getUser();
+ final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
+ final List<LibInstallDTO> libsToInstall = getLibs("installing");
+ libraryInstallDTO.setLibs(libsToInstall);
+ libraryInstallDTO.setProject(PROJECT);
+ final UserInfo user = getUser();
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
- when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
- any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class)))
- .thenReturn(libraryInstallDTO);
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
+ when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
+ any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class)))
+ .thenReturn(libraryInstallDTO);
- expectedException.expect(DlabException.class);
- expectedException.expectMessage("Computational with name " + COMPUTATIONAL_NAME + "X was not found");
+ expectedException.expect(DlabException.class);
+ expectedException.expectMessage("Computational with name " + COMPUTATIONAL_NAME + "X was not found");
- libraryService.installComputationalLibs(user, EXPLORATORY_NAME, COMPUTATIONAL_NAME + "X",
- getLibs(null));
- }
+ libraryService.installComputationalLibs(user, PROJECT, EXPLORATORY_NAME,
+ COMPUTATIONAL_NAME + "X", getLibs(null));
+ }
@Test
public void installComputationalLibsWithOverride() {
- final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
- final List<LibInstallDTO> libsToInstall = getLibs("installing");
- libraryInstallDTO.setLibs(libsToInstall);
- final UserInfo user = getUser();
-
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
- when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
- any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class)))
- .thenReturn(libraryInstallDTO);
- when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLED));
-
- final String uuid = libraryService.installComputationalLibs(user, EXPLORATORY_NAME, COMPUTATIONAL_NAME,
- getLibs(null));
-
- assertEquals(UUID, uuid);
-
- libsToInstall.get(0).setOverride(true);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
- verify(libraryDAO).getLibrary(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME, LIB_GROUP, LIB_NAME);
- verify(libraryDAO).addLibrary(eq(USER), eq(EXPLORATORY_NAME), eq(COMPUTATIONAL_NAME),
- refEq(libsToInstall.get(0)), eq(true));
- verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()),
- refEq(getUserComputationalResourceWithName(COMPUTATIONAL_NAME)), eq(libsToInstall), refEq(endpointDTO()));
- verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/computational/lib_install"),
- eq(user.getAccessToken()),
- refEq(libraryInstallDTO), eq(String.class));
- verify(requestId).put(user.getName(), UUID);
- verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
-
- }
+ final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
+ final List<LibInstallDTO> libsToInstall = getLibs("installing");
+ libraryInstallDTO.setProject(PROJECT);
+ libraryInstallDTO.setLibs(libsToInstall);
+ final UserInfo user = getUser();
+
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
+ when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
+ any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class)))
+ .thenReturn(libraryInstallDTO);
+ when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLED));
+
+ final String uuid = libraryService.installComputationalLibs(user, PROJECT, EXPLORATORY_NAME,
+ COMPUTATIONAL_NAME, getLibs(null));
+
+ assertEquals(UUID, uuid);
+
+ libsToInstall.get(0).setOverride(true);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(libraryDAO).getLibrary(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, LIB_GROUP, LIB_NAME);
+ verify(libraryDAO).addLibrary(eq(USER), eq(PROJECT), eq(EXPLORATORY_NAME),
+ eq(COMPUTATIONAL_NAME), refEq(libsToInstall.get(0)), eq(true));
+ verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()),
+ refEq(getUserComputationalResourceWithName(COMPUTATIONAL_NAME)), eq(libsToInstall), refEq(endpointDTO()));
+ verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/computational/lib_install"),
+ eq(user.getAccessToken()),
+ refEq(libraryInstallDTO), eq(String.class));
+ verify(requestId).put(user.getName(), UUID);
+ verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
+
+ }
@Test
public void installComputationalLibsWhenLibraryIsAlreadyInstalling() {
- final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
- final List<LibInstallDTO> libsToInstall = getLibs("installing");
- libraryInstallDTO.setLibs(libsToInstall);
- final UserInfo user = getUser();
-
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
- when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
- any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class)))
- .thenReturn(libraryInstallDTO);
- when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLING));
-
- try {
- libraryService.installComputationalLibs(user, EXPLORATORY_NAME, COMPUTATIONAL_NAME,
- getLibs(null));
- } catch (DlabException e) {
- assertEquals("Library name is already installing", e.getMessage());
- }
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
- verify(libraryDAO).getLibrary(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME, LIB_GROUP, LIB_NAME);
- verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
- }
+ final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
+ final List<LibInstallDTO> libsToInstall = getLibs("installing");
+ libraryInstallDTO.setLibs(libsToInstall);
+ final UserInfo user = getUser();
+
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
+ when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class),
+ any(UserComputationalResource.class), anyListOf(LibInstallDTO.class), any(EndpointDTO.class)))
+ .thenReturn(libraryInstallDTO);
+ when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLING));
+
+ try {
+ libraryService.installComputationalLibs(user, PROJECT, EXPLORATORY_NAME,
+ COMPUTATIONAL_NAME, getLibs(null));
+ } catch (DlabException e) {
+ assertEquals("Library name is already installing", e.getMessage());
+ }
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(libraryDAO).getLibrary(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, LIB_GROUP, LIB_NAME);
+ verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
+ }
@Test
public void installExploratoryLibsWithoutOverride() {
- final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
- final List<LibInstallDTO> libsToInstall = getLibs("installing");
- libraryInstallDTO.setLibs(libsToInstall);
- final UserInfo user = getUser();
-
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
- when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
- anyListOf(LibInstallDTO.class))).thenReturn(libraryInstallDTO);
-
-
- final String uuid = libraryService.installExploratoryLibs(user, EXPLORATORY_NAME, getLibs(null));
-
- assertEquals(UUID, uuid);
-
- verify(libraryDAO).getLibrary(USER, EXPLORATORY_NAME, LIB_GROUP, LIB_NAME);
- verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()), eq(endpointDTO()), eq(libsToInstall));
- verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/exploratory/lib_install"), eq(user.getAccessToken()),
- refEq(libraryInstallDTO), eq(String.class));
- verify(libraryDAO).addLibrary(eq(USER), eq(EXPLORATORY_NAME), refEq(libsToInstall.get(0)), eq(false));
- verify(requestId).put(user.getName(), UUID);
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
- }
+ final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
+ final List<LibInstallDTO> libsToInstall = getLibs("installing");
+ libraryInstallDTO.setLibs(libsToInstall);
+ final UserInfo user = getUser();
+
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
+ when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
+ anyListOf(LibInstallDTO.class))).thenReturn(libraryInstallDTO);
+
+
+ final String uuid = libraryService.installExploratoryLibs(user, PROJECT, EXPLORATORY_NAME, getLibs(null));
+
+ assertEquals(UUID, uuid);
+
+ verify(libraryDAO).getLibrary(USER, PROJECT, EXPLORATORY_NAME, LIB_GROUP, LIB_NAME);
+ verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()), eq(endpointDTO()), eq(libsToInstall));
+ verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/exploratory/lib_install"), eq(user.getAccessToken()),
+ refEq(libraryInstallDTO), eq(String.class));
+ verify(libraryDAO).addLibrary(eq(USER), eq(PROJECT), eq(EXPLORATORY_NAME), refEq(libsToInstall.get(0)), eq(false));
+ verify(requestId).put(user.getName(), UUID);
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
+ }
@Test
public void installExploratoryLibsWithOverride() {
- final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
- final List<LibInstallDTO> libsToInstall = getLibs("installing");
- libraryInstallDTO.setLibs(libsToInstall);
- final UserInfo user = getUser();
-
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
- when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
- anyListOf(LibInstallDTO.class))).thenReturn(libraryInstallDTO);
- when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLED));
-
- final String uuid = libraryService.installExploratoryLibs(user, EXPLORATORY_NAME, getLibs(null));
-
- assertEquals(UUID, uuid);
-
- libsToInstall.get(0).setOverride(true);
- verify(libraryDAO).getLibrary(USER, EXPLORATORY_NAME, LIB_GROUP, LIB_NAME);
- verify(libraryDAO).addLibrary(eq(USER), eq(EXPLORATORY_NAME), refEq(libsToInstall.get(0)), eq(true));
- verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()), eq(endpointDTO()), eq(libsToInstall));
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
- verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/exploratory/lib_install"), eq(user.getAccessToken()),
- refEq(libraryInstallDTO), eq(String.class));
- verify(requestId).put(USER, uuid);
- verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
- }
+ final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
+ final List<LibInstallDTO> libsToInstall = getLibs("installing");
+ libraryInstallDTO.setLibs(libsToInstall);
+ final UserInfo user = getUser();
+
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
+ when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
+ anyListOf(LibInstallDTO.class))).thenReturn(libraryInstallDTO);
+ when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLED));
+
+ final String uuid = libraryService.installExploratoryLibs(user, PROJECT, EXPLORATORY_NAME, getLibs(null));
+
+ assertEquals(UUID, uuid);
+
+ libsToInstall.get(0).setOverride(true);
+ verify(libraryDAO).getLibrary(USER, PROJECT, EXPLORATORY_NAME, LIB_GROUP, LIB_NAME);
+ verify(libraryDAO).addLibrary(eq(USER), eq(PROJECT), eq(EXPLORATORY_NAME), refEq(libsToInstall.get(0)), eq(true));
+ verify(requestBuilder).newLibInstall(refEq(user), refEq(getUserInstanceDto()), eq(endpointDTO()), eq(libsToInstall));
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(provisioningService).post(eq(endpointDTO().getUrl() + "library/exploratory/lib_install"), eq(user.getAccessToken()),
+ refEq(libraryInstallDTO), eq(String.class));
+ verify(requestId).put(USER, uuid);
+ verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
+ }
@Test
public void installExploratoryLibsWhenLibIsAlreadyInstalling() {
- final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
- final List<LibInstallDTO> libsToInstall = getLibs("installing");
- libraryInstallDTO.setLibs(libsToInstall);
- final UserInfo user = getUser();
-
- when(endpointService.get(anyString())).thenReturn(endpointDTO());
- when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString())).thenReturn(getUserInstanceDto());
- when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
- when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
- anyListOf(LibInstallDTO.class))).thenReturn(libraryInstallDTO);
- when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLING));
-
- try {
- libraryService.installExploratoryLibs(user, EXPLORATORY_NAME, getLibs(null));
- } catch (DlabException e) {
- assertEquals("Library name is already installing", e.getMessage());
- }
-
- verify(libraryDAO).getLibrary(USER, EXPLORATORY_NAME, LIB_GROUP, LIB_NAME);
- verify(exploratoryDAO).fetchRunningExploratoryFields(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
-
- }
+ final LibraryInstallDTO libraryInstallDTO = new LibraryInstallDTO();
+ final List<LibInstallDTO> libsToInstall = getLibs("installing");
+ libraryInstallDTO.setLibs(libsToInstall);
+ final UserInfo user = getUser();
+
+ when(endpointService.get(anyString())).thenReturn(endpointDTO());
+ when(exploratoryDAO.fetchRunningExploratoryFields(anyString(), anyString(), anyString())).thenReturn(getUserInstanceDto());
+ when(provisioningService.post(anyString(), anyString(), any(LibraryInstallDTO.class), any())).thenReturn(UUID);
+ when(requestBuilder.newLibInstall(any(UserInfo.class), any(UserInstanceDTO.class), any(EndpointDTO.class),
+ anyListOf(LibInstallDTO.class))).thenReturn(libraryInstallDTO);
+ when(libraryDAO.getLibrary(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(getLibrary(LibStatus.INSTALLING));
+
+ try {
+ libraryService.installExploratoryLibs(user, PROJECT, EXPLORATORY_NAME, getLibs(null));
+ } catch (DlabException e) {
+ assertEquals("Library name is already installing", e.getMessage());
+ }
+
+ verify(libraryDAO).getLibrary(USER, PROJECT, EXPLORATORY_NAME, LIB_GROUP, LIB_NAME);
+ verify(exploratoryDAO).fetchRunningExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(libraryDAO, requestBuilder, provisioningService, requestId, exploratoryDAO);
+
+ }
private Library getLibrary(LibStatus status) {
return new Library(LIB_GROUP, LIB_NAME, "1", status, "");
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImplTest.java
index 9b5e887..1aefbbb 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/ReuploadKeyServiceImplTest.java
@@ -25,13 +25,10 @@ import com.epam.dlab.backendapi.dao.ExploratoryDAO;
import com.epam.dlab.backendapi.domain.RequestId;
import com.epam.dlab.backendapi.service.ExploratoryService;
import com.epam.dlab.backendapi.util.RequestBuilder;
-import com.epam.dlab.dto.UserInstanceDTO;
import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.reuploadkey.ReuploadKeyCallbackDTO;
-import com.epam.dlab.dto.reuploadkey.ReuploadKeyDTO;
import com.epam.dlab.dto.reuploadkey.ReuploadKeyStatus;
import com.epam.dlab.dto.reuploadkey.ReuploadKeyStatusDTO;
-import com.epam.dlab.exceptions.DlabException;
import com.epam.dlab.model.ResourceData;
import com.epam.dlab.model.ResourceType;
import com.epam.dlab.rest.client.RESTService;
@@ -45,14 +42,16 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import static com.epam.dlab.dto.UserInstanceStatus.REUPLOADING_KEY;
import static com.epam.dlab.dto.UserInstanceStatus.RUNNING;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyBoolean;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ReuploadKeyServiceImplTest {
@@ -111,16 +110,16 @@ public class ReuploadKeyServiceImplTest {
@Test
public void updateResourceDataForExploratoryWhenStatusCompleted() {
ResourceData resource = new ResourceData(ResourceType.EXPLORATORY, "someId", EXPLORATORY_NAME, null);
- when(exploratoryDAO.updateStatusForExploratory(anyString(), anyString(),
+ when(exploratoryDAO.updateStatusForExploratory(anyString(), anyString(), anyString(),
any(UserInstanceStatus.class))).thenReturn(mock(UpdateResult.class));
- doNothing().when(exploratoryDAO).updateReuploadKeyForExploratory(anyString(), anyString(), anyBoolean());
+ doNothing().when(exploratoryDAO).updateReuploadKeyForExploratory(anyString(), anyString(), anyString(), anyBoolean());
ReuploadKeyStatusDTO dto = getReuploadKeyStatusDTO(resource, ReuploadKeyStatus.COMPLETED);
reuploadKeyService.updateResourceData(dto);
- verify(exploratoryDAO).updateStatusForExploratory(USER, EXPLORATORY_NAME, RUNNING);
- verify(exploratoryDAO).updateReuploadKeyForExploratory(USER, EXPLORATORY_NAME, false);
+ verify(exploratoryDAO).updateStatusForExploratory(USER, null, EXPLORATORY_NAME, RUNNING);
+ verify(exploratoryDAO).updateReuploadKeyForExploratory(USER, null, EXPLORATORY_NAME, false);
verifyNoMoreInteractions(exploratoryDAO);
verifyZeroInteractions(computationalDAO);
}
@@ -128,14 +127,14 @@ public class ReuploadKeyServiceImplTest {
@Test
public void updateResourceDataForExploratoryWhenStatusFailed() {
ResourceData resource = new ResourceData(ResourceType.EXPLORATORY, "someId", EXPLORATORY_NAME, null);
- when(exploratoryDAO.updateStatusForExploratory(anyString(), anyString(),
+ when(exploratoryDAO.updateStatusForExploratory(anyString(), anyString(), anyString(),
any(UserInstanceStatus.class))).thenReturn(mock(UpdateResult.class));
ReuploadKeyStatusDTO dto = getReuploadKeyStatusDTO(resource, ReuploadKeyStatus.FAILED);
reuploadKeyService.updateResourceData(dto);
- verify(exploratoryDAO).updateStatusForExploratory(USER, EXPLORATORY_NAME, RUNNING);
+ verify(exploratoryDAO).updateStatusForExploratory(USER, null, EXPLORATORY_NAME, RUNNING);
verifyNoMoreInteractions(exploratoryDAO);
verifyZeroInteractions(computationalDAO);
}
@@ -144,16 +143,16 @@ public class ReuploadKeyServiceImplTest {
public void updateResourceDataForClusterWhenStatusCompleted() {
ResourceData resource = new ResourceData(ResourceType.COMPUTATIONAL, "someId", EXPLORATORY_NAME, "compName");
doNothing().when(computationalDAO).updateStatusForComputationalResource(anyString(), anyString(), anyString(),
- any(UserInstanceStatus.class));
+ anyString(), any(UserInstanceStatus.class));
doNothing().when(computationalDAO).updateReuploadKeyFlagForComputationalResource(anyString(), anyString(),
- anyString(), anyBoolean());
+ anyString(), anyString(), anyBoolean());
ReuploadKeyStatusDTO dto = getReuploadKeyStatusDTO(resource, ReuploadKeyStatus.COMPLETED);
reuploadKeyService.updateResourceData(dto);
- verify(computationalDAO).updateStatusForComputationalResource(USER, EXPLORATORY_NAME, "compName", RUNNING);
- verify(computationalDAO).updateReuploadKeyFlagForComputationalResource(USER, EXPLORATORY_NAME, "compName",
- false);
+ verify(computationalDAO).updateStatusForComputationalResource(USER, null, EXPLORATORY_NAME, "compName", RUNNING);
+ verify(computationalDAO).updateReuploadKeyFlagForComputationalResource(USER, null, EXPLORATORY_NAME,
+ "compName", false);
verifyNoMoreInteractions(computationalDAO);
verifyZeroInteractions(exploratoryDAO);
}
@@ -162,12 +161,12 @@ public class ReuploadKeyServiceImplTest {
public void updateResourceDataForClusterWhenStatusFailed() {
ResourceData resource = new ResourceData(ResourceType.COMPUTATIONAL, "someId", EXPLORATORY_NAME, "compName");
doNothing().when(computationalDAO).updateStatusForComputationalResource(anyString(), anyString(), anyString(),
- any(UserInstanceStatus.class));
+ anyString(), any(UserInstanceStatus.class));
ReuploadKeyStatusDTO dto = getReuploadKeyStatusDTO(resource, ReuploadKeyStatus.FAILED);
reuploadKeyService.updateResourceData(dto);
- verify(computationalDAO).updateStatusForComputationalResource(USER, EXPLORATORY_NAME, "compName", RUNNING);
+ verify(computationalDAO).updateStatusForComputationalResource(USER, null, EXPLORATORY_NAME, "compName", RUNNING);
verifyNoMoreInteractions(computationalDAO);
verifyZeroInteractions(exploratoryDAO);
}
@@ -176,10 +175,6 @@ public class ReuploadKeyServiceImplTest {
return new UserInfo(USER, TOKEN);
}
- private UserInstanceDTO getUserInstance() {
- return new UserInstanceDTO().withUser(USER).withExploratoryName(EXPLORATORY_NAME);
- }
-
private ReuploadKeyStatusDTO getReuploadKeyStatusDTO(ResourceData resource, ReuploadKeyStatus status) {
return new ReuploadKeyStatusDTO().withReuploadKeyCallbackDto(
new ReuploadKeyCallbackDTO().withResource(resource)).withReuploadKeyStatus(status).withUser(USER);
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImplTest.java
index 8a7d8ec..c025651 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/SchedulerJobServiceImplTest.java
@@ -43,16 +43,40 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import java.time.*;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
import java.util.stream.Collectors;
-import static com.epam.dlab.dto.UserInstanceStatus.*;
+import static com.epam.dlab.dto.UserInstanceStatus.RUNNING;
+import static com.epam.dlab.dto.UserInstanceStatus.STARTING;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPED;
+import static com.epam.dlab.dto.UserInstanceStatus.STOPPING;
import static java.util.Collections.singletonList;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.anyVararg;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.refEq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class SchedulerJobServiceImplTest {
@@ -92,84 +116,83 @@ public class SchedulerJobServiceImplTest {
@Test
public void fetchSchedulerJobForUserAndExploratory() {
- when(schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(anyString(), anyString()))
+ when(schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(anyString(), anyString(), anyString()))
.thenReturn(Optional.of(schedulerJobDTO));
SchedulerJobDTO actualSchedulerJobDto =
- schedulerJobService.fetchSchedulerJobForUserAndExploratory(USER, EXPLORATORY_NAME);
+ schedulerJobService.fetchSchedulerJobForUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME);
assertNotNull(actualSchedulerJobDto);
assertEquals(schedulerJobDTO, actualSchedulerJobDto);
- verify(schedulerJobDAO).fetchSingleSchedulerJobByUserAndExploratory(USER, EXPLORATORY_NAME);
+ verify(schedulerJobDAO).fetchSingleSchedulerJobByUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME);
verifyNoMoreInteractions(exploratoryDAO, schedulerJobDAO);
}
@Test
public void fetchSchedulerJobForUserAndExploratoryWhenNotebookNotExist() {
- when(schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(anyString(), anyString())).thenReturn(Optional.empty());
+ when(schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(anyString(), anyString(), anyString())).thenReturn(Optional.empty());
try {
- schedulerJobService.fetchSchedulerJobForUserAndExploratory(USER, EXPLORATORY_NAME);
+ schedulerJobService.fetchSchedulerJobForUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME);
} catch (ResourceNotFoundException e) {
assertEquals("Scheduler job data not found for user test with exploratory explName", e.getMessage());
}
- verify(schedulerJobDAO).fetchSingleSchedulerJobByUserAndExploratory(USER, EXPLORATORY_NAME);
+ verify(schedulerJobDAO).fetchSingleSchedulerJobByUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME);
verifyNoMoreInteractions(schedulerJobDAO);
}
@Test
public void fetchEmptySchedulerJobForUserAndExploratory() {
- when(exploratoryDAO.isExploratoryExist(anyString(), anyString())).thenReturn(true);
- when(schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(anyString(), anyString()))
+ when(schedulerJobDAO.fetchSingleSchedulerJobByUserAndExploratory(anyString(), anyString(), anyString()))
.thenReturn(Optional.empty());
try {
- schedulerJobService.fetchSchedulerJobForUserAndExploratory(USER, EXPLORATORY_NAME);
+ schedulerJobService.fetchSchedulerJobForUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME);
} catch (ResourceNotFoundException e) {
assertEquals("Scheduler job data not found for user test with exploratory explName", e.getMessage());
}
- verify(schedulerJobDAO).fetchSingleSchedulerJobByUserAndExploratory(USER, EXPLORATORY_NAME);
- verifyNoMoreInteractions(exploratoryDAO, schedulerJobDAO);
+ verify(schedulerJobDAO).fetchSingleSchedulerJobByUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME);
+ verifyNoMoreInteractions(schedulerJobDAO);
}
@Test
public void fetchSchedulerJobForComputationalResource() {
- when(schedulerJobDAO.fetchSingleSchedulerJobForCluster(anyString(), anyString(), anyString()))
+ when(schedulerJobDAO.fetchSingleSchedulerJobForCluster(anyString(), anyString(), anyString(), anyString()))
.thenReturn(Optional.of(schedulerJobDTO));
SchedulerJobDTO actualSchedulerJobDto = schedulerJobService
- .fetchSchedulerJobForComputationalResource(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ .fetchSchedulerJobForComputationalResource(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
assertNotNull(actualSchedulerJobDto);
assertEquals(schedulerJobDTO, actualSchedulerJobDto);
- verify(schedulerJobDAO).fetchSingleSchedulerJobForCluster(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(schedulerJobDAO).fetchSingleSchedulerJobForCluster(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
verifyNoMoreInteractions(computationalDAO, schedulerJobDAO);
}
@Test
public void fetchEmptySchedulerJobForComputationalResource() {
- when(schedulerJobDAO.fetchSingleSchedulerJobForCluster(anyString(), anyString(), anyString()))
+ when(schedulerJobDAO.fetchSingleSchedulerJobForCluster(anyString(), anyString(), anyString(), anyString()))
.thenReturn(Optional.empty());
try {
- schedulerJobService.fetchSchedulerJobForComputationalResource(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ schedulerJobService.fetchSchedulerJobForComputationalResource(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
} catch (ResourceNotFoundException e) {
assertEquals("Scheduler job data not found for user test with exploratory explName with " +
"computational resource compName", e.getMessage());
}
- verify(schedulerJobDAO).fetchSingleSchedulerJobForCluster(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(schedulerJobDAO).fetchSingleSchedulerJobForCluster(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
verifyNoMoreInteractions(computationalDAO, schedulerJobDAO);
}
@Test
public void updateSchedulerDataForUserAndExploratory() {
userInstance.withStatus("running");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(),
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(), anyString(),
any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
- schedulerJobService.updateExploratorySchedulerData(USER, EXPLORATORY_NAME, schedulerJobDTO);
+ schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, EXPLORATORY_NAME, schedulerJobDTO);
- verify(computationalDAO).updateSchedulerSyncFlag(USER, EXPLORATORY_NAME, false);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+ verify(computationalDAO).updateSchedulerSyncFlag(USER, PROJECT, EXPLORATORY_NAME, false);
verifyNoMoreInteractions(exploratoryDAO);
verifyZeroInteractions(computationalDAO);
}
@@ -177,13 +200,13 @@ public class SchedulerJobServiceImplTest {
@Test
public void updateSchedulerDataForUserAndExploratoryWhenMethodFetchExploratoryFieldsThrowsException() {
doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
- .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString());
+ .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
try {
- schedulerJobService.updateExploratorySchedulerData(USER, EXPLORATORY_NAME, schedulerJobDTO);
+ schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
} catch (ResourceNotFoundException e) {
assertEquals("Exploratory for user with name not found", e.getMessage());
}
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
verifyNoMoreInteractions(exploratoryDAO);
verifyZeroInteractions(computationalDAO);
}
@@ -191,14 +214,14 @@ public class SchedulerJobServiceImplTest {
@Test
public void updateSchedulerDataForUserAndExploratoryWithInapproprietaryStatus() {
userInstance.withStatus("terminated");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
try {
- schedulerJobService.updateExploratorySchedulerData(USER, EXPLORATORY_NAME, schedulerJobDTO);
+ schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
} catch (ResourceInappropriateStateException e) {
assertEquals("Can not create/update scheduler for user instance with status: terminated",
e.getMessage());
}
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
verifyNoMoreInteractions(exploratoryDAO);
verifyZeroInteractions(computationalDAO);
}
@@ -208,21 +231,21 @@ public class SchedulerJobServiceImplTest {
schedulerJobDTO.setBeginDate(null);
schedulerJobDTO.setTimeZoneOffset(null);
userInstance.withStatus("running");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(),
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(), anyString(),
any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
assertNull(schedulerJobDTO.getBeginDate());
assertNull(schedulerJobDTO.getTimeZoneOffset());
- schedulerJobService.updateExploratorySchedulerData(USER, EXPLORATORY_NAME, schedulerJobDTO);
+ schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
assertEquals(LocalDate.now(), schedulerJobDTO.getBeginDate());
assertEquals(OffsetDateTime.now(ZoneId.systemDefault()).getOffset(), schedulerJobDTO.getTimeZoneOffset());
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, EXPLORATORY_NAME, schedulerJobDTO);
- verify(computationalDAO).updateSchedulerSyncFlag(USER, EXPLORATORY_NAME, false);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+ verify(computationalDAO).updateSchedulerSyncFlag(USER, PROJECT, EXPLORATORY_NAME, false);
verifyNoMoreInteractions(exploratoryDAO);
verifyZeroInteractions(computationalDAO);
}
@@ -232,25 +255,24 @@ public class SchedulerJobServiceImplTest {
public void updateSchedulerDataForUserAndExploratoryWithSyncStartRequiredParam() {
userInstance.withStatus("running");
schedulerJobDTO.setSyncStartRequired(true);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(),
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(), anyString(),
any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
- when(computationalDAO.getComputationalResourcesWhereStatusIn(anyString(), any(List.class),
- anyString(), anyVararg())).thenReturn(singletonList(COMPUTATIONAL_NAME));
+ when(computationalDAO.getComputationalResourcesWhereStatusIn(anyString(), anyString(),
+ any(List.class), anyString(), anyVararg())).thenReturn(singletonList(COMPUTATIONAL_NAME));
when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
- any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
- schedulerJobService.updateExploratorySchedulerData(USER, EXPLORATORY_NAME, schedulerJobDTO);
+ schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, EXPLORATORY_NAME, schedulerJobDTO);
- verify(computationalDAO).getComputationalResourcesWhereStatusIn(USER,
- singletonList(DataEngineType.SPARK_STANDALONE),
- EXPLORATORY_NAME, STARTING, RUNNING, STOPPING, STOPPED);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+ verify(computationalDAO).getComputationalResourcesWhereStatusIn(USER, PROJECT,
+ singletonList(DataEngineType.SPARK_STANDALONE), EXPLORATORY_NAME, STARTING, RUNNING, STOPPING, STOPPED);
schedulerJobDTO.setEndTime(null);
schedulerJobDTO.setStopDaysRepeat(Collections.emptyList());
- verify(computationalDAO).updateSchedulerDataForComputationalResource(USER, EXPLORATORY_NAME,
- COMPUTATIONAL_NAME, schedulerJobDTO);
+ verify(computationalDAO).updateSchedulerDataForComputationalResource(USER, PROJECT,
+ EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@@ -259,19 +281,18 @@ public class SchedulerJobServiceImplTest {
public void updateSchedulerDataForUserAndExploratoryWithSyncStartRequiredParamButAbsenceClusters() {
userInstance.withStatus("running");
schedulerJobDTO.setSyncStartRequired(true);
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(),
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(), anyString(),
any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
- when(computationalDAO.getComputationalResourcesWhereStatusIn(anyString(), any(List.class),
- anyString(), anyVararg())).thenReturn(Collections.emptyList());
+ when(computationalDAO.getComputationalResourcesWhereStatusIn(anyString(), anyString(),
+ any(List.class), anyString(), anyVararg())).thenReturn(Collections.emptyList());
- schedulerJobService.updateExploratorySchedulerData(USER, EXPLORATORY_NAME, schedulerJobDTO);
+ schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, EXPLORATORY_NAME, schedulerJobDTO);
- verify(computationalDAO).getComputationalResourcesWhereStatusIn(USER,
- singletonList(DataEngineType.SPARK_STANDALONE),
- EXPLORATORY_NAME, STARTING, RUNNING, STOPPING, STOPPED);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(exploratoryDAO).updateSchedulerDataForUserAndExploratory(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+ verify(computationalDAO).getComputationalResourcesWhereStatusIn(USER, PROJECT,
+ singletonList(DataEngineType.SPARK_STANDALONE), EXPLORATORY_NAME, STARTING, RUNNING, STOPPING, STOPPED);
verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@@ -279,30 +300,30 @@ public class SchedulerJobServiceImplTest {
@Test
public void updateSchedulerDataForComputationalResource() {
userInstance.withStatus("running");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString()))
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString()))
.thenReturn(userInstance.getResources().get(0));
when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
- any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
-
- schedulerJobService.updateComputationalSchedulerData(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME,
- schedulerJobDTO);
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
- verify(computationalDAO).updateSchedulerDataForComputationalResource(USER, EXPLORATORY_NAME,
+ schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME,
COMPUTATIONAL_NAME, schedulerJobDTO);
+
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(computationalDAO).updateSchedulerDataForComputationalResource(USER, PROJECT,
+ EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@Test
public void updateSchedulerDataForComputationalResourceWhenSchedulerIsNull() {
userInstance.withStatus("running");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString()))
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString()))
.thenReturn(userInstance.getResources().get(0));
when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
- any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
final SchedulerJobDTO schedulerJobDTO = getSchedulerJobDTO(LocalDate.now(), LocalDate.now().plusDays(1),
Arrays.asList(DayOfWeek.values()), Arrays.asList(DayOfWeek.values()), false,
@@ -310,12 +331,12 @@ public class SchedulerJobServiceImplTest {
LocalTime.now().truncatedTo(ChronoUnit.MINUTES));
schedulerJobDTO.setStartDaysRepeat(null);
schedulerJobDTO.setStopDaysRepeat(null);
- schedulerJobService.updateComputationalSchedulerData(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME,
- schedulerJobDTO);
+ schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME,
+ COMPUTATIONAL_NAME, schedulerJobDTO);
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
- verify(computationalDAO).updateSchedulerDataForComputationalResource(eq(USER), eq(EXPLORATORY_NAME),
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(computationalDAO).updateSchedulerDataForComputationalResource(eq(USER), eq(PROJECT), eq(EXPLORATORY_NAME),
eq(COMPUTATIONAL_NAME), refEq(schedulerJobDTO));
verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@@ -323,18 +344,17 @@ public class SchedulerJobServiceImplTest {
@Test
public void updateSchedulerDataForComputationalResourceWhenMethodFetchComputationalFieldsThrowsException() {
userInstance.withStatus("running");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
doThrow(new ResourceNotFoundException("Computational resource for user with name not found"))
- .when(computationalDAO).fetchComputationalFields(anyString(), anyString(), anyString());
+ .when(computationalDAO).fetchComputationalFields(anyString(), anyString(), anyString(), anyString());
try {
- schedulerJobService.updateComputationalSchedulerData(USER, EXPLORATORY_NAME,
- COMPUTATIONAL_NAME, schedulerJobDTO);
+ schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
} catch (ResourceNotFoundException e) {
assertEquals("Computational resource for user with name not found", e.getMessage());
}
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@@ -342,18 +362,17 @@ public class SchedulerJobServiceImplTest {
public void updateSchedulerDataForComputationalResourceWithInapproprietaryClusterStatus() {
userInstance.setStatus("running");
userInstance.getResources().get(0).setStatus("terminated");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString()))
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString()))
.thenReturn(userInstance.getResources().get(0));
try {
- schedulerJobService.updateComputationalSchedulerData(USER, EXPLORATORY_NAME,
- COMPUTATIONAL_NAME, schedulerJobDTO);
+ schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
} catch (ResourceInappropriateStateException e) {
assertEquals("Can not create/update scheduler for user instance with status: terminated",
e.getMessage());
}
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@@ -362,25 +381,25 @@ public class SchedulerJobServiceImplTest {
schedulerJobDTO.setBeginDate(null);
schedulerJobDTO.setTimeZoneOffset(null);
userInstance.withStatus("running");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString())).thenReturn(userInstance);
- when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString()))
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString()))
.thenReturn(userInstance.getResources().get(0));
when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
- any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
assertNull(schedulerJobDTO.getBeginDate());
assertNull(schedulerJobDTO.getTimeZoneOffset());
- schedulerJobService.updateComputationalSchedulerData(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME,
- schedulerJobDTO);
+ schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME,
+ COMPUTATIONAL_NAME, schedulerJobDTO);
assertEquals(LocalDate.now(), schedulerJobDTO.getBeginDate());
assertEquals(OffsetDateTime.now(ZoneId.systemDefault()).getOffset(), schedulerJobDTO.getTimeZoneOffset());
- verify(exploratoryDAO).fetchExploratoryFields(USER, EXPLORATORY_NAME);
- verify(computationalDAO).fetchComputationalFields(USER, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
- verify(computationalDAO).updateSchedulerDataForComputationalResource(USER, EXPLORATORY_NAME,
- COMPUTATIONAL_NAME, schedulerJobDTO);
+ verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
+ verify(computationalDAO).fetchComputationalFields(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME);
+ verify(computationalDAO).updateSchedulerDataForComputationalResource(USER, PROJECT,
+ EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@@ -499,7 +518,7 @@ public class SchedulerJobServiceImplTest {
verify(securityService).getServiceAccountInfo(USER);
verify(schedulerJobDAO)
.getComputationalSchedulerDataWithOneOfStatus(RUNNING, DataEngineType.SPARK_STANDALONE, RUNNING);
- verify(computationalService).stopSparkCluster(refEq(getUserInfo()), eq(EXPLORATORY_NAME),
+ verify(computationalService).stopSparkCluster(refEq(getUserInfo()), eq(PROJECT), eq(EXPLORATORY_NAME),
eq(COMPUTATIONAL_NAME));
verifyNoMoreInteractions(securityService, schedulerJobDAO, computationalService);
}
@@ -597,7 +616,7 @@ public class SchedulerJobServiceImplTest {
verify(securityService).getServiceAccountInfo(USER);
verify(schedulerJobDAO).getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(eq(RUNNING),
any(Date.class));
- verify(exploratoryService).stop(refEq(getUserInfo()), eq(EXPLORATORY_NAME));
+ verify(exploratoryService).stop(refEq(getUserInfo()), eq(PROJECT), eq(EXPLORATORY_NAME));
verifyNoMoreInteractions(securityService, schedulerJobDAO, exploratoryService);
}
@@ -711,7 +730,7 @@ public class SchedulerJobServiceImplTest {
)));
when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo());
when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(),
- any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource(
+ anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource(
DataEngineType.SPARK_STANDALONE, true)));
schedulerJobService.startExploratoryByScheduler();
@@ -719,7 +738,7 @@ public class SchedulerJobServiceImplTest {
verify(securityService, times(2)).getServiceAccountInfo(USER);
verify(schedulerJobDAO).getExploratorySchedulerDataWithStatus(STOPPED);
verify(exploratoryService).start(refEq(getUserInfo()), eq(EXPLORATORY_NAME), eq(PROJECT));
- verify(computationalDAO).findComputationalResourcesWithStatus(USER, EXPLORATORY_NAME, STOPPED);
+ verify(computationalDAO).findComputationalResourcesWithStatus(USER, PROJECT, EXPLORATORY_NAME, STOPPED);
verify(computationalService).startSparkCluster(refEq(getUserInfo()), eq(EXPLORATORY_NAME),
eq(COMPUTATIONAL_NAME), eq(PROJECT));
verifyNoMoreInteractions(securityService, schedulerJobDAO, exploratoryService, computationalService,
@@ -738,7 +757,7 @@ public class SchedulerJobServiceImplTest {
)));
when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo());
when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(),
- any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource(
+ anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource(
DataEngineType.CLOUD_SERVICE, true)));
schedulerJobService.startExploratoryByScheduler();
@@ -746,7 +765,7 @@ public class SchedulerJobServiceImplTest {
verify(securityService).getServiceAccountInfo(USER);
verify(schedulerJobDAO).getExploratorySchedulerDataWithStatus(STOPPED);
verify(exploratoryService).start(refEq(getUserInfo()), eq(EXPLORATORY_NAME), eq(PROJECT));
- verify(computationalDAO).findComputationalResourcesWithStatus(USER, EXPLORATORY_NAME, STOPPED);
+ verify(computationalDAO).findComputationalResourcesWithStatus(USER, PROJECT, EXPLORATORY_NAME, STOPPED);
verifyNoMoreInteractions(securityService, schedulerJobDAO, exploratoryService, computationalDAO);
verifyZeroInteractions(computationalService);
}
@@ -763,7 +782,7 @@ public class SchedulerJobServiceImplTest {
)));
when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo());
when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(),
- any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource(
+ anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource(
DataEngineType.SPARK_STANDALONE, false)));
schedulerJobService.startExploratoryByScheduler();
@@ -771,7 +790,7 @@ public class SchedulerJobServiceImplTest {
verify(securityService).getServiceAccountInfo(USER);
verify(schedulerJobDAO).getExploratorySchedulerDataWithStatus(STOPPED);
verify(exploratoryService).start(refEq(getUserInfo()), eq(EXPLORATORY_NAME), eq(PROJECT));
- verify(computationalDAO).findComputationalResourcesWithStatus(USER, EXPLORATORY_NAME, STOPPED);
+ verify(computationalDAO).findComputationalResourcesWithStatus(USER, PROJECT, EXPLORATORY_NAME, STOPPED);
verifyNoMoreInteractions(securityService, schedulerJobDAO, exploratoryService, computationalDAO);
verifyZeroInteractions(computationalService);
}
@@ -862,8 +881,8 @@ public class SchedulerJobServiceImplTest {
verify(securityService).getServiceAccountInfo(USER);
verify(schedulerJobDAO)
.getComputationalSchedulerDataWithOneOfStatus(RUNNING, STOPPED, RUNNING);
- verify(computationalService).terminateComputational(refEq(getUserInfo()), eq(EXPLORATORY_NAME),
- eq(COMPUTATIONAL_NAME));
+ verify(computationalService).terminateComputational(refEq(getUserInfo()), eq(PROJECT),
+ eq(EXPLORATORY_NAME), eq(COMPUTATIONAL_NAME));
verifyNoMoreInteractions(securityService, schedulerJobDAO, computationalService);
}
@@ -955,7 +974,7 @@ public class SchedulerJobServiceImplTest {
verify(securityService).getUserInfoOffline(USER);
verify(schedulerJobDAO).getExploratorySchedulerDataWithOneOfStatus(RUNNING, STOPPED);
- verify(exploratoryService).terminate(refEq(getUserInfo()), eq(EXPLORATORY_NAME));
+ verify(exploratoryService).terminate(refEq(getUserInfo()), eq(PROJECT), eq(EXPLORATORY_NAME));
verifyNoMoreInteractions(securityService, schedulerJobDAO, computationalService, exploratoryService);
}
@@ -1085,8 +1104,11 @@ public class SchedulerJobServiceImplTest {
private UserInstanceDTO getUserInstanceDTO() {
UserComputationalResource computationalResource = new UserComputationalResource();
computationalResource.setStatus("running");
- return new UserInstanceDTO().withUser(USER).withExploratoryName(EXPLORATORY_NAME)
- .withResources(singletonList(computationalResource));
+ return new UserInstanceDTO()
+ .withUser(USER)
+ .withExploratoryName(EXPLORATORY_NAME)
+ .withResources(singletonList(computationalResource))
+ .withProject(PROJECT);
}
private AwsComputationalResource getComputationalResource(DataEngineType dataEngineType,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org