Search in sources :

Example 6 with PoolUsageMetrics

use of com.microsoft.azure.batch.protocol.models.PoolUsageMetrics in project azure-sdk-for-java by Azure.

the class PoolsImpl method listPoolUsageMetricsAsync.

/**
     * Lists the usage metrics, aggregated by pool across individual time intervals, for the specified account.
     *
     * @param poolListPoolUsageMetricsOptions Additional parameters for the operation
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall listPoolUsageMetricsAsync(final PoolListPoolUsageMetricsOptions poolListPoolUsageMetricsOptions, final ListOperationCallback<PoolUsageMetrics> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(poolListPoolUsageMetricsOptions, serviceCallback);
    DateTime startTime = null;
    if (poolListPoolUsageMetricsOptions != null) {
        startTime = poolListPoolUsageMetricsOptions.startTime();
    }
    DateTime endTime = null;
    if (poolListPoolUsageMetricsOptions != null) {
        endTime = poolListPoolUsageMetricsOptions.endTime();
    }
    String filter = null;
    if (poolListPoolUsageMetricsOptions != null) {
        filter = poolListPoolUsageMetricsOptions.filter();
    }
    Integer maxResults = null;
    if (poolListPoolUsageMetricsOptions != null) {
        maxResults = poolListPoolUsageMetricsOptions.maxResults();
    }
    Integer timeout = null;
    if (poolListPoolUsageMetricsOptions != null) {
        timeout = poolListPoolUsageMetricsOptions.timeout();
    }
    String clientRequestId = null;
    if (poolListPoolUsageMetricsOptions != null) {
        clientRequestId = poolListPoolUsageMetricsOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (poolListPoolUsageMetricsOptions != null) {
        returnClientRequestId = poolListPoolUsageMetricsOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (poolListPoolUsageMetricsOptions != null) {
        ocpDate = poolListPoolUsageMetricsOptions.ocpDate();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    Call<ResponseBody> call = service.listPoolUsageMetrics(this.client.apiVersion(), this.client.acceptLanguage(), startTime, endTime, filter, maxResults, timeout, clientRequestId, returnClientRequestId, ocpDateConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<List<PoolUsageMetrics>>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                ServiceResponseWithHeaders<PageImpl<PoolUsageMetrics>, PoolListPoolUsageMetricsHeaders> result = listPoolUsageMetricsDelegate(response);
                serviceCallback.load(result.getBody().getItems());
                if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) {
                    PoolListPoolUsageMetricsNextOptions poolListPoolUsageMetricsNextOptions = null;
                    if (poolListPoolUsageMetricsOptions != null) {
                        poolListPoolUsageMetricsNextOptions = new PoolListPoolUsageMetricsNextOptions();
                        poolListPoolUsageMetricsNextOptions.withClientRequestId(poolListPoolUsageMetricsOptions.clientRequestId());
                        poolListPoolUsageMetricsNextOptions.withReturnClientRequestId(poolListPoolUsageMetricsOptions.returnClientRequestId());
                        poolListPoolUsageMetricsNextOptions.withOcpDate(poolListPoolUsageMetricsOptions.ocpDate());
                    }
                    listPoolUsageMetricsNextAsync(result.getBody().getNextPageLink(), poolListPoolUsageMetricsNextOptions, serviceCall, serviceCallback);
                } else {
                    serviceCallback.success(new ServiceResponseWithHeaders<>(serviceCallback.get(), result.getHeaders(), result.getResponse()));
                }
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) PoolListPoolUsageMetricsNextOptions(com.microsoft.azure.batch.protocol.models.PoolListPoolUsageMetricsNextOptions) DateTime(org.joda.time.DateTime) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123) PoolUsageMetrics(com.microsoft.azure.batch.protocol.models.PoolUsageMetrics) List(java.util.List) PagedList(com.microsoft.azure.PagedList)

Aggregations

PagedList (com.microsoft.azure.PagedList)6 PoolUsageMetrics (com.microsoft.azure.batch.protocol.models.PoolUsageMetrics)6 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)6 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)6 ResponseBody (okhttp3.ResponseBody)6 DateTime (org.joda.time.DateTime)6 List (java.util.List)4 PoolListPoolUsageMetricsNextOptions (com.microsoft.azure.batch.protocol.models.PoolListPoolUsageMetricsNextOptions)3 PageImpl (com.microsoft.azure.batch.protocol.models.PageImpl)2 PoolListPoolUsageMetricsHeaders (com.microsoft.azure.batch.protocol.models.PoolListPoolUsageMetricsHeaders)2 PoolListPoolUsageMetricsOptions (com.microsoft.azure.batch.protocol.models.PoolListPoolUsageMetricsOptions)2 ServiceCall (com.microsoft.rest.ServiceCall)2