Skip to content

Commit 001a4d2

Browse files
salaboymarcduikersiri-varmadapr-bot
authored
Jobs promotion to DaprClient (#1602)
* job promotion to DaprClient Signed-off-by: salaboy <Salaboy@gmail.com> * updating Jobs readme Signed-off-by: salaboy <Salaboy@gmail.com> * fixing IT tests for Jobs Signed-off-by: salaboy <Salaboy@gmail.com> * Remove SDK docs due to migration to main Docs repo (#1593) * Remove SDK docs due to migration to main Docs repo Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com> * Remove sed lines related to sdk docs Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com> --------- Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com> Co-authored-by: salaboy <Salaboy@gmail.com> Signed-off-by: salaboy <Salaboy@gmail.com> * adding client config for sdk tests Signed-off-by: salaboy <Salaboy@gmail.com> --------- Signed-off-by: salaboy <Salaboy@gmail.com> Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com> Co-authored-by: Marc Duiker <marcduiker@users.noreply.github.com> Co-authored-by: Siri Varma Vegiraju <siri.varma@outlook.com> Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
1 parent 304fb2b commit 001a4d2

File tree

8 files changed

+749
-707
lines changed

8 files changed

+749
-707
lines changed

examples/src/main/java/io/dapr/examples/jobs/DemoJobsClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package io.dapr.examples.jobs;
1515

16+
import io.dapr.client.DaprClient;
1617
import io.dapr.client.DaprClientBuilder;
1718
import io.dapr.client.DaprPreviewClient;
1819
import io.dapr.client.domain.GetJobRequest;
@@ -35,7 +36,7 @@ public static void main(String[] args) throws Exception {
3536
Properties.GRPC_PORT, "51439"
3637
);
3738

38-
try (DaprPreviewClient client = new DaprClientBuilder().withPropertyOverrides(overrides).buildPreviewClient()) {
39+
try (DaprClient client = new DaprClientBuilder().withPropertyOverrides(overrides).build()) {
3940

4041
// Schedule a job.
4142
System.out.println("**** Scheduling a Job with name dapr-jobs-1 *****");

examples/src/main/java/io/dapr/examples/jobs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export DAPR_API_TOKEN="your-dapr-api-token"
6464

6565
This example uses the Java SDK Dapr client in order to **Schedule and Get** Jobs.
6666
`DemoJobsClient.java` is the example class demonstrating these features.
67-
Kindly check [DaprPreviewClient.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/DaprPreviewClient.java) for a detailed description of the supported APIs.
67+
Kindly check [DaprClient.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/DaprClient.java) for a detailed description of the supported APIs.
6868

6969
```java
7070
public class DemoJobsClient {
@@ -77,7 +77,7 @@ public class DemoJobsClient {
7777
Properties.GRPC_PORT, "51439"
7878
);
7979

80-
try (DaprPreviewClient client = new DaprClientBuilder().withPropertyOverrides(overrides).buildPreviewClient()) {
80+
try (DaprClient client = new DaprClientBuilder().withPropertyOverrides(overrides).build()) {
8181

8282
// Schedule a job.
8383
ScheduleJobRequest scheduleJobRequest = new ScheduleJobRequest("dapr-job-1",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.it.testcontainers;
15+
16+
import io.dapr.client.DaprClient;
17+
import io.dapr.client.DaprClientBuilder;
18+
import io.dapr.client.DaprPreviewClient;
19+
import io.dapr.config.Properties;
20+
import io.dapr.config.Property;
21+
import org.springframework.beans.factory.annotation.Value;
22+
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
import java.util.Map;
26+
27+
@Configuration
28+
public class DaprClientConfiguration {
29+
@Bean
30+
public DaprClient daprClient(
31+
@Value("${dapr.http.endpoint}") String daprHttpEndpoint,
32+
@Value("${dapr.grpc.endpoint}") String daprGrpcEndpoint
33+
){
34+
Map<Property<?>, String> overrides = Map.of(
35+
Properties.HTTP_ENDPOINT, daprHttpEndpoint,
36+
Properties.GRPC_ENDPOINT, daprGrpcEndpoint
37+
);
38+
39+
return new DaprClientBuilder().withPropertyOverrides(overrides).build();
40+
}
41+
}

sdk-tests/src/test/java/io/dapr/it/testcontainers/jobs/DaprJobsIT.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
package io.dapr.it.testcontainers.jobs;
1515

16-
import io.dapr.client.DaprPreviewClient;
16+
import io.dapr.client.DaprClient;
1717
import io.dapr.client.domain.ConstantFailurePolicy;
1818
import io.dapr.client.domain.DeleteJobRequest;
1919
import io.dapr.client.domain.DropFailurePolicy;
@@ -22,13 +22,12 @@
2222
import io.dapr.client.domain.GetJobResponse;
2323
import io.dapr.client.domain.JobSchedule;
2424
import io.dapr.client.domain.ScheduleJobRequest;
25-
import io.dapr.it.testcontainers.DaprPreviewClientConfiguration;
25+
import io.dapr.it.testcontainers.DaprClientConfiguration;
2626
import io.dapr.testcontainers.DaprContainer;
2727
import io.dapr.testcontainers.DaprLogLevel;
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Tag;
3030
import org.junit.jupiter.api.Test;
31-
import org.junit.runner.notification.Failure;
3231
import org.springframework.beans.factory.annotation.Autowired;
3332
import org.springframework.boot.test.context.SpringBootTest;
3433
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -51,7 +50,7 @@
5150
@SpringBootTest(
5251
webEnvironment = WebEnvironment.RANDOM_PORT,
5352
classes = {
54-
DaprPreviewClientConfiguration.class,
53+
DaprClientConfiguration.class,
5554
TestJobsApplication.class
5655
}
5756
)
@@ -85,7 +84,7 @@ static void daprProperties(DynamicPropertyRegistry registry) {
8584
}
8685

8786
@Autowired
88-
private DaprPreviewClient daprPreviewClient;
87+
private DaprClient daprClient;
8988

9089
@BeforeEach
9190
public void setUp(){
@@ -98,12 +97,12 @@ public void testJobScheduleCreationWithDueTime() {
9897
.withZone(ZoneOffset.UTC);
9998

10099
Instant currentTime = Instant.now();
101-
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime).setOverwrite(true)).block();
100+
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime).setOverwrite(true)).block();
102101

103102
GetJobResponse getJobResponse =
104-
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
103+
daprClient.getJob(new GetJobRequest("Job")).block();
105104

106-
daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
105+
daprClient.deleteJob(new DeleteJobRequest("Job")).block();
107106

108107
assertEquals(iso8601Formatter.format(currentTime), getJobResponse.getDueTime().toString());
109108
assertEquals("Job", getJobResponse.getName());
@@ -115,13 +114,13 @@ public void testJobScheduleCreationWithSchedule() {
115114
.withZone(ZoneOffset.UTC);
116115

117116
Instant currentTime = Instant.now();
118-
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", JobSchedule.hourly())
117+
daprClient.scheduleJob(new ScheduleJobRequest("Job", JobSchedule.hourly())
119118
.setDueTime(currentTime).setOverwrite(true)).block();
120119

121120
GetJobResponse getJobResponse =
122-
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
121+
daprClient.getJob(new GetJobRequest("Job")).block();
123122

124-
daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
123+
daprClient.deleteJob(new DeleteJobRequest("Job")).block();
125124

126125
assertEquals(iso8601Formatter.format(currentTime), getJobResponse.getDueTime().toString());
127126
assertEquals(JobSchedule.hourly().getExpression(), getJobResponse.getSchedule().getExpression());
@@ -136,17 +135,17 @@ public void testJobScheduleCreationWithAllParameters() {
136135

137136
String cronExpression = "2 * 3 * * FRI";
138137

139-
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
138+
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
140139
.setTtl(currentTime.plus(2, ChronoUnit.HOURS))
141140
.setData("Job data".getBytes())
142141
.setRepeat(3)
143142
.setOverwrite(true)
144143
.setSchedule(JobSchedule.fromString(cronExpression))).block();
145144

146145
GetJobResponse getJobResponse =
147-
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
146+
daprClient.getJob(new GetJobRequest("Job")).block();
148147

149-
daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
148+
daprClient.deleteJob(new DeleteJobRequest("Job")).block();
150149

151150
assertEquals(iso8601Formatter.format(currentTime), getJobResponse.getDueTime().toString());
152151
assertEquals("2 * 3 * * FRI", getJobResponse.getSchedule().getExpression());
@@ -165,17 +164,17 @@ public void testJobScheduleCreationWithDropFailurePolicy() {
165164

166165
String cronExpression = "2 * 3 * * FRI";
167166

168-
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
167+
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
169168
.setTtl(currentTime.plus(2, ChronoUnit.HOURS))
170169
.setData("Job data".getBytes())
171170
.setRepeat(3)
172171
.setFailurePolicy(new DropFailurePolicy())
173172
.setSchedule(JobSchedule.fromString(cronExpression))).block();
174173

175174
GetJobResponse getJobResponse =
176-
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
175+
daprClient.getJob(new GetJobRequest("Job")).block();
177176

178-
daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
177+
daprClient.deleteJob(new DeleteJobRequest("Job")).block();
179178

180179
assertEquals(FailurePolicyType.DROP, getJobResponse.getFailurePolicy().getFailurePolicyType());
181180
}
@@ -188,7 +187,7 @@ public void testJobScheduleCreationWithConstantFailurePolicy() {
188187

189188
String cronExpression = "2 * 3 * * FRI";
190189

191-
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
190+
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
192191
.setTtl(currentTime.plus(2, ChronoUnit.HOURS))
193192
.setData("Job data".getBytes())
194193
.setRepeat(3)
@@ -197,9 +196,9 @@ public void testJobScheduleCreationWithConstantFailurePolicy() {
197196
.setSchedule(JobSchedule.fromString(cronExpression))).block();
198197

199198
GetJobResponse getJobResponse =
200-
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
199+
daprClient.getJob(new GetJobRequest("Job")).block();
201200

202-
daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
201+
daprClient.deleteJob(new DeleteJobRequest("Job")).block();
203202

204203
ConstantFailurePolicy jobFailurePolicyConstant = (ConstantFailurePolicy) getJobResponse.getFailurePolicy();
205204
assertEquals(FailurePolicyType.CONSTANT, getJobResponse.getFailurePolicy().getFailurePolicyType());
@@ -214,13 +213,13 @@ public void testDeleteJobRequest() {
214213

215214
String cronExpression = "2 * 3 * * FRI";
216215

217-
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
216+
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
218217
.setTtl(currentTime.plus(2, ChronoUnit.HOURS))
219218
.setData("Job data".getBytes())
220219
.setRepeat(3)
221220
.setOverwrite(true)
222221
.setSchedule(JobSchedule.fromString(cronExpression))).block();
223222

224-
daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
223+
daprClient.deleteJob(new DeleteJobRequest("Job")).block();
225224
}
226225
}

sdk/src/main/java/io/dapr/client/DaprClient.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515

1616
import io.dapr.client.domain.ConfigurationItem;
1717
import io.dapr.client.domain.DaprMetadata;
18+
import io.dapr.client.domain.DeleteJobRequest;
1819
import io.dapr.client.domain.DeleteStateRequest;
1920
import io.dapr.client.domain.ExecuteStateTransactionRequest;
2021
import io.dapr.client.domain.GetBulkSecretRequest;
2122
import io.dapr.client.domain.GetBulkStateRequest;
2223
import io.dapr.client.domain.GetConfigurationRequest;
24+
import io.dapr.client.domain.GetJobRequest;
25+
import io.dapr.client.domain.GetJobResponse;
2326
import io.dapr.client.domain.GetSecretRequest;
2427
import io.dapr.client.domain.GetStateRequest;
2528
import io.dapr.client.domain.HttpExtension;
2629
import io.dapr.client.domain.InvokeBindingRequest;
2730
import io.dapr.client.domain.InvokeMethodRequest;
2831
import io.dapr.client.domain.PublishEventRequest;
2932
import io.dapr.client.domain.SaveStateRequest;
33+
import io.dapr.client.domain.ScheduleJobRequest;
3034
import io.dapr.client.domain.State;
3135
import io.dapr.client.domain.StateOptions;
3236
import io.dapr.client.domain.SubscribeConfigurationRequest;
@@ -702,6 +706,38 @@ Flux<SubscribeConfigurationResponse> subscribeConfiguration(String storeName, Li
702706
*/
703707
Mono<DaprMetadata> getMetadata();
704708

709+
/**
710+
* Schedules a job using the provided job request details.
711+
*
712+
* @param scheduleJobRequest The request containing the details of the job to schedule.
713+
* Must include a name and optional schedule, data, and other related properties.
714+
* @return A {@link Mono} that completes when the job scheduling operation is successful or raises an error.
715+
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
716+
*/
717+
public Mono<Void> scheduleJob(ScheduleJobRequest scheduleJobRequest);
718+
719+
/**
720+
* Retrieves details of a specific job.
721+
*
722+
* @param getJobRequest The request containing the job name for which the details are to be fetched.
723+
* The name property is mandatory.
724+
* @return A {@link Mono} that emits the {@link GetJobResponse} containing job details or raises an
725+
* error if the job is not found.
726+
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
727+
*/
728+
729+
public Mono<GetJobResponse> getJob(GetJobRequest getJobRequest);
730+
731+
/**
732+
* Deletes a job based on the given request.
733+
*
734+
* @param deleteJobRequest The request containing the job name to be deleted.
735+
* The name property is mandatory.
736+
* @return A {@link Mono} that completes when the job is successfully deleted or raises an error.
737+
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
738+
*/
739+
public Mono<Void> deleteJob(DeleteJobRequest deleteJobRequest);
740+
705741
/**
706742
* Gracefully shutdown the dapr runtime.
707743
*

sdk/src/main/java/io/dapr/client/DaprPreviewClient.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -291,38 +291,6 @@ <T> Subscription subscribeToEvents(
291291
*/
292292
<T> Flux<CloudEvent<T>> subscribeToEvents(String pubsubName, String topic, TypeRef<T> type);
293293

294-
/**
295-
* Schedules a job using the provided job request details.
296-
*
297-
* @param scheduleJobRequest The request containing the details of the job to schedule.
298-
* Must include a name and optional schedule, data, and other related properties.
299-
* @return A {@link Mono} that completes when the job scheduling operation is successful or raises an error.
300-
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
301-
*/
302-
public Mono<Void> scheduleJob(ScheduleJobRequest scheduleJobRequest);
303-
304-
/**
305-
* Retrieves details of a specific job.
306-
*
307-
* @param getJobRequest The request containing the job name for which the details are to be fetched.
308-
* The name property is mandatory.
309-
* @return A {@link Mono} that emits the {@link GetJobResponse} containing job details or raises an
310-
* error if the job is not found.
311-
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
312-
*/
313-
314-
public Mono<GetJobResponse> getJob(GetJobRequest getJobRequest);
315-
316-
/**
317-
* Deletes a job based on the given request.
318-
*
319-
* @param deleteJobRequest The request containing the job name to be deleted.
320-
* The name property is mandatory.
321-
* @return A {@link Mono} that completes when the job is successfully deleted or raises an error.
322-
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
323-
*/
324-
public Mono<Void> deleteJob(DeleteJobRequest deleteJobRequest);
325-
326294
/*
327295
* Converse with an LLM.
328296
*

0 commit comments

Comments
 (0)