8
8
import com .azure .core .http .HttpClient ;
9
9
import com .azure .core .http .HttpPipeline ;
10
10
import com .azure .core .http .HttpPipelineBuilder ;
11
+ import com .azure .core .http .HttpPipelinePosition ;
11
12
import com .azure .core .http .policy .AddDatePolicy ;
13
+ import com .azure .core .http .policy .AddHeadersFromContextPolicy ;
12
14
import com .azure .core .http .policy .HttpLogOptions ;
13
15
import com .azure .core .http .policy .HttpLoggingPolicy ;
14
16
import com .azure .core .http .policy .HttpPipelinePolicy ;
15
17
import com .azure .core .http .policy .HttpPolicyProviders ;
16
18
import com .azure .core .http .policy .RequestIdPolicy ;
19
+ import com .azure .core .http .policy .RetryOptions ;
17
20
import com .azure .core .http .policy .RetryPolicy ;
18
21
import com .azure .core .http .policy .UserAgentPolicy ;
19
22
import com .azure .core .management .http .policy .ArmChallengeAuthenticationPolicy ;
49
52
import java .util .ArrayList ;
50
53
import java .util .List ;
51
54
import java .util .Objects ;
55
+ import java .util .stream .Collectors ;
52
56
53
57
/** Entry point to HDInsightManager. HDInsight Management Client. */
54
58
public final class HDInsightManager {
@@ -101,6 +105,19 @@ public static HDInsightManager authenticate(TokenCredential credential, AzurePro
101
105
return configure ().authenticate (credential , profile );
102
106
}
103
107
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
+
104
121
/**
105
122
* Gets a Configurable instance that can be used to create HDInsightManager with optional configuration.
106
123
*
@@ -112,13 +129,14 @@ public static Configurable configure() {
112
129
113
130
/** The Configurable allowing configurations to be set. */
114
131
public static final class Configurable {
115
- private final ClientLogger logger = new ClientLogger (Configurable .class );
132
+ private static final ClientLogger LOGGER = new ClientLogger (Configurable .class );
116
133
117
134
private HttpClient httpClient ;
118
135
private HttpLogOptions httpLogOptions ;
119
136
private final List <HttpPipelinePolicy > policies = new ArrayList <>();
120
137
private final List <String > scopes = new ArrayList <>();
121
138
private RetryPolicy retryPolicy ;
139
+ private RetryOptions retryOptions ;
122
140
private Duration defaultPollInterval ;
123
141
124
142
private Configurable () {
@@ -179,16 +197,31 @@ public Configurable withRetryPolicy(RetryPolicy retryPolicy) {
179
197
return this ;
180
198
}
181
199
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
+
182
213
/**
183
214
* Sets the default poll interval, used when service does not provide "Retry-After" header.
184
215
*
185
216
* @param defaultPollInterval the default poll interval.
186
217
* @return the configurable object itself.
187
218
*/
188
219
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." );
190
222
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" ));
192
225
}
193
226
return this ;
194
227
}
@@ -210,7 +243,7 @@ public HDInsightManager authenticate(TokenCredential credential, AzureProfile pr
210
243
.append ("-" )
211
244
.append ("com.azure.resourcemanager.hdinsight" )
212
245
.append ("/" )
213
- .append ("1.0.0-beta.5 " );
246
+ .append ("1.0.0-beta.1 " );
214
247
if (!Configuration .getGlobalConfiguration ().get ("AZURE_TELEMETRY_DISABLED" , false )) {
215
248
userAgentBuilder
216
249
.append (" (" )
@@ -228,16 +261,34 @@ public HDInsightManager authenticate(TokenCredential credential, AzureProfile pr
228
261
scopes .add (profile .getEnvironment ().getManagementEndpoint () + "/.default" );
229
262
}
230
263
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
+ }
232
269
}
233
270
List <HttpPipelinePolicy > policies = new ArrayList <>();
234
271
policies .add (new UserAgentPolicy (userAgentBuilder .toString ()));
272
+ policies .add (new AddHeadersFromContextPolicy ());
235
273
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 ()));
236
281
HttpPolicyProviders .addBeforeRetryPolicies (policies );
237
282
policies .add (retryPolicy );
238
283
policies .add (new AddDatePolicy ());
239
284
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 ()));
241
292
HttpPolicyProviders .addAfterRetryPolicies (policies );
242
293
policies .add (new HttpLoggingPolicy (httpLogOptions ));
243
294
HttpPipeline httpPipeline =
@@ -249,55 +300,83 @@ public HDInsightManager authenticate(TokenCredential credential, AzureProfile pr
249
300
}
250
301
}
251
302
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
+ */
253
308
public Clusters clusters () {
254
309
if (this .clusters == null ) {
255
310
this .clusters = new ClustersImpl (clientObject .getClusters (), this );
256
311
}
257
312
return clusters ;
258
313
}
259
314
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
+ */
261
320
public Applications applications () {
262
321
if (this .applications == null ) {
263
322
this .applications = new ApplicationsImpl (clientObject .getApplications (), this );
264
323
}
265
324
return applications ;
266
325
}
267
326
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
+ */
269
332
public Locations locations () {
270
333
if (this .locations == null ) {
271
334
this .locations = new LocationsImpl (clientObject .getLocations (), this );
272
335
}
273
336
return locations ;
274
337
}
275
338
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
+ */
277
344
public Configurations configurations () {
278
345
if (this .configurations == null ) {
279
346
this .configurations = new ConfigurationsImpl (clientObject .getConfigurations (), this );
280
347
}
281
348
return configurations ;
282
349
}
283
350
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
+ */
285
356
public Extensions extensions () {
286
357
if (this .extensions == null ) {
287
358
this .extensions = new ExtensionsImpl (clientObject .getExtensions (), this );
288
359
}
289
360
return extensions ;
290
361
}
291
362
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
+ */
293
368
public ScriptActions scriptActions () {
294
369
if (this .scriptActions == null ) {
295
370
this .scriptActions = new ScriptActionsImpl (clientObject .getScriptActions (), this );
296
371
}
297
372
return scriptActions ;
298
373
}
299
374
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
+ */
301
380
public ScriptExecutionHistories scriptExecutionHistories () {
302
381
if (this .scriptExecutionHistories == null ) {
303
382
this .scriptExecutionHistories =
@@ -306,23 +385,35 @@ public ScriptExecutionHistories scriptExecutionHistories() {
306
385
return scriptExecutionHistories ;
307
386
}
308
387
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
+ */
310
393
public Operations operations () {
311
394
if (this .operations == null ) {
312
395
this .operations = new OperationsImpl (clientObject .getOperations (), this );
313
396
}
314
397
return operations ;
315
398
}
316
399
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
+ */
318
405
public VirtualMachines virtualMachines () {
319
406
if (this .virtualMachines == null ) {
320
407
this .virtualMachines = new VirtualMachinesImpl (clientObject .getVirtualMachines (), this );
321
408
}
322
409
return virtualMachines ;
323
410
}
324
411
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
+ */
326
417
public PrivateEndpointConnections privateEndpointConnections () {
327
418
if (this .privateEndpointConnections == null ) {
328
419
this .privateEndpointConnections =
@@ -331,7 +422,11 @@ public PrivateEndpointConnections privateEndpointConnections() {
331
422
return privateEndpointConnections ;
332
423
}
333
424
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
+ */
335
430
public PrivateLinkResources privateLinkResources () {
336
431
if (this .privateLinkResources == null ) {
337
432
this .privateLinkResources = new PrivateLinkResourcesImpl (clientObject .getPrivateLinkResources (), this );
0 commit comments