Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
86 changes: 48 additions & 38 deletions eng/emitter-package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eng/emitter-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"main": "dist/src/index.js",
"dependencies": {
"@azure-tools/typespec-java": "0.49.1"
"@azure-tools/typespec-java": "/mnt/vss/_work/1/typespec-azure/packages/typespec-java/azure-tools-typespec-java-0.49.1.tgz"
},
"devDependencies": {
"@azure-tools/typespec-autorest": "0.74.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.polling.AsyncPollResponse;
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.polling.PollResponse;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.core.util.serializer.SerializerAdapter;
Expand Down Expand Up @@ -231,6 +232,24 @@ public <T, U> SyncPoller<PollResult<T>, U> getLroResult(Response<BinaryData> act
defaultPollInterval, () -> activationResponse, context);
}

/**
* Waits for completion and gets the final result, or throws an error.
*
* @param poller the synchronous poller.
* @param <T> type of poll result.
* @param <U> type of final result.
* @return the final result.
* @throws ManagementException if the long running operation fails.
*/
public <T, U> U getLroFinalResultOrError(SyncPoller<PollResult<T>, U> poller) {
PollResponse<PollResult<T>> response = poller.waitForCompletion();
ManagementException exception = getLroException(response.getStatus(), response.getValue());
if (exception != null) {
throw exception;
}
return poller.getFinalResult();
}

/**
* Gets the final result, or an error, based on last async poll response.
*
Expand All @@ -240,17 +259,25 @@ public <T, U> SyncPoller<PollResult<T>, U> getLroResult(Response<BinaryData> act
* @return the final result, or an error.
*/
public <T, U> Mono<U> getLroFinalResultOrError(AsyncPollResponse<PollResult<T>, U> response) {
if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
ManagementException exception = getLroException(response.getStatus(), response.getValue());
if (exception != null) {
return Mono.error(exception);
}
return response.getFinalResult();
}

private ManagementException getLroException(LongRunningOperationStatus status, PollResult<?> result) {
PollResult.Error lroError = result == null ? null : result.getError();
if (status != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED || lroError != null) {
String errorMessage;
ManagementError managementError = null;
HttpResponse errorResponse = null;
PollResult.Error lroError = response.getValue().getError();
if (lroError != null) {
errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(),
lroError.getResponseBody());

errorMessage = response.getValue().getError().getMessage();
String errorBody = response.getValue().getError().getResponseBody();
errorMessage = lroError.getMessage();
String errorBody = lroError.getResponseBody();
if (errorBody != null) {
// try to deserialize error body to ManagementError
try {
Expand All @@ -269,12 +296,11 @@ public <T, U> Mono<U> getLroFinalResultOrError(AsyncPollResponse<PollResult<T>,
}
if (managementError == null) {
// fallback to default ManagementError
managementError = new ManagementError(response.getStatus().toString(), errorMessage);
managementError = new ManagementError(status.toString(), errorMessage);
}
return Mono.error(new ManagementException(errorMessage, errorResponse, managementError));
} else {
return response.getFinalResult();
return new ManagementException(errorMessage, errorResponse, managementError);
}
return null;
}

private static final class HttpResponseImpl extends HttpResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ private PagedFlux<OperationInner> listAsync() {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private PagedResponse<OperationInner> listSinglePage() {
final String accept = "application/json";
Response<OperationListResult> res
= service.listSync(this.client.getEndpoint(), this.client.getApiVersion(), accept, Context.NONE);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(),
res.getValue().nextLink(), null);
return listSinglePage(Context.NONE);
}

/**
Expand All @@ -157,29 +153,13 @@ private PagedResponse<OperationInner> listSinglePage(Context context) {
res.getValue().nextLink(), null);
}

/**
* List the operations for the provider.
*
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return a list of REST API operations supported by an Azure Resource Provider as paginated response with
* {@link PagedIterable}.
*/
@Override
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<OperationInner> list() {
return new PagedIterable<>(() -> listSinglePage(), nextLink -> listNextSinglePage(nextLink));
return list(Context.NONE);
}

/**
* List the operations for the provider.
*
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return a list of REST API operations supported by an Azure Resource Provider as paginated response with
* {@link PagedIterable}.
*/
@Override
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<OperationInner> list(Context context) {
return new PagedIterable<>(() -> listSinglePage(context), nextLink -> listNextSinglePage(nextLink, context));
Expand Down Expand Up @@ -215,11 +195,7 @@ private Mono<PagedResponse<OperationInner>> listNextSinglePageAsync(String nextL
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private PagedResponse<OperationInner> listNextSinglePage(String nextLink) {
final String accept = "application/json";
Response<OperationListResult> res
= service.listNextSync(nextLink, this.client.getEndpoint(), accept, Context.NONE);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(),
res.getValue().nextLink(), null);
return listNextSinglePage(nextLink, Context.NONE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public OperationsImpl(OperationsClient innerClient,
}

public PagedIterable<Operation> list() {
PagedIterable<OperationInner> inner = this.serviceClient().list();
return ResourceManagerUtils.mapPage(inner, inner1 -> new OperationImpl(inner1, this.manager()));
return this.list(Context.NONE);
}

public PagedIterable<Operation> list(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,7 @@ private Mono<RecommendVmSkuResponseInner> recommendVmSkuAsync(String location, R
return recommendVmSkuWithResponseAsync(location, body).flatMap(res -> Mono.justOrEmpty(res.getValue()));
}

/**
* Recommends Azure virtual machine sizes for an AI workload in the specified subscription and azure location.
*
* @param location The name of the Azure region.
* @param body The request body.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the recommended Azure virtual machine sizes for the workload, with the sizing calculation they were
* derived from along with {@link Response}.
*/
@Override
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<RecommendVmSkuResponseInner> recommendVmSkuWithResponse(String location, RecommendVmSkuRequest body,
Context context) {
Expand All @@ -136,17 +125,7 @@ public Response<RecommendVmSkuResponseInner> recommendVmSkuWithResponse(String l
this.client.getSubscriptionId(), location, contentType, accept, body, context);
}

/**
* Recommends Azure virtual machine sizes for an AI workload in the specified subscription and azure location.
*
* @param location The name of the Azure region.
* @param body The request body.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the recommended Azure virtual machine sizes for the workload, with the sizing calculation they were
* derived from.
*/
@Override
@ServiceMethod(returns = ReturnType.SINGLE)
public RecommendVmSkuResponseInner recommendVmSku(String location, RecommendVmSkuRequest body) {
return recommendVmSkuWithResponse(location, body, Context.NONE).getValue();
Expand Down
Loading
Loading