Skip to content

Commit cbe7eb8

Browse files
Add sync stack to azure-iot-deviceupdate (Azure#36905)
1 parent fd6547b commit cbe7eb8

File tree

12 files changed

+7584
-3648
lines changed

12 files changed

+7584
-3648
lines changed

sdk/deviceupdate/azure-iot-deviceupdate/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/deviceupdate/azure-iot-deviceupdate",
5-
"Tag": "java/deviceupdate/azure-iot-deviceupdate_6e7c02a488"
5+
"Tag": "java/deviceupdate/azure-iot-deviceupdate_e6c0b7421b"
66
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use: '@autorest/[email protected]'
2+
input-file: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/deviceupdate/data-plane/Microsoft.DeviceUpdate/stable/2022-10-01/deviceupdate.json
3+
java: true
4+
output-folder: ./
5+
enable-sync-stack: true
6+
generate-tests: true
7+
regenerate-pom: false
8+
title: DeviceUpdateClient
9+
generate-sync-async-clients: true
10+
generate-client-as-impl: true
11+
generate-client-interfaces: false
12+
service-interface-as-public: true
13+
add-context-parameter: true
14+
artifact-id: azure-iot-deviceupdate
15+
data-plane: true
16+
sync-methods: all
17+
generate-samples: true
18+
license-header: MICROSOFT_MIT_SMALL
19+
namespace: com.azure.iot.deviceupdate
20+
service-name: DeviceUpdate
21+
context-client-method-parameter: true
22+
azure-arm: false
23+
credential-types: tokencredential
24+
credential-scopes: https://api.adu.microsoft.com/.default
25+
service-versions:
26+
- '2022-10-01'
27+
polling:
28+
default:
29+
strategy: >-
30+
new OperationResourcePollingStrategyWithEndpoint<>({httpPipeline}, "https://" + this.client.getEndpoint(), null, null, {context})

sdk/deviceupdate/azure-iot-deviceupdate/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
<properties>
3030
<jacoco.min.linecoverage>0.25</jacoco.min.linecoverage>
3131
<jacoco.min.branchcoverage>0.1</jacoco.min.branchcoverage>
32+
<!-- Configures the Java 9+ run to perform the required module exports, opens, and reads that are necessary for testing but shouldn't be part of the module-info. -->
33+
<javaModulesSurefireArgLine>
34+
--add-opens com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED
35+
</javaModulesSurefireArgLine>
3236
</properties>
3337

3438
<dependencies>

sdk/deviceupdate/azure-iot-deviceupdate/src/main/java/com/azure/iot/deviceupdate/DeviceManagementClient.java

Lines changed: 51 additions & 60 deletions
Large diffs are not rendered by default.

sdk/deviceupdate/azure-iot-deviceupdate/src/main/java/com/azure/iot/deviceupdate/DeviceManagementClientBuilder.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import java.util.ArrayList;
3939
import java.util.List;
4040
import java.util.Map;
41-
import java.util.stream.Collectors;
41+
import java.util.Objects;
4242

4343
/** A builder for creating a new instance of the DeviceManagementClient type. */
4444
@ServiceClientBuilder(serviceClients = {DeviceManagementClient.class, DeviceManagementAsyncClient.class})
@@ -54,7 +54,7 @@ public final class DeviceManagementClientBuilder
5454
@Generated private static final String[] DEFAULT_SCOPES = new String[] {"https://api.adu.microsoft.com/.default"};
5555

5656
@Generated
57-
private final Map<String, String> properties = CoreUtils.getProperties("azure-iot-deviceupdate.properties");
57+
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties("azure-iot-deviceupdate.properties");
5858

5959
@Generated private final List<HttpPipelinePolicy> pipelinePolicies;
6060

@@ -133,6 +133,7 @@ public DeviceManagementClientBuilder retryOptions(RetryOptions retryOptions) {
133133
@Generated
134134
@Override
135135
public DeviceManagementClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
136+
Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null.");
136137
pipelinePolicies.add(customPolicy);
137138
return this;
138139
}
@@ -251,46 +252,40 @@ private DeviceUpdateClientImpl buildInnerClient() {
251252
private HttpPipeline createHttpPipeline() {
252253
Configuration buildConfiguration =
253254
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
254-
if (httpLogOptions == null) {
255-
httpLogOptions = new HttpLogOptions();
256-
}
257-
if (clientOptions == null) {
258-
clientOptions = new ClientOptions();
259-
}
255+
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;
256+
ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;
260257
List<HttpPipelinePolicy> policies = new ArrayList<>();
261-
String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
262-
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
263-
String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions);
258+
String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName");
259+
String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion");
260+
String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions);
264261
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration));
265262
policies.add(new RequestIdPolicy());
266263
policies.add(new AddHeadersFromContextPolicy());
267264
HttpHeaders headers = new HttpHeaders();
268-
clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue()));
265+
localClientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue()));
269266
if (headers.getSize() > 0) {
270267
policies.add(new AddHeadersPolicy(headers));
271268
}
272-
policies.addAll(
273-
this.pipelinePolicies.stream()
274-
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
275-
.collect(Collectors.toList()));
269+
this.pipelinePolicies.stream()
270+
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
271+
.forEach(p -> policies.add(p));
276272
HttpPolicyProviders.addBeforeRetryPolicies(policies);
277273
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
278274
policies.add(new AddDatePolicy());
279275
policies.add(new CookiePolicy());
280276
if (tokenCredential != null) {
281277
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
282278
}
283-
policies.addAll(
284-
this.pipelinePolicies.stream()
285-
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
286-
.collect(Collectors.toList()));
279+
this.pipelinePolicies.stream()
280+
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
281+
.forEach(p -> policies.add(p));
287282
HttpPolicyProviders.addAfterRetryPolicies(policies);
288283
policies.add(new HttpLoggingPolicy(httpLogOptions));
289284
HttpPipeline httpPipeline =
290285
new HttpPipelineBuilder()
291286
.policies(policies.toArray(new HttpPipelinePolicy[0]))
292287
.httpClient(httpClient)
293-
.clientOptions(clientOptions)
288+
.clientOptions(localClientOptions)
294289
.build();
295290
return httpPipeline;
296291
}
@@ -312,6 +307,6 @@ public DeviceManagementAsyncClient buildAsyncClient() {
312307
*/
313308
@Generated
314309
public DeviceManagementClient buildClient() {
315-
return new DeviceManagementClient(new DeviceManagementAsyncClient(buildInnerClient().getDeviceManagements()));
310+
return new DeviceManagementClient(buildInnerClient().getDeviceManagements());
316311
}
317312
}

sdk/deviceupdate/azure-iot-deviceupdate/src/main/java/com/azure/iot/deviceupdate/DeviceUpdateClient.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
import com.azure.core.http.rest.Response;
1818
import com.azure.core.util.BinaryData;
1919
import com.azure.core.util.polling.SyncPoller;
20+
import com.azure.iot.deviceupdate.implementation.DeviceUpdatesImpl;
2021

2122
/** Initializes a new instance of the synchronous DeviceUpdateClient type. */
2223
@ServiceClient(builder = DeviceUpdateClientBuilder.class)
2324
public final class DeviceUpdateClient {
24-
@Generated private final DeviceUpdateAsyncClient client;
25+
@Generated private final DeviceUpdatesImpl serviceClient;
2526

2627
/**
2728
* Initializes an instance of DeviceUpdateClient class.
2829
*
29-
* @param client the async client.
30+
* @param serviceClient the service client implementation.
3031
*/
3132
@Generated
32-
DeviceUpdateClient(DeviceUpdateAsyncClient client) {
33-
this.client = client;
33+
DeviceUpdateClient(DeviceUpdatesImpl serviceClient) {
34+
this.serviceClient = serviceClient;
3435
}
3536

3637
/**
@@ -107,7 +108,7 @@ public final class DeviceUpdateClient {
107108
@Generated
108109
@ServiceMethod(returns = ReturnType.COLLECTION)
109110
public PagedIterable<BinaryData> listUpdates(RequestOptions requestOptions) {
110-
return new PagedIterable<>(this.client.listUpdates(requestOptions));
111+
return this.serviceClient.listUpdates(requestOptions);
111112
}
112113

113114
/**
@@ -194,7 +195,7 @@ public PagedIterable<BinaryData> listUpdates(RequestOptions requestOptions) {
194195
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
195196
public SyncPoller<BinaryData, BinaryData> beginImportUpdate(
196197
BinaryData updateToImport, RequestOptions requestOptions) {
197-
return this.client.beginImportUpdate(updateToImport, requestOptions).getSyncPoller();
198+
return this.serviceClient.beginImportUpdate(updateToImport, requestOptions);
198199
}
199200

200201
/**
@@ -268,7 +269,7 @@ public SyncPoller<BinaryData, BinaryData> beginImportUpdate(
268269
@ServiceMethod(returns = ReturnType.SINGLE)
269270
public Response<BinaryData> getUpdateWithResponse(
270271
String provider, String name, String version, RequestOptions requestOptions) {
271-
return this.client.getUpdateWithResponse(provider, name, version, requestOptions).block();
272+
return this.serviceClient.getUpdateWithResponse(provider, name, version, requestOptions);
272273
}
273274

274275
/**
@@ -289,7 +290,7 @@ public Response<BinaryData> getUpdateWithResponse(
289290
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
290291
public SyncPoller<BinaryData, BinaryData> beginDeleteUpdate(
291292
String provider, String name, String version, RequestOptions requestOptions) {
292-
return this.client.beginDeleteUpdate(provider, name, version, requestOptions).getSyncPoller();
293+
return this.serviceClient.beginDeleteUpdate(provider, name, version, requestOptions);
293294
}
294295

295296
/**
@@ -317,7 +318,7 @@ public SyncPoller<BinaryData, BinaryData> beginDeleteUpdate(
317318
@Generated
318319
@ServiceMethod(returns = ReturnType.COLLECTION)
319320
public PagedIterable<BinaryData> listProviders(RequestOptions requestOptions) {
320-
return new PagedIterable<>(this.client.listProviders(requestOptions));
321+
return this.serviceClient.listProviders(requestOptions);
321322
}
322323

323324
/**
@@ -346,7 +347,7 @@ public PagedIterable<BinaryData> listProviders(RequestOptions requestOptions) {
346347
@Generated
347348
@ServiceMethod(returns = ReturnType.COLLECTION)
348349
public PagedIterable<BinaryData> listNames(String provider, RequestOptions requestOptions) {
349-
return new PagedIterable<>(this.client.listNames(provider, requestOptions));
350+
return this.serviceClient.listNames(provider, requestOptions);
350351
}
351352

352353
/**
@@ -386,7 +387,7 @@ public PagedIterable<BinaryData> listNames(String provider, RequestOptions reque
386387
@Generated
387388
@ServiceMethod(returns = ReturnType.COLLECTION)
388389
public PagedIterable<BinaryData> listVersions(String provider, String name, RequestOptions requestOptions) {
389-
return new PagedIterable<>(this.client.listVersions(provider, name, requestOptions));
390+
return this.serviceClient.listVersions(provider, name, requestOptions);
390391
}
391392

392393
/**
@@ -418,7 +419,7 @@ public PagedIterable<BinaryData> listVersions(String provider, String name, Requ
418419
@ServiceMethod(returns = ReturnType.COLLECTION)
419420
public PagedIterable<BinaryData> listFiles(
420421
String provider, String name, String version, RequestOptions requestOptions) {
421-
return new PagedIterable<>(this.client.listFiles(provider, name, version, requestOptions));
422+
return this.serviceClient.listFiles(provider, name, version, requestOptions);
422423
}
423424

424425
/**
@@ -487,7 +488,7 @@ public PagedIterable<BinaryData> listFiles(
487488
@ServiceMethod(returns = ReturnType.SINGLE)
488489
public Response<BinaryData> getFileWithResponse(
489490
String provider, String name, String version, String fileId, RequestOptions requestOptions) {
490-
return this.client.getFileWithResponse(provider, name, version, fileId, requestOptions).block();
491+
return this.serviceClient.getFileWithResponse(provider, name, version, fileId, requestOptions);
491492
}
492493

493494
/**
@@ -558,7 +559,7 @@ public Response<BinaryData> getFileWithResponse(
558559
@Generated
559560
@ServiceMethod(returns = ReturnType.COLLECTION)
560561
public PagedIterable<BinaryData> listOperationStatuses(RequestOptions requestOptions) {
561-
return new PagedIterable<>(this.client.listOperationStatuses(requestOptions));
562+
return this.serviceClient.listOperationStatuses(requestOptions);
562563
}
563564

564565
/**
@@ -623,6 +624,6 @@ public PagedIterable<BinaryData> listOperationStatuses(RequestOptions requestOpt
623624
@Generated
624625
@ServiceMethod(returns = ReturnType.SINGLE)
625626
public Response<BinaryData> getOperationStatusWithResponse(String operationId, RequestOptions requestOptions) {
626-
return this.client.getOperationStatusWithResponse(operationId, requestOptions).block();
627+
return this.serviceClient.getOperationStatusWithResponse(operationId, requestOptions);
627628
}
628629
}

sdk/deviceupdate/azure-iot-deviceupdate/src/main/java/com/azure/iot/deviceupdate/DeviceUpdateClientBuilder.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import java.util.ArrayList;
3939
import java.util.List;
4040
import java.util.Map;
41-
import java.util.stream.Collectors;
41+
import java.util.Objects;
4242

4343
/** A builder for creating a new instance of the DeviceUpdateClient type. */
4444
@ServiceClientBuilder(serviceClients = {DeviceUpdateClient.class, DeviceUpdateAsyncClient.class})
@@ -54,7 +54,7 @@ public final class DeviceUpdateClientBuilder
5454
@Generated private static final String[] DEFAULT_SCOPES = new String[] {"https://api.adu.microsoft.com/.default"};
5555

5656
@Generated
57-
private final Map<String, String> properties = CoreUtils.getProperties("azure-iot-deviceupdate.properties");
57+
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties("azure-iot-deviceupdate.properties");
5858

5959
@Generated private final List<HttpPipelinePolicy> pipelinePolicies;
6060

@@ -133,6 +133,7 @@ public DeviceUpdateClientBuilder retryOptions(RetryOptions retryOptions) {
133133
@Generated
134134
@Override
135135
public DeviceUpdateClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
136+
Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null.");
136137
pipelinePolicies.add(customPolicy);
137138
return this;
138139
}
@@ -251,46 +252,40 @@ private DeviceUpdateClientImpl buildInnerClient() {
251252
private HttpPipeline createHttpPipeline() {
252253
Configuration buildConfiguration =
253254
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
254-
if (httpLogOptions == null) {
255-
httpLogOptions = new HttpLogOptions();
256-
}
257-
if (clientOptions == null) {
258-
clientOptions = new ClientOptions();
259-
}
255+
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;
256+
ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;
260257
List<HttpPipelinePolicy> policies = new ArrayList<>();
261-
String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
262-
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
263-
String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions);
258+
String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName");
259+
String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion");
260+
String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions);
264261
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration));
265262
policies.add(new RequestIdPolicy());
266263
policies.add(new AddHeadersFromContextPolicy());
267264
HttpHeaders headers = new HttpHeaders();
268-
clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue()));
265+
localClientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue()));
269266
if (headers.getSize() > 0) {
270267
policies.add(new AddHeadersPolicy(headers));
271268
}
272-
policies.addAll(
273-
this.pipelinePolicies.stream()
274-
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
275-
.collect(Collectors.toList()));
269+
this.pipelinePolicies.stream()
270+
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
271+
.forEach(p -> policies.add(p));
276272
HttpPolicyProviders.addBeforeRetryPolicies(policies);
277273
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
278274
policies.add(new AddDatePolicy());
279275
policies.add(new CookiePolicy());
280276
if (tokenCredential != null) {
281277
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
282278
}
283-
policies.addAll(
284-
this.pipelinePolicies.stream()
285-
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
286-
.collect(Collectors.toList()));
279+
this.pipelinePolicies.stream()
280+
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
281+
.forEach(p -> policies.add(p));
287282
HttpPolicyProviders.addAfterRetryPolicies(policies);
288283
policies.add(new HttpLoggingPolicy(httpLogOptions));
289284
HttpPipeline httpPipeline =
290285
new HttpPipelineBuilder()
291286
.policies(policies.toArray(new HttpPipelinePolicy[0]))
292287
.httpClient(httpClient)
293-
.clientOptions(clientOptions)
288+
.clientOptions(localClientOptions)
294289
.build();
295290
return httpPipeline;
296291
}
@@ -312,6 +307,6 @@ public DeviceUpdateAsyncClient buildAsyncClient() {
312307
*/
313308
@Generated
314309
public DeviceUpdateClient buildClient() {
315-
return new DeviceUpdateClient(new DeviceUpdateAsyncClient(buildInnerClient().getDeviceUpdates()));
310+
return new DeviceUpdateClient(buildInnerClient().getDeviceUpdates());
316311
}
317312
}

0 commit comments

Comments
 (0)