generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 94
Adds REST API to list jobs with an option to list them per node #786
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
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
3a79f49
remove guava dependency (#773)
jngz-es 04b175e
added Request API, Action API and Test
e776d9c
changing file names
0a6f46c
need to resolve permission issues/ changes to gather all scheduled jo…
1ffaf43
adding to RestGetSchedulingAction
287b89d
adding additionl tests
92398d5
Added IT test for ScheduleInfo
3dd6186
updating progres - verified API calls in terminal
188e5ef
adding new values to prepare request
5d3fafb
removing unneeded code
2260586
adding transport level API
8242d31
adding job type and refactoring json output
9a0bd1f
adding node selection, duplicate filtering and total job count
3b79d11
removing node specific API
c0d100f
adding integration tests
66e6275
updating Scheduled JobInfoIT
4572873
removing comments
9c214df
Adding comments
a9e3489
removing unnessessary tests
a12301b
Add a CHANGELOG and changelog_verifier workflow (#778)
cwperks 363e354
Add 3.1.0 release notes (#779)
prudhvigodithi 3fe788a
Update Maven snapshots publishing endpoint and credential retrieval (…
zelinh 8c33308
Increment version to 3.2.0 (#783)
cwperks 7bf5dbf
removing .idea files
3816f43
fixing formatting issues
9dfb943
adding license header
8fd9c80
change api call, add testing functionality
e0b6793
stop tracking .idea/*
7fe4813
changing constant calls
ba0aabd
adding additional testing fields
45af721
changing permissions
66b115f
removing file
11a297c
adding files -s
35fa41f
reset
3c4ba6c
adding to reset
a5d4da3
deleting comment
b0db328
Merge branch 'main' into lists-jobs
Jeremydupras 61530d3
adding .idea files
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
206 changes: 206 additions & 0 deletions
206
...ugin/src/test/java/org/opensearch/jobscheduler/sampleextension/GetScheduledJobInfoIT.java
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,206 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.jobscheduler.sampleextension; | ||
|
||
import org.opensearch.client.Response; | ||
import org.opensearch.common.xcontent.LoggingDeprecationHandler; | ||
import org.opensearch.common.xcontent.json.JsonXContent; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.jobscheduler.spi.schedule.CronSchedule; | ||
import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; | ||
import org.junit.Before; | ||
import org.junit.After; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.HashSet; | ||
|
||
public class GetScheduledJobInfoIT extends SampleExtensionIntegTestCase { | ||
|
||
@Before | ||
public void setupJobs() throws IOException, InterruptedException { | ||
SampleJobParameter jobParam1 = new SampleJobParameter( | ||
"test-job-1", | ||
"Test Job 1", | ||
"test-index-1", | ||
new IntervalSchedule(Instant.now(), 5, ChronoUnit.MINUTES), | ||
30L, | ||
0.1 | ||
); | ||
|
||
SampleJobParameter jobParam2 = new SampleJobParameter( | ||
"test-job-2", | ||
"Test Job 2", | ||
"test-index-2", | ||
new IntervalSchedule(Instant.now(), 10, ChronoUnit.MINUTES), | ||
60L, | ||
0.2 | ||
); | ||
|
||
SampleJobParameter jobParam3 = new SampleJobParameter( | ||
"test-job-3", | ||
"Test Job 3", | ||
"test-index-3", | ||
new CronSchedule("30 2 * * *", ZoneId.of("America/New_York")), | ||
90L, | ||
0.3 | ||
); | ||
|
||
SampleJobParameter jobParam4 = new SampleJobParameter( | ||
"test-job-4", | ||
"Test Job 4", | ||
"test-index-4", | ||
new CronSchedule("0 9 * * MON", ZoneId.systemDefault()), | ||
120L, | ||
0.4 | ||
); | ||
|
||
createWatcherJob("test-job-1", jobParam1); | ||
createWatcherJob("test-job-2", jobParam2); | ||
createWatcherJob("test-job-3", jobParam3); | ||
createWatcherJob("test-job-4", jobParam4); | ||
// Refresh indices to ensure all jobs are available | ||
makeRequest(client(), "POST", "/_refresh", Collections.emptyMap(), null); | ||
|
||
} | ||
|
||
public void testGetScheduledJobInfoEntireCluster() throws IOException { | ||
|
||
Response response = makeRequest(client(), "GET", "/_plugins/_job_scheduler/api/jobs", Collections.emptyMap(), null); | ||
|
||
assertEquals(200, response.getStatusLine().getStatusCode()); | ||
|
||
Map<String, Object> responseJson = JsonXContent.jsonXContent.createParser( | ||
NamedXContentRegistry.EMPTY, | ||
LoggingDeprecationHandler.INSTANCE, | ||
response.getEntity().getContent() | ||
).map(); | ||
|
||
assertNotNull(responseJson); | ||
assertTrue("Response should contain scheduled job information", responseJson.containsKey("jobs")); | ||
assertEquals("Should have 4 total jobs", 4, responseJson.get("total_jobs")); | ||
|
||
// Verify all test jobs are present | ||
@SuppressWarnings("unchecked") | ||
List<Map<String, Object>> jobs = (List<Map<String, Object>>) responseJson.get("jobs"); | ||
assertNotNull("Jobs list should not be null", jobs); | ||
assertEquals("Should have 4 jobs in the list", 4, jobs.size()); | ||
|
||
// Check that all expected job IDs are present and validate job fields | ||
Set<String> expectedJobIds = Set.of("test-job-1", "test-job-2", "test-job-3", "test-job-4"); | ||
Set<String> actualJobIds = new HashSet<>(); | ||
for (Map<String, Object> job : jobs) { | ||
actualJobIds.add((String) job.get("job_id")); | ||
|
||
// Validate required fields are present | ||
assertEquals("job_type should be scheduler_sample_extension", "scheduler_sample_extension", job.get("job_type")); | ||
assertNotNull("job_id should not be null", job.get("job_id")); | ||
assertEquals("index_name should not be .scheduler_sample_extension", ".scheduler_sample_extension", job.get("index_name")); | ||
assertNotNull("name should not be null", job.get("name")); | ||
assertFalse("descheduled should be False", (Boolean) job.get("descheduled")); | ||
assertTrue("enabled should be True", (Boolean) job.get("enabled")); | ||
assertNotNull("enabled_time should not be null", job.get("enabled_time")); | ||
assertNotNull("last_update_time should not be null", job.get("last_update_time")); | ||
assertNotNull("schedule should not be null", job.get("schedule")); | ||
assertTrue(job.get("lock_duration") instanceof Integer); | ||
assertEquals("none", job.get("jitter")); | ||
assertEquals("none", job.get("delay")); | ||
|
||
// Validate schedule object | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> schedule = (Map<String, Object>) job.get("schedule"); | ||
assertTrue( | ||
"schedule should be interval or Cron", | ||
((schedule.get("type").equals("interval")) || (schedule.get("type").equals("cron"))) | ||
); | ||
} | ||
assertEquals("All expected job IDs should be present", expectedJobIds, actualJobIds); | ||
} | ||
|
||
public void testGetScheduledJobInfoByNode() throws IOException { | ||
|
||
Response response = makeRequest(client(), "GET", "/_plugins/_job_scheduler/api/jobs?by_node", Collections.emptyMap(), null); | ||
|
||
assertEquals(200, response.getStatusLine().getStatusCode()); | ||
|
||
Map<String, Object> responseJson = JsonXContent.jsonXContent.createParser( | ||
NamedXContentRegistry.EMPTY, | ||
LoggingDeprecationHandler.INSTANCE, | ||
response.getEntity().getContent() | ||
).map(); | ||
|
||
assertNotNull(responseJson); | ||
assertTrue("Response should contain scheduled job information", responseJson.containsKey("nodes")); | ||
assertEquals("Should have 4 total jobs", 4, responseJson.get("total_jobs")); | ||
|
||
// Verify nodes array contains job information | ||
@SuppressWarnings("unchecked") | ||
List<Map<String, Object>> nodes = (List<Map<String, Object>>) responseJson.get("nodes"); | ||
assertNotNull("Nodes list should not be null", nodes); | ||
assertFalse("Should have at least one node", nodes.isEmpty()); | ||
|
||
// Collect all job IDs across all nodes | ||
Set<String> allJobIds = new HashSet<>(); | ||
for (Map<String, Object> node : nodes) { | ||
|
||
@SuppressWarnings("unchecked") | ||
List<Map<String, Object>> nodeJobs = (List<Map<String, Object>>) ((Map<String, Object>) node.get("scheduled_job_info")).get( | ||
"jobs" | ||
); | ||
if (nodeJobs != null) { | ||
for (Map<String, Object> job : nodeJobs) { | ||
allJobIds.add((String) job.get("job_id")); | ||
assertEquals("job_type should be scheduler_sample_extension", "scheduler_sample_extension", job.get("job_type")); | ||
assertNotNull("job_id should not be null", job.get("job_id")); | ||
assertEquals( | ||
"index_name should not be .scheduler_sample_extension", | ||
".scheduler_sample_extension", | ||
job.get("index_name") | ||
); | ||
assertNotNull("name should not be null", job.get("name")); | ||
assertFalse("descheduled should be False", (Boolean) job.get("descheduled")); | ||
assertTrue("enabled should be True", (Boolean) job.get("enabled")); | ||
assertNotNull("enabled_time should not be null", job.get("enabled_time")); | ||
assertNotNull("last_update_time should not be null", job.get("last_update_time")); | ||
assertNotNull("schedule should not be null", job.get("schedule")); | ||
assertTrue(job.get("lock_duration") instanceof Integer); | ||
assertEquals("none", job.get("jitter")); | ||
assertEquals("none", job.get("delay")); | ||
// Validate schedule object | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> schedule = (Map<String, Object>) job.get("schedule"); | ||
assertTrue( | ||
"schedule should be interval or Cron", | ||
((schedule.get("type").equals("interval")) || (schedule.get("type").equals("cron"))) | ||
); | ||
} | ||
} | ||
} | ||
|
||
java.util.Set<String> expectedJobIds = java.util.Set.of("test-job-1", "test-job-2", "test-job-3", "test-job-4"); | ||
assertEquals("All expected job IDs should be present across nodes", expectedJobIds, allJobIds); | ||
|
||
// Validate job fields across all nodes | ||
|
||
} | ||
|
||
@After | ||
public void cleanupJobs() throws IOException { | ||
deleteWatcherJob("test-job-1"); | ||
deleteWatcherJob("test-job-2"); | ||
deleteWatcherJob("test-job-3"); | ||
deleteWatcherJob("test-job-4"); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.