Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/resources/azure-resourcemanager-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For documentation on how to use this package, please see [Azure Management Libra
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-resources</artifactId>
<version>2.53.1</version>
<version>2.53.5</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand Down
2 changes: 1 addition & 1 deletion sdk/resources/azure-resourcemanager-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-resources</artifactId>
<version>2.54.0-beta.1</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;current} -->
<version>2.53.5</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;current} -->
<packaging>jar</packaging>

<name>Microsoft Azure SDK for Resource Management</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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<Class<? extends AzureServiceClient>, String> SDK_VERSION_MAP = new ConcurrentHashMap<>();
private static final String UNKNOWN_VERSION = "UnknownVersion";

/**
* Creates a new instance of {@link AzureServiceClient}.
Expand All @@ -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<String, String> 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());
}

/**
Expand Down Expand Up @@ -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()));
}

/**
Expand Down Expand Up @@ -184,6 +174,43 @@ public <T, U> Mono<U> getLroFinalResultOrError(AsyncPollResponse<PollResult<T>,
}
}

/**
* 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<? extends AzureServiceClient> 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<String, String> 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<? extends AzureServiceClient> 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;
Expand Down
Loading