Skip to content

Commit aa94d9c

Browse files
committed
fix
1 parent c7eb4f1 commit aa94d9c

File tree

13 files changed

+50
-183
lines changed

13 files changed

+50
-183
lines changed

azuremanaged/client/build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ def protocVersion = '3.12.0'
2323
def jacksonVersion = '2.15.3'
2424
def azureCoreVersion = '1.45.0'
2525
def azureIdentityVersion = '1.11.1'
26+
def durabletaskClientVersion = '1.5.0'
2627
// When build on local, you need to set this value to your local jdk11 directory.
2728
// Java11 is used to compile and run all the tests.
2829
def PATH_TO_TEST_JAVA_RUNTIME = System.env.JDK_11 ?: System.getProperty("java.home")
2930

3031
repositories {
3132
mavenCentral()
32-
jcenter()
3333
}
3434

3535
dependencies {
@@ -38,13 +38,7 @@ dependencies {
3838
implementation "io.grpc:grpc-stub:${grpcVersion}"
3939
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
4040

41-
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
42-
43-
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
44-
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
45-
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
46-
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}"
47-
41+
implementation "com.microsoft:durabletask-client:${durabletaskClientVersion}"
4842
implementation "com.azure:azure-core:${azureCoreVersion}"
4943
implementation "com.azure:azure-identity:${azureIdentityVersion}"
5044

azuremanaged/client/src/main/java/com/microsoft/durabletask/client/azuremanaged/DurableTaskSchedulerClientExtensions.java

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
package com.microsoft.durabletask.client.azuremanaged;
55

6-
import com.azure.core.credential.TokenCredential;
7-
import com.microsoft.durabletask.DurableTaskClient;
86
import com.microsoft.durabletask.DurableTaskGrpcClientBuilder;
7+
import com.azure.core.credential.TokenCredential;
98
import io.grpc.Channel;
109
import java.util.Objects;
1110
import javax.annotation.Nullable;
@@ -14,52 +13,9 @@
1413
* Extension methods for creating DurableTaskClient instances that connect to Azure-managed Durable Task Scheduler.
1514
* This class provides various methods to create and configure clients using either connection strings or explicit parameters.
1615
*/
17-
public static class DurableTaskSchedulerClientExtensions {
18-
/**
19-
* Creates a DurableTaskClient using a connection string.
20-
*
21-
* @param connectionString The connection string for Azure-managed Durable Task Scheduler.
22-
* @return A new DurableTaskClient instance.
23-
*/
24-
public static DurableTaskClient createClient(String connectionString) {
25-
return createClient(connectionString, null);
26-
}
16+
public final class DurableTaskSchedulerClientExtensions {
2717

28-
/**
29-
* Creates a DurableTaskClient using a connection string and token credential.
30-
*
31-
* @param connectionString The connection string for Azure-managed Durable Task Scheduler.
32-
* @param tokenCredential The token credential for authentication, or null to use connection string credentials.
33-
* @return A new DurableTaskClient instance.
34-
* @throws NullPointerException if connectionString is null
35-
*/
36-
public static DurableTaskClient createClient(String connectionString, @Nullable TokenCredential tokenCredential) {
37-
Objects.requireNonNull(connectionString, "connectionString must not be null");
38-
return createClientFromOptions(
39-
DurableTaskSchedulerClientOptions.fromConnectionString(connectionString, tokenCredential));
40-
}
41-
42-
/**
43-
* Creates a DurableTaskClient using explicit endpoint and task hub parameters.
44-
*
45-
* @param endpoint The endpoint address for Azure-managed Durable Task Scheduler.
46-
* @param taskHubName The name of the task hub to connect to.
47-
* @param tokenCredential The token credential for authentication, or null for anonymous access.
48-
* @return A new DurableTaskClient instance.
49-
* @throws NullPointerException if endpoint or taskHubName is null
50-
*/
51-
public static DurableTaskClient createClient(
52-
String endpoint,
53-
String taskHubName,
54-
@Nullable TokenCredential tokenCredential) {
55-
Objects.requireNonNull(endpoint, "endpoint must not be null");
56-
Objects.requireNonNull(taskHubName, "taskHubName must not be null");
57-
58-
return createClientFromOptions(new DurableTaskSchedulerClientOptions()
59-
.setEndpointAddress(endpoint)
60-
.setTaskHubName(taskHubName)
61-
.setCredential(tokenCredential));
62-
}
18+
private DurableTaskSchedulerClientExtensions() {}
6319

6420
/**
6521
* Configures a DurableTaskGrpcClientBuilder to use Azure-managed Durable Task Scheduler with a connection string.
@@ -143,11 +99,6 @@ public static DurableTaskGrpcClientBuilder createClientBuilder(
14399
}
144100

145101
// Private helper methods to reduce code duplication
146-
147-
private static DurableTaskClient createClientFromOptions(DurableTaskSchedulerClientOptions options) {
148-
return createBuilderFromOptions(options).build();
149-
}
150-
151102
private static DurableTaskGrpcClientBuilder createBuilderFromOptions(DurableTaskSchedulerClientOptions options) {
152103
Channel grpcChannel = options.createGrpcChannel();
153104
return new DurableTaskGrpcClientBuilder().grpcChannel(grpcChannel);

azuremanaged/client/src/main/java/com/microsoft/durabletask/client/azuremanaged/DurableTaskSchedulerClientOptions.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,21 @@
44
package com.microsoft.durabletask.client.azuremanaged;
55

66
import com.azure.core.credential.TokenCredential;
7-
import com.azure.identity.DefaultAzureCredential;
8-
import com.azure.identity.ManagedIdentityCredential;
9-
import com.azure.identity.WorkloadIdentityCredential;
10-
import com.azure.identity.WorkloadIdentityCredentialOptions;
11-
import com.azure.identity.EnvironmentCredential;
12-
import com.azure.identity.AzureCliCredential;
13-
import com.azure.identity.AzurePowerShellCredential;
7+
import com.azure.core.credential.TokenRequestContext;
148
import com.microsoft.durabletask.shared.azuremanaged.DurableTaskSchedulerConnectionString;
15-
import io.grpc.ManagedChannel;
16-
import io.grpc.ManagedChannelBuilder;
17-
import io.grpc.Metadata;
18-
import io.grpc.stub.MetadataUtils;
19-
20-
import jakarta.validation.constraints.NotBlank;
9+
import com.microsoft.durabletask.shared.azuremanaged.AccessTokenCache;
10+
import io.grpc.*;
11+
import javax.annotation.Nullable;
12+
import java.net.MalformedURLException;
2113
import java.time.Duration;
2214
import java.util.Objects;
2315
import java.net.URL;
24-
import java.net.MalformedURLException;
2516

2617
/**
2718
* Options for configuring the Durable Task Scheduler.
2819
*/
2920
public class DurableTaskSchedulerClientOptions {
30-
@NotBlank(message = "Endpoint address is required")
3121
private String endpointAddress = "";
32-
33-
@NotBlank(message = "Task hub name is required")
3422
private String taskHubName = "";
3523

3624
private TokenCredential credential;
@@ -48,10 +36,11 @@ public DurableTaskSchedulerClientOptions() {
4836
* Creates a new instance of DurableTaskSchedulerClientOptions from a connection string.
4937
*
5038
* @param connectionString The connection string to parse.
39+
* @param credential The credential to use for authentication. It is nullable for anonymous access.
5140
* @return A new DurableTaskSchedulerClientOptions object.
5241
*/
5342
public static DurableTaskSchedulerClientOptions fromConnectionString(String connectionString, @Nullable TokenCredential credential) {
54-
DurableTaskSchedulerConnectionString parsedConnectionString = DurableTaskSchedulerConnectionString.parse(connectionString);
43+
DurableTaskSchedulerConnectionString parsedConnectionString = new DurableTaskSchedulerConnectionString(connectionString);
5544
return fromConnectionString(parsedConnectionString, credential);
5645
}
5746

@@ -201,6 +190,11 @@ public void validate() {
201190
Objects.requireNonNull(taskHubName, "taskHubName must not be null");
202191
}
203192

193+
/**
194+
* Creates a gRPC channel using the configured options.
195+
*
196+
* @return A configured gRPC channel for communication with the Durable Task service.
197+
*/
204198
public Channel createGrpcChannel() {
205199
// Create token cache only if credential is not null
206200
AccessTokenCache tokenCache = null;
@@ -217,13 +211,20 @@ public Channel createGrpcChannel() {
217211
endpoint = "https://" + endpoint;
218212
}
219213

220-
URL url = new URL(endpoint);
214+
URL url;
215+
try {
216+
url = new URL(endpoint);
217+
} catch (MalformedURLException e) {
218+
throw new IllegalArgumentException("Invalid endpoint URL: " + endpoint);
219+
}
220+
221221
String authority = url.getHost();
222222
if (url.getPort() != -1) {
223223
authority += ":" + url.getPort();
224224
}
225225

226226
// Create metadata interceptor to add task hub name and auth token
227+
AccessTokenCache finalTokenCache = tokenCache;
227228
ClientInterceptor metadataInterceptor = new ClientInterceptor() {
228229
@Override
229230
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
@@ -240,8 +241,8 @@ public void start(ClientCall.Listener<RespT> responseListener, Metadata headers)
240241
);
241242

242243
// Add authorization token if credentials are configured
243-
if (tokenCache != null) {
244-
String token = tokenCache.getToken().getToken();
244+
if (finalTokenCache != null) {
245+
String token = finalTokenCache.getToken().getToken();
245246
headers.put(
246247
Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER),
247248
"Bearer " + token
@@ -255,7 +256,7 @@ public void start(ClientCall.Listener<RespT> responseListener, Metadata headers)
255256
};
256257

257258
ChannelCredentials credentials;
258-
if (!this.allowInsecure) {
259+
if (!this.allowInsecureCredentials) {
259260
credentials = io.grpc.TlsChannelCredentials.create();
260261
} else {
261262
credentials = InsecureChannelCredentials.create();

azuremanaged/shared/build.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ dependencies {
2727
implementation "io.grpc:grpc-stub:${grpcVersion}"
2828
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
2929

30-
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
31-
32-
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
33-
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
34-
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
35-
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}"
36-
3730
implementation "com.azure:azure-core:${azureCoreVersion}"
3831
implementation "com.azure:azure-identity:${azureIdentityVersion}"
3932

azuremanaged/shared/AccessTokenCache.java renamed to azuremanaged/shared/src/main/java/com/microsoft/durabletask/shared/azuremanaged/AccessTokenCache.java

File renamed without changes.

azuremanaged/shared/DurableTaskSchedulerConnectionString.java renamed to azuremanaged/shared/src/main/java/com/microsoft/durabletask/shared/azuremanaged/DurableTaskSchedulerConnectionString.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.HashMap;
88
import java.util.List;
99
import java.util.Map;
10-
import java.util.Objects;
1110

1211
/**
1312
* Represents the constituent parts of a connection string for a Durable Task Scheduler service.

azuremanaged/worker/build.gradle

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,21 @@ def protocVersion = '3.12.0'
2323
def jacksonVersion = '2.15.3'
2424
def azureCoreVersion = '1.45.0'
2525
def azureIdentityVersion = '1.11.1'
26+
def durabletaskClientVersion = '1.5.0'
2627
// When build on local, you need to set this value to your local jdk11 directory.
2728
// Java11 is used to compile and run all the tests.
2829
def PATH_TO_TEST_JAVA_RUNTIME = System.env.JDK_11 ?: System.getProperty("java.home")
2930

3031
repositories {
3132
mavenCentral()
32-
jcenter()
3333
}
3434

3535
dependencies {
3636
implementation project(':azuremanaged:shared')
3737
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
3838
implementation "io.grpc:grpc-stub:${grpcVersion}"
39+
implementation "com.microsoft:durabletask-client:${durabletaskClientVersion}"
3940
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
40-
41-
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
42-
43-
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
44-
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
45-
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
46-
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}"
47-
4841
implementation "com.azure:azure-core:${azureCoreVersion}"
4942
implementation "com.azure:azure-identity:${azureIdentityVersion}"
5043

azuremanaged/worker/src/main/java/com/microsoft/durabletask/worker/azuremanaged/DurableTaskSchedulerWorkerExtensions.java

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,18 @@
44
package com.microsoft.durabletask.worker.azuremanaged;
55

66
import com.azure.core.credential.TokenCredential;
7-
import com.azure.core.credential.TokenRequestContext;
8-
import com.microsoft.durabletask.DurableTaskGrpcWorker;
97
import com.microsoft.durabletask.DurableTaskGrpcWorkerBuilder;
10-
import com.microsoft.durabletask.shared.azuremanaged.AccessTokenCache;
118

129
import io.grpc.Channel;
13-
import io.grpc.ClientCall;
14-
import io.grpc.ClientInterceptor;
15-
import io.grpc.ForwardingClientCall;
16-
import io.grpc.ManagedChannelBuilder;
17-
import io.grpc.Metadata;
18-
import io.grpc.MethodDescriptor;
19-
import io.grpc.CallOptions;
20-
2110
import java.util.Objects;
2211
import javax.annotation.Nullable;
2312

2413
/**
2514
* Extension methods for creating DurableTaskWorker instances that connect to Azure-managed Durable Task Scheduler.
2615
* This class provides various methods to create and configure workers using either connection strings or explicit parameters.
2716
*/
28-
public static class DurableTaskSchedulerWorkerExtensions {
29-
/**
30-
* Creates a DurableTaskWorker using a connection string.
31-
*
32-
* @param connectionString The connection string for Azure-managed Durable Task Scheduler.
33-
* @return A new DurableTaskWorker instance.
34-
*/
35-
public static DurableTaskWorker createWorker(String connectionString) {
36-
return createWorker(connectionString, null);
37-
}
38-
39-
/**
40-
* Creates a DurableTaskWorker using a connection string and token credential.
41-
*
42-
* @param connectionString The connection string for Azure-managed Durable Task Scheduler.
43-
* @param tokenCredential The token credential for authentication, or null to use connection string credentials.
44-
* @return A new DurableTaskWorker instance.
45-
* @throws NullPointerException if connectionString is null
46-
*/
47-
public static DurableTaskWorker createWorker(String connectionString, @Nullable TokenCredential tokenCredential) {
48-
Objects.requireNonNull(connectionString, "connectionString must not be null");
49-
return createWorkerFromOptions(
50-
DurableTaskSchedulerWorkerOptions.fromConnectionString(connectionString, tokenCredential));
51-
}
52-
53-
/**
54-
* Creates a DurableTaskWorker using explicit endpoint and task hub parameters.
55-
*
56-
* @param endpoint The endpoint address for Azure-managed Durable Task Scheduler.
57-
* @param taskHubName The name of the task hub to connect to.
58-
* @param tokenCredential The token credential for authentication, or null for anonymous access.
59-
* @return A new DurableTaskWorker instance.
60-
* @throws NullPointerException if endpoint or taskHubName is null
61-
*/
62-
public static DurableTaskWorker createWorker(
63-
String endpoint,
64-
String taskHubName,
65-
@Nullable TokenCredential tokenCredential) {
66-
Objects.requireNonNull(endpoint, "endpoint must not be null");
67-
Objects.requireNonNull(taskHubName, "taskHubName must not be null");
68-
69-
return createWorkerFromOptions(new DurableTaskSchedulerWorkerOptions()
70-
.setEndpointAddress(endpoint)
71-
.setTaskHubName(taskHubName)
72-
.setCredential(tokenCredential));
73-
}
17+
public final class DurableTaskSchedulerWorkerExtensions {
18+
private DurableTaskSchedulerWorkerExtensions() {}
7419

7520
/**
7621
* Configures a DurableTaskGrpcWorkerBuilder to use Azure-managed Durable Task Scheduler with a connection string.
@@ -154,11 +99,6 @@ public static DurableTaskGrpcWorkerBuilder createWorkerBuilder(
15499
}
155100

156101
// Private helper methods to reduce code duplication
157-
158-
private static DurableTaskWorker createWorkerFromOptions(DurableTaskSchedulerWorkerOptions options) {
159-
return createBuilderFromOptions(options).build();
160-
}
161-
162102
private static DurableTaskGrpcWorkerBuilder createBuilderFromOptions(DurableTaskSchedulerWorkerOptions options) {
163103
Channel grpcChannel = options.createGrpcChannel();
164104
return new DurableTaskGrpcWorkerBuilder().grpcChannel(grpcChannel);

0 commit comments

Comments
 (0)