Search in sources :

Example 91 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class PoolsImpl method upgradeOSAsync.

/**
     * Upgrades the operating system of the specified pool.
     *
     * @param poolId The id of the pool to upgrade.
     * @param targetOSVersion The Azure Guest OS version to be installed on the virtual machines in the pool.
     * @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 upgradeOSAsync(String poolId, String targetOSVersion, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (poolId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter poolId is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    if (targetOSVersion == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter targetOSVersion is required and cannot be null."));
        return null;
    }
    final PoolUpgradeOSOptions poolUpgradeOSOptions = null;
    Integer timeout = null;
    String clientRequestId = null;
    Boolean returnClientRequestId = null;
    DateTime ocpDate = null;
    String ifMatch = null;
    String ifNoneMatch = null;
    DateTime ifModifiedSince = null;
    DateTime ifUnmodifiedSince = null;
    PoolUpgradeOSParameter poolUpgradeOSParameter = new PoolUpgradeOSParameter();
    poolUpgradeOSParameter.withTargetOSVersion(targetOSVersion);
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.upgradeOS(poolId, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, poolUpgradeOSParameter, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(upgradeOSDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) PoolUpgradeOSOptions(com.microsoft.azure.batch.protocol.models.PoolUpgradeOSOptions) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) PoolUpgradeOSParameter(com.microsoft.azure.batch.protocol.models.PoolUpgradeOSParameter) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Example 92 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class PoolsImpl method evaluateAutoScaleAsync.

/**
     * Gets the result of evaluating an automatic scaling formula on the pool.
     *
     * @param poolId The id of the pool on which to evaluate the automatic scaling formula.
     * @param autoScaleFormula A formula for the desired number of compute nodes in the pool.
     * @param poolEvaluateAutoScaleOptions 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 evaluateAutoScaleAsync(String poolId, String autoScaleFormula, PoolEvaluateAutoScaleOptions poolEvaluateAutoScaleOptions, final ServiceCallback<AutoScaleRun> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (poolId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter poolId is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    if (autoScaleFormula == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter autoScaleFormula is required and cannot be null."));
        return null;
    }
    Validator.validate(poolEvaluateAutoScaleOptions, serviceCallback);
    Integer timeout = null;
    if (poolEvaluateAutoScaleOptions != null) {
        timeout = poolEvaluateAutoScaleOptions.timeout();
    }
    String clientRequestId = null;
    if (poolEvaluateAutoScaleOptions != null) {
        clientRequestId = poolEvaluateAutoScaleOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (poolEvaluateAutoScaleOptions != null) {
        returnClientRequestId = poolEvaluateAutoScaleOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (poolEvaluateAutoScaleOptions != null) {
        ocpDate = poolEvaluateAutoScaleOptions.ocpDate();
    }
    PoolEvaluateAutoScaleParameter poolEvaluateAutoScaleParameter = new PoolEvaluateAutoScaleParameter();
    poolEvaluateAutoScaleParameter.withAutoScaleFormula(autoScaleFormula);
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    Call<ResponseBody> call = service.evaluateAutoScale(poolId, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, poolEvaluateAutoScaleParameter, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<AutoScaleRun>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(evaluateAutoScaleDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) AutoScaleRun(com.microsoft.azure.batch.protocol.models.AutoScaleRun) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123) PoolEvaluateAutoScaleParameter(com.microsoft.azure.batch.protocol.models.PoolEvaluateAutoScaleParameter)

Example 93 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class PoolsImpl method stopResizeAsync.

/**
     * Stops an ongoing resize operation on the pool.
     * This does not restore the pool to its previous state before the resize operation: it only stops any further changes being made, and the pool maintains its current state.
     *
     * @param poolId The id of the pool whose resizing you want to stop.
     * @param poolStopResizeOptions 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 stopResizeAsync(String poolId, PoolStopResizeOptions poolStopResizeOptions, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (poolId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter poolId is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(poolStopResizeOptions, serviceCallback);
    Integer timeout = null;
    if (poolStopResizeOptions != null) {
        timeout = poolStopResizeOptions.timeout();
    }
    String clientRequestId = null;
    if (poolStopResizeOptions != null) {
        clientRequestId = poolStopResizeOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (poolStopResizeOptions != null) {
        returnClientRequestId = poolStopResizeOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (poolStopResizeOptions != null) {
        ocpDate = poolStopResizeOptions.ocpDate();
    }
    String ifMatch = null;
    if (poolStopResizeOptions != null) {
        ifMatch = poolStopResizeOptions.ifMatch();
    }
    String ifNoneMatch = null;
    if (poolStopResizeOptions != null) {
        ifNoneMatch = poolStopResizeOptions.ifNoneMatch();
    }
    DateTime ifModifiedSince = null;
    if (poolStopResizeOptions != null) {
        ifModifiedSince = poolStopResizeOptions.ifModifiedSince();
    }
    DateTime ifUnmodifiedSince = null;
    if (poolStopResizeOptions != null) {
        ifUnmodifiedSince = poolStopResizeOptions.ifUnmodifiedSince();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.stopResize(poolId, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(stopResizeDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Example 94 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class PoolsImpl method deleteAsync.

/**
     * Deletes a pool from the specified account.
     *
     * @param poolId The id of the pool to delete.
     * @param poolDeleteOptions 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 deleteAsync(String poolId, PoolDeleteOptions poolDeleteOptions, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (poolId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter poolId is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(poolDeleteOptions, serviceCallback);
    Integer timeout = null;
    if (poolDeleteOptions != null) {
        timeout = poolDeleteOptions.timeout();
    }
    String clientRequestId = null;
    if (poolDeleteOptions != null) {
        clientRequestId = poolDeleteOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (poolDeleteOptions != null) {
        returnClientRequestId = poolDeleteOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (poolDeleteOptions != null) {
        ocpDate = poolDeleteOptions.ocpDate();
    }
    String ifMatch = null;
    if (poolDeleteOptions != null) {
        ifMatch = poolDeleteOptions.ifMatch();
    }
    String ifNoneMatch = null;
    if (poolDeleteOptions != null) {
        ifNoneMatch = poolDeleteOptions.ifNoneMatch();
    }
    DateTime ifModifiedSince = null;
    if (poolDeleteOptions != null) {
        ifModifiedSince = poolDeleteOptions.ifModifiedSince();
    }
    DateTime ifUnmodifiedSince = null;
    if (poolDeleteOptions != null) {
        ifUnmodifiedSince = poolDeleteOptions.ifUnmodifiedSince();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.delete(poolId, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(deleteDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Example 95 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class PoolsImpl method listPoolUsageMetricsNextAsync.

/**
     * Lists the usage metrics, aggregated by pool across individual time intervals, for the specified account.
     *
     * @param nextPageLink The NextLink from the previous successful call to List operation.
     * @param poolListPoolUsageMetricsNextOptions Additional parameters for the operation
     * @param serviceCall the ServiceCall object tracking the Retrofit calls
     * @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 listPoolUsageMetricsNextAsync(final String nextPageLink, final PoolListPoolUsageMetricsNextOptions poolListPoolUsageMetricsNextOptions, final ServiceCall serviceCall, final ListOperationCallback<PoolUsageMetrics> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (nextPageLink == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."));
        return null;
    }
    Validator.validate(poolListPoolUsageMetricsNextOptions, serviceCallback);
    String clientRequestId = null;
    if (poolListPoolUsageMetricsNextOptions != null) {
        clientRequestId = poolListPoolUsageMetricsNextOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (poolListPoolUsageMetricsNextOptions != null) {
        returnClientRequestId = poolListPoolUsageMetricsNextOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (poolListPoolUsageMetricsNextOptions != null) {
        ocpDate = poolListPoolUsageMetricsNextOptions.ocpDate();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    Call<ResponseBody> call = service.listPoolUsageMetricsNext(nextPageLink, this.client.acceptLanguage(), clientRequestId, returnClientRequestId, ocpDateConverted, this.client.userAgent());
    serviceCall.newCall(call);
    call.enqueue(new ServiceResponseCallback<List<PoolUsageMetrics>>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                ServiceResponseWithHeaders<PageImpl<PoolUsageMetrics>, PoolListPoolUsageMetricsHeaders> result = listPoolUsageMetricsNextDelegate(response);
                serviceCallback.load(result.getBody().getItems());
                if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) {
                    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 : 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

ResponseBody (okhttp3.ResponseBody)248 Response (okhttp3.Response)214 Request (okhttp3.Request)208 IOException (java.io.IOException)203 Callback (okhttp3.Callback)172 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)166 Call (okhttp3.Call)166 DateTime (org.joda.time.DateTime)166 ServiceCall (com.microsoft.rest.ServiceCall)140 Test (org.junit.Test)119 List (java.util.List)101 Call (retrofit2.Call)87 MockResponse (okhttp3.mockwebserver.MockResponse)72 RequestBody (okhttp3.RequestBody)62 OkHttpClient (okhttp3.OkHttpClient)61 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)57 GsonBuilder (com.google.gson.GsonBuilder)53 Retrofit (retrofit2.Retrofit)53 PagedList (com.microsoft.azure.PagedList)52 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)52