com.microsoft.azure.management.monitor.implementation.MetricDefinitionsInner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-monitor Show documentation
Show all versions of azure-mgmt-monitor Show documentation
This package contains Microsoft Azure Monitor SDK. This package has been deprecated. A replacement package com.azure.resourcemanager:azure-resourcemanager-monitor is available as of 31-March-2022. We strongly encourage you to upgrade to continue receiving updates. See Migration Guide https://aka.ms/java-track2-migration-guide for guidance on upgrading. Refer to our deprecation policy https://azure.github.io/azure-sdk/policies_support.html for more details.
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
*/
package com.microsoft.azure.management.monitor.implementation;
import retrofit2.Retrofit;
import com.google.common.reflect.TypeToken;
import com.microsoft.azure.management.monitor.ErrorResponseException;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import java.io.IOException;
import java.util.List;
import okhttp3.ResponseBody;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.Response;
import rx.functions.Func1;
import rx.Observable;
/**
* An instance of this class provides access to all the operations defined
* in MetricDefinitions.
*/
public class MetricDefinitionsInner {
/** The Retrofit service to perform REST calls. */
private MetricDefinitionsService service;
/** The service client containing this operation class. */
private MonitorManagementClientImpl client;
/**
* Initializes an instance of MetricDefinitionsInner.
*
* @param retrofit the Retrofit instance built from a Retrofit Builder.
* @param client the instance of the service client containing this operation class.
*/
public MetricDefinitionsInner(Retrofit retrofit, MonitorManagementClientImpl client) {
this.service = retrofit.create(MetricDefinitionsService.class);
this.client = client;
}
/**
* The interface defining all the services for MetricDefinitions to be
* used by Retrofit to perform actually REST calls.
*/
interface MetricDefinitionsService {
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.monitor.MetricDefinitions list" })
@GET("{resourceUri}/providers/microsoft.insights/metricDefinitions")
Observable> list(@Path(value = "resourceUri", encoded = true) String resourceUri, @Query("api-version") String apiVersion, @Query("metricnamespace") String metricnamespace, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws ErrorResponseException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the List<MetricDefinitionInner> object if successful.
*/
public List list(String resourceUri) {
return listWithServiceResponseAsync(resourceUri).toBlocking().single().body();
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture> listAsync(String resourceUri, final ServiceCallback> serviceCallback) {
return ServiceFuture.fromResponse(listWithServiceResponseAsync(resourceUri), serviceCallback);
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<MetricDefinitionInner> object
*/
public Observable> listAsync(String resourceUri) {
return listWithServiceResponseAsync(resourceUri).map(new Func1>, List>() {
@Override
public List call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<MetricDefinitionInner> object
*/
public Observable>> listWithServiceResponseAsync(String resourceUri) {
if (resourceUri == null) {
throw new IllegalArgumentException("Parameter resourceUri is required and cannot be null.");
}
final String apiVersion = "2018-01-01";
final String metricnamespace = null;
return service.list(resourceUri, apiVersion, metricnamespace, this.client.acceptLanguage(), this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> result = listDelegate(response);
List items = null;
if (result.body() != null) {
items = result.body().items();
}
ServiceResponse> clientResponse = new ServiceResponse>(items, result.response());
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @param metricnamespace Metric namespace to query metric definitions for.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws ErrorResponseException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the List<MetricDefinitionInner> object if successful.
*/
public List list(String resourceUri, String metricnamespace) {
return listWithServiceResponseAsync(resourceUri, metricnamespace).toBlocking().single().body();
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @param metricnamespace Metric namespace to query metric definitions for.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture> listAsync(String resourceUri, String metricnamespace, final ServiceCallback> serviceCallback) {
return ServiceFuture.fromResponse(listWithServiceResponseAsync(resourceUri, metricnamespace), serviceCallback);
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @param metricnamespace Metric namespace to query metric definitions for.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<MetricDefinitionInner> object
*/
public Observable> listAsync(String resourceUri, String metricnamespace) {
return listWithServiceResponseAsync(resourceUri, metricnamespace).map(new Func1>, List>() {
@Override
public List call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Lists the metric definitions for the resource.
*
* @param resourceUri The identifier of the resource.
* @param metricnamespace Metric namespace to query metric definitions for.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<MetricDefinitionInner> object
*/
public Observable>> listWithServiceResponseAsync(String resourceUri, String metricnamespace) {
if (resourceUri == null) {
throw new IllegalArgumentException("Parameter resourceUri is required and cannot be null.");
}
final String apiVersion = "2018-01-01";
return service.list(resourceUri, apiVersion, metricnamespace, this.client.acceptLanguage(), this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> result = listDelegate(response);
List items = null;
if (result.body() != null) {
items = result.body().items();
}
ServiceResponse> clientResponse = new ServiceResponse>(items, result.response());
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> listDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(ErrorResponseException.class)
.build(response);
}
}