diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index c2ce58888a1e..fdd679e240a7 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -289,7 +289,7 @@ com.azure.resourcemanager:azure-resourcemanager-msi;2.53.4;2.54.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-network;2.56.0;2.57.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-privatedns;2.53.4;2.54.0-beta.1 -com.azure.resourcemanager:azure-resourcemanager-resources;2.53.4;2.54.0-beta.1 +com.azure.resourcemanager:azure-resourcemanager-resources;2.53.4;2.53.5 com.azure.resourcemanager:azure-resourcemanager-redis;2.53.4;2.54.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-samples;2.0.0-beta.1;2.0.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-search;2.54.3;2.55.0-beta.1 diff --git a/sdk/resources/azure-resourcemanager-resources/README.md b/sdk/resources/azure-resourcemanager-resources/README.md index d8573aa29b9a..28acacb1e9ad 100644 --- a/sdk/resources/azure-resourcemanager-resources/README.md +++ b/sdk/resources/azure-resourcemanager-resources/README.md @@ -18,7 +18,7 @@ For documentation on how to use this package, please see [Azure Management Libra com.azure.resourcemanager azure-resourcemanager-resources - 2.53.1 + 2.53.5 ``` [//]: # ({x-version-update-end}) diff --git a/sdk/resources/azure-resourcemanager-resources/pom.xml b/sdk/resources/azure-resourcemanager-resources/pom.xml index b36c8b5f5e6b..ba603666989d 100644 --- a/sdk/resources/azure-resourcemanager-resources/pom.xml +++ b/sdk/resources/azure-resourcemanager-resources/pom.xml @@ -14,7 +14,7 @@ com.azure.resourcemanager azure-resourcemanager-resources - 2.54.0-beta.1 + 2.53.5 jar Microsoft Azure SDK for Resource Management diff --git a/sdk/resources/azure-resourcemanager-resources/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java b/sdk/resources/azure-resourcemanager-resources/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java index e3d5238a153e..5045b82e8444 100644 --- a/sdk/resources/azure-resourcemanager-resources/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java +++ b/sdk/resources/azure-resourcemanager-resources/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java @@ -10,8 +10,8 @@ import com.azure.core.management.AzureEnvironment; import com.azure.core.management.exception.ManagementError; import com.azure.core.management.exception.ManagementException; -import com.azure.core.management.polling.PollerFactory; import com.azure.core.management.polling.PollResult; +import com.azure.core.management.polling.PollerFactory; import com.azure.core.util.Context; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; @@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * ServiceClient is the abstraction for accessing REST operations and their payload data types. @@ -39,12 +40,12 @@ public abstract class AzureServiceClient { private final ClientLogger logger = new ClientLogger(getClass()); - private final String sdkVersion; - private final SerializerAdapter serializerAdapter; private final HttpPipeline httpPipeline; - private final String sdkName; + // A holder to record "service client instance class -> version of the library where it belongs". + private static final Map, String> SDK_VERSION_MAP = new ConcurrentHashMap<>(); + private static final String UNKNOWN_VERSION = "UnknownVersion"; /** * Creates a new instance of {@link AzureServiceClient}. @@ -58,20 +59,8 @@ protected AzureServiceClient(HttpPipeline httpPipeline, SerializerAdapter serial this.httpPipeline = httpPipeline; this.serializerAdapter = serializerAdapter; - String packageName = this.getClass().getPackage().getName(); - String implementationSegment = ".implementation"; - if (packageName.endsWith(implementationSegment)) { - packageName = packageName.substring(0, packageName.length() - implementationSegment.length()); - } - this.sdkName = packageName; - if (packageName.startsWith("com.")) { - // com.azure.resourcemanager.compute -> azure-resourcemanager-compute.properties - String artifactId = packageName.substring("com.".length()).replace(".", "-"); - Map properties = CoreUtils.getProperties(artifactId + ".properties"); - sdkVersion = properties.getOrDefault("version", "UnknownVersion"); - } else { - sdkVersion = "UnknownVersion"; - } + // register SDK info during initialization, speed up future retrievals + readSdkVersionFromPropertiesFileIfAbsent(this.getClass()); } /** @@ -105,7 +94,8 @@ public HttpPipeline getHttpPipeline() { * @return the default client context. */ public Context getContext() { - return new Context("Sdk-Name", sdkName).addData("Sdk-Version", sdkVersion); + return new Context("Sdk-Name", getSdkName(getClass())).addData("Sdk-Version", + readSdkVersionFromPropertiesFileIfAbsent(getClass())); } /** @@ -184,6 +174,43 @@ public Mono getLroFinalResultOrError(AsyncPollResponse, } } + /** + * Gets the SDK version of the provided service client instance class. + * If not cached, read from properties file. + * + * @param serviceClientClazz the service client instance class + * @return the sdk info of the provided service client instance class + */ + private String readSdkVersionFromPropertiesFileIfAbsent(Class serviceClientClazz) { + return SDK_VERSION_MAP.computeIfAbsent(serviceClientClazz, ignored -> { + String sdkName = getSdkName(serviceClientClazz); + if (sdkName.startsWith("com.")) { + // com.azure.resourcemanager.compute -> azure-resourcemanager-compute.properties + String artifactId = sdkName.substring("com.".length()).replace(".", "-"); + Map properties = CoreUtils.getProperties(artifactId + ".properties"); + return properties.getOrDefault("version", UNKNOWN_VERSION); + } else { + return UNKNOWN_VERSION; + } + }); + } + + /** + * Gets the sdk name where current service client instance class belongs. + * + * @param serviceClientClazz service client instance class + * @return the sdk name where current service client instance class belongs. + */ + private static String getSdkName(Class serviceClientClazz) { + String packageName = serviceClientClazz.getPackage().getName(); + + String implementationSegment = ".implementation"; + if (packageName.endsWith(implementationSegment)) { + packageName = packageName.substring(0, packageName.length() - implementationSegment.length()); + } + return packageName; + } + private static class HttpResponseImpl extends HttpResponse { private final int statusCode; private final byte[] responseBody;