Skip to content

Commit 696df6d

Browse files
authored
mgmt resources, fix generic resources api version (Azure#36194)
* fix default api-version unused import * assets.json * combine exact and relaxed match * fix potential bug for level > 2 * do relaxed match after exact match * fix lower case * deprecate v1 ApplicationGatewaySku * add javadocs * assets.json * javadocs and assets.json * remove relaxed match
1 parent 97d9896 commit 696df6d

File tree

8 files changed

+141
-25
lines changed

8 files changed

+141
-25
lines changed

sdk/resourcemanager/api-specs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@
175175
"dir": "azure-resourcemanager-network",
176176
"source": "specification/network/resource-manager/readme.md",
177177
"package": "com.azure.resourcemanager.network",
178-
"args": "--tag=package-2023-02 --add-inner=ApplicationGatewayIpConfiguration,ApplicationGatewayPathRule,ApplicationGatewayProbe,ApplicationGatewayRedirectConfiguration,ApplicationGatewayRequestRoutingRule,ApplicationGatewaySslCertificate,ApplicationGatewayUrlPathMap,ApplicationGatewayAuthenticationCertificate,VirtualNetworkGatewayIpConfiguration,ConnectionMonitor,PacketCapture,ApplicationGateway,ApplicationGatewayListener"
178+
"args": "--tag=package-2023-02 --add-inner=ApplicationGatewayIpConfiguration,ApplicationGatewayPathRule,ApplicationGatewayProbe,ApplicationGatewayRedirectConfiguration,ApplicationGatewayRequestRoutingRule,ApplicationGatewaySslCertificate,ApplicationGatewayUrlPathMap,ApplicationGatewayAuthenticationCertificate,VirtualNetworkGatewayIpConfiguration,ConnectionMonitor,PacketCapture,ApplicationGateway,ApplicationGatewayListener",
179+
"note": "Deprecate v1 sku/tier in ApplicationGatewaySku(except BASIC) and add deprecation javadocs."
179180
},
180181
"network-hybrid": {
181182
"dir": "../resourcemanagerhybrid/azure-resourcemanager-network",

sdk/resourcemanager/azure-resourcemanager-network/src/main/java/com/azure/resourcemanager/network/models/ApplicationGateway.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ interface WithSku {
403403
*
404404
* <p>Application Gateway V1 is officially deprecated on April 28, 2023.
405405
*
406-
* See <a href="https://learn.microsoft.com/en-us/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
406+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
407407
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.</p>
408408
*
409409
* @param tier the tier value to set
@@ -420,7 +420,7 @@ interface WithSku {
420420
* <p>By default, the smallest size is used.
421421
*
422422
* <p>Application Gateway V1 is officially deprecated on April 28, 2023.
423-
* See <a href="https://learn.microsoft.com/en-us/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
423+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
424424
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.</p>
425425
*
426426
* @param size an application gateway SKU name
@@ -1002,7 +1002,7 @@ interface WithSku {
10021002
* Set tier of an application gateway. Possible values include: 'Standard', 'WAF', 'Standard_v2', 'WAF_v2'.
10031003
*
10041004
* <p>Application Gateway V1 is officially deprecated on April 28, 2023.
1005-
* See <a href="https://learn.microsoft.com/en-us/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
1005+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
10061006
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.</p>
10071007
*
10081008
* @param tier the tier value to set
@@ -1014,7 +1014,7 @@ interface WithSku {
10141014
* Specifies the size of the application gateway to use within the context of the selected tier.
10151015
*
10161016
* <p>Application Gateway V1 is officially deprecated on April 28, 2023.
1017-
* See <a href="https://learn.microsoft.com/en-us/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
1017+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
10181018
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.</p>
10191019
*
10201020
* @param size an application gateway size name

sdk/resourcemanager/azure-resourcemanager-network/src/main/java/com/azure/resourcemanager/network/models/ApplicationGatewaySkuName.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,54 @@
1010

1111
/** Name of an application gateway SKU. */
1212
public final class ApplicationGatewaySkuName extends ExpandableStringEnum<ApplicationGatewaySkuName> {
13-
/** Static value Standard_Small for ApplicationGatewaySkuName. */
13+
/**
14+
* Static value Standard_Small for ApplicationGatewaySkuName.
15+
*
16+
* @deprecated Application Gateway V1 is officially deprecated on April 28, 2023.
17+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
18+
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.
19+
*/
20+
@Deprecated
1421
public static final ApplicationGatewaySkuName STANDARD_SMALL = fromString("Standard_Small");
1522

16-
/** Static value Standard_Medium for ApplicationGatewaySkuName. */
23+
/**
24+
* Static value Standard_Medium for ApplicationGatewaySkuName.
25+
*
26+
* @deprecated Application Gateway V1 is officially deprecated on April 28, 2023.
27+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
28+
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.
29+
*/
30+
@Deprecated
1731
public static final ApplicationGatewaySkuName STANDARD_MEDIUM = fromString("Standard_Medium");
1832

19-
/** Static value Standard_Large for ApplicationGatewaySkuName. */
33+
/**
34+
* Static value Standard_Large for ApplicationGatewaySkuName.
35+
*
36+
* @deprecated Application Gateway V1 is officially deprecated on April 28, 2023.
37+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
38+
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.
39+
*/
40+
@Deprecated
2041
public static final ApplicationGatewaySkuName STANDARD_LARGE = fromString("Standard_Large");
2142

22-
/** Static value WAF_Medium for ApplicationGatewaySkuName. */
43+
/**
44+
* Static value WAF_Medium for ApplicationGatewaySkuName.
45+
*
46+
* @deprecated Application Gateway V1 is officially deprecated on April 28, 2023.
47+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
48+
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.
49+
*/
50+
@Deprecated
2351
public static final ApplicationGatewaySkuName WAF_MEDIUM = fromString("WAF_Medium");
2452

25-
/** Static value WAF_Large for ApplicationGatewaySkuName. */
53+
/**
54+
* Static value WAF_Large for ApplicationGatewaySkuName.
55+
*
56+
* @deprecated Application Gateway V1 is officially deprecated on April 28, 2023.
57+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
58+
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.
59+
*/
60+
@Deprecated
2661
public static final ApplicationGatewaySkuName WAF_LARGE = fromString("WAF_Large");
2762

2863
/** Static value Standard_v2 for ApplicationGatewaySkuName. */

sdk/resourcemanager/azure-resourcemanager-network/src/main/java/com/azure/resourcemanager/network/models/ApplicationGatewayTier.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@
1010

1111
/** Tier of an application gateway. */
1212
public final class ApplicationGatewayTier extends ExpandableStringEnum<ApplicationGatewayTier> {
13-
/** Static value Standard for ApplicationGatewayTier. */
13+
/**
14+
* Static value Standard for ApplicationGatewayTier.
15+
*
16+
* @deprecated Application Gateway V1 is officially deprecated on April 28, 2023.
17+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
18+
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.
19+
*/
20+
@Deprecated
1421
public static final ApplicationGatewayTier STANDARD = fromString("Standard");
1522

16-
/** Static value WAF for ApplicationGatewayTier. */
23+
/**
24+
* Static value WAF for ApplicationGatewayTier.
25+
*
26+
* @deprecated Application Gateway V1 is officially deprecated on April 28, 2023.
27+
* See <a href="https://learn.microsoft.com/azure/application-gateway/v1-retirement#retirement-timelines">v1-retirement-timeline</a>
28+
* for V1 retirement timeline and start planning your migration to Application Gateway V2 today.
29+
*/
30+
@Deprecated
1731
public static final ApplicationGatewayTier WAF = fromString("WAF");
1832

1933
/** Static value Standard_v2 for ApplicationGatewayTier. */

sdk/resourcemanager/azure-resourcemanager-resources/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
### Bugs Fixed
1010

11+
- Fixed a bug that `GenericResources.deleteById` might select the wrong default api-version for resources whose child
12+
resource type collides with other resources.
13+
1114
### Other Changes
1215

1316
## 2.29.0 (2023-07-28)

sdk/resourcemanager/azure-resourcemanager-resources/src/main/java/com/azure/resourcemanager/resources/fluentcore/arm/ResourceUtils.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.azure.resourcemanager.resources.fluentcore.arm;
55

6+
import com.azure.core.util.CoreUtils;
67
import com.azure.resourcemanager.resources.models.Provider;
78
import com.azure.resourcemanager.resources.models.ProviderResourceType;
89

@@ -156,23 +157,22 @@ public static String nameFromResourceId(String id) {
156157
* @return the default api version to use
157158
*/
158159
public static String defaultApiVersion(String id, Provider provider) {
159-
String resourceType = resourceTypeFromResourceId(id).toLowerCase(Locale.ROOT);
160-
// Exact match
161-
for (ProviderResourceType prt : provider.resourceTypes()) {
162-
if (prt.resourceType().equalsIgnoreCase(resourceType)) {
163-
return prt.defaultApiVersion() == null ? prt.apiVersions().get(0) : prt.defaultApiVersion();
164-
}
160+
if (id == null || provider == null) {
161+
return null;
165162
}
166-
// child resource, e.g. sites/config
163+
ResourceId resourceId = ResourceId.fromString(id);
164+
String resourceTypeWithoutNamespace = getFullResourceTypeWithoutNamespace(resourceId);
167165
for (ProviderResourceType prt : provider.resourceTypes()) {
168-
if (prt.resourceType().toLowerCase(Locale.ROOT).contains("/" + resourceType)) {
166+
// There is an edge case that two resource types share the same child resource type name, so parent type name check is needed.
167+
// e.g. "dnsForwardingRulesets/virtualNetworkLinks" and "privateDnsZones/virtualNetworkLinks"
168+
if (prt.resourceType().equalsIgnoreCase(resourceTypeWithoutNamespace)) {
169169
return prt.defaultApiVersion() == null ? prt.apiVersions().get(0) : prt.defaultApiVersion();
170170
}
171171
}
172-
// look for parent
173-
String parentId = parentResourceIdFromResourceId(id);
174-
if (parentId != null) {
175-
return defaultApiVersion(parentId, provider);
172+
173+
ResourceId parent = resourceId.parent();
174+
if (parent != null && !CoreUtils.isNullOrEmpty(parent.id())) {
175+
return defaultApiVersion(parent.id(), provider);
176176
} else {
177177
// Fallback: use a random one, not guaranteed to work
178178
return provider.resourceTypes().get(0).apiVersions().get(0);
@@ -224,4 +224,10 @@ public static String encodeResourceId(String resourceId) {
224224
}
225225
return resourceId.replaceAll(" ", "%20");
226226
}
227+
228+
private static String getFullResourceTypeWithoutNamespace(ResourceId resourceId) {
229+
return resourceId.fullResourceType()
230+
.substring(resourceId.fullResourceType().indexOf("/") + 1) // e.g. "Microsoft.Web/sites" will return "sites"
231+
.toLowerCase(Locale.ROOT);
232+
}
227233
}

sdk/resourcemanager/azure-resourcemanager/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/resourcemanager/azure-resourcemanager",
5-
"Tag": "java/resourcemanager/azure-resourcemanager_eaff6e96ea"
5+
"Tag": "java/resourcemanager/azure-resourcemanager_ff6a2c95f8"
66
}

sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/GenericResourceTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
import com.azure.core.http.policy.RetryPolicy;
1212
import com.azure.core.management.Region;
1313
import com.azure.core.management.profile.AzureProfile;
14+
import com.azure.resourcemanager.appservice.fluent.models.SiteConfigResourceInner;
15+
import com.azure.resourcemanager.appservice.models.NetFrameworkVersion;
16+
import com.azure.resourcemanager.appservice.models.PricingTier;
17+
import com.azure.resourcemanager.appservice.models.SupportedTlsVersions;
18+
import com.azure.resourcemanager.network.models.Network;
19+
import com.azure.resourcemanager.privatedns.models.PrivateDnsZone;
1420
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
1521
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
1622
import com.azure.resourcemanager.resources.models.GenericResource;
@@ -129,6 +135,57 @@ public void testResourceWithSpaceInName() {
129135
azureResourceManager.genericResources().deleteById(poolId);
130136
}
131137

138+
@Test
139+
public void canGetDefaultApiVersionForChildResources() {
140+
// test privateDnsZones/virtualNetworkLinks which has the same child resource name as dnsForwardingRulesets/virtualNetworkLinks
141+
String vnetName = generateRandomResourceName("vnet", 15);
142+
String topLevelDomain = "www.contoso" + generateRandomResourceName("z", 10) + ".com";
143+
String vnetLinkName = generateRandomResourceName("pdvnl", 15);
144+
145+
Network network = azureResourceManager.networks().define(vnetName)
146+
.withRegion(region)
147+
.withNewResourceGroup(rgName)
148+
.withAddressSpace("10.0.0.0/28")
149+
.withSubnet("subnetA", "10.0.0.0/29")
150+
.create();
151+
152+
PrivateDnsZone pdz = azureResourceManager.privateDnsZones().define(topLevelDomain)
153+
.withExistingResourceGroup(rgName)
154+
.defineVirtualNetworkLink(vnetLinkName)
155+
.disableAutoRegistration()
156+
.withVirtualNetworkId(network.id())
157+
.withETagCheck()
158+
.attach()
159+
.create();
160+
161+
String vnetLinkId = pdz.virtualNetworkLinks().list().stream().iterator().next().id();
162+
GenericResource vnetLink = azureResourceManager.genericResources().getById(vnetLinkId);
163+
Assertions.assertEquals(vnetLinkName, vnetLink.name());
164+
165+
azureResourceManager.genericResources().deleteById(vnetLinkId);
166+
167+
// test sites/config, which searches its parent's(sites) api-version
168+
String webappName = generateRandomResourceName("webapp", 15);
169+
azureResourceManager.webApps()
170+
.define(webappName)
171+
.withRegion(Region.US_EAST)
172+
.withNewResourceGroup(rgName)
173+
.withNewWindowsPlan(PricingTier.BASIC_B1)
174+
.withNetFrameworkVersion(NetFrameworkVersion.V3_0)
175+
.withMinTlsVersion(SupportedTlsVersions.ONE_ONE)
176+
.create();
177+
178+
SiteConfigResourceInner configInner = azureResourceManager
179+
.webApps()
180+
.manager()
181+
.serviceClient()
182+
.getWebApps()
183+
.getConfiguration(rgName, webappName);
184+
185+
GenericResource genericConfig = azureResourceManager.genericResources().getById(configInner.id());
186+
Assertions.assertEquals(configInner.name(), genericConfig.name());
187+
}
188+
132189
private SqlElasticPool ensureElasticPoolWithSpace() {
133190
String sqlServerName = generateRandomResourceName("JMonitorSql-", 18);
134191

0 commit comments

Comments
 (0)