diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/LogsQueryClientBuilder.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/LogsQueryClientBuilder.java index 53458299f1bb4..8c3a3a72a472f 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/LogsQueryClientBuilder.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/LogsQueryClientBuilder.java @@ -14,6 +14,7 @@ import com.azure.core.util.Configuration; import com.azure.core.util.logging.ClientLogger; import com.azure.monitor.query.implementation.logs.AzureLogAnalyticsImplBuilder; +import com.azure.monitor.query.models.LogsQueryClientAudience; /** * Fluent builder for creating instances of {@link LogsQueryClient} and {@link LogsQueryAsyncClient}. @@ -116,17 +117,29 @@ public LogsQueryClientBuilder credential(TokenCredential tokenCredential) { /** * Set the {@link ClientOptions} used for creating the client. * @param clientOptions The {@link ClientOptions}. - * @return the {@link LogsQueryClientBuilder} + * @return the {@link LogsQueryClientBuilder}. */ public LogsQueryClientBuilder clientOptions(ClientOptions clientOptions) { this.clientOptions = clientOptions; return this; } + /** + * Sets the audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience will be + * used if the property is null. + * @param audience audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience + * will be used if the property is null. + * @return the {@link LogsQueryClientBuilder}. + */ + public LogsQueryClientBuilder audience(LogsQueryClientAudience audience) { + innerLogBuilder.audience(audience == null ? null : audience.toString()); + return this; + } + /** * The service version to use when creating the client. * @param serviceVersion The {@link LogsQueryServiceVersion}. - * @return the {@link LogsQueryClientBuilder} + * @return the {@link LogsQueryClientBuilder}. */ public LogsQueryClientBuilder serviceVersion(LogsQueryServiceVersion serviceVersion) { this.serviceVersion = serviceVersion; diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/MetricsQueryClientBuilder.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/MetricsQueryClientBuilder.java index 903812e3a572d..2384a9cf838b4 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/MetricsQueryClientBuilder.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/MetricsQueryClientBuilder.java @@ -16,6 +16,7 @@ import com.azure.monitor.query.implementation.metrics.MonitorManagementClientImplBuilder; import com.azure.monitor.query.implementation.metricsdefinitions.MetricsDefinitionsClientImplBuilder; import com.azure.monitor.query.implementation.metricsnamespaces.MetricsNamespacesClientImplBuilder; +import com.azure.monitor.query.models.MetricsQueryClientAudience; /** * Fluent builder for creating instances of {@link MetricsQueryClient} and {@link MetricsQueryAsyncClient}. @@ -137,6 +138,20 @@ public MetricsQueryClientBuilder credential(TokenCredential tokenCredential) { return this; } + /** + * Sets the audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience will be + * used if the property is null. + * @param audience audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience + * will be used if the property is null. + * @return the {@link MetricsQueryClientBuilder}. + */ + public MetricsQueryClientBuilder audience(MetricsQueryClientAudience audience) { + innerMetricsBuilder.audience(audience == null ? null : audience.toString()); + innerMetricsDefinitionsBuilder.audience(audience == null ? null : audience.toString()); + innerMetricsNamespaceBuilder.audience(audience == null ? null : audience.toString()); + return this; + } + /** * Set the {@link ClientOptions} used for creating the client. * @param clientOptions The {@link ClientOptions}. diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/logs/AzureLogAnalyticsImplBuilder.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/logs/AzureLogAnalyticsImplBuilder.java index 9181980729998..b903bccb77d59 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/logs/AzureLogAnalyticsImplBuilder.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/logs/AzureLogAnalyticsImplBuilder.java @@ -21,6 +21,10 @@ import com.azure.core.util.CoreUtils; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.monitor.query.LogsQueryClientBuilder; +import com.azure.monitor.query.models.LogsQueryClientAudience; +import com.azure.monitor.query.models.MetricsQueryClientAudience; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,6 +37,7 @@ public final class AzureLogAnalyticsImplBuilder { private static final String SDK_VERSION = "version"; private final Map properties = CoreUtils.getProperties("azure-monitor-query.properties"); + private String audience; /** Create an instance of the AzureLogAnalyticsImplBuilder. */ public AzureLogAnalyticsImplBuilder() { @@ -185,6 +190,18 @@ public AzureLogAnalyticsImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { return this; } + /** + * Sets the audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience will be + * used if the property is null. + * @param audience audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience + * will be used if the property is null. + * @return the {@link AzureLogAnalyticsImplBuilder}. + */ + public AzureLogAnalyticsImplBuilder audience(String audience) { + this.audience = audience; + return this; + } + /** * Builds an instance of AzureLogAnalyticsImpl with the provided parameters. * @@ -192,15 +209,16 @@ public AzureLogAnalyticsImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { */ public AzureLogAnalyticsImpl buildClient() { if (host == null) { - this.host = "https://api.loganalytics.io/v1"; + this.host = "https://api.loganalytics.io"; } + String hostVersion = this.host + "/v1"; if (pipeline == null) { this.pipeline = createHttpPipeline(); } if (serializerAdapter == null) { this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); } - AzureLogAnalyticsImpl client = new AzureLogAnalyticsImpl(pipeline, serializerAdapter, host); + AzureLogAnalyticsImpl client = new AzureLogAnalyticsImpl(pipeline, serializerAdapter, hostVersion); return client; } @@ -217,8 +235,14 @@ private HttpPipeline createHttpPipeline() { new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration)); HttpPolicyProviders.addBeforeRetryPolicies(policies); + String resolvedAudience = this.audience; + if (resolvedAudience == null) { + resolvedAudience = LogsQueryClientAudience.AZURE_PUBLIC_CLOUD.toString(); + } + resolvedAudience += "/.default"; BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(this.tokenCredential, - "https://api.loganalytics.io/.default"); + resolvedAudience); + policies.add(tokenPolicy); policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); policies.add(new CookiePolicy()); diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metrics/MonitorManagementClientImplBuilder.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metrics/MonitorManagementClientImplBuilder.java index 4acc85e81e693..7d3ba5f022a02 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metrics/MonitorManagementClientImplBuilder.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metrics/MonitorManagementClientImplBuilder.java @@ -21,6 +21,8 @@ import com.azure.core.util.CoreUtils; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.monitor.query.models.MetricsQueryClientAudience; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,6 +35,7 @@ public final class MonitorManagementClientImplBuilder { private static final String SDK_VERSION = "version"; private final Map properties = CoreUtils.getProperties("azure-monitor-query.properties"); + private String audience; /** Create an instance of the MonitorManagementClientImplBuilder. */ public MonitorManagementClientImplBuilder() { @@ -201,6 +204,18 @@ public MonitorManagementClientImplBuilder addPolicy(HttpPipelinePolicy customPol return this; } + /** + * Sets the audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience will be + * used if the property is null. + * @param audience audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience + * will be used if the property is null. + * @return the {@link MonitorManagementClientImplBuilder}. + */ + public MonitorManagementClientImplBuilder audience(String audience) { + this.audience = audience; + return this; + } + /** * Builds an instance of MonitorManagementClientImpl with the provided parameters. * @@ -210,6 +225,7 @@ public MonitorManagementClientImpl buildClient() { if (host == null) { this.host = "https://management.azure.com"; } + if (apiVersion == null) { this.apiVersion = "2018-01-01"; } @@ -237,8 +253,13 @@ private HttpPipeline createHttpPipeline() { new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration)); HttpPolicyProviders.addBeforeRetryPolicies(policies); policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); - BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(this.tokenCredential, " https://management.azure.com" + - "/.default"); + String resolvedAudience = this.audience; + if (resolvedAudience == null) { + resolvedAudience = MetricsQueryClientAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD.toString(); + } + resolvedAudience += "/.default"; + BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(this.tokenCredential, + resolvedAudience); policies.add(tokenPolicy); policies.add(new CookiePolicy()); policies.addAll(this.pipelinePolicies); diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricDefinitionsImpl.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricDefinitionsImpl.java index 47f4eb1763e07..0f3b26b180e07 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricDefinitionsImpl.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricDefinitionsImpl.java @@ -15,12 +15,14 @@ import com.azure.core.annotation.ServiceInterface; import com.azure.core.annotation.ServiceMethod; import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.HttpResponseException; import com.azure.core.http.rest.PagedFlux; import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.PagedResponse; import com.azure.core.http.rest.PagedResponseBase; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; +import com.azure.core.models.ResponseError; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; import com.azure.monitor.query.implementation.metricsdefinitions.models.ErrorResponseException; @@ -96,6 +98,8 @@ public Mono> listSinglePageAsync(String resource metricnamespace, accept, context)) + .onErrorMap(ErrorResponseException.class, ex -> new HttpResponseException(ex.getMessage(), + ex.getResponse(), new ResponseError(ex.getValue().getCode(), ex.getValue().getMessage()))) .map( res -> new PagedResponseBase<>( @@ -136,6 +140,8 @@ public Mono> listSinglePageAsync( metricnamespace, accept, context) + .onErrorMap(ErrorResponseException.class, ex -> new HttpResponseException(ex.getMessage(), + ex.getResponse(), new ResponseError(ex.getValue().getCode(), ex.getValue().getMessage()))) .map( res -> new PagedResponseBase<>( diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricsDefinitionsClientImplBuilder.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricsDefinitionsClientImplBuilder.java index 6743c7c098c05..f21be74c1db78 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricsDefinitionsClientImplBuilder.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsdefinitions/MetricsDefinitionsClientImplBuilder.java @@ -21,6 +21,8 @@ import com.azure.core.util.CoreUtils; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.monitor.query.models.MetricsQueryClientAudience; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,6 +35,7 @@ public final class MetricsDefinitionsClientImplBuilder { private static final String SDK_VERSION = "version"; private final Map properties = CoreUtils.getProperties("azure-monitor-query.properties"); + private String audience; /** Create an instance of the MetricsDefinitionsClientImplBuilder. */ public MetricsDefinitionsClientImplBuilder() { @@ -201,6 +204,18 @@ public MetricsDefinitionsClientImplBuilder addPolicy(HttpPipelinePolicy customPo return this; } + /** + * Sets the audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience will be + * used if the property is null. + * @param audience audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience + * will be used if the property is null. + * @return the {@link MetricsDefinitionsClientImplBuilder}. + */ + public MetricsDefinitionsClientImplBuilder audience(String audience) { + this.audience = audience; + return this; + } + /** * Builds an instance of MetricsDefinitionsClientImpl with the provided parameters. * @@ -236,8 +251,13 @@ private HttpPipeline createHttpPipeline() { policies.add( new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration)); HttpPolicyProviders.addBeforeRetryPolicies(policies); - BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(this.tokenCredential, "https://management.azure.com" + - "/.default"); + String resolvedAudience = this.audience; + if (resolvedAudience == null) { + resolvedAudience = MetricsQueryClientAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD.toString(); + } + resolvedAudience += "/.default"; + BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(this.tokenCredential, + resolvedAudience); policies.add(tokenPolicy); policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); policies.add(new CookiePolicy()); diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricNamespacesImpl.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricNamespacesImpl.java index 164d4378fef10..9451dc053b2bb 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricNamespacesImpl.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricNamespacesImpl.java @@ -15,12 +15,14 @@ import com.azure.core.annotation.ServiceInterface; import com.azure.core.annotation.ServiceMethod; import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.HttpResponseException; import com.azure.core.http.rest.PagedFlux; import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.PagedResponse; import com.azure.core.http.rest.PagedResponseBase; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; +import com.azure.core.models.ResponseError; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; import com.azure.monitor.query.implementation.metricsnamespaces.models.ErrorResponseException; @@ -88,14 +90,16 @@ public Mono> listSinglePageAsync(String resourceU } final String accept = "application/json"; return FluxUtil.withContext( - context -> - service.list( - this.client.getHost(), - resourceUri, - this.client.getApiVersion(), - startTime, - accept, - context)) + context -> + service.list( + this.client.getHost(), + resourceUri, + this.client.getApiVersion(), + startTime, + accept, + context)) + .onErrorMap(ErrorResponseException.class, ex -> new HttpResponseException(ex.getMessage(), + ex.getResponse(), new ResponseError(ex.getValue().getCode(), ex.getValue().getMessage()))) .map( res -> new PagedResponseBase<>( @@ -130,6 +134,8 @@ public Mono> listSinglePageAsync( } final String accept = "application/json"; return service.list(this.client.getHost(), resourceUri, this.client.getApiVersion(), startTime, accept, context) + .onErrorMap(ErrorResponseException.class, ex -> new HttpResponseException(ex.getMessage(), + ex.getResponse(), new ResponseError(ex.getValue().getCode(), ex.getValue().getMessage()))) .map( res -> new PagedResponseBase<>( diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricsNamespacesClientImplBuilder.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricsNamespacesClientImplBuilder.java index ae7e680aa02c9..d58a910fde526 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricsNamespacesClientImplBuilder.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/implementation/metricsnamespaces/MetricsNamespacesClientImplBuilder.java @@ -21,6 +21,8 @@ import com.azure.core.util.CoreUtils; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.monitor.query.models.MetricsQueryClientAudience; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,6 +35,7 @@ public final class MetricsNamespacesClientImplBuilder { private static final String SDK_VERSION = "version"; private final Map properties = CoreUtils.getProperties("azure-monitor-query.properties"); + private String audience; /** Create an instance of the MetricsNamespacesClientImplBuilder. */ public MetricsNamespacesClientImplBuilder() { @@ -201,6 +204,18 @@ public MetricsNamespacesClientImplBuilder addPolicy(HttpPipelinePolicy customPol return this; } + /** + * Sets the audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience will be + * used if the property is null. + * @param audience audience to use for authentication with Azure Active Directory. The Azure Public Cloud audience + * will be used if the property is null. + * @return the {@link MetricsNamespacesClientImplBuilder}. + */ + public MetricsNamespacesClientImplBuilder audience(String audience) { + this.audience = audience; + return this; + } + /** * Builds an instance of MetricsNamespacesClientImpl with the provided parameters. * @@ -236,8 +251,13 @@ private HttpPipeline createHttpPipeline() { policies.add( new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration)); HttpPolicyProviders.addBeforeRetryPolicies(policies); - BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(this.tokenCredential, "https://management.azure.com" + - "/.default"); + String resolvedAudience = this.audience; + if (resolvedAudience == null) { + resolvedAudience = MetricsQueryClientAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD.toString(); + } + resolvedAudience += "/.default"; + BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(this.tokenCredential, + resolvedAudience); policies.add(tokenPolicy); policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); policies.add(new CookiePolicy()); diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/LogsQueryClientAudience.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/LogsQueryClientAudience.java new file mode 100644 index 0000000000000..9a52f44d63c90 --- /dev/null +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/LogsQueryClientAudience.java @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.query.models; + +import com.azure.core.util.ExpandableStringEnum; +import com.azure.monitor.query.LogsQueryClient; +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.util.Collection; + +/** + * Cloud audiences available for {@link LogsQueryClient}. + */ +public final class LogsQueryClientAudience extends ExpandableStringEnum { + + /** Static audience for Azure public cloud. */ + public static final LogsQueryClientAudience AZURE_PUBLIC_CLOUD = fromString("https://api.monitor.azure.com"); + + /** Static default audience that uses Azure public cloud. */ + public static final LogsQueryClientAudience DEFAULT = fromString("https://api.monitor.azure.com"); + + /** + * Creates or finds a LogsQueryClientAudience from its string representation. + * + * @param name a name to look for. + * @return the corresponding LogsQueryClientAudience. + */ + @JsonCreator + public static LogsQueryClientAudience fromString(String name) { + return fromString(name, LogsQueryClientAudience.class); + } + + /** @return known LogsQueryClientAudience values. */ + public static Collection values() { + return values(LogsQueryClientAudience.class); + } +} diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/MetricsQueryClientAudience.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/MetricsQueryClientAudience.java new file mode 100644 index 0000000000000..56390299bdc3c --- /dev/null +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/MetricsQueryClientAudience.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.query.models; + +import com.azure.core.util.ExpandableStringEnum; +import com.azure.monitor.query.MetricsQueryClient; +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.util.Collection; + +/** + * Cloud audiences available for {@link MetricsQueryClient}. + */ +public final class MetricsQueryClientAudience extends ExpandableStringEnum { + /** Static value AZURE_RESOURCE_MANAGER_CHINA for MetricsQueryClientAudience. */ + public static final MetricsQueryClientAudience AZURE_RESOURCE_MANAGER_CHINA = fromString("https://management.chinacloudapi.cn"); + + /** Static value AZURE_RESOURCE_MANAGER_GERMANY for MetricsQueryClientAudience. */ + public static final MetricsQueryClientAudience AZURE_RESOURCE_MANAGER_GERMANY = fromString("https://management.microsoftazure.de"); + + /** Static value AZURE_RESOURCE_MANAGER_GOVERNMENT for MetricsQueryClientAudience. */ + public static final MetricsQueryClientAudience AZURE_RESOURCE_MANAGER_GOVERNMENT = fromString("https://management.usgovcloudapi.net"); + + /** Static value AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD for MetricsQueryClientAudience. */ + public static final MetricsQueryClientAudience AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD = fromString("https://management.azure.com"); + + /** Static default audience that uses Azure public cloud. */ + public static final MetricsQueryClientAudience DEFAULT = fromString("https://management.azure.com"); + + /** + * Creates or finds a MetricsQueryClientAudience from its string representation. + * @param name a name to look for. + * @return the corresponding MetricsQueryClientAudience. + */ + @JsonCreator + public static MetricsQueryClientAudience fromString(String name) { + return fromString(name, MetricsQueryClientAudience.class); + } + + /** @return known MetricsQueryClientAudience values. */ + public static Collection values() { + return values(MetricsQueryClientAudience.class); + } +} diff --git a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/MetricsQueryResult.java b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/MetricsQueryResult.java index c994a2a0a9917..5aaf078ed444c 100644 --- a/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/MetricsQueryResult.java +++ b/sdk/monitor/azure-monitor-query/src/main/java/com/azure/monitor/query/models/MetricsQueryResult.java @@ -96,7 +96,7 @@ public List getMetrics() { * @param metricName The name of the metric to look up the result for. * @return The {@link MetricResult} for {@code metricName} if found, {@code null} otherwise. */ - public MetricResult getMetrics(String metricName) { + public MetricResult getMetricByName(String metricName) { Objects.requireNonNull(metricName, "'metricName' cannot be null"); if (CoreUtils.isNullOrEmpty(metrics)) { return null;