Skip to content

Commit c451395

Browse files
mgmt, support kind, sku, identity for generic resource (Azure#19449)
1 parent 1dfc609 commit c451395

File tree

4 files changed

+400
-0
lines changed

4 files changed

+400
-0
lines changed

sdk/resourcemanager/azure-resourcemanager-resources/src/main/java/com/azure/resourcemanager/resources/implementation/GenericResourceImpl.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
import com.azure.resourcemanager.resources.fluentcore.model.implementation.AcceptedImpl;
1010
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
1111
import com.azure.resourcemanager.resources.models.GenericResource;
12+
import com.azure.resourcemanager.resources.models.Identity;
1213
import com.azure.resourcemanager.resources.models.Plan;
1314
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils;
1415
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
1516
import com.azure.resourcemanager.resources.fluent.models.GenericResourceInner;
1617
import com.azure.resourcemanager.resources.fluent.ResourcesClient;
18+
import com.azure.resourcemanager.resources.models.ResourceIdentityType;
19+
import com.azure.resourcemanager.resources.models.Sku;
1720
import reactor.core.publisher.Mono;
1821

1922
/**
@@ -84,6 +87,26 @@ public Object properties() {
8487
return innerModel().properties();
8588
}
8689

90+
@Override
91+
public String kind() {
92+
return innerModel().kind();
93+
}
94+
95+
@Override
96+
public Sku sku() {
97+
return innerModel().sku();
98+
}
99+
100+
@Override
101+
public Identity identity() {
102+
return innerModel().identity();
103+
}
104+
105+
@Override
106+
public String managedBy() {
107+
return innerModel().managedBy();
108+
}
109+
87110
@Override
88111
protected Mono<GenericResourceInner> getInnerAsync() {
89112
return this.manager().serviceClient().getResources().getAsync(
@@ -100,6 +123,30 @@ public GenericResourceImpl withProperties(Object properties) {
100123
return this;
101124
}
102125

126+
@Override
127+
public GenericResourceImpl withKind(String kind) {
128+
innerModel().withKind(kind);
129+
return this;
130+
}
131+
132+
@Override
133+
public GenericResourceImpl withSku(Sku sku) {
134+
innerModel().withSku(sku);
135+
return this;
136+
}
137+
138+
@Override
139+
public GenericResourceImpl withIdentity(Identity identity) {
140+
innerModel().withIdentity(identity);
141+
return this;
142+
}
143+
144+
@Override
145+
public GenericResourceImpl withoutIdentity() {
146+
innerModel().withIdentity(new Identity().withType(ResourceIdentityType.NONE));
147+
return this;
148+
}
149+
103150
@Override
104151
public GenericResourceImpl withParentResourceId(String parentResourceId) {
105152
return withParentResourcePath(ResourceUtils.relativePathFromResourceId(parentResourceId));

sdk/resourcemanager/azure-resourcemanager-resources/src/main/java/com/azure/resourcemanager/resources/models/GenericResource.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ public interface GenericResource extends
5252
*/
5353
Object properties();
5454

55+
/**
56+
* @return the kind of the resource
57+
*/
58+
String kind();
59+
60+
/**
61+
* @return the SKU of the resource
62+
*/
63+
Sku sku();
64+
65+
/**
66+
* @return the managed identity of the resource
67+
*/
68+
Identity identity();
69+
70+
/**
71+
* @return the ID of the resource that manages this resource
72+
*/
73+
String managedBy();
74+
5575
/**
5676
* The entirety of the generic resource definition.
5777
*/
@@ -183,6 +203,30 @@ interface WithCreate extends
183203
*/
184204
WithCreate withProperties(Object properties);
185205

206+
/**
207+
* Specifies resource kind.
208+
*
209+
* @param kind the kind of the resource
210+
* @return the next stage of generic resource definition
211+
*/
212+
WithCreate withKind(String kind);
213+
214+
/**
215+
* Specifies resource SKU.
216+
*
217+
* @param sku the SKU of the resource
218+
* @return the next stage of generic resource definition
219+
*/
220+
WithCreate withSku(Sku sku);
221+
222+
/**
223+
* Specifies managed identity.
224+
*
225+
* @param identity the managed identity
226+
* @return the next stage of generic resource definition
227+
*/
228+
WithCreate withIdentity(Identity identity);
229+
186230
/**
187231
* Begins creating the Azure resource.
188232
*
@@ -265,6 +309,52 @@ interface WithApiVersion {
265309
*/
266310
Update withApiVersion(String apiVersion);
267311
}
312+
313+
/**
314+
* The template for a generic resource update operation for specifying the resource kind.
315+
*/
316+
interface WithKind {
317+
/**
318+
* Specifies resource kind.
319+
*
320+
* @param kind the kind of the resource
321+
* @return the next stage of generic resource update
322+
*/
323+
Update withKind(String kind);
324+
}
325+
326+
/**
327+
* The template for a generic resource update operation for specifying the resource SKU.
328+
*/
329+
interface WithSku {
330+
/**
331+
* Specifies resource SKU.
332+
*
333+
* @param sku the SKU of the resource
334+
* @return the next stage of generic resource update
335+
*/
336+
Update withSku(Sku sku);
337+
}
338+
339+
/**
340+
* The template for a generic resource update operation for specifying the managed identity.
341+
*/
342+
interface WithIdentity {
343+
/**
344+
* Specifies managed identity.
345+
*
346+
* @param identity the managed identity
347+
* @return the next stage of generic resource update
348+
*/
349+
Update withIdentity(Identity identity);
350+
351+
/**
352+
* Specifies managed identity.
353+
*
354+
* @return the next stage of generic resource update
355+
*/
356+
Update withoutIdentity();
357+
}
268358
}
269359

270360
/**
@@ -276,6 +366,9 @@ interface Update extends
276366
UpdateStages.WithPlan,
277367
UpdateStages.WithParentResource,
278368
UpdateStages.WithProperties,
369+
UpdateStages.WithKind,
370+
UpdateStages.WithSku,
371+
UpdateStages.WithIdentity,
279372
Resource.UpdateWithTags<Update> {
280373
}
281374
}

sdk/resourcemanager/azure-resourcemanager-resources/src/test/java/com/azure/resourcemanager/resources/GenericResourcesTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
1717
import com.azure.resourcemanager.resources.models.GenericResource;
1818
import com.azure.resourcemanager.resources.models.GenericResources;
19+
import com.azure.resourcemanager.resources.models.Identity;
1920
import com.azure.resourcemanager.resources.models.ResourceGroups;
21+
import com.azure.resourcemanager.resources.models.ResourceIdentityType;
22+
import com.azure.resourcemanager.resources.models.Sku;
2023
import com.fasterxml.jackson.databind.ObjectMapper;
2124
import org.junit.jupiter.api.Assertions;
2225
import org.junit.jupiter.api.Test;
@@ -145,4 +148,43 @@ public void canCreateDeleteResourceSyncPoll() throws Exception {
145148
boolean deleted = resourcesAfterDelete.stream().noneMatch(r -> resourceName.equals(r.name()));
146149
Assertions.assertTrue(deleted);
147150
}
151+
152+
@Test
153+
public void canCreateUpdateKindSkuIdentity() throws Exception {
154+
final String resourceName = "rs" + testId;
155+
final String apiVersion = "2021-01-01";
156+
157+
GenericResource storageResource = resourceClient.genericResources().define(resourceName)
158+
.withRegion(Region.US_WEST)
159+
.withExistingResourceGroup(rgName)
160+
.withResourceType("storageAccounts")
161+
.withProviderNamespace("Microsoft.Storage")
162+
.withoutPlan()
163+
.withKind("Storage")
164+
.withSku(new Sku().withName("Standard_LRS"))
165+
.withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
166+
.withProperties(new ObjectMapper().readTree("{\"minimumTlsVersion\": \"TLS1_2\", \"supportsHttpsTrafficOnly\": true}"))
167+
.withApiVersion(apiVersion)
168+
.create();
169+
Assertions.assertEquals("Storage", storageResource.kind());
170+
Assertions.assertEquals("Standard_LRS", storageResource.sku().name());
171+
Assertions.assertNotNull(storageResource.identity());
172+
Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, storageResource.identity().type());
173+
Assertions.assertNotNull(storageResource.identity().principalId());
174+
Assertions.assertNotNull(storageResource.identity().tenantId());
175+
176+
storageResource.update()
177+
.withKind("StorageV2")
178+
.withoutIdentity()
179+
.withApiVersion(apiVersion)
180+
.apply();
181+
Assertions.assertEquals("StorageV2", storageResource.kind());
182+
Assertions.assertEquals(ResourceIdentityType.NONE, storageResource.identity().type());
183+
184+
storageResource.update()
185+
.withSku(new Sku().withName("Standard_RAGRS"))
186+
.withApiVersion(apiVersion)
187+
.apply();
188+
Assertions.assertEquals("Standard_RAGRS", storageResource.sku().name());
189+
}
148190
}

0 commit comments

Comments
 (0)