ofuks commented on a change in pull request #926:
URL: https://github.com/apache/incubator-datalab/pull/926#discussion_r507890942



##########
File path: 
services/self-service/src/main/java/com/epam/dlab/backendapi/dao/OdahuDAO.java
##########
@@ -39,4 +39,6 @@
     void updateStatus(String name, String project, String endpoint, 
UserInstanceStatus status);
 
     void updateStatusAndUrls(OdahuResult result, UserInstanceStatus status);
+
+    List<OdahuDTO> getOdahuProjectClusters(String project, String endpoint);

Review comment:
       1) Move it under the  **findOdahuClusters()** declaration.
   2) Name it **findOdahuClusters**

##########
File path: 
services/self-service/src/main/java/com/epam/dlab/backendapi/dao/OdahuDAOImpl.java
##########
@@ -69,23 +71,34 @@
                 fields(include(ODAHU_FIELD), excludeId()),
                 ProjectDTO.class);
 
-        return projectDTO.flatMap(p -> p.getOdahu()
-                .stream()
+        return projectDTO.flatMap(p -> p.getOdahu().stream()
                 .filter(odahu -> project.equals(odahu.getProject()) && 
endpoint.equals(odahu.getEndpoint()))
                 .findAny());
     }
 
+    @Override
+    public List<OdahuDTO> getOdahuProjectClusters(String project, String 
endpoint) {
+        Optional<ProjectDTO> projectDTO = findOne(PROJECTS_COLLECTION, 
odahuProjectEndpointCondition(project, endpoint),
+                fields(include(ODAHU_FIELD), excludeId()),
+                ProjectDTO.class);
+
+        return projectDTO.map(p -> p.getOdahu().stream()
+                .filter(odahu -> project.equals(odahu.getProject()) && 
endpoint.equals(odahu.getEndpoint()))
+                .collect(Collectors.toList()))
+                .orElseThrow(() -> new DlabException("Unable to find the odahu 
clusters in the " + project));
+    }
+
     @Override
     public OdahuFieldsDTO getFields(String name, String project, String 
endpoint) {
-        Optional<Document> one = findOne(PROJECTS_COLLECTION, 
odahuProjectEndpointCondition(name, project, endpoint),
-                fields(include(ODAHU_FIELD), excludeId()));
-        OdahuFieldsDTO odahuFields = null;
-        if (one.isPresent()) {
-            List<OdahuFieldsDTO> list = 
convertFromDocument(one.get().get(ODAHU_FIELD, ArrayList.class), new 
TypeReference<List<OdahuFieldsDTO>>() {
-            });
-            odahuFields = list.get(0);
-        }
-        return odahuFields;
+        Document odahuDocument = findOne(PROJECTS_COLLECTION, 
odahuProjectEndpointCondition(name, project, endpoint),
+                fields(include(ODAHU_FIELD), excludeId()))
+                .orElseThrow(() -> new DlabException(project.toString() + "{} 
does not contain odahu {}" + name.toString() + "cluster"));

Review comment:
       You cannot use **{}** in this way. Use **String.format()** or 
concatenation

##########
File path: 
services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/OdahuServiceImpl.java
##########
@@ -132,14 +134,18 @@ public void stop(String name, String project, String 
endpoint, UserInfo user) {
 
     @Override
     public void terminate(String name, String project, String endpoint, 
UserInfo user) {
-        Optional<OdahuDTO> odahuDTO = get(project, endpoint);
-        if (odahuDTO.isPresent() && UserInstanceStatus.RUNNING == 
odahuDTO.get().getStatus()) {
-            odahuDAO.updateStatus(name, project, endpoint, 
UserInstanceStatus.TERMINATING);
-            actionOnCloud(user, TERMINATE_ODAHU_API, name, project, endpoint);
-        } else {
-            log.error("Cannot terminate odahu cluster {}", odahuDTO);
-            throw new DlabException(String.format("Cannot terminate odahu 
cluster %s", odahuDTO));
-        }
+        odahuDAO.getOdahuProjectClusters(project, endpoint).stream()

Review comment:
       Move **.stream()** to new line

##########
File path: 
services/self-service/src/main/java/com/epam/dlab/backendapi/dao/OdahuDAOImpl.java
##########
@@ -69,23 +71,34 @@
                 fields(include(ODAHU_FIELD), excludeId()),
                 ProjectDTO.class);
 
-        return projectDTO.flatMap(p -> p.getOdahu()
-                .stream()
+        return projectDTO.flatMap(p -> p.getOdahu().stream()

Review comment:
       Revert this changes pls

##########
File path: 
services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/OdahuServiceImpl.java
##########
@@ -91,8 +92,9 @@ public OdahuServiceImpl(ProjectService projectService, 
EndpointService endpointS
     @BudgetLimited
     @Override
     public void create(@Project String project, OdahuCreateDTO odahuCreateDTO, 
UserInfo user) {
-        Optional<OdahuDTO> odahuDTO = 
odahuDAO.getByProjectEndpoint(odahuCreateDTO.getProject(), 
odahuCreateDTO.getEndpoint());
-        if (odahuDTO.isPresent()) {
+        boolean activeCluster = 
odahuDAO.getOdahuProjectClusters(odahuCreateDTO.getProject(), 
odahuCreateDTO.getEndpoint()).stream()

Review comment:
       Move **.stream()** to new line

##########
File path: 
services/self-service/src/main/java/com/epam/dlab/backendapi/dao/OdahuDAOImpl.java
##########
@@ -69,23 +71,34 @@
                 fields(include(ODAHU_FIELD), excludeId()),
                 ProjectDTO.class);
 
-        return projectDTO.flatMap(p -> p.getOdahu()
-                .stream()
+        return projectDTO.flatMap(p -> p.getOdahu().stream()
                 .filter(odahu -> project.equals(odahu.getProject()) && 
endpoint.equals(odahu.getEndpoint()))
                 .findAny());
     }
 
+    @Override
+    public List<OdahuDTO> getOdahuProjectClusters(String project, String 
endpoint) {
+        Optional<ProjectDTO> projectDTO = findOne(PROJECTS_COLLECTION, 
odahuProjectEndpointCondition(project, endpoint),
+                fields(include(ODAHU_FIELD), excludeId()),
+                ProjectDTO.class);
+
+        return projectDTO.map(p -> p.getOdahu().stream()

Review comment:
       Move **.stream()** to new line




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to