-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f46e740
commit e8dddef
Showing
53 changed files
with
2,623 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 148 additions & 50 deletions
198
...ot-deviceupdate/src/main/java/com/azure/iot/deviceupdate/DeviceManagementAsyncClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
196 changes: 146 additions & 50 deletions
196
...ure-iot-deviceupdate/src/main/java/com/azure/iot/deviceupdate/DeviceManagementClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
329 changes: 329 additions & 0 deletions
329
...-deviceupdate/src/main/java/com/azure/iot/deviceupdate/DeviceManagementClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,329 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// Code generated by Microsoft (R) AutoRest Code Generator. | ||
|
||
package com.azure.iot.deviceupdate; | ||
|
||
import com.azure.core.annotation.Generated; | ||
import com.azure.core.annotation.ServiceClientBuilder; | ||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.core.http.HttpClient; | ||
import com.azure.core.http.HttpHeaders; | ||
import com.azure.core.http.HttpPipeline; | ||
import com.azure.core.http.HttpPipelineBuilder; | ||
import com.azure.core.http.HttpPipelinePosition; | ||
import com.azure.core.http.policy.AddHeadersPolicy; | ||
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; | ||
import com.azure.core.http.policy.CookiePolicy; | ||
import com.azure.core.http.policy.HttpLogOptions; | ||
import com.azure.core.http.policy.HttpLoggingPolicy; | ||
import com.azure.core.http.policy.HttpPipelinePolicy; | ||
import com.azure.core.http.policy.HttpPolicyProviders; | ||
import com.azure.core.http.policy.RetryPolicy; | ||
import com.azure.core.http.policy.UserAgentPolicy; | ||
import com.azure.core.util.ClientOptions; | ||
import com.azure.core.util.Configuration; | ||
import com.azure.core.util.CoreUtils; | ||
import com.azure.core.util.serializer.JacksonAdapter; | ||
import com.azure.iot.deviceupdate.implementation.DeviceUpdateClientImpl; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** A builder for creating a new instance of the DeviceManagementClient type. */ | ||
@ServiceClientBuilder(serviceClients = {DeviceManagementClient.class, DeviceManagementAsyncClient.class}) | ||
public final class DeviceManagementClientBuilder { | ||
@Generated private static final String SDK_NAME = "name"; | ||
|
||
@Generated private static final String SDK_VERSION = "version"; | ||
|
||
@Generated private static final String[] DEFAULT_SCOPES = new String[] {"https://api.adu.microsoft.com/.default"}; | ||
|
||
@Generated | ||
private final Map<String, String> properties = CoreUtils.getProperties("azure-iot-deviceupdate.properties"); | ||
|
||
/** Create an instance of the DeviceManagementClientBuilder. */ | ||
@Generated | ||
public DeviceManagementClientBuilder() { | ||
this.pipelinePolicies = new ArrayList<>(); | ||
} | ||
|
||
/* | ||
* Account endpoint. | ||
*/ | ||
@Generated private String endpoint; | ||
|
||
/** | ||
* Sets Account endpoint. | ||
* | ||
* @param endpoint the endpoint value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder endpoint(String endpoint) { | ||
this.endpoint = endpoint; | ||
return this; | ||
} | ||
|
||
/* | ||
* Account instance identifier. | ||
*/ | ||
@Generated private String instanceId; | ||
|
||
/** | ||
* Sets Account instance identifier. | ||
* | ||
* @param instanceId the instanceId value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder instanceId(String instanceId) { | ||
this.instanceId = instanceId; | ||
return this; | ||
} | ||
|
||
/* | ||
* Service version | ||
*/ | ||
@Generated private DeviceUpdateServiceVersion serviceVersion; | ||
|
||
/** | ||
* Sets Service version. | ||
* | ||
* @param serviceVersion the serviceVersion value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder serviceVersion(DeviceUpdateServiceVersion serviceVersion) { | ||
this.serviceVersion = serviceVersion; | ||
return this; | ||
} | ||
|
||
/* | ||
* The HTTP pipeline to send requests through | ||
*/ | ||
@Generated private HttpPipeline pipeline; | ||
|
||
/** | ||
* Sets The HTTP pipeline to send requests through. | ||
* | ||
* @param pipeline the pipeline value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder pipeline(HttpPipeline pipeline) { | ||
this.pipeline = pipeline; | ||
return this; | ||
} | ||
|
||
/* | ||
* The HTTP client used to send the request. | ||
*/ | ||
@Generated private HttpClient httpClient; | ||
|
||
/** | ||
* Sets The HTTP client used to send the request. | ||
* | ||
* @param httpClient the httpClient value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder httpClient(HttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
return this; | ||
} | ||
|
||
/* | ||
* The configuration store that is used during construction of the service | ||
* client. | ||
*/ | ||
@Generated private Configuration configuration; | ||
|
||
/** | ||
* Sets The configuration store that is used during construction of the service client. | ||
* | ||
* @param configuration the configuration value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder configuration(Configuration configuration) { | ||
this.configuration = configuration; | ||
return this; | ||
} | ||
|
||
/* | ||
* The TokenCredential used for authentication. | ||
*/ | ||
@Generated private TokenCredential tokenCredential; | ||
|
||
/** | ||
* Sets The TokenCredential used for authentication. | ||
* | ||
* @param tokenCredential the tokenCredential value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder credential(TokenCredential tokenCredential) { | ||
this.tokenCredential = tokenCredential; | ||
return this; | ||
} | ||
|
||
/* | ||
* The logging configuration for HTTP requests and responses. | ||
*/ | ||
@Generated private HttpLogOptions httpLogOptions; | ||
|
||
/** | ||
* Sets The logging configuration for HTTP requests and responses. | ||
* | ||
* @param httpLogOptions the httpLogOptions value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { | ||
this.httpLogOptions = httpLogOptions; | ||
return this; | ||
} | ||
|
||
/* | ||
* The retry policy that will attempt to retry failed requests, if | ||
* applicable. | ||
*/ | ||
@Generated private RetryPolicy retryPolicy; | ||
|
||
/** | ||
* Sets The retry policy that will attempt to retry failed requests, if applicable. | ||
* | ||
* @param retryPolicy the retryPolicy value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder retryPolicy(RetryPolicy retryPolicy) { | ||
this.retryPolicy = retryPolicy; | ||
return this; | ||
} | ||
|
||
/* | ||
* The list of Http pipeline policies to add. | ||
*/ | ||
@Generated private final List<HttpPipelinePolicy> pipelinePolicies; | ||
|
||
/* | ||
* The client options such as application ID and custom headers to set on a | ||
* request. | ||
*/ | ||
@Generated private ClientOptions clientOptions; | ||
|
||
/** | ||
* Sets The client options such as application ID and custom headers to set on a request. | ||
* | ||
* @param clientOptions the clientOptions value. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder clientOptions(ClientOptions clientOptions) { | ||
this.clientOptions = clientOptions; | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds a custom Http pipeline policy. | ||
* | ||
* @param customPolicy The custom Http pipeline policy to add. | ||
* @return the DeviceManagementClientBuilder. | ||
*/ | ||
@Generated | ||
public DeviceManagementClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { | ||
pipelinePolicies.add(customPolicy); | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds an instance of DeviceUpdateClientImpl with the provided parameters. | ||
* | ||
* @return an instance of DeviceUpdateClientImpl. | ||
*/ | ||
@Generated | ||
private DeviceUpdateClientImpl buildInnerClient() { | ||
if (serviceVersion == null) { | ||
this.serviceVersion = DeviceUpdateServiceVersion.getLatest(); | ||
} | ||
if (pipeline == null) { | ||
this.pipeline = createHttpPipeline(); | ||
} | ||
DeviceUpdateClientImpl client = | ||
new DeviceUpdateClientImpl( | ||
pipeline, | ||
JacksonAdapter.createDefaultSerializerAdapter(), | ||
endpoint, | ||
instanceId, | ||
serviceVersion); | ||
return client; | ||
} | ||
|
||
@Generated | ||
private HttpPipeline createHttpPipeline() { | ||
Configuration buildConfiguration = | ||
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration; | ||
if (httpLogOptions == null) { | ||
httpLogOptions = new HttpLogOptions(); | ||
} | ||
if (clientOptions == null) { | ||
clientOptions = new ClientOptions(); | ||
} | ||
List<HttpPipelinePolicy> policies = new ArrayList<>(); | ||
String clientName = properties.getOrDefault(SDK_NAME, "UnknownName"); | ||
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion"); | ||
String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions); | ||
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); | ||
HttpHeaders headers = new HttpHeaders(); | ||
clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); | ||
if (headers.getSize() > 0) { | ||
policies.add(new AddHeadersPolicy(headers)); | ||
} | ||
policies.addAll( | ||
this.pipelinePolicies.stream() | ||
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) | ||
.collect(Collectors.toList())); | ||
HttpPolicyProviders.addBeforeRetryPolicies(policies); | ||
policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); | ||
policies.add(new CookiePolicy()); | ||
if (tokenCredential != null) { | ||
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES)); | ||
} | ||
policies.addAll( | ||
this.pipelinePolicies.stream() | ||
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) | ||
.collect(Collectors.toList())); | ||
HttpPolicyProviders.addAfterRetryPolicies(policies); | ||
policies.add(new HttpLoggingPolicy(httpLogOptions)); | ||
HttpPipeline httpPipeline = | ||
new HttpPipelineBuilder() | ||
.policies(policies.toArray(new HttpPipelinePolicy[0])) | ||
.httpClient(httpClient) | ||
.clientOptions(clientOptions) | ||
.build(); | ||
return httpPipeline; | ||
} | ||
|
||
/** | ||
* Builds an instance of DeviceManagementAsyncClient async client. | ||
* | ||
* @return an instance of DeviceManagementAsyncClient. | ||
*/ | ||
@Generated | ||
public DeviceManagementAsyncClient buildAsyncClient() { | ||
return new DeviceManagementAsyncClient(buildInnerClient().getDeviceManagements()); | ||
} | ||
|
||
/** | ||
* Builds an instance of DeviceManagementClient sync client. | ||
* | ||
* @return an instance of DeviceManagementClient. | ||
*/ | ||
@Generated | ||
public DeviceManagementClient buildClient() { | ||
return new DeviceManagementClient(buildInnerClient().getDeviceManagements()); | ||
} | ||
} |
Oops, something went wrong.