com.microsoft.azure.management.sql.implementation.SubscriptionUsagesInner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-sql Show documentation
Show all versions of azure-mgmt-sql Show documentation
This package contains Microsoft Azure SDK for SQL Management module.
/**
* 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.sql.implementation;
import retrofit2.Retrofit;
import com.google.common.reflect.TypeToken;
import com.microsoft.azure.AzureServiceFuture;
import com.microsoft.azure.CloudException;
import com.microsoft.azure.ListOperationCallback;
import com.microsoft.azure.Page;
import com.microsoft.azure.PagedList;
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.http.Url;
import retrofit2.Response;
import rx.functions.Func1;
import rx.Observable;
/**
* An instance of this class provides access to all the operations defined
* in SubscriptionUsages.
*/
public class SubscriptionUsagesInner {
/** The Retrofit service to perform REST calls. */
private SubscriptionUsagesService service;
/** The service client containing this operation class. */
private SqlManagementClientImpl client;
/**
* Initializes an instance of SubscriptionUsagesInner.
*
* @param retrofit the Retrofit instance built from a Retrofit Builder.
* @param client the instance of the service client containing this operation class.
*/
public SubscriptionUsagesInner(Retrofit retrofit, SqlManagementClientImpl client) {
this.service = retrofit.create(SubscriptionUsagesService.class);
this.client = client;
}
/**
* The interface defining all the services for SubscriptionUsages to be
* used by Retrofit to perform actually REST calls.
*/
interface SubscriptionUsagesService {
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.sql.SubscriptionUsages listByLocation" })
@GET("subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages")
Observable> listByLocation(@Path("locationName") String locationName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.sql.SubscriptionUsages get" })
@GET("subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages/{usageName}")
Observable> get(@Path("locationName") String locationName, @Path("usageName") String usageName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.sql.SubscriptionUsages listByLocationNext" })
@GET
Observable> listByLocationNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param locationName The name of the region where the resource is located.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws CloudException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the PagedList<SubscriptionUsageInner> object if successful.
*/
public PagedList listByLocation(final String locationName) {
ServiceResponse> response = listByLocationSinglePageAsync(locationName).toBlocking().single();
return new PagedList(response.body()) {
@Override
public Page nextPage(String nextPageLink) {
return listByLocationNextSinglePageAsync(nextPageLink).toBlocking().single().body();
}
};
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param locationName The name of the region where the resource is located.
* @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> listByLocationAsync(final String locationName, final ListOperationCallback serviceCallback) {
return AzureServiceFuture.fromPageResponse(
listByLocationSinglePageAsync(locationName),
new Func1>>>() {
@Override
public Observable>> call(String nextPageLink) {
return listByLocationNextSinglePageAsync(nextPageLink);
}
},
serviceCallback);
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param locationName The name of the region where the resource is located.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PagedList<SubscriptionUsageInner> object
*/
public Observable> listByLocationAsync(final String locationName) {
return listByLocationWithServiceResponseAsync(locationName)
.map(new Func1>, Page>() {
@Override
public Page call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param locationName The name of the region where the resource is located.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PagedList<SubscriptionUsageInner> object
*/
public Observable>> listByLocationWithServiceResponseAsync(final String locationName) {
return listByLocationSinglePageAsync(locationName)
.concatMap(new Func1>, Observable>>>() {
@Override
public Observable>> call(ServiceResponse> page) {
String nextPageLink = page.body().nextPageLink();
if (nextPageLink == null) {
return Observable.just(page);
}
return Observable.just(page).concatWith(listByLocationNextWithServiceResponseAsync(nextPageLink));
}
});
}
/**
* Gets all subscription usage metrics in a given location.
*
ServiceResponse> * @param locationName The name of the region where the resource is located.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the PagedList<SubscriptionUsageInner> object wrapped in {@link ServiceResponse} if successful.
*/
public Observable>> listByLocationSinglePageAsync(final String locationName) {
if (locationName == null) {
throw new IllegalArgumentException("Parameter locationName is required and cannot be null.");
}
if (this.client.subscriptionId() == null) {
throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
}
final String apiVersion = "2015-05-01-preview";
return service.listByLocation(locationName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> result = listByLocationDelegate(response);
return Observable.just(new ServiceResponse>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> listByLocationDelegate(Response response) throws CloudException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(CloudException.class)
.build(response);
}
/**
* Gets a subscription usage metric.
*
* @param locationName The name of the region where the resource is located.
* @param usageName Name of usage metric to return.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws CloudException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the SubscriptionUsageInner object if successful.
*/
public SubscriptionUsageInner get(String locationName, String usageName) {
return getWithServiceResponseAsync(locationName, usageName).toBlocking().single().body();
}
/**
* Gets a subscription usage metric.
*
* @param locationName The name of the region where the resource is located.
* @param usageName Name of usage metric to return.
* @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 getAsync(String locationName, String usageName, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(getWithServiceResponseAsync(locationName, usageName), serviceCallback);
}
/**
* Gets a subscription usage metric.
*
* @param locationName The name of the region where the resource is located.
* @param usageName Name of usage metric to return.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the SubscriptionUsageInner object
*/
public Observable getAsync(String locationName, String usageName) {
return getWithServiceResponseAsync(locationName, usageName).map(new Func1, SubscriptionUsageInner>() {
@Override
public SubscriptionUsageInner call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Gets a subscription usage metric.
*
* @param locationName The name of the region where the resource is located.
* @param usageName Name of usage metric to return.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the SubscriptionUsageInner object
*/
public Observable> getWithServiceResponseAsync(String locationName, String usageName) {
if (locationName == null) {
throw new IllegalArgumentException("Parameter locationName is required and cannot be null.");
}
if (usageName == null) {
throw new IllegalArgumentException("Parameter usageName is required and cannot be null.");
}
if (this.client.subscriptionId() == null) {
throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
}
final String apiVersion = "2015-05-01-preview";
return service.get(locationName, usageName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = getDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(CloudException.class)
.build(response);
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param nextPageLink The NextLink from the previous successful call to List operation.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws CloudException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the PagedList<SubscriptionUsageInner> object if successful.
*/
public PagedList listByLocationNext(final String nextPageLink) {
ServiceResponse> response = listByLocationNextSinglePageAsync(nextPageLink).toBlocking().single();
return new PagedList(response.body()) {
@Override
public Page nextPage(String nextPageLink) {
return listByLocationNextSinglePageAsync(nextPageLink).toBlocking().single().body();
}
};
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param nextPageLink The NextLink from the previous successful call to List operation.
* @param serviceFuture the ServiceFuture object tracking the Retrofit calls
* @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> listByLocationNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) {
return AzureServiceFuture.fromPageResponse(
listByLocationNextSinglePageAsync(nextPageLink),
new Func1>>>() {
@Override
public Observable>> call(String nextPageLink) {
return listByLocationNextSinglePageAsync(nextPageLink);
}
},
serviceCallback);
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param nextPageLink The NextLink from the previous successful call to List operation.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PagedList<SubscriptionUsageInner> object
*/
public Observable> listByLocationNextAsync(final String nextPageLink) {
return listByLocationNextWithServiceResponseAsync(nextPageLink)
.map(new Func1>, Page>() {
@Override
public Page call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Gets all subscription usage metrics in a given location.
*
* @param nextPageLink The NextLink from the previous successful call to List operation.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the PagedList<SubscriptionUsageInner> object
*/
public Observable>> listByLocationNextWithServiceResponseAsync(final String nextPageLink) {
return listByLocationNextSinglePageAsync(nextPageLink)
.concatMap(new Func1>, Observable>>>() {
@Override
public Observable>> call(ServiceResponse> page) {
String nextPageLink = page.body().nextPageLink();
if (nextPageLink == null) {
return Observable.just(page);
}
return Observable.just(page).concatWith(listByLocationNextWithServiceResponseAsync(nextPageLink));
}
});
}
/**
* Gets all subscription usage metrics in a given location.
*
ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the PagedList<SubscriptionUsageInner> object wrapped in {@link ServiceResponse} if successful.
*/
public Observable>> listByLocationNextSinglePageAsync(final String nextPageLink) {
if (nextPageLink == null) {
throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.");
}
String nextUrl = String.format("%s", nextPageLink);
return service.listByLocationNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> result = listByLocationNextDelegate(response);
return Observable.just(new ServiceResponse>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> listByLocationNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(CloudException.class)
.build(response);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy