diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/EnvDAO.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/EnvDAO.java index 1e03de1c47..68083d5d72 100644 --- a/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/EnvDAO.java +++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/dao/EnvDAO.java @@ -319,6 +319,22 @@ private void updateEdgeStatus(String user, List hostList) { } + /** + * If NoteBook is started within scheduler interface, the edge node should be RUNNING + * @param user + * @return true or false + */ + public Boolean isEdgeNodeRunning(String user) { + LOGGER.trace("Verify if the edge node is stopped for user {}", user); + boolean isNodeRunning = true; + Optional edgeNode = getEdgeNode(user); + if (edgeNode.isPresent()) { + String edgeStatus = edgeNode.get().getString(EDGE_STATUS); + isNodeRunning =edgeStatus.equals(RUNNING.toString()); + } + return isNodeRunning; + } + private void updateEdgeStatus(String user, Document edge, String instanceId, EnvResource r) { final String oldStatus = edge.getString(EDGE_STATUS); LOGGER.trace("Update EDGE status for user {} with instance_id {} from {} to {}", diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ExploratoryServiceImpl.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ExploratoryServiceImpl.java index 60d4c84e43..ff6c66023b 100644 --- a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ExploratoryServiceImpl.java +++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/ExploratoryServiceImpl.java @@ -22,10 +22,7 @@ import com.epam.datalab.auth.UserInfo; import com.epam.datalab.backendapi.annotation.*; import com.epam.datalab.backendapi.conf.SelfServiceApplicationConfiguration; -import com.epam.datalab.backendapi.dao.ComputationalDAO; -import com.epam.datalab.backendapi.dao.ExploratoryDAO; -import com.epam.datalab.backendapi.dao.GitCredsDAO; -import com.epam.datalab.backendapi.dao.ImageExploratoryDAO; +import com.epam.datalab.backendapi.dao.*; import com.epam.datalab.backendapi.domain.*; import com.epam.datalab.backendapi.resources.dto.ExploratoryCreatePopUp; import com.epam.datalab.backendapi.service.*; diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImpl.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImpl.java index 546a0444a4..277983743d 100644 --- a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImpl.java +++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImpl.java @@ -264,7 +264,11 @@ private void startExploratory(SchedulerJobData schedulerJobData) { final String user = schedulerJobData.getUser(); final String exploratoryName = schedulerJobData.getExploratoryName(); final String project = schedulerJobData.getProject(); - log.debug("Starting exploratory {} for user {} by scheduler", exploratoryName, user); + log.info("Trying to start the exploratory {} for user {} by scheduler", exploratoryName, user); + if (!envDAO.isEdgeNodeRunning(user)) { + log.warn("The edge node of {} is not started for user {}", exploratoryName, user); + return; + } exploratoryService.start(securityService.getServiceAccountInfo(user), exploratoryName, project, String.format(AUDIT_MESSAGE, exploratoryName)); if (schedulerJobData.getJobDTO().isSyncStartRequired()) { log.trace("Starting computational for exploratory {} for user {} by scheduler", exploratoryName, user); diff --git a/services/self-service/src/test/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImplTest.java b/services/self-service/src/test/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImplTest.java index 98fa7501d0..e3c69008b2 100644 --- a/services/self-service/src/test/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImplTest.java +++ b/services/self-service/src/test/java/com/epam/datalab/backendapi/service/impl/SchedulerJobServiceImplTest.java @@ -21,6 +21,7 @@ import com.epam.datalab.auth.UserInfo; import com.epam.datalab.backendapi.dao.ComputationalDAO; +import com.epam.datalab.backendapi.dao.EnvDAO; import com.epam.datalab.backendapi.dao.ExploratoryDAO; import com.epam.datalab.backendapi.dao.SchedulerJobDAO; import com.epam.datalab.backendapi.service.ComputationalService; @@ -100,6 +101,8 @@ public class SchedulerJobServiceImplTest { private ExploratoryService exploratoryService; @Mock private ComputationalService computationalService; + @Mock + private EnvDAO envDAO; @InjectMocks private SchedulerJobServiceImpl schedulerJobService; @@ -706,7 +709,7 @@ public void testStartExploratoryByScheduler() { LocalTime.now().truncatedTo(ChronoUnit.MINUTES) ))); when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); - + when(envDAO.isEdgeNodeRunning(USER)).thenReturn(true); schedulerJobService.startExploratoryByScheduler(); verify(securityService).getServiceAccountInfo(USER); @@ -732,7 +735,7 @@ public void testStartExploratoryBySchedulerWithSyncComputationalStart() { when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(), anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource( DataEngineType.SPARK_STANDALONE, true))); - + when(envDAO.isEdgeNodeRunning(USER)).thenReturn(true); schedulerJobService.startExploratoryByScheduler(); verify(securityService, times(2)).getServiceAccountInfo(USER); @@ -759,7 +762,7 @@ public void testStartExploratoryBySchedulerWithSyncComputationalStartDataEngine( when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(), anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource( DataEngineType.CLOUD_SERVICE, true))); - + when(envDAO.isEdgeNodeRunning(USER)).thenReturn(true); schedulerJobService.startExploratoryByScheduler(); verify(securityService).getServiceAccountInfo(USER); @@ -784,7 +787,7 @@ public void testStartExploratoryBySchedulerWithSyncComputationalStartOnExplorato when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(), anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource( DataEngineType.SPARK_STANDALONE, false))); - + when(envDAO.isEdgeNodeRunning(USER)).thenReturn(true); schedulerJobService.startExploratoryByScheduler(); verify(securityService).getServiceAccountInfo(USER);