This is an automated email from the ASF dual-hosted git repository. ofuks pushed a commit to branch v2.2-RC1 in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/v2.2-RC1 by this push: new 074f4bb Fixed issue with scheduler and quote 074f4bb is described below commit 074f4bb895e2a2261497706c9e12d9537e272755 Author: Oleh Fuks <olegfuk...@gmail.com> AuthorDate: Fri Nov 15 17:47:13 2019 +0200 Fixed issue with scheduler and quote --- .../dlab/backendapi/service/SecurityService.java | 2 +- .../backendapi/service/SecurityServiceImpl.java | 5 ++-- .../service/impl/EnvironmentServiceImpl.java | 4 +-- .../service/impl/SchedulerJobServiceImpl.java | 10 +++---- .../service/impl/EnvironmentServiceImplTest.java | 5 ++-- .../service/impl/SchedulerJobServiceImplTest.java | 32 +++++++++++----------- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityService.java index 699557f..c30a670 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityService.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityService.java @@ -26,5 +26,5 @@ public interface SecurityService { UserInfo getUserInfoOffline(String username); - UserInfo getServiceAccountInfo(); + UserInfo getServiceAccountInfo(String username); } diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityServiceImpl.java index 9357929..db41a13 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityServiceImpl.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/SecurityServiceImpl.java @@ -57,9 +57,8 @@ public class SecurityServiceImpl implements SecurityService { } @Override - public UserInfo getServiceAccountInfo() { + public UserInfo getServiceAccountInfo(String username) { AccessTokenResponse accessTokenResponse = keycloakService.generateServiceAccountToken(); - return new UserInfo(KeycloakUtil.parseToken(accessTokenResponse.getToken()).getPreferredUsername(), - accessTokenResponse.getToken()); + return new UserInfo(username, accessTokenResponse.getToken()); } } 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 f062c7f..09428c4 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 @@ -139,7 +139,7 @@ public class EnvironmentServiceImpl implements EnvironmentService { projectService.get(project).getEndpoints().stream() .filter(e -> UserInstanceStatus.RUNNING == e.getStatus()) - .forEach(endpoint -> projectService.stop(securityService.getServiceAccountInfo(), + .forEach(endpoint -> projectService.stop(securityService.getServiceAccountInfo("admin"), endpoint.getName(), project)); } @@ -210,7 +210,7 @@ public class EnvironmentServiceImpl implements EnvironmentService { } private void stopNotebookWithServiceAccount(UserInstanceDTO instance) { - final UserInfo userInfo = securityService.getServiceAccountInfo(); + final UserInfo userInfo = securityService.getServiceAccountInfo(instance.getUser()); exploratoryService.stop(userInfo, instance.getExploratoryName()); } 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 2d67665..e84908e 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 @@ -207,14 +207,14 @@ public class SchedulerJobServiceImpl implements SchedulerJobService { 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(), expName, compName); + computationalService.stopSparkCluster(securityService.getServiceAccountInfo(user), expName, compName); } private void terminateComputational(SchedulerJobData job) { final String user = job.getUser(); final String expName = job.getExploratoryName(); final String compName = job.getComputationalName(); - final UserInfo userInfo = securityService.getServiceAccountInfo(); + final UserInfo userInfo = securityService.getServiceAccountInfo(user); log.debug("Terminating exploratory {} computational {} for user {} by scheduler", expName, compName, user); computationalService.terminateComputational(userInfo, expName, compName); } @@ -223,7 +223,7 @@ public class SchedulerJobServiceImpl implements SchedulerJobService { final String expName = job.getExploratoryName(); final String user = job.getUser(); log.debug("Stopping exploratory {} for user {} by scheduler", expName, user); - exploratoryService.stop(securityService.getServiceAccountInfo(), expName); + exploratoryService.stop(securityService.getServiceAccountInfo(user), expName); } private List<SchedulerJobData> getExploratorySchedulersForTerminating(OffsetDateTime now) { @@ -245,7 +245,7 @@ public class SchedulerJobServiceImpl implements SchedulerJobService { final String exploratoryName = schedulerJobData.getExploratoryName(); final String project = schedulerJobData.getProject(); log.debug("Starting exploratory {} for user {} by scheduler", exploratoryName, user); - exploratoryService.start(securityService.getServiceAccountInfo(), exploratoryName, project); + exploratoryService.start(securityService.getServiceAccountInfo(user), exploratoryName, project); if (schedulerJobData.getJobDTO().isSyncStartRequired()) { log.trace("Starting computational for exploratory {} for user {} by scheduler", exploratoryName, user); final DataEngineType sparkCluster = DataEngineType.SPARK_STANDALONE; @@ -268,7 +268,7 @@ public class SchedulerJobServiceImpl implements SchedulerJobService { private void startSpark(String user, String expName, String compName, String project) { log.debug("Starting exploratory {} computational {} for user {} by scheduler", expName, compName, user); - computationalService.startSparkCluster(securityService.getServiceAccountInfo(), expName, compName, project); + computationalService.startSparkCluster(securityService.getServiceAccountInfo(user), expName, compName, project); } private boolean shouldClusterBeStarted(DataEngineType sparkCluster, UserComputationalResource compResource) { 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 3344ad3..1df2245 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 @@ -211,7 +211,7 @@ public class EnvironmentServiceImplTest { final UserInfo userInfo = getUserInfo(); final ProjectDTO projectDTO = getProjectDTO(); when(exploratoryDAO.fetchRunningExploratoryFieldsForProject(anyString())).thenReturn(getUserInstances()); - when(securityService.getServiceAccountInfo()).thenReturn(userInfo); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(userInfo); when(exploratoryService.stop(any(UserInfo.class), anyString())).thenReturn(UUID); when(projectService.get(anyString())).thenReturn(projectDTO); doNothing().when(projectService).stop(any(UserInfo.class), anyString(), anyString()); @@ -221,7 +221,8 @@ public class EnvironmentServiceImplTest { verify(exploratoryDAO).fetchRunningExploratoryFieldsForProject(PROJECT_NAME); verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_1)); verify(exploratoryService).stop(refEq(userInfo), eq(EXPLORATORY_NAME_2)); - verify(securityService, times(3)).getServiceAccountInfo(); + verify(securityService, times(2)).getServiceAccountInfo(USER); + verify(securityService).getServiceAccountInfo(ADMIN); verify(projectService).get(eq(PROJECT_NAME)); verify(projectService).stop(refEq(userInfo), eq(ENDPOINT_NAME), eq(PROJECT_NAME)); verify(exploratoryDAO).fetchProjectExploratoriesWhereStatusIn(PROJECT_NAME, Arrays.asList(UserInstanceStatus.CREATING, 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 0cd0cd3..8a7d8ec 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 @@ -392,11 +392,11 @@ public class SchedulerJobServiceImplTest { LocalDateTime.of(LocalDate.now(), LocalTime.now().truncatedTo(ChronoUnit.MINUTES)), false, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES)))); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); schedulerJobService.startComputationalByScheduler(); - verify(securityService).getServiceAccountInfo(); + verify(securityService).getServiceAccountInfo(USER); verify(schedulerJobDAO) .getComputationalSchedulerDataWithOneOfStatus(RUNNING, DataEngineType.SPARK_STANDALONE, STOPPED); verify(computationalService).startSparkCluster(refEq(getUserInfo()), eq(EXPLORATORY_NAME), @@ -492,11 +492,11 @@ public class SchedulerJobServiceImplTest { LocalDateTime.of(LocalDate.now(), LocalTime.now().truncatedTo(ChronoUnit.MINUTES)), false, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES)))); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); schedulerJobService.stopComputationalByScheduler(); - verify(securityService).getServiceAccountInfo(); + verify(securityService).getServiceAccountInfo(USER); verify(schedulerJobDAO) .getComputationalSchedulerDataWithOneOfStatus(RUNNING, DataEngineType.SPARK_STANDALONE, RUNNING); verify(computationalService).stopSparkCluster(refEq(getUserInfo()), eq(EXPLORATORY_NAME), @@ -590,11 +590,11 @@ public class SchedulerJobServiceImplTest { LocalDateTime.of(LocalDate.now(), LocalTime.now().truncatedTo(ChronoUnit.MINUTES)), false, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES)))); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); schedulerJobService.stopExploratoryByScheduler(); - verify(securityService).getServiceAccountInfo(); + verify(securityService).getServiceAccountInfo(USER); verify(schedulerJobDAO).getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(eq(RUNNING), any(Date.class)); verify(exploratoryService).stop(refEq(getUserInfo()), eq(EXPLORATORY_NAME)); @@ -686,11 +686,11 @@ public class SchedulerJobServiceImplTest { LocalTime.now().truncatedTo(ChronoUnit.MINUTES)), false, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES) ))); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); schedulerJobService.startExploratoryByScheduler(); - verify(securityService).getServiceAccountInfo(); + verify(securityService).getServiceAccountInfo(USER); verify(schedulerJobDAO).getExploratorySchedulerDataWithStatus(STOPPED); verify(exploratoryService).start(refEq(getUserInfo()), eq(EXPLORATORY_NAME), eq(PROJECT)); verifyNoMoreInteractions(securityService, schedulerJobDAO, exploratoryService); @@ -709,14 +709,14 @@ public class SchedulerJobServiceImplTest { LocalTime.now().truncatedTo(ChronoUnit.MINUTES)), true, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES) ))); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource( DataEngineType.SPARK_STANDALONE, true))); schedulerJobService.startExploratoryByScheduler(); - verify(securityService, times(2)).getServiceAccountInfo(); + 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); @@ -736,14 +736,14 @@ public class SchedulerJobServiceImplTest { LocalTime.now().truncatedTo(ChronoUnit.MINUTES)), true, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES) ))); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource( DataEngineType.CLOUD_SERVICE, true))); schedulerJobService.startExploratoryByScheduler(); - verify(securityService).getServiceAccountInfo(); + 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); @@ -761,14 +761,14 @@ public class SchedulerJobServiceImplTest { LocalTime.now().truncatedTo(ChronoUnit.MINUTES)), true, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES) ))); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); when(computationalDAO.findComputationalResourcesWithStatus(anyString(), anyString(), any(UserInstanceStatus.class))).thenReturn(singletonList(getComputationalResource( DataEngineType.SPARK_STANDALONE, false))); schedulerJobService.startExploratoryByScheduler(); - verify(securityService).getServiceAccountInfo(); + 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); @@ -855,11 +855,11 @@ public class SchedulerJobServiceImplTest { ); when(schedulerJobDAO.getComputationalSchedulerDataWithOneOfStatus(any(UserInstanceStatus.class), anyVararg())).thenReturn(singletonList(schedulerJobData)); - when(securityService.getServiceAccountInfo()).thenReturn(getUserInfo()); + when(securityService.getServiceAccountInfo(anyString())).thenReturn(getUserInfo()); schedulerJobService.terminateComputationalByScheduler(); - verify(securityService).getServiceAccountInfo(); + verify(securityService).getServiceAccountInfo(USER); verify(schedulerJobDAO) .getComputationalSchedulerDataWithOneOfStatus(RUNNING, STOPPED, RUNNING); verify(computationalService).terminateComputational(refEq(getUserInfo()), eq(EXPLORATORY_NAME), --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org