88import com .azure .core .http .HttpClient ;
99import com .azure .core .http .HttpPipeline ;
1010import com .azure .core .http .HttpPipelineBuilder ;
11+ import com .azure .core .http .HttpPipelinePosition ;
1112import com .azure .core .http .policy .AddDatePolicy ;
13+ import com .azure .core .http .policy .AddHeadersFromContextPolicy ;
1214import com .azure .core .http .policy .HttpLogOptions ;
1315import com .azure .core .http .policy .HttpLoggingPolicy ;
1416import com .azure .core .http .policy .HttpPipelinePolicy ;
1517import com .azure .core .http .policy .HttpPolicyProviders ;
1618import com .azure .core .http .policy .RequestIdPolicy ;
19+ import com .azure .core .http .policy .RetryOptions ;
1720import com .azure .core .http .policy .RetryPolicy ;
1821import com .azure .core .http .policy .UserAgentPolicy ;
1922import com .azure .core .management .http .policy .ArmChallengeAuthenticationPolicy ;
4952import java .util .ArrayList ;
5053import java .util .List ;
5154import java .util .Objects ;
55+ import java .util .stream .Collectors ;
5256
5357/** Entry point to HDInsightManager. HDInsight Management Client. */
5458public final class HDInsightManager {
@@ -101,6 +105,19 @@ public static HDInsightManager authenticate(TokenCredential credential, AzurePro
101105 return configure ().authenticate (credential , profile );
102106 }
103107
108+ /**
109+ * Creates an instance of HDInsight service API entry point.
110+ *
111+ * @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential.
112+ * @param profile the Azure profile for client.
113+ * @return the HDInsight service API instance.
114+ */
115+ public static HDInsightManager authenticate (HttpPipeline httpPipeline , AzureProfile profile ) {
116+ Objects .requireNonNull (httpPipeline , "'httpPipeline' cannot be null." );
117+ Objects .requireNonNull (profile , "'profile' cannot be null." );
118+ return new HDInsightManager (httpPipeline , profile , null );
119+ }
120+
104121 /**
105122 * Gets a Configurable instance that can be used to create HDInsightManager with optional configuration.
106123 *
@@ -112,13 +129,14 @@ public static Configurable configure() {
112129
113130 /** The Configurable allowing configurations to be set. */
114131 public static final class Configurable {
115- private final ClientLogger logger = new ClientLogger (Configurable .class );
132+ private static final ClientLogger LOGGER = new ClientLogger (Configurable .class );
116133
117134 private HttpClient httpClient ;
118135 private HttpLogOptions httpLogOptions ;
119136 private final List <HttpPipelinePolicy > policies = new ArrayList <>();
120137 private final List <String > scopes = new ArrayList <>();
121138 private RetryPolicy retryPolicy ;
139+ private RetryOptions retryOptions ;
122140 private Duration defaultPollInterval ;
123141
124142 private Configurable () {
@@ -179,16 +197,31 @@ public Configurable withRetryPolicy(RetryPolicy retryPolicy) {
179197 return this ;
180198 }
181199
200+ /**
201+ * Sets the retry options for the HTTP pipeline retry policy.
202+ *
203+ * <p>This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}.
204+ *
205+ * @param retryOptions the retry options for the HTTP pipeline retry policy.
206+ * @return the configurable object itself.
207+ */
208+ public Configurable withRetryOptions (RetryOptions retryOptions ) {
209+ this .retryOptions = Objects .requireNonNull (retryOptions , "'retryOptions' cannot be null." );
210+ return this ;
211+ }
212+
182213 /**
183214 * Sets the default poll interval, used when service does not provide "Retry-After" header.
184215 *
185216 * @param defaultPollInterval the default poll interval.
186217 * @return the configurable object itself.
187218 */
188219 public Configurable withDefaultPollInterval (Duration defaultPollInterval ) {
189- this .defaultPollInterval = Objects .requireNonNull (defaultPollInterval , "'retryPolicy' cannot be null." );
220+ this .defaultPollInterval =
221+ Objects .requireNonNull (defaultPollInterval , "'defaultPollInterval' cannot be null." );
190222 if (this .defaultPollInterval .isNegative ()) {
191- throw logger .logExceptionAsError (new IllegalArgumentException ("'httpPipeline' cannot be negative" ));
223+ throw LOGGER
224+ .logExceptionAsError (new IllegalArgumentException ("'defaultPollInterval' cannot be negative" ));
192225 }
193226 return this ;
194227 }
@@ -210,7 +243,7 @@ public HDInsightManager authenticate(TokenCredential credential, AzureProfile pr
210243 .append ("-" )
211244 .append ("com.azure.resourcemanager.hdinsight" )
212245 .append ("/" )
213- .append ("1.0.0-beta.5 " );
246+ .append ("1.0.0-beta.1 " );
214247 if (!Configuration .getGlobalConfiguration ().get ("AZURE_TELEMETRY_DISABLED" , false )) {
215248 userAgentBuilder
216249 .append (" (" )
@@ -228,16 +261,34 @@ public HDInsightManager authenticate(TokenCredential credential, AzureProfile pr
228261 scopes .add (profile .getEnvironment ().getManagementEndpoint () + "/.default" );
229262 }
230263 if (retryPolicy == null ) {
231- retryPolicy = new RetryPolicy ("Retry-After" , ChronoUnit .SECONDS );
264+ if (retryOptions != null ) {
265+ retryPolicy = new RetryPolicy (retryOptions );
266+ } else {
267+ retryPolicy = new RetryPolicy ("Retry-After" , ChronoUnit .SECONDS );
268+ }
232269 }
233270 List <HttpPipelinePolicy > policies = new ArrayList <>();
234271 policies .add (new UserAgentPolicy (userAgentBuilder .toString ()));
272+ policies .add (new AddHeadersFromContextPolicy ());
235273 policies .add (new RequestIdPolicy ());
274+ policies
275+ .addAll (
276+ this
277+ .policies
278+ .stream ()
279+ .filter (p -> p .getPipelinePosition () == HttpPipelinePosition .PER_CALL )
280+ .collect (Collectors .toList ()));
236281 HttpPolicyProviders .addBeforeRetryPolicies (policies );
237282 policies .add (retryPolicy );
238283 policies .add (new AddDatePolicy ());
239284 policies .add (new ArmChallengeAuthenticationPolicy (credential , scopes .toArray (new String [0 ])));
240- policies .addAll (this .policies );
285+ policies
286+ .addAll (
287+ this
288+ .policies
289+ .stream ()
290+ .filter (p -> p .getPipelinePosition () == HttpPipelinePosition .PER_RETRY )
291+ .collect (Collectors .toList ()));
241292 HttpPolicyProviders .addAfterRetryPolicies (policies );
242293 policies .add (new HttpLoggingPolicy (httpLogOptions ));
243294 HttpPipeline httpPipeline =
@@ -249,55 +300,83 @@ public HDInsightManager authenticate(TokenCredential credential, AzureProfile pr
249300 }
250301 }
251302
252- /** @return Resource collection API of Clusters. */
303+ /**
304+ * Gets the resource collection API of Clusters. It manages Cluster.
305+ *
306+ * @return Resource collection API of Clusters.
307+ */
253308 public Clusters clusters () {
254309 if (this .clusters == null ) {
255310 this .clusters = new ClustersImpl (clientObject .getClusters (), this );
256311 }
257312 return clusters ;
258313 }
259314
260- /** @return Resource collection API of Applications. */
315+ /**
316+ * Gets the resource collection API of Applications. It manages Application.
317+ *
318+ * @return Resource collection API of Applications.
319+ */
261320 public Applications applications () {
262321 if (this .applications == null ) {
263322 this .applications = new ApplicationsImpl (clientObject .getApplications (), this );
264323 }
265324 return applications ;
266325 }
267326
268- /** @return Resource collection API of Locations. */
327+ /**
328+ * Gets the resource collection API of Locations.
329+ *
330+ * @return Resource collection API of Locations.
331+ */
269332 public Locations locations () {
270333 if (this .locations == null ) {
271334 this .locations = new LocationsImpl (clientObject .getLocations (), this );
272335 }
273336 return locations ;
274337 }
275338
276- /** @return Resource collection API of Configurations. */
339+ /**
340+ * Gets the resource collection API of Configurations.
341+ *
342+ * @return Resource collection API of Configurations.
343+ */
277344 public Configurations configurations () {
278345 if (this .configurations == null ) {
279346 this .configurations = new ConfigurationsImpl (clientObject .getConfigurations (), this );
280347 }
281348 return configurations ;
282349 }
283350
284- /** @return Resource collection API of Extensions. */
351+ /**
352+ * Gets the resource collection API of Extensions.
353+ *
354+ * @return Resource collection API of Extensions.
355+ */
285356 public Extensions extensions () {
286357 if (this .extensions == null ) {
287358 this .extensions = new ExtensionsImpl (clientObject .getExtensions (), this );
288359 }
289360 return extensions ;
290361 }
291362
292- /** @return Resource collection API of ScriptActions. */
363+ /**
364+ * Gets the resource collection API of ScriptActions.
365+ *
366+ * @return Resource collection API of ScriptActions.
367+ */
293368 public ScriptActions scriptActions () {
294369 if (this .scriptActions == null ) {
295370 this .scriptActions = new ScriptActionsImpl (clientObject .getScriptActions (), this );
296371 }
297372 return scriptActions ;
298373 }
299374
300- /** @return Resource collection API of ScriptExecutionHistories. */
375+ /**
376+ * Gets the resource collection API of ScriptExecutionHistories.
377+ *
378+ * @return Resource collection API of ScriptExecutionHistories.
379+ */
301380 public ScriptExecutionHistories scriptExecutionHistories () {
302381 if (this .scriptExecutionHistories == null ) {
303382 this .scriptExecutionHistories =
@@ -306,23 +385,35 @@ public ScriptExecutionHistories scriptExecutionHistories() {
306385 return scriptExecutionHistories ;
307386 }
308387
309- /** @return Resource collection API of Operations. */
388+ /**
389+ * Gets the resource collection API of Operations.
390+ *
391+ * @return Resource collection API of Operations.
392+ */
310393 public Operations operations () {
311394 if (this .operations == null ) {
312395 this .operations = new OperationsImpl (clientObject .getOperations (), this );
313396 }
314397 return operations ;
315398 }
316399
317- /** @return Resource collection API of VirtualMachines. */
400+ /**
401+ * Gets the resource collection API of VirtualMachines.
402+ *
403+ * @return Resource collection API of VirtualMachines.
404+ */
318405 public VirtualMachines virtualMachines () {
319406 if (this .virtualMachines == null ) {
320407 this .virtualMachines = new VirtualMachinesImpl (clientObject .getVirtualMachines (), this );
321408 }
322409 return virtualMachines ;
323410 }
324411
325- /** @return Resource collection API of PrivateEndpointConnections. */
412+ /**
413+ * Gets the resource collection API of PrivateEndpointConnections. It manages PrivateEndpointConnection.
414+ *
415+ * @return Resource collection API of PrivateEndpointConnections.
416+ */
326417 public PrivateEndpointConnections privateEndpointConnections () {
327418 if (this .privateEndpointConnections == null ) {
328419 this .privateEndpointConnections =
@@ -331,7 +422,11 @@ public PrivateEndpointConnections privateEndpointConnections() {
331422 return privateEndpointConnections ;
332423 }
333424
334- /** @return Resource collection API of PrivateLinkResources. */
425+ /**
426+ * Gets the resource collection API of PrivateLinkResources.
427+ *
428+ * @return Resource collection API of PrivateLinkResources.
429+ */
335430 public PrivateLinkResources privateLinkResources () {
336431 if (this .privateLinkResources == null ) {
337432 this .privateLinkResources = new PrivateLinkResourcesImpl (clientObject .getPrivateLinkResources (), this );
0 commit comments