Skip to content

Commit 07b0b2b

Browse files
Deprecate admin client (#632)
1 parent 31b1474 commit 07b0b2b

8 files changed

Lines changed: 89 additions & 16 deletions

File tree

admin-client/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ tasks.withType<GenerateTask> {
4343

4444
configOptions.put("openApiNullable", "false")
4545

46+
// This whole client is deprecated in favour of dev.restate.client.Client. We deprecate every
47+
// generated type:
48+
// * The custom generatedAnnotation.mustache template (see openapi-templates) adds @Deprecated to
49+
// all the api/model/invoker classes, right after the @Generated annotation.
50+
// * additionalEnumTypeAnnotations covers the standalone enums, which don't carry @Generated.
51+
templateDir.set("$projectDir/openapi-templates")
52+
configOptions.put("additionalEnumTypeAnnotations", "@Deprecated")
53+
4654
finalizedBy("spotlessJava")
4755
}
4856

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
2+
@Deprecated

sdk-testing/src/main/java/dev/restate/sdk/testing/RestateAdminClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
/**
1717
* Inject the Restate {@link dev.restate.admin.client.ApiClient}, useful to build admin clients,
1818
* such as {@link dev.restate.admin.api.DeploymentApi}.
19+
*
20+
* @deprecated The code-generated admin client (the {@code dev.restate.admin} package) is
21+
* deprecated. Use {@link RestateAdminURL} instead to inject the admin URL.
1922
*/
23+
@Deprecated
2024
@Target(value = ElementType.PARAMETER)
2125
@Retention(RetentionPolicy.RUNTIME)
2226
public @interface RestateAdminClient {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
2+
//
3+
// This file is part of the Restate Java SDK,
4+
// which is released under the MIT license.
5+
//
6+
// You can find a copy of the license in file LICENSE in the root
7+
// directory of this repository or package, or at
8+
// https://github.com/restatedev/sdk-java/blob/main/LICENSE
9+
package dev.restate.sdk.testing;
10+
11+
import java.lang.annotation.ElementType;
12+
import java.lang.annotation.Retention;
13+
import java.lang.annotation.RetentionPolicy;
14+
import java.lang.annotation.Target;
15+
import java.net.URI;
16+
import java.net.URL;
17+
18+
/**
19+
* Inject Restate's admin URL (either {@link String} or {@link URL} or {@link URI}) to interact with
20+
* the <a href="https://docs.restate.dev/references/admin-api">admin API</a> of the deployed server.
21+
*/
22+
@Target(value = ElementType.PARAMETER)
23+
@Retention(RetentionPolicy.RUNTIME)
24+
public @interface RestateAdminURL {}

sdk-testing/src/main/java/dev/restate/sdk/testing/RestateExtension.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public void beforeAll(ExtensionContext extensionContext) {
3333
}
3434

3535
@Override
36+
@SuppressWarnings(
37+
"deprecation") // RestateAdminClient/ApiClient are deprecated but still supported
3638
public boolean supportsParameter(
3739
ParameterContext parameterContext, ExtensionContext extensionContext)
3840
throws ParameterResolutionException {
@@ -42,11 +44,14 @@ public boolean supportsParameter(
4244
|| (parameterContext.isAnnotated(RestateClient.class)
4345
&& Client.class.isAssignableFrom(parameterContext.getParameter().getType()))
4446
|| (parameterContext.isAnnotated(RestateURL.class)
45-
&& (String.class.isAssignableFrom(parameterContext.getParameter().getType())
46-
|| URL.class.isAssignableFrom(parameterContext.getParameter().getType())));
47+
&& isStringOrUrlOrUri(parameterContext.getParameter().getType()))
48+
|| (parameterContext.isAnnotated(RestateAdminURL.class)
49+
&& isStringOrUrlOrUri(parameterContext.getParameter().getType()));
4750
}
4851

4952
@Override
53+
@SuppressWarnings(
54+
"deprecation") // RestateAdminClient/ApiClient are deprecated but still supported
5055
public Object resolveParameter(
5156
ParameterContext parameterContext, ExtensionContext extensionContext)
5257
throws ParameterResolutionException {
@@ -57,22 +62,33 @@ public Object resolveParameter(
5762
URL url = runner.getIngressUrl();
5863
return Client.connect(url.toString());
5964
} else if (parameterContext.isAnnotated(RestateURL.class)) {
60-
URL url = runner.getIngressUrl();
61-
if (parameterContext.getParameter().getType().equals(String.class)) {
62-
return url.toString();
63-
}
64-
if (parameterContext.getParameter().getType().equals(URI.class)) {
65-
try {
66-
return url.toURI();
67-
} catch (URISyntaxException e) {
68-
throw new RuntimeException(e);
69-
}
70-
}
71-
return url;
65+
return convertUrl(parameterContext.getParameter().getType(), runner.getIngressUrl());
66+
} else if (parameterContext.isAnnotated(RestateAdminURL.class)) {
67+
return convertUrl(parameterContext.getParameter().getType(), runner.getAdminUrl());
7268
}
7369
throw new ParameterResolutionException("The parameter is not supported");
7470
}
7571

72+
private static boolean isStringOrUrlOrUri(Class<?> type) {
73+
return String.class.isAssignableFrom(type)
74+
|| URL.class.isAssignableFrom(type)
75+
|| URI.class.isAssignableFrom(type);
76+
}
77+
78+
private static Object convertUrl(Class<?> type, URL url) {
79+
if (type.equals(String.class)) {
80+
return url.toString();
81+
}
82+
if (type.equals(URI.class)) {
83+
try {
84+
return url.toURI();
85+
} catch (URISyntaxException e) {
86+
throw new RuntimeException(e);
87+
}
88+
}
89+
return url;
90+
}
91+
7692
private RestateRunner getOrCreateRunner(ExtensionContext extensionContext) {
7793
return extensionContext
7894
.getStore(NAMESPACE)

sdk-testing/src/main/java/dev/restate/sdk/testing/RestateRunner.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public RestateRunner build() {
143143
}
144144

145145
/** Run restate, run the embedded service endpoint server, and register the services. */
146+
@SuppressWarnings(
147+
"deprecation") // Internally still uses the deprecated code-generated admin client
146148
public void start() {
147149
// Start listening the local server
148150
try {
@@ -234,6 +236,7 @@ public void close() {
234236

235237
// -- Methods used by the JUnit5 extension
236238

239+
@SuppressWarnings("deprecation") // Returns the deprecated code-generated admin client
237240
ApiClient getAdminClient() {
238241
return new ApiClient()
239242
.setHost(runtimeContainer.getHost())

sdk-testing/src/main/java/dev/restate/sdk/testing/RestateTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
* test methods. Because of this behaviour, the extension sets the {@link TestInstance} as {@link
4646
* TestInstance.Lifecycle#PER_CLASS} automatically.
4747
*
48-
* <p>Use the annotations {@link RestateClient}, {@link RestateURL} and {@link RestateAdminClient}
49-
* to interact with the deployed environment:
48+
* <p>Use the annotations {@link RestateClient}, {@link RestateURL} and {@link RestateAdminURL} to
49+
* interact with the deployed environment:
5050
*
5151
* <pre>
5252
* {@code @Test}

sdk-testing/src/test/java/dev/restate/sdk/testing/CounterTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
import static org.assertj.core.api.Assertions.assertThat;
1212

1313
import dev.restate.client.Client;
14+
import java.net.URI;
15+
import java.net.URL;
16+
import java.net.http.HttpClient;
17+
import java.net.http.HttpRequest;
18+
import java.net.http.HttpResponse;
1419
import org.junit.jupiter.api.Test;
1520
import org.junit.jupiter.api.Timeout;
1621

@@ -27,4 +32,15 @@ void testGreet(@RestateClient Client ingressClient) {
2732
long response = client.get();
2833
assertThat(response).isEqualTo(0L);
2934
}
35+
36+
@Test
37+
@Timeout(value = 10)
38+
void adminUrlIsInjected(@RestateAdminURL URL adminUrl) throws Exception {
39+
HttpResponse<Void> response =
40+
HttpClient.newHttpClient()
41+
.send(
42+
HttpRequest.newBuilder(URI.create(adminUrl.toString()).resolve("/health")).build(),
43+
HttpResponse.BodyHandlers.discarding());
44+
assertThat(response.statusCode()).isEqualTo(200);
45+
}
3046
}

0 commit comments

Comments
 (0)