Skip to content

Commit 9881f38

Browse files
committed
Polish 'Add the ability to trigger a Quartz job through an Actuator endpoint'
See gh-43086
1 parent fbeace3 commit 9881f38

File tree

3 files changed

+8
-51
lines changed

3 files changed

+8
-51
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/antora/modules/api/pages/rest/actuator/quartz.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ The following table describes the structure of the response:
156156
include::partial$rest/actuator/quartz/job-details/response-fields.adoc[]
157157

158158

159+
159160
[[quartz.trigger-job]]
160161
== Trigger Quartz Job On Demand
161162

@@ -170,6 +171,7 @@ The response will look similar to the following:
170171
include::partial$rest/actuator/quartz/trigger-job/http-response.adoc[]
171172

172173

174+
173175
[[quartz.trigger-job.request-structure]]
174176
=== Request Structure
175177

@@ -190,6 +192,7 @@ The following table describes the structure of the response:
190192
include::partial$rest/actuator/quartz/trigger-job/response-fields.adoc[]
191193

192194

195+
193196
[[quartz.trigger]]
194197
== Retrieving Details of a Trigger
195198

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/quartz/QuartzEndpoint.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ public QuartzJobDetailsDescriptor quartzJob(String groupName, String jobName, bo
223223
* @since 3.5.0
224224
*/
225225
public QuartzJobTriggerDescriptor triggerQuartzJob(String groupName, String jobName) throws SchedulerException {
226-
JobKey jobKey = JobKey.jobKey(jobName, groupName);
226+
return triggerQuartzJob(JobKey.jobKey(jobName, groupName));
227+
}
228+
229+
private QuartzJobTriggerDescriptor triggerQuartzJob(JobKey jobKey) throws SchedulerException {
227230
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
228231
if (jobDetail == null) {
229232
return null;

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/quartz/QuartzEndpointWebIntegrationTests.java

+1-50
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.quartz.TriggerKey;
4444
import org.quartz.impl.matchers.GroupMatcher;
4545

46-
import org.springframework.boot.actuate.endpoint.ApiVersion;
4746
import org.springframework.boot.actuate.endpoint.Show;
4847
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
4948
import org.springframework.context.annotation.Bean;
@@ -65,10 +64,6 @@
6564
*/
6665
class QuartzEndpointWebIntegrationTests {
6766

68-
private static final String V2_JSON = ApiVersion.V2.getProducedMimeType().toString();
69-
70-
private static final String V3_JSON = ApiVersion.V3.getProducedMimeType().toString();
71-
7267
private static final JobDetail jobOne = JobBuilder.newJob(Job.class)
7368
.withIdentity("jobOne", "samples")
7469
.usingJobData(new JobDataMap(Collections.singletonMap("name", "test")))
@@ -261,49 +256,6 @@ void quartzTriggerJob(WebTestClient client) {
261256
client.post()
262257
.uri("/actuator/quartz/jobs/samples/jobOne")
263258
.contentType(MediaType.APPLICATION_JSON)
264-
.accept(MediaType.APPLICATION_JSON)
265-
.bodyValue(Map.of("state", "running"))
266-
.exchange()
267-
.expectStatus()
268-
.isOk()
269-
.expectBody()
270-
.jsonPath("group")
271-
.isEqualTo("samples")
272-
.jsonPath("name")
273-
.isEqualTo("jobOne")
274-
.jsonPath("className")
275-
.isEqualTo("org.quartz.Job")
276-
.jsonPath("triggerTime")
277-
.isNotEmpty();
278-
}
279-
280-
@WebEndpointTest
281-
void quartzTriggerJobV2(WebTestClient client) {
282-
client.post()
283-
.uri("/actuator/quartz/jobs/samples/jobOne")
284-
.contentType(MediaType.parseMediaType(V2_JSON))
285-
.accept(MediaType.APPLICATION_JSON)
286-
.bodyValue(Map.of("state", "running"))
287-
.exchange()
288-
.expectStatus()
289-
.isOk()
290-
.expectBody()
291-
.jsonPath("group")
292-
.isEqualTo("samples")
293-
.jsonPath("name")
294-
.isEqualTo("jobOne")
295-
.jsonPath("className")
296-
.isEqualTo("org.quartz.Job")
297-
.jsonPath("triggerTime")
298-
.isNotEmpty();
299-
}
300-
301-
@WebEndpointTest
302-
void quartzTriggerJobV3(WebTestClient client) {
303-
client.post()
304-
.uri("/actuator/quartz/jobs/samples/jobOne")
305-
.contentType(MediaType.parseMediaType(V3_JSON))
306-
.accept(MediaType.APPLICATION_JSON)
307259
.bodyValue(Map.of("state", "running"))
308260
.exchange()
309261
.expectStatus()
@@ -334,8 +286,7 @@ void quartzTriggerJobWithUnknownJobKey(WebTestClient client) {
334286
void quartzTriggerJobWithUnknownState(WebTestClient client) {
335287
client.post()
336288
.uri("/actuator/quartz/jobs/samples/jobOne")
337-
.contentType(MediaType.parseMediaType(V3_JSON))
338-
.accept(MediaType.APPLICATION_JSON)
289+
.contentType(MediaType.APPLICATION_JSON)
339290
.bodyValue(Map.of("state", "unknown"))
340291
.exchange()
341292
.expectStatus()

0 commit comments

Comments
 (0)