You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by of...@apache.org on 2019/12/03 11:17:09 UTC
[incubator-dlab] branch develop updated: [DLAB-1334] Error handling
improvement for project actions
This is an automated email from the ASF dual-hosted git repository.
ofuks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/develop by this push:
new 49e111f [DLAB-1334] Error handling improvement for project actions
49e111f is described below
commit 49e111f589e85c83ef3236360789e45d49189c71
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Tue Dec 3 13:16:52 2019 +0200
[DLAB-1334] Error handling improvement for project actions
---
.../service/impl/ProjectServiceImpl.java | 28 ++++++++++++----------
1 file changed, 15 insertions(+), 13 deletions(-)
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 694c5c4..b3c3665 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
@@ -27,9 +27,9 @@ import com.google.inject.name.Named;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
-import java.util.Collections;
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;
@@ -221,30 +221,32 @@ public class ProjectServiceImpl implements ProjectService {
}
private void checkProjectRelatedResourcesInProgress(String projectName, String action) {
- boolean projectProgress = get(projectName).getEndpoints().stream().anyMatch(e ->
- Arrays.asList(UserInstanceStatus.CREATING, UserInstanceStatus.STARTING, UserInstanceStatus.STOPPING)
- .contains(e.getStatus()));
+ boolean edgeProgress = get(projectName).getEndpoints().stream().anyMatch(e ->
+ Arrays.asList(UserInstanceStatus.CREATING, UserInstanceStatus.STARTING, UserInstanceStatus.STOPPING,
+ UserInstanceStatus.TERMINATING).contains(e.getStatus()));
List<UserInstanceDTO> userInstanceDTOs = exploratoryDAO.fetchProjectExploratoriesWhereStatusIn(projectName,
Arrays.asList(UserInstanceStatus.CREATING, UserInstanceStatus.STARTING,
- UserInstanceStatus.CREATING_IMAGE, UserInstanceStatus.RECONFIGURING), UserInstanceStatus.CREATING,
- UserInstanceStatus.CONFIGURING, UserInstanceStatus.STARTING, UserInstanceStatus.RECONFIGURING,
- UserInstanceStatus.CREATING_IMAGE);
- if (projectProgress || !userInstanceDTOs.isEmpty()) {
+ UserInstanceStatus.CREATING_IMAGE, UserInstanceStatus.RECONFIGURING),
+ UserInstanceStatus.CREATING, UserInstanceStatus.CONFIGURING, UserInstanceStatus.STARTING,
+ UserInstanceStatus.RECONFIGURING, UserInstanceStatus.CREATING_IMAGE);
+ if (edgeProgress || !userInstanceDTOs.isEmpty()) {
throw new ResourceConflictException((String.format("Can not %s environment because one of project " +
"resource is in processing stage", action)));
}
}
private boolean isCanBeStopped(ProjectDTO projectDTO) {
- return !exploratoryDAO.fetchProjectExploratoriesWhereStatusIn(projectDTO.getName(),
- Collections.singletonList(UserInstanceStatus.RUNNING), UserInstanceStatus.RUNNING).isEmpty() ||
- projectDTO.getEndpoints().stream().allMatch(e -> e.getStatus() == UserInstanceStatus.RUNNING);
+ List<ProjectEndpointDTO> endpoints = projectDTO.getEndpoints();
+ return !endpoints.stream().allMatch(e -> exploratoryDAO.fetchProjectExploratoriesWhereStatusNotIn(
+ projectDTO.getName(), e.getName(), UserInstanceStatus.STOPPED, UserInstanceStatus.TERMINATED,
+ UserInstanceStatus.TERMINATING).isEmpty()) ||
+ endpoints.stream().anyMatch(e -> e.getStatus() == UserInstanceStatus.RUNNING);
}
private boolean isCanBeTerminated(ProjectDTO projectDTO) {
- return !projectDTO.getEndpoints().stream().allMatch(e -> Arrays.asList(UserInstanceStatus.STARTING,
- UserInstanceStatus.TERMINATED, UserInstanceStatus.TERMINATING).contains(e.getStatus()));
+ return !projectDTO.getEndpoints().stream().allMatch(e -> Objects.equals(UserInstanceStatus.TERMINATED,
+ e.getStatus()));
}
private Supplier<ResourceNotFoundException> projectNotFound() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org