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 815548c [DLAB-1907] Support retrieving schedulers for stop for
specific duration(now() - minuteOffset)
815548c is described below
commit 815548c5db13854c395b749b10a9444dcdbb69a1
Author: Oleh Fuks <[email protected]>
AuthorDate: Wed Jul 1 16:53:52 2020 +0300
[DLAB-1907] Support retrieving schedulers for stop for specific
duration(now() - minuteOffset)
---
.../service/impl/SchedulerJobServiceImpl.java | 40 ++++++++++++++++------
.../service/impl/SchedulerJobServiceImplTest.java | 4 +--
2 files changed, 31 insertions(+), 13 deletions(-)
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 e822090..5b80c42 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
@@ -209,11 +209,11 @@ public class SchedulerJobServiceImpl implements
SchedulerJobService {
final OffsetDateTime desiredDateTime =
OffsetDateTime.now().plusMinutes(minutesOffset);
final Predicate<SchedulerJobData> userPredicate = s ->
user.equals(s.getUser());
final Stream<SchedulerJobData> computationalSchedulersStream =
-
getComputationalSchedulersForStopping(desiredDateTime, false)
+
getComputationalSchedulersForStopping(desiredDateTime)
.stream()
.filter(userPredicate);
final Stream<SchedulerJobData> exploratorySchedulersStream =
-
getExploratorySchedulersForStopping(desiredDateTime, false)
+
getExploratorySchedulersForStopping(desiredDateTime)
.stream()
.filter(userPredicate);
return Stream.concat(computationalSchedulersStream,
exploratorySchedulersStream)
@@ -320,15 +320,21 @@ public class SchedulerJobServiceImpl implements
SchedulerJobService {
}
}
+ private List<SchedulerJobData>
getExploratorySchedulersForStopping(OffsetDateTime currentDateTime) {
+ return
schedulerJobDAO.getExploratorySchedulerDataWithStatus(RUNNING)
+ .stream()
+
.filter(canSchedulerForStoppingBeApplied(currentDateTime, true))
+ .collect(Collectors.toList());
+ }
+
private List<SchedulerJobData>
getExploratorySchedulersForStopping(OffsetDateTime currentDateTime,
boolean
checkInactivity) {
-
final Date clusterMaxInactivityAllowedDate =
from(LocalDateTime.now().minusMinutes(ALLOWED_INACTIVITY_MINUTES).atZone(systemDefault()).toInstant());
return
schedulerJobDAO.getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(RUNNING,
clusterMaxInactivityAllowedDate)
.stream()
-
.filter(canSchedulerForStoppingBeApplied(currentDateTime)
+
.filter(canSchedulerForStoppingBeApplied(currentDateTime, false)
.or(schedulerJobData ->
checkInactivity && exploratoryInactivityCondition(schedulerJobData)))
.collect(Collectors.toList());
}
@@ -348,16 +354,16 @@ public class SchedulerJobServiceImpl implements
SchedulerJobService {
.collect(Collectors.toList());
}
- private Predicate<SchedulerJobData>
canSchedulerForStoppingBeApplied(OffsetDateTime currentDateTime) {
+ private Predicate<SchedulerJobData>
canSchedulerForStoppingBeApplied(OffsetDateTime currentDateTime, boolean
usingOffset) {
return schedulerJobData ->
shouldSchedulerBeExecuted(schedulerJobData.getJobDTO(),
currentDateTime,
schedulerJobData.getJobDTO().getStopDaysRepeat(),
- schedulerJobData.getJobDTO().getEndTime());
+ schedulerJobData.getJobDTO().getEndTime(),
usingOffset);
}
private Predicate<SchedulerJobData>
canSchedulerForStartingBeApplied(OffsetDateTime currentDateTime) {
return schedulerJobData ->
shouldSchedulerBeExecuted(schedulerJobData.getJobDTO(),
currentDateTime,
schedulerJobData.getJobDTO().getStartDaysRepeat(),
- schedulerJobData.getJobDTO().getStartTime());
+ schedulerJobData.getJobDTO().getStartTime(),
false);
}
private Predicate<SchedulerJobData>
canSchedulerForTerminatingBeApplied(OffsetDateTime currentDateTime) {
@@ -373,12 +379,20 @@ public class SchedulerJobServiceImpl implements
SchedulerJobService {
convertedCurrentTime.equals(terminateDateTime.atOffset(timeZoneOffset).toLocalDateTime());
}
+ private List<SchedulerJobData>
getComputationalSchedulersForStopping(OffsetDateTime currentDateTime) {
+ return schedulerJobDAO
+
.getComputationalSchedulerDataWithOneOfStatus(RUNNING,
DataEngineType.SPARK_STANDALONE, RUNNING)
+ .stream()
+
.filter(canSchedulerForStoppingBeApplied(currentDateTime, true))
+ .collect(Collectors.toList());
+ }
+
private List<SchedulerJobData>
getComputationalSchedulersForStopping(OffsetDateTime currentDateTime,
boolean
checkInactivity) {
return schedulerJobDAO
.getComputationalSchedulerDataWithOneOfStatus(RUNNING,
DataEngineType.SPARK_STANDALONE, RUNNING)
.stream()
-
.filter(canSchedulerForStoppingBeApplied(currentDateTime)
+
.filter(canSchedulerForStoppingBeApplied(currentDateTime, false)
.or(schedulerJobData ->
checkInactivity && computationalInactivityCondition(schedulerJobData)))
.collect(Collectors.toList());
}
@@ -455,12 +469,16 @@ public class SchedulerJobServiceImpl implements
SchedulerJobService {
}
private boolean shouldSchedulerBeExecuted(SchedulerJobDTO dto,
OffsetDateTime dateTime, List<DayOfWeek> daysRepeat,
-
LocalTime time) {
+
LocalTime time, boolean usingOffset) {
LocalDateTime convertedDateTime = localDateTimeAtZone(dateTime,
dto.getTimeZoneOffset());
-
return isSchedulerActive(dto, convertedDateTime)
&&
daysRepeat.contains(convertedDateTime.toLocalDate().getDayOfWeek())
- && convertedDateTime.toLocalTime().equals(time);
+ && timeFilter(time,
convertedDateTime.toLocalTime(), usingOffset);
+ }
+
+ private boolean timeFilter(LocalTime time, LocalTime convertedDateTime,
boolean usingOffset) {
+ return usingOffset ? (time.isBefore(convertedDateTime) &&
time.isAfter(LocalDateTime.now().toLocalTime())) :
+ convertedDateTime.equals(time);
}
private boolean isSchedulerActive(SchedulerJobDTO dto, LocalDateTime
convertedDateTime) {
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 33b03b3..c66ba83 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
@@ -1053,7 +1053,7 @@ public class SchedulerJobServiceImplTest {
final LocalDate now = LocalDate.now();
final DayOfWeek[] weekDays = DayOfWeek.values();
final LocalTime currentTime = LocalTime.now();
- final LocalTime offsetTime =
LocalTime.now().plusMinutes(minutesOffset);
+ final LocalTime offsetTime = LocalTime.now().plusMinutes(1);
final SchedulerJobData schedulerJobData =
getSchedulerJobData(now,
now.plusDays(1), Arrays.asList(weekDays),
Arrays.asList(weekDays),
LocalDateTime.of(now,
currentTime.plusMinutes(minutesOffset).truncatedTo(ChronoUnit.MINUTES)), false,
@@ -1064,7 +1064,7 @@ public class SchedulerJobServiceImplTest {
LocalDateTime.of(now,
currentTime.plusMinutes(minutesOffset).truncatedTo(ChronoUnit.MINUTES)),
false, "user123",
offsetTime.truncatedTo(ChronoUnit.MINUTES));
-
when(schedulerJobDAO.getExploratorySchedulerWithStatusAndClusterLastActivityLessThan(any(UserInstanceStatus.class),
any(Date.class))).thenReturn(Arrays.asList(schedulerJobData, secondScheduler));
+
when(schedulerJobDAO.getExploratorySchedulerDataWithStatus(any(UserInstanceStatus.class))).thenReturn(Arrays.asList(schedulerJobData,
secondScheduler));
when(securityService.getUserInfoOffline(anyString())).thenReturn(getUserInfo());
when(schedulerJobDAO.getComputationalSchedulerDataWithOneOfStatus(any(UserInstanceStatus.class),
any(DataEngineType.class),
anyVararg())).thenReturn(singletonList(schedulerJobData));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]