Skip to content
Merged
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
4 changes: 2 additions & 2 deletions sdk/management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Azure Management Libraries require a `TokenCredential` implementation for authen
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.0-beta.5</version>
<version>1.0.8</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand All @@ -58,7 +58,7 @@ Azure Management Libraries require a `TokenCredential` implementation for authen
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand Down
9 changes: 2 additions & 7 deletions sdk/management/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
Expand Down Expand Up @@ -113,13 +108,13 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.4.0</version>
<version>1.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.0-beta.3</version>
<version>1.0.8</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
11 changes: 7 additions & 4 deletions sdk/resources/mgmt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
</developers>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
Expand Down Expand Up @@ -92,6 +88,13 @@
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Comment on lines +91 to +96
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now doing this for version @yungezz


<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,22 @@ public abstract class AzureServiceClient {

private final ClientLogger logger = new ClientLogger(getClass());

protected AzureServiceClient(HttpPipeline httpPipeline, AzureEnvironment environment) {
((AzureJacksonAdapter) serializerAdapter).serializer().registerModule(DateTimeDeserializer.getModule());
}

private static final String OS;
private static final String OS_NAME;
private static final String OS_VERSION;
private static final String JAVA_VERSION;
private static final String SDK_VERSION = "2.0.0-SNAPSHOT";
private static final Map<String, String> PROPERTIES =
CoreUtils.getProperties("azure.properties");

private static final String SDK_VERSION;
static {
OS_NAME = System.getProperty("os.name");
OS_VERSION = System.getProperty("os.version");
OS = OS_NAME + "/" + OS_VERSION;
String version = System.getProperty("java.version");
JAVA_VERSION = version != null ? version : "Unknown";
SDK_VERSION = PROPERTIES.getOrDefault("version", "UnknownVersion");
}

private final SerializerAdapter serializerAdapter = new AzureJacksonAdapter();

private String sdkName;
private final String sdkName;

protected AzureServiceClient(HttpPipeline httpPipeline, AzureEnvironment environment) {
sdkName = this.getClass().getPackage().getName();
((AzureJacksonAdapter) serializerAdapter).serializer().registerModule(DateTimeDeserializer.getModule());
}

/**
* Gets serializer adapter for JSON serialization/de-serialization.
Expand All @@ -83,24 +78,8 @@ public SerializerAdapter getSerializerAdapter() {
* @return the default client context.
*/
public Context getContext() {
Context context = new Context("java.version", JAVA_VERSION);
if (!CoreUtils.isNullOrEmpty(OS_NAME)) {
context = context.addData("os.name", OS_NAME);
}
if (!CoreUtils.isNullOrEmpty(OS_VERSION)) {
context = context.addData("os.version", OS_VERSION);
}
if (sdkName == null) {
String packageName = this.getClass().getPackage().getName();
if (packageName.endsWith(".models")) {
sdkName = packageName.substring(0, packageName.length() - ".models".length());
} else {
sdkName = packageName;
}
}
context = context.addData("Sdk-Name", sdkName);
context = context.addData("Sdk-Version", SDK_VERSION);
return context;
return new Context("Sdk-Name", sdkName)
.addData("Sdk-Version", SDK_VERSION);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why sdk version hardcoded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be other approach. not investigated yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. let's fix it before GA.

Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already fixed in this PR.

now the flow is:

  1. maven package the project, one step it would populate azure.properties with its current project.version.
  2. jar now has this azure.properties packaged and released with the jar
  3. runtime, code read version from azure.properties

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,12 @@ public class UserAgentPolicy implements HttpPipelinePolicy {
private static final String SDK_VERSION_KEY = "Sdk-Version";
private static final String APPLICATION_ID_KEY = "Application-Id";

private static final String OS_NAME = System.getProperty("os.name");
private static final String OS_VERSION = System.getProperty("os.version");
private static final String JAVA_VERSION = System.getProperty("java.version");

/*
* The base User-Agent header format is azsdk-java-<client_lib>/<sdk_version>. Additional information such as the
* application ID will be prepended and platform telemetry will be appended, a fully configured User-Agent header
* format is <application_id> azsdk-java-<client_lib>/<sdk_version> <platform_info>.
*/
private static final String DEFAULT_USER_AGENT_FORMAT = "azsdk-java-%s/%s";

// From the design guidelines, the platform info format is:
// <language runtime>; <os name> <os version>
private static final String PLATFORM_INFO_FORMAT = "%s; %s %s";

private final String defaultSdkName = this.getClass().getPackage().getName();
private final String defaultSdkVersion = this.getClass().getPackage().getSpecificationVersion();

private final HttpLogOptions httpLogOptions;
private final Configuration configuration;

private static final UserAgentPolicy DEFAULT_USER_AGENT_POLICY = new UserAgentPolicy(null, null);

/**
* @return default user agent policy
*/
public static UserAgentPolicy getDefaultUserAgentPolicy() {
return DEFAULT_USER_AGENT_POLICY;
}

/**
* @param httpLogOptions used for get application id
* @param configuration used for check telemetry enable or not
Expand All @@ -69,32 +45,54 @@ public UserAgentPolicy(HttpLogOptions httpLogOptions, Configuration configuratio
}
}

protected String buildUserAgent(String applicationId, String sdkName, String sdkVersion) {
// begin of UserAgentUtil.toUserAgentString
public static final String DEFAULT_USER_AGENT_HEADER = "azsdk-java";
private static final String PLATFORM_INFO_FORMAT = "%s; %s; %s";
private static final int MAX_APP_ID_LENGTH = 24;

private static String toUserAgentString(String applicationId, String sdkName, String sdkVersion,
Configuration configuration) {
StringBuilder userAgentBuilder = new StringBuilder();

// Only add the application ID if it is present as it is optional.
if (applicationId != null) {
applicationId = applicationId.length() > MAX_APP_ID_LENGTH ? applicationId.substring(0, MAX_APP_ID_LENGTH)
: applicationId;
userAgentBuilder.append(applicationId).append(" ");
}

// Add the required default User-Agent string.
userAgentBuilder.append(String.format(DEFAULT_USER_AGENT_FORMAT, sdkName, sdkVersion));
userAgentBuilder.append(DEFAULT_USER_AGENT_HEADER)
.append("-")
.append(sdkName)
.append("/")
.append(sdkVersion);

// Only add the platform telemetry if it is allowed as it is optional.
if (!telemetryDisabled()) {
String platformInfo = String.format(PLATFORM_INFO_FORMAT, JAVA_VERSION, OS_NAME, OS_VERSION);
if (!isTelemetryDisabled(configuration)) {
userAgentBuilder.append(" ")
.append("(")
.append(platformInfo)
.append(")");
.append("(")
.append(getPlatformInfo())
.append(")");
}

return userAgentBuilder.toString();
}

private boolean telemetryDisabled() {
return configuration.get(Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED, false);
private static String getPlatformInfo() {
String javaVersion = Configuration.getGlobalConfiguration().get("java.version");
String osName = Configuration.getGlobalConfiguration().get("os.name");
String osVersion = Configuration.getGlobalConfiguration().get("os.version");

return String.format(PLATFORM_INFO_FORMAT, javaVersion, osName, osVersion);
}

private static boolean isTelemetryDisabled(Configuration configuration) {
return (configuration == null)
? Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED, false)
: configuration.get(Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED, false);
}
// end of UserAgentUtil.toUserAgentString

@Override
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
Expand Down Expand Up @@ -124,7 +122,9 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
applicationId = httpLogOptions.getApplicationId();
}

context.getHttpRequest().setHeader(USER_AGENT_KEY, buildUserAgent(applicationId, sdkName, sdkVersion));
context.getHttpRequest().setHeader(USER_AGENT_KEY,
//UserAgentUtil.toUserAgentString(applicationId, sdkName, sdkVersion, configuration));
toUserAgentString(applicationId, sdkName, sdkVersion, configuration));
return next.process();
}
}
1 change: 1 addition & 0 deletions sdk/resources/mgmt/src/main/resources/azure.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=${project.version}