-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Singularity Request - Timezone field (API) #1150
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
98223aa
added Optional<TimeZone> scheduledTimeZone to relevant request classes
MattCCS 5b7bee2
updated CronExpression to use SingularityRequest TimeZone, if present
MattCCS 4985d16
name changed to match convetion
MattCCS eb0f438
changed scheduleTimeZone type from TimeZone to String (to prevent Jac…
MattCCS 9fab67b
decoupled remaining badRequest() calls from WebExceptions library
MattCCS f703b88
added API timezone string validation; updated SingularityScheduler ap…
MattCCS b454d57
Update schedule validator error msg to give better hint
MattCCS bd3b9dd
add test: Quartz + Scheduler + bad TZ should fail
MattCCS 6a907f2
[WIP] added valid TZ test; fixed bad TZ test; added WIP TZ compare test
MattCCS 48975f9
[WIP] modify broken test to report
MattCCS 85ec657
Fixed TZ comparison test; removed logging
MattCCS ae38f47
remove unnecessary TZ test, remove unused import
MattCCS f8971bc
clean Quartz TZ test
MattCCS f42f946
change TZ error message; align tenses
MattCCS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
|
||
import org.apache.mesos.Protos.Offer; | ||
import org.apache.mesos.Protos.SlaveID; | ||
import org.apache.mesos.Protos.TaskID; | ||
|
@@ -39,6 +41,7 @@ | |
import com.hubspot.singularity.RequestCleanupType; | ||
import com.hubspot.singularity.RequestState; | ||
import com.hubspot.singularity.RequestType; | ||
import com.hubspot.singularity.ScheduleType; | ||
import com.hubspot.singularity.SingularityDeploy; | ||
import com.hubspot.singularity.SingularityDeployBuilder; | ||
import com.hubspot.singularity.SingularityDeployProgress; | ||
|
@@ -3058,6 +3061,66 @@ public void testCronScheduleChanges() throws Exception { | |
Assert.assertEquals(newScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe()); | ||
} | ||
|
||
@Test(expected = WebApplicationException.class) | ||
public void testInvalidQuartzTimeZoneErrors() { | ||
SingularityRequest req = new SingularityRequestBuilder(requestId, RequestType.SCHEDULED) | ||
.setQuartzSchedule(Optional.of("*/1 * * * * ? 2020")) | ||
.setScheduleType(Optional.of(ScheduleType.QUARTZ)) | ||
.setScheduleTimeZone(Optional.of("invalid_timezone")) | ||
.build(); | ||
|
||
requestResource.postRequest(req); | ||
} | ||
|
||
@Test | ||
public void testDifferentQuartzTimeZones() { | ||
final Optional<String> schedule = Optional.of("* 30 14 22 3 ? 2083"); | ||
|
||
SingularityRequest requestEST = new SingularityRequestBuilder("est_id", RequestType.SCHEDULED) | ||
.setSchedule(schedule) | ||
.setScheduleType(Optional.of(ScheduleType.QUARTZ)) | ||
.setScheduleTimeZone(Optional.of("EST")) // fixed in relation to GMT | ||
.build(); | ||
|
||
SingularityRequest requestGMT = new SingularityRequestBuilder("gmt_id", RequestType.SCHEDULED) | ||
.setSchedule(schedule) | ||
.setScheduleType(Optional.of(ScheduleType.QUARTZ)) | ||
.setScheduleTimeZone(Optional.of("GMT")) | ||
.build(); | ||
|
||
requestResource.postRequest(requestEST); | ||
requestResource.postRequest(requestGMT); | ||
|
||
SingularityDeploy deployEST = new SingularityDeployBuilder(requestEST.getId(), "est_deploy_id") | ||
.setCommand(Optional.of("sleep 1")) | ||
.build(); | ||
|
||
SingularityDeploy deployGMT = new SingularityDeployBuilder(requestGMT.getId(), "gmt_deploy_id") | ||
.setCommand(Optional.of("sleep 1")) | ||
.build(); | ||
|
||
deployResource.deploy(new SingularityDeployRequest(deployEST, Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<SingularityRequest>absent())); | ||
deployResource.deploy(new SingularityDeployRequest(deployGMT, Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<SingularityRequest>absent())); | ||
|
||
deployChecker.checkDeploys(); | ||
scheduler.drainPendingQueue(stateCacheProvider.get()); | ||
|
||
final long nextRunEST; | ||
final long nextRunGMT; | ||
final long fiveHoursInMilliseconds = TimeUnit.HOURS.toMillis(5); | ||
final List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds(); | ||
if (pendingTaskIds.get(0).getRequestId().equals(requestEST.getId())) { | ||
nextRunEST = pendingTaskIds.get(0).getNextRunAt(); | ||
nextRunGMT = pendingTaskIds.get(1).getNextRunAt(); | ||
} else { | ||
nextRunEST = pendingTaskIds.get(1).getNextRunAt(); | ||
nextRunGMT = pendingTaskIds.get(0).getNextRunAt(); | ||
} | ||
|
||
// GMT happens first, so EST is a larger timestamp | ||
Assert.assertEquals(nextRunEST - nextRunGMT, fiveHoursInMilliseconds); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using TimeUnit.HOURS.toMillis() instead |
||
} | ||
|
||
@Test | ||
public void testUsesNewRequestDataFromPendingDeploy() { | ||
initRequest(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, but the variable here is probably unnecessary. also, if the variable is needed, try to make all your variables
final
unless they definitely need to be mutable (see above for an example)