Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package io.dapr.examples.jobs;

import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;
import io.dapr.client.DaprPreviewClient;
import io.dapr.client.domain.GetJobRequest;
Expand All @@ -35,7 +36,7 @@ public static void main(String[] args) throws Exception {
Properties.GRPC_PORT, "51439"
);

try (DaprPreviewClient client = new DaprClientBuilder().withPropertyOverrides(overrides).buildPreviewClient()) {
try (DaprClient client = new DaprClientBuilder().withPropertyOverrides(overrides).build()) {

// Schedule a job.
System.out.println("**** Scheduling a Job with name dapr-jobs-1 *****");
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/java/io/dapr/examples/jobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export DAPR_API_TOKEN="your-dapr-api-token"

This example uses the Java SDK Dapr client in order to **Schedule and Get** Jobs.
`DemoJobsClient.java` is the example class demonstrating these features.
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.
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.

```java
public class DemoJobsClient {
Expand All @@ -77,7 +77,7 @@ public class DemoJobsClient {
Properties.GRPC_PORT, "51439"
);

try (DaprPreviewClient client = new DaprClientBuilder().withPropertyOverrides(overrides).buildPreviewClient()) {
try (DaprClient client = new DaprClientBuilder().withPropertyOverrides(overrides).build()) {

// Schedule a job.
ScheduleJobRequest scheduleJobRequest = new ScheduleJobRequest("dapr-job-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package io.dapr.it.testcontainers.jobs;

import io.dapr.client.DaprPreviewClient;
import io.dapr.client.DaprClient;
import io.dapr.client.domain.ConstantFailurePolicy;
import io.dapr.client.domain.DeleteJobRequest;
import io.dapr.client.domain.DropFailurePolicy;
Expand All @@ -28,7 +28,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.runner.notification.Failure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
Expand Down Expand Up @@ -85,7 +84,7 @@ static void daprProperties(DynamicPropertyRegistry registry) {
}

@Autowired
private DaprPreviewClient daprPreviewClient;
private DaprClient daprClient;

@BeforeEach
public void setUp(){
Expand All @@ -98,12 +97,12 @@ public void testJobScheduleCreationWithDueTime() {
.withZone(ZoneOffset.UTC);

Instant currentTime = Instant.now();
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime).setOverwrite(true)).block();
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime).setOverwrite(true)).block();

GetJobResponse getJobResponse =
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
daprClient.getJob(new GetJobRequest("Job")).block();

daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
daprClient.deleteJob(new DeleteJobRequest("Job")).block();

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

Instant currentTime = Instant.now();
daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", JobSchedule.hourly())
daprClient.scheduleJob(new ScheduleJobRequest("Job", JobSchedule.hourly())
.setDueTime(currentTime).setOverwrite(true)).block();

GetJobResponse getJobResponse =
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
daprClient.getJob(new GetJobRequest("Job")).block();

daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
daprClient.deleteJob(new DeleteJobRequest("Job")).block();

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

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

daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
.setTtl(currentTime.plus(2, ChronoUnit.HOURS))
.setData("Job data".getBytes())
.setRepeat(3)
.setOverwrite(true)
.setSchedule(JobSchedule.fromString(cronExpression))).block();

GetJobResponse getJobResponse =
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
daprClient.getJob(new GetJobRequest("Job")).block();

daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
daprClient.deleteJob(new DeleteJobRequest("Job")).block();

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

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

daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
.setTtl(currentTime.plus(2, ChronoUnit.HOURS))
.setData("Job data".getBytes())
.setRepeat(3)
.setFailurePolicy(new DropFailurePolicy())
.setSchedule(JobSchedule.fromString(cronExpression))).block();

GetJobResponse getJobResponse =
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
daprClient.getJob(new GetJobRequest("Job")).block();

daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
daprClient.deleteJob(new DeleteJobRequest("Job")).block();

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

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

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

GetJobResponse getJobResponse =
daprPreviewClient.getJob(new GetJobRequest("Job")).block();
daprClient.getJob(new GetJobRequest("Job")).block();

daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
daprClient.deleteJob(new DeleteJobRequest("Job")).block();

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

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

daprPreviewClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
daprClient.scheduleJob(new ScheduleJobRequest("Job", currentTime)
.setTtl(currentTime.plus(2, ChronoUnit.HOURS))
.setData("Job data".getBytes())
.setRepeat(3)
.setOverwrite(true)
.setSchedule(JobSchedule.fromString(cronExpression))).block();

daprPreviewClient.deleteJob(new DeleteJobRequest("Job")).block();
daprClient.deleteJob(new DeleteJobRequest("Job")).block();
}
}
36 changes: 36 additions & 0 deletions sdk/src/main/java/io/dapr/client/DaprClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@

import io.dapr.client.domain.ConfigurationItem;
import io.dapr.client.domain.DaprMetadata;
import io.dapr.client.domain.DeleteJobRequest;
import io.dapr.client.domain.DeleteStateRequest;
import io.dapr.client.domain.ExecuteStateTransactionRequest;
import io.dapr.client.domain.GetBulkSecretRequest;
import io.dapr.client.domain.GetBulkStateRequest;
import io.dapr.client.domain.GetConfigurationRequest;
import io.dapr.client.domain.GetJobRequest;
import io.dapr.client.domain.GetJobResponse;
import io.dapr.client.domain.GetSecretRequest;
import io.dapr.client.domain.GetStateRequest;
import io.dapr.client.domain.HttpExtension;
import io.dapr.client.domain.InvokeBindingRequest;
import io.dapr.client.domain.InvokeMethodRequest;
import io.dapr.client.domain.PublishEventRequest;
import io.dapr.client.domain.SaveStateRequest;
import io.dapr.client.domain.ScheduleJobRequest;
import io.dapr.client.domain.State;
import io.dapr.client.domain.StateOptions;
import io.dapr.client.domain.SubscribeConfigurationRequest;
Expand Down Expand Up @@ -702,6 +706,38 @@ Flux<SubscribeConfigurationResponse> subscribeConfiguration(String storeName, Li
*/
Mono<DaprMetadata> getMetadata();

/**
* Schedules a job using the provided job request details.
*
* @param scheduleJobRequest The request containing the details of the job to schedule.
* Must include a name and optional schedule, data, and other related properties.
* @return A {@link Mono} that completes when the job scheduling operation is successful or raises an error.
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
*/
public Mono<Void> scheduleJob(ScheduleJobRequest scheduleJobRequest);

/**
* Retrieves details of a specific job.
*
* @param getJobRequest The request containing the job name for which the details are to be fetched.
* The name property is mandatory.
* @return A {@link Mono} that emits the {@link GetJobResponse} containing job details or raises an
* error if the job is not found.
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
*/

public Mono<GetJobResponse> getJob(GetJobRequest getJobRequest);

/**
* Deletes a job based on the given request.
*
* @param deleteJobRequest The request containing the job name to be deleted.
* The name property is mandatory.
* @return A {@link Mono} that completes when the job is successfully deleted or raises an error.
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
*/
public Mono<Void> deleteJob(DeleteJobRequest deleteJobRequest);

/**
* Gracefully shutdown the dapr runtime.
*
Expand Down
32 changes: 0 additions & 32 deletions sdk/src/main/java/io/dapr/client/DaprPreviewClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,38 +291,6 @@ <T> Subscription subscribeToEvents(
*/
<T> Flux<CloudEvent<T>> subscribeToEvents(String pubsubName, String topic, TypeRef<T> type);

/**
* Schedules a job using the provided job request details.
*
* @param scheduleJobRequest The request containing the details of the job to schedule.
* Must include a name and optional schedule, data, and other related properties.
* @return A {@link Mono} that completes when the job scheduling operation is successful or raises an error.
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
*/
public Mono<Void> scheduleJob(ScheduleJobRequest scheduleJobRequest);

/**
* Retrieves details of a specific job.
*
* @param getJobRequest The request containing the job name for which the details are to be fetched.
* The name property is mandatory.
* @return A {@link Mono} that emits the {@link GetJobResponse} containing job details or raises an
* error if the job is not found.
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
*/

public Mono<GetJobResponse> getJob(GetJobRequest getJobRequest);

/**
* Deletes a job based on the given request.
*
* @param deleteJobRequest The request containing the job name to be deleted.
* The name property is mandatory.
* @return A {@link Mono} that completes when the job is successfully deleted or raises an error.
* @throws IllegalArgumentException If the request or its required fields like name are null or empty.
*/
public Mono<Void> deleteJob(DeleteJobRequest deleteJobRequest);

/*
* Converse with an LLM.
*
Expand Down
Loading
Loading