Skip to content

Commit a843c83

Browse files
Proof of concept, add x-ms-correlation-request-id to Deployment (#1371)
1 parent f8a67c3 commit a843c83

9 files changed

Lines changed: 934 additions & 34 deletions

File tree

azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployment.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.microsoft.azure.management.apigeneration.LangMethodDefinition;
1111
import com.microsoft.azure.management.apigeneration.LangMethodDefinition.LangMethodType;
1212
import com.microsoft.azure.management.apigeneration.Method;
13+
import com.microsoft.azure.management.resources.fluentcore.arm.Context;
1314
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
1415
import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource;
1516
import com.microsoft.azure.management.resources.fluentcore.arm.models.HasId;
@@ -295,11 +296,61 @@ interface WithMode {
295296
* deployment in the cloud, but exposing additional optional inputs to specify.
296297
*/
297298
interface WithCreate extends Creatable<Deployment> {
299+
300+
/**
301+
* Begin executing the create request.
302+
*
303+
* @return the resource in creating
304+
*/
298305
@Method
299306
Deployment beginCreate();
300307

308+
/**
309+
* Puts the request into the queue and allow the HTTP client to begin execute
310+
* it when system resources are available.
311+
*
312+
* @return an observable of the request
313+
*/
301314
@Method
302315
Observable<Deployment> beginCreateAsync();
316+
317+
/**
318+
* Begin executing the create request.
319+
*
320+
* @param context the context for the request
321+
* @return the resource in creating
322+
*/
323+
@Method
324+
Deployment beginCreate(Context context);
325+
326+
/**
327+
* Puts the request into the queue and allow the HTTP client to begin execute
328+
* it when system resources are available.
329+
*
330+
* @param context the context for the request
331+
* @return an observable of the request
332+
*/
333+
@Method
334+
Observable<Deployment> beginCreateAsync(Context context);
335+
336+
/**
337+
* Execute the create request.
338+
*
339+
* @param context the context for the request
340+
* @return the create resource
341+
*/
342+
@Method
343+
Deployment create(Context context);
344+
345+
/**
346+
* Puts the request into the queue and allow the HTTP client to execute
347+
* it when system resources are available.
348+
*
349+
* @param context the context for the request
350+
* @return an observable of the request
351+
*/
352+
@Method
353+
Observable<Indexable> createAsync(Context context);
303354
}
304355
}
305356

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
7+
package com.microsoft.azure.management.resources.fluentcore.arm;
8+
9+
/**
10+
* The immutable context for ARM request.
11+
*/
12+
public final class Context {
13+
14+
// nullable
15+
private final String correlationRequestId;
16+
17+
/**
18+
* The empty context.
19+
*/
20+
public static final Context NONE = new Context.Builder().build();
21+
22+
private Context(String correlationRequestId) {
23+
this.correlationRequestId = correlationRequestId;
24+
}
25+
26+
/**
27+
* @return the x-ms-correlation-request-id for ARM request.
28+
*/
29+
public String correlationRequestId() {
30+
return correlationRequestId;
31+
}
32+
33+
/**
34+
* The context builder.
35+
*/
36+
public static final class Builder {
37+
38+
private String correlationRequestId = null;
39+
40+
/**
41+
* The constructor of the builder.
42+
*/
43+
public Builder() {
44+
}
45+
46+
/**
47+
* Sets the x-ms-correlation-request-id for ARM request.
48+
*
49+
* @param correlationRequestId the x-ms-correlation-request-id for ARM request.
50+
* @return the Builder.
51+
*/
52+
public Builder withCorrelationRequestId(String correlationRequestId) {
53+
this.correlationRequestId = correlationRequestId;
54+
return this;
55+
}
56+
57+
/**
58+
* Creates the Context instance.
59+
*
60+
* @return the Context instance.
61+
*/
62+
public Context build() {
63+
return new Context(correlationRequestId);
64+
}
65+
}
66+
}

azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/dag/TaskGroup.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ public interface HasTaskGroup {
579579
* of the TaskGroup.
580580
*/
581581
public static final class InvocationContext {
582+
/** Key of context for request. */
583+
public static final String KEY_CONTEXT = "CONTEXT";
584+
582585
private final Map<String, Object> properties;
583586
private final TaskGroup taskGroup;
584587
private TaskGroupTerminateOnErrorStrategy terminateOnErrorStrategy;

azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/CreatableUpdatableImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package com.microsoft.azure.management.resources.fluentcore.model.implementation;
88

9+
import com.microsoft.azure.management.resources.fluentcore.arm.Context;
910
import com.microsoft.azure.management.resources.fluentcore.dag.FunctionalTaskItem;
1011
import com.microsoft.azure.management.resources.fluentcore.dag.TaskGroup;
1112
import com.microsoft.azure.management.resources.fluentcore.model.Appliable;
@@ -271,6 +272,16 @@ public Observable<FluentModelT> updateResourceAsync() {
271272
return this.createResourceAsync();
272273
}
273274

275+
@Override
276+
public Observable<FluentModelT> updateResourceAsync(Context context) {
277+
return this.updateResourceAsync();
278+
}
279+
280+
@Override
281+
public Observable<FluentModelT> createResourceAsync(Context context) {
282+
return this.createResourceAsync();
283+
}
284+
274285
/**
275286
* Get result of one of the task that belongs to this task's task group.
276287
*

azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/CreateUpdateTask.java

Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package com.microsoft.azure.management.resources.fluentcore.model.implementation;
88

9+
import com.microsoft.azure.management.resources.fluentcore.arm.Context;
910
import com.microsoft.azure.management.resources.fluentcore.dag.TaskGroup;
1011
import com.microsoft.azure.management.resources.fluentcore.dag.TaskItem;
1112
import com.microsoft.azure.management.resources.fluentcore.model.Indexable;
@@ -53,35 +54,69 @@ public void beforeGroupInvoke() {
5354

5455
@Override
5556
public Observable<Indexable> invokeAsync(TaskGroup.InvocationContext context) {
56-
if (this.resourceCreatorUpdater.isInCreateMode()) {
57-
return this.resourceCreatorUpdater.createResourceAsync()
58-
.subscribeOn(SdkContext.getRxScheduler())
59-
.doOnNext(new Action1<ResourceT>() {
60-
@Override
61-
public void call(ResourceT resourceT) {
62-
resource = resourceT;
63-
}
64-
}).map(new Func1<ResourceT, Indexable>() {
65-
@Override
66-
public Indexable call(ResourceT resourceT) {
67-
return resourceT;
68-
}
69-
});
57+
Object context1 = context.get(TaskGroup.InvocationContext.KEY_CONTEXT);
58+
if (context1 instanceof Context) {
59+
if (this.resourceCreatorUpdater.isInCreateMode()) {
60+
return this.resourceCreatorUpdater.createResourceAsync((Context) context1)
61+
.subscribeOn(SdkContext.getRxScheduler())
62+
.doOnNext(new Action1<ResourceT>() {
63+
@Override
64+
public void call(ResourceT resourceT) {
65+
resource = resourceT;
66+
}
67+
}).map(new Func1<ResourceT, Indexable>() {
68+
@Override
69+
public Indexable call(ResourceT resourceT) {
70+
return resourceT;
71+
}
72+
});
73+
} else {
74+
return this.resourceCreatorUpdater.updateResourceAsync((Context) context1)
75+
.subscribeOn(SdkContext.getRxScheduler())
76+
.doOnNext(new Action1<ResourceT>() {
77+
@Override
78+
public void call(ResourceT resourceT) {
79+
resource = resourceT;
80+
}
81+
})
82+
.map(new Func1<ResourceT, Indexable>() {
83+
@Override
84+
public Indexable call(ResourceT resourceT) {
85+
return resourceT;
86+
}
87+
});
88+
}
7089
} else {
71-
return this.resourceCreatorUpdater.updateResourceAsync()
72-
.subscribeOn(SdkContext.getRxScheduler())
73-
.doOnNext(new Action1<ResourceT>() {
74-
@Override
75-
public void call(ResourceT resourceT) {
76-
resource = resourceT;
77-
}
78-
})
79-
.map(new Func1<ResourceT, Indexable>() {
80-
@Override
81-
public Indexable call(ResourceT resourceT) {
82-
return resourceT;
83-
}
84-
});
90+
if (this.resourceCreatorUpdater.isInCreateMode()) {
91+
return this.resourceCreatorUpdater.createResourceAsync()
92+
.subscribeOn(SdkContext.getRxScheduler())
93+
.doOnNext(new Action1<ResourceT>() {
94+
@Override
95+
public void call(ResourceT resourceT) {
96+
resource = resourceT;
97+
}
98+
}).map(new Func1<ResourceT, Indexable>() {
99+
@Override
100+
public Indexable call(ResourceT resourceT) {
101+
return resourceT;
102+
}
103+
});
104+
} else {
105+
return this.resourceCreatorUpdater.updateResourceAsync()
106+
.subscribeOn(SdkContext.getRxScheduler())
107+
.doOnNext(new Action1<ResourceT>() {
108+
@Override
109+
public void call(ResourceT resourceT) {
110+
resource = resourceT;
111+
}
112+
})
113+
.map(new Func1<ResourceT, Indexable>() {
114+
@Override
115+
public Indexable call(ResourceT resourceT) {
116+
return resourceT;
117+
}
118+
});
119+
}
85120
}
86121
}
87122

@@ -130,6 +165,22 @@ public interface ResourceCreatorUpdater<T extends Indexable> {
130165
*/
131166
Observable<T> updateResourceAsync();
132167

168+
/**
169+
* Creates the resource asynchronously.
170+
*
171+
* @param context the context for request
172+
* @return an observable that create the resource when subscribed
173+
*/
174+
Observable<T> createResourceAsync(Context context);
175+
176+
/**
177+
* Update the resource asynchronously.
178+
*
179+
* @param context the context for request
180+
* @return an observable that update the resource when subscribed
181+
*/
182+
Observable<T> updateResourceAsync(Context context);
183+
133184
/**
134185
* @return true if the observable returned by {@link this#createResourceAsync()} and
135186
* {@link this#updateResourceAsync()} are hot observables, false if they are cold

0 commit comments

Comments
 (0)