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/06/12 11:13:00 UTC
[incubator-dlab] branch audit updated: Added audit for schedulers
This is an automated email from the ASF dual-hosted git repository.
ofuks pushed a commit to branch audit
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/audit by this push:
new cebfbd4 Added audit for schedulers
cebfbd4 is described below
commit cebfbd45d458d2e5076bf2dc543ff310ef75b520
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Fri Jun 12 14:12:48 2020 +0300
Added audit for schedulers
---
.../dlab/backendapi/domain/AuditActionEnum.java | 4 +-
.../backendapi/resources/SchedulerJobResource.java | 7 +-
.../backendapi/service/SchedulerJobService.java | 5 +-
.../service/impl/ProjectServiceImpl.java | 2 +-
.../service/impl/SchedulerJobServiceImpl.java | 26 +-
.../resources/SchedulerJobResourceTest.java | 25 +-
.../service/impl/SchedulerJobServiceImplTest.java | 299 ++++++++++-----------
7 files changed, 186 insertions(+), 182 deletions(-)
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java
index 45ae492..f7542b7 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java
@@ -21,8 +21,8 @@ package com.epam.dlab.backendapi.domain;
public enum AuditActionEnum {
CREATE_EDGE_NODE, START_EDGE_NODE, STOP_EDGE_NODE, TERMINATE_EDGE_NODE, UPDATE_PROJECT,
- CREATE_NOTEBOOK, START_NOTEBOOK, STOP_NOTEBOOK, TERMINATE_NOTEBOOK, UPDATE_CLUSTER_CONFIG,
- CREATE_DATA_ENGINE, CREATE_DATA_ENGINE_SERVICE, START_COMPUTATIONAL, STOP_COMPUTATIONAL, TERMINATE_COMPUTATIONAL, UPDATE_DATA_ENGINE_CONFIG,
+ CREATE_NOTEBOOK, START_NOTEBOOK, STOP_NOTEBOOK, TERMINATE_NOTEBOOK, UPDATE_CLUSTER_CONFIG, CREATE_NOTEBOOK_SCHEDULER,
+ CREATE_DATA_ENGINE, CREATE_DATA_ENGINE_SERVICE, START_COMPUTATIONAL, STOP_COMPUTATIONAL, TERMINATE_COMPUTATIONAL, UPDATE_DATA_ENGINE_CONFIG, CREATE_COMPUTATIONAL_SCHEDULER,
BUCKET_UPLOAD_OBJECT, BUCKET_DOWNLOAD_OBJECT, BUCKET_DELETE_OBJECT,
CREATE_ENDPOINT, DELETE_ENDPOINT,
INSTALL_NOTEBOOK_LIBS, INSTALL_COMPUTATIONAL_LIBS,
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 dd8f82f..f34897f 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
@@ -69,7 +69,7 @@ public class SchedulerJobResource {
@PathParam("projectName") String projectName,
@PathParam("exploratoryName") String exploratoryName,
@SchedulerJobDTOValid SchedulerJobDTO dto) {
- schedulerJobService.updateExploratorySchedulerData(userInfo.getName(), projectName, exploratoryName, dto);
+ schedulerJobService.updateExploratorySchedulerData(userInfo, projectName, exploratoryName, dto);
return Response.ok().build();
}
@@ -107,10 +107,9 @@ public class SchedulerJobResource {
@PathParam("exploratoryName") String exploratoryName,
@PathParam("computationalName") String computationalName,
@SchedulerJobDTOValid SchedulerJobDTO dto) {
- schedulerJobService.updateComputationalSchedulerData(userInfo.getName(), projectName, exploratoryName,
- computationalName, dto);
+ schedulerJobService.updateComputationalSchedulerData(userInfo, projectName, exploratoryName, computationalName, dto);
return Response.ok().build();
- }
+ }
/**
* Updates computational resource <code>computationalName<code/> affiliated with exploratory
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 7702601..7ac7f94 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
@@ -19,6 +19,7 @@
package com.epam.dlab.backendapi.service;
+import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.dto.SchedulerJobDTO;
import com.epam.dlab.model.scheduler.SchedulerJobData;
@@ -56,7 +57,7 @@ public interface SchedulerJobService {
* @param exploratoryName name of exploratory resource
* @param dto scheduler job data
*/
- void updateExploratorySchedulerData(String user, String project, String exploratoryName, SchedulerJobDTO dto);
+ void updateExploratorySchedulerData(UserInfo user, String project, String exploratoryName, SchedulerJobDTO dto);
/**
* Updates scheduler job data for computational resource <code>computationalName<code/> affiliated with
@@ -68,7 +69,7 @@ public interface SchedulerJobService {
* @param computationalName name of computational resource
* @param dto scheduler job data
*/
- void updateComputationalSchedulerData(String user, String project, String exploratoryName,
+ void updateComputationalSchedulerData(UserInfo user, String project, String exploratoryName,
String computationalName, SchedulerJobDTO dto);
void stopComputationalByScheduler();
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 b1156f6..634022c 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
@@ -154,7 +154,7 @@ public class ProjectServiceImpl implements ProjectService {
@ProjectAdmin
@Override
- public void start(UserInfo userInfo, List<String> endpoints, @Project String name) {
+ public void start(@User UserInfo userInfo, List<String> endpoints, @Project String name) {
endpoints.forEach(endpoint -> start(userInfo, endpoint, name));
}
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 127c394..5b465f6 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
@@ -20,10 +20,15 @@
package com.epam.dlab.backendapi.service.impl;
import com.epam.dlab.auth.UserInfo;
+import com.epam.dlab.backendapi.annotation.Audit;
+import com.epam.dlab.backendapi.annotation.Project;
+import com.epam.dlab.backendapi.annotation.ResourceName;
+import com.epam.dlab.backendapi.annotation.User;
import com.epam.dlab.backendapi.dao.ComputationalDAO;
import com.epam.dlab.backendapi.dao.EnvDAO;
import com.epam.dlab.backendapi.dao.ExploratoryDAO;
import com.epam.dlab.backendapi.dao.SchedulerJobDAO;
+import com.epam.dlab.backendapi.domain.AuditActionEnum;
import com.epam.dlab.backendapi.domain.RequestId;
import com.epam.dlab.backendapi.service.ComputationalService;
import com.epam.dlab.backendapi.service.ExploratoryService;
@@ -122,30 +127,31 @@ public class SchedulerJobServiceImpl implements SchedulerJobService {
exploratoryName) + " with computational resource " + computationalName));
}
+ @Audit(action = AuditActionEnum.CREATE_NOTEBOOK_SCHEDULER)
@Override
- public void updateExploratorySchedulerData(String user, String project, String exploratoryName, SchedulerJobDTO dto) {
- validateExploratoryStatus(user, project, exploratoryName);
+ public void updateExploratorySchedulerData(@User UserInfo user, @Project String project, @ResourceName String exploratoryName, SchedulerJobDTO dto) {
+ validateExploratoryStatus(user.getName(), project, exploratoryName);
populateDefaultSchedulerValues(dto);
log.debug("Updating exploratory {} for user {} with new scheduler job data: {}...", exploratoryName, user,
dto);
- exploratoryDAO.updateSchedulerDataForUserAndExploratory(user, project, exploratoryName, dto);
+ exploratoryDAO.updateSchedulerDataForUserAndExploratory(user.getName(), project, exploratoryName, dto);
if (!dto.inactivityScheduler() && dto.isSyncStartRequired()) {
- shareSchedulerJobDataToSparkClusters(user, project, exploratoryName, dto);
+ shareSchedulerJobDataToSparkClusters(user.getName(), project, exploratoryName, dto);
} else if (!dto.inactivityScheduler()) {
- computationalDAO.updateSchedulerSyncFlag(user, project, exploratoryName, dto.isSyncStartRequired());
+ computationalDAO.updateSchedulerSyncFlag(user.getName(), project, exploratoryName, dto.isSyncStartRequired());
}
}
+ @Audit(action = AuditActionEnum.CREATE_COMPUTATIONAL_SCHEDULER)
@Override
- public void updateComputationalSchedulerData(String user, String project, String exploratoryName, String computationalName,
- SchedulerJobDTO dto) {
- validateExploratoryStatus(user, project, exploratoryName);
- validateComputationalStatus(user, project, exploratoryName, computationalName);
+ public void updateComputationalSchedulerData(@User UserInfo user, @Project String project, String exploratoryName, @ResourceName String computationalName, SchedulerJobDTO dto) {
+ validateExploratoryStatus(user.getName(), project, exploratoryName);
+ validateComputationalStatus(user.getName(), 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, project, exploratoryName, computationalName, dto);
+ computationalDAO.updateSchedulerDataForComputationalResource(user.getName(), project, exploratoryName, computationalName, dto);
}
@Override
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 c763238..994564d 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
@@ -19,6 +19,7 @@
package com.epam.dlab.backendapi.resources;
+import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.service.SchedulerJobService;
import com.epam.dlab.dto.SchedulerJobDTO;
import com.epam.dlab.exceptions.ResourceInappropriateStateException;
@@ -75,7 +76,7 @@ public class SchedulerJobResourceTest extends TestBase {
@Test
public void updateExploratoryScheduler() {
doNothing().when(schedulerJobService)
- .updateExploratorySchedulerData(anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ .updateExploratorySchedulerData(any(UserInfo.class), anyString(), anyString(), any(SchedulerJobDTO.class));
final Response response = resources.getJerseyTest()
.target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
.request()
@@ -85,7 +86,7 @@ public class SchedulerJobResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(), "projectName",
+ verify(schedulerJobService).updateExploratorySchedulerData(getUserInfo(), "projectName",
"explName", getSchedulerJobDTO());
verifyNoMoreInteractions(schedulerJobService);
}
@@ -94,7 +95,7 @@ public class SchedulerJobResourceTest extends TestBase {
public void updateExploratorySchedulerWithFailedAuth() throws AuthenticationException {
authFailSetup();
doNothing().when(schedulerJobService)
- .updateExploratorySchedulerData(anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ .updateExploratorySchedulerData(any(UserInfo.class), anyString(), anyString(), any(SchedulerJobDTO.class));
final Response response = resources.getJerseyTest()
.target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
.request()
@@ -104,7 +105,7 @@ public class SchedulerJobResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(), "projectName",
+ verify(schedulerJobService).updateExploratorySchedulerData(getUserInfo(), "projectName",
"explName", getSchedulerJobDTO());
verifyNoMoreInteractions(schedulerJobService);
}
@@ -112,7 +113,7 @@ public class SchedulerJobResourceTest extends TestBase {
@Test
public void updateExploratorySchedulerWithException() {
doThrow(new ResourceInappropriateStateException("Can't create/update scheduler for user instance with status"))
- .when(schedulerJobService).updateExploratorySchedulerData(anyString(), anyString(), anyString(),
+ .when(schedulerJobService).updateExploratorySchedulerData(any(UserInfo.class), anyString(), anyString(),
any(SchedulerJobDTO.class));
final Response response = resources.getJerseyTest()
.target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName")
@@ -123,7 +124,7 @@ public class SchedulerJobResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).updateExploratorySchedulerData(USER.toLowerCase(), "projectName",
+ verify(schedulerJobService).updateExploratorySchedulerData(getUserInfo(), "projectName",
"explName", getSchedulerJobDTO());
verifyNoMoreInteractions(schedulerJobService);
}
@@ -131,7 +132,7 @@ public class SchedulerJobResourceTest extends TestBase {
@Test
public void upsertComputationalScheduler() {
doNothing().when(schedulerJobService)
- .updateComputationalSchedulerData(anyString(), anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ .updateComputationalSchedulerData(any(UserInfo.class), anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
final Response response = resources.getJerseyTest()
.target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
.request()
@@ -141,7 +142,7 @@ public class SchedulerJobResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "projectName",
+ verify(schedulerJobService).updateComputationalSchedulerData(getUserInfo(), "projectName",
"explName", "compName", getSchedulerJobDTO());
verifyNoMoreInteractions(schedulerJobService);
}
@@ -150,7 +151,7 @@ public class SchedulerJobResourceTest extends TestBase {
public void upsertComputationalSchedulerWithFailedAuth() throws AuthenticationException {
authFailSetup();
doNothing().when(schedulerJobService)
- .updateComputationalSchedulerData(anyString(), anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
+ .updateComputationalSchedulerData(any(UserInfo.class), anyString(), anyString(), anyString(), any(SchedulerJobDTO.class));
final Response response = resources.getJerseyTest()
.target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
.request()
@@ -160,7 +161,7 @@ public class SchedulerJobResourceTest extends TestBase {
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertNull(response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "projectName",
+ verify(schedulerJobService).updateComputationalSchedulerData(getUserInfo(), "projectName",
"explName", "compName", getSchedulerJobDTO());
verifyNoMoreInteractions(schedulerJobService);
}
@@ -168,7 +169,7 @@ public class SchedulerJobResourceTest extends TestBase {
@Test
public void upsertComputationalSchedulerWithException() {
doThrow(new ResourceInappropriateStateException("Can't create/update scheduler for user instance with status"))
- .when(schedulerJobService).updateComputationalSchedulerData(anyString(), anyString(), anyString(),
+ .when(schedulerJobService).updateComputationalSchedulerData(any(UserInfo.class), anyString(), anyString(),
anyString(), any(SchedulerJobDTO.class));
final Response response = resources.getJerseyTest()
.target("/infrastructure_provision/exploratory_environment/scheduler/projectName/explName/compName")
@@ -179,7 +180,7 @@ public class SchedulerJobResourceTest extends TestBase {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
- verify(schedulerJobService).updateComputationalSchedulerData(USER.toLowerCase(), "projectName",
+ verify(schedulerJobService).updateComputationalSchedulerData(getUserInfo(), "projectName",
"explName", "compName", getSchedulerJobDTO());
verifyNoMoreInteractions(schedulerJobService);
}
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 6c72ef8..33b03b3 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
@@ -85,7 +85,6 @@ public class SchedulerJobServiceImplTest {
private final String EXPLORATORY_NAME = "explName";
private final String COMPUTATIONAL_NAME = "compName";
private final String PROJECT = "project";
- private static final String DLAB_SYSTEM_USER = "DLab system user";
private SchedulerJobDTO schedulerJobDTO;
private UserInstanceDTO userInstance;
@@ -184,27 +183,27 @@ public class SchedulerJobServiceImplTest {
@Test
public void updateSchedulerDataForUserAndExploratory() {
- userInstance.withStatus("running");
- when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
- when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(), anyString(),
- any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
-
- schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
-
- 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);
- }
+ userInstance.withStatus("running");
+ when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
+ when(exploratoryDAO.updateSchedulerDataForUserAndExploratory(anyString(), anyString(), anyString(),
+ any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
+
+ schedulerJobService.updateExploratorySchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+
+ 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);
+ }
@Test
public void updateSchedulerDataForUserAndExploratoryWhenMethodFetchExploratoryFieldsThrowsException() {
doThrow(new ResourceNotFoundException("Exploratory for user with name not found"))
.when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString());
try {
- schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
- } catch (ResourceNotFoundException e) {
+ schedulerJobService.updateExploratorySchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+ } catch (ResourceNotFoundException e) {
assertEquals("Exploratory for user with name not found", e.getMessage());
}
verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME);
@@ -217,8 +216,8 @@ public class SchedulerJobServiceImplTest {
userInstance.withStatus("terminated");
when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance);
try {
- schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
- } catch (ResourceInappropriateStateException e) {
+ schedulerJobService.updateExploratorySchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+ } catch (ResourceInappropriateStateException e) {
assertEquals("Can not create/update scheduler for user instance with status: terminated",
e.getMessage());
}
@@ -229,118 +228,117 @@ public class SchedulerJobServiceImplTest {
@Test
public void updateSchedulerDataForUserAndExploratoryWithEnrichingSchedulerJob() {
- schedulerJobDTO.setBeginDate(null);
- schedulerJobDTO.setTimeZoneOffset(null);
- userInstance.withStatus("running");
- 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, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
-
- assertEquals(LocalDate.now(), schedulerJobDTO.getBeginDate());
- assertEquals(OffsetDateTime.now(ZoneId.systemDefault()).getOffset(), schedulerJobDTO.getTimeZoneOffset());
-
- 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);
- }
+ schedulerJobDTO.setBeginDate(null);
+ schedulerJobDTO.setTimeZoneOffset(null);
+ userInstance.withStatus("running");
+ 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(getUserInfo(), PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+
+ assertEquals(LocalDate.now(), schedulerJobDTO.getBeginDate());
+ assertEquals(OffsetDateTime.now(ZoneId.systemDefault()).getOffset(), schedulerJobDTO.getTimeZoneOffset());
+
+ 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);
+ }
@Test
@SuppressWarnings("unchecked")
public void updateSchedulerDataForUserAndExploratoryWithSyncStartRequiredParam() {
- userInstance.withStatus("running");
- schedulerJobDTO.setSyncStartRequired(true);
- 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(), anyString(),
- any(List.class), anyString(), anyVararg())).thenReturn(singletonList(COMPUTATIONAL_NAME));
- when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
- anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
-
- schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
-
- 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, PROJECT,
- EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
- verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
+ userInstance.withStatus("running");
+ schedulerJobDTO.setSyncStartRequired(true);
+ 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(), anyString(),
+ any(List.class), anyString(), anyVararg())).thenReturn(singletonList(COMPUTATIONAL_NAME));
+ when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
+
+ schedulerJobService.updateExploratorySchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+
+ 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, PROJECT,
+ EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
+ verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
}
@Test
@SuppressWarnings("unchecked")
public void updateSchedulerDataForUserAndExploratoryWithSyncStartRequiredParamButAbsenceClusters() {
- userInstance.withStatus("running");
- schedulerJobDTO.setSyncStartRequired(true);
- 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(), anyString(),
- any(List.class), anyString(), anyVararg())).thenReturn(Collections.emptyList());
-
- schedulerJobService.updateExploratorySchedulerData(USER, PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
-
- 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);
- }
-
+ userInstance.withStatus("running");
+ schedulerJobDTO.setSyncStartRequired(true);
+ 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(), anyString(),
+ any(List.class), anyString(), anyVararg())).thenReturn(Collections.emptyList());
+
+ schedulerJobService.updateExploratorySchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME, schedulerJobDTO);
+
+ 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);
+ }
@Test
public void updateSchedulerDataForComputationalResource() {
- userInstance.withStatus("running");
- 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(),
- anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
-
- 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);
- }
+ userInstance.withStatus("running");
+ 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(),
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
+
+ schedulerJobService.updateComputationalSchedulerData(getUserInfo(), 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(), anyString())).thenReturn(userInstance);
when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString()))
- .thenReturn(userInstance.getResources().get(0));
- when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
- 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,
- LocalDateTime.of(LocalDate.now(), LocalTime.now().truncatedTo(ChronoUnit.MINUTES)),
- LocalTime.now().truncatedTo(ChronoUnit.MINUTES));
- schedulerJobDTO.setStartDaysRepeat(null);
- schedulerJobDTO.setStopDaysRepeat(null);
- schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME,
- COMPUTATIONAL_NAME, schedulerJobDTO);
+ .thenReturn(userInstance.getResources().get(0));
+ when(computationalDAO.updateSchedulerDataForComputationalResource(anyString(), anyString(), anyString(),
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
- 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);
- }
+ final SchedulerJobDTO schedulerJobDTO = getSchedulerJobDTO(LocalDate.now(), LocalDate.now().plusDays(1),
+ Arrays.asList(DayOfWeek.values()), Arrays.asList(DayOfWeek.values()), false,
+ LocalDateTime.of(LocalDate.now(), LocalTime.now().truncatedTo(ChronoUnit.MINUTES)),
+ LocalTime.now().truncatedTo(ChronoUnit.MINUTES));
+ schedulerJobDTO.setStartDaysRepeat(null);
+ schedulerJobDTO.setStopDaysRepeat(null);
+ schedulerJobService.updateComputationalSchedulerData(getUserInfo(), 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(eq(USER), eq(PROJECT), eq(EXPLORATORY_NAME),
+ eq(COMPUTATIONAL_NAME), refEq(schedulerJobDTO));
+ verifyNoMoreInteractions(exploratoryDAO, computationalDAO);
+ }
@Test
public void updateSchedulerDataForComputationalResourceWhenMethodFetchComputationalFieldsThrowsException() {
@@ -349,8 +347,8 @@ public class SchedulerJobServiceImplTest {
doThrow(new ResourceNotFoundException("Computational resource for user with name not found"))
.when(computationalDAO).fetchComputationalFields(anyString(), anyString(), anyString(), anyString());
try {
- schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
- } catch (ResourceNotFoundException e) {
+ schedulerJobService.updateComputationalSchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
+ } catch (ResourceNotFoundException e) {
assertEquals("Computational resource for user with name not found", e.getMessage());
}
@@ -367,8 +365,8 @@ public class SchedulerJobServiceImplTest {
when(computationalDAO.fetchComputationalFields(anyString(), anyString(), anyString(), anyString()))
.thenReturn(userInstance.getResources().get(0));
try {
- schedulerJobService.updateComputationalSchedulerData(USER, PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
- } catch (ResourceInappropriateStateException e) {
+ schedulerJobService.updateComputationalSchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME, COMPUTATIONAL_NAME, schedulerJobDTO);
+ } catch (ResourceInappropriateStateException e) {
assertEquals("Can not create/update scheduler for user instance with status: terminated",
e.getMessage());
}
@@ -381,27 +379,27 @@ public class SchedulerJobServiceImplTest {
public void updateSchedulerDataForComputationalResourceWithEnrichingSchedulerJob() {
schedulerJobDTO.setBeginDate(null);
schedulerJobDTO.setTimeZoneOffset(null);
- userInstance.withStatus("running");
- 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(),
- anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
-
- assertNull(schedulerJobDTO.getBeginDate());
- assertNull(schedulerJobDTO.getTimeZoneOffset());
-
- 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, 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);
+ userInstance.withStatus("running");
+ 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(),
+ anyString(), any(SchedulerJobDTO.class))).thenReturn(mock(UpdateResult.class));
+
+ assertNull(schedulerJobDTO.getBeginDate());
+ assertNull(schedulerJobDTO.getTimeZoneOffset());
+
+ schedulerJobService.updateComputationalSchedulerData(getUserInfo(), PROJECT, EXPLORATORY_NAME,
+ COMPUTATIONAL_NAME, schedulerJobDTO);
+
+ assertEquals(LocalDate.now(), schedulerJobDTO.getBeginDate());
+ assertEquals(OffsetDateTime.now(ZoneId.systemDefault()).getOffset(), schedulerJobDTO.getTimeZoneOffset());
+
+ 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
@@ -657,23 +655,22 @@ public class SchedulerJobServiceImplTest {
@Test
public void testStopExploratoryBySchedulerWhenSchedulerStartDateAfterNow() {
- final LocalDate now = LocalDate.now();
- final LocalDate finishDate = now;
- final List<DayOfWeek> stopDays = Arrays.asList(DayOfWeek.values());
- final List<DayOfWeek> startDays = Arrays.asList(DayOfWeek.values());
- final LocalDate beginDate = now.plusDays(1);
- final LocalDateTime terminateDateTime = LocalDateTime.of(now, LocalTime.now().truncatedTo(ChronoUnit.MINUTES));
- final SchedulerJobData schedulerJobData = getSchedulerJobData(beginDate, finishDate, startDays, stopDays,
- terminateDateTime, false, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES)
- );
- when(schedulerJobDAO.getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(any(UserInstanceStatus.class), any(Date.class)))
- .thenReturn(singletonList(schedulerJobData));
- when(securityService.getUserInfoOffline(anyString())).thenReturn(getUserInfo());
+ final LocalDate now = LocalDate.now();
+ final List<DayOfWeek> stopDays = Arrays.asList(DayOfWeek.values());
+ final List<DayOfWeek> startDays = Arrays.asList(DayOfWeek.values());
+ final LocalDate beginDate = now.plusDays(1);
+ final LocalDateTime terminateDateTime = LocalDateTime.of(now, LocalTime.now().truncatedTo(ChronoUnit.MINUTES));
+ final SchedulerJobData schedulerJobData = getSchedulerJobData(beginDate, now, startDays, stopDays,
+ terminateDateTime, false, USER, LocalTime.now().truncatedTo(ChronoUnit.MINUTES)
+ );
+ when(schedulerJobDAO.getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(any(UserInstanceStatus.class), any(Date.class)))
+ .thenReturn(singletonList(schedulerJobData));
+ when(securityService.getUserInfoOffline(anyString())).thenReturn(getUserInfo());
- schedulerJobService.stopExploratoryByScheduler();
+ schedulerJobService.stopExploratoryByScheduler();
- verify(schedulerJobDAO).getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(eq(RUNNING),
- any(Date.class));
+ verify(schedulerJobDAO).getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(eq(RUNNING),
+ any(Date.class));
verifyNoMoreInteractions(securityService, schedulerJobDAO, exploratoryService);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org