-
Notifications
You must be signed in to change notification settings - Fork 2.2k
move PollerFactory to polling package; remove AzureHost #11203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
5d4bc4e
b07ffb3
e510fa0
a9cade7
c274057
90eee83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,142 +7,28 @@ | |
| import com.azure.core.http.HttpPipeline; | ||
| import com.azure.core.http.HttpRequest; | ||
| import com.azure.core.http.HttpResponse; | ||
| import com.azure.core.http.rest.Response; | ||
| import com.azure.core.management.polling.PollResult; | ||
| import com.azure.core.util.FluxUtil; | ||
| import com.azure.core.util.logging.ClientLogger; | ||
| 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.PollingContext; | ||
| import com.azure.core.util.serializer.SerializerAdapter; | ||
| import com.azure.core.util.serializer.SerializerEncoding; | ||
| import reactor.core.publisher.Flux; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.reflect.Type; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.Duration; | ||
| import java.util.Objects; | ||
| import java.util.function.BiFunction; | ||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * Factory to create PollerFlux for Azure resource manager (ARM) long-running-operation (LRO). | ||
| * Poll operation for Azure resource manager (ARM) long-running-operation (LRO). | ||
| */ | ||
| public final class PollerFactory { | ||
| private static final ClientLogger LOGGER = new ClientLogger(PollerFactory.class); | ||
| public final class PollOperation { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The remaining public method (used by Let me know if any suggestion. |
||
| private static final ClientLogger LOGGER = new ClientLogger(PollOperation.class); | ||
| private static final LongRunningOperationStatus LRO_CANCELLED = LongRunningOperationStatus.fromString("Cancelled", | ||
| true); | ||
|
|
||
| /** | ||
| * Creates a PollerFlux with default ARM LRO init operation. | ||
| * | ||
| * @param serializerAdapter the serializer for any encoding and decoding | ||
| * @param pipeline the HttpPipeline for making any Http request (e.g. poll) | ||
| * @param pollResultType the type of the poll result, if no result is expecting then this should be Void.class | ||
| * @param finalResultType the type of the final result, if no result is expecting then this should be Void.class | ||
| * @param defaultPollInterval the default poll interval to use if service does not return retry-after | ||
| * @param lroInitMono the Mono on subscribe send the service request to initiate the long-running-operation | ||
| * @param <T> the type of poll result | ||
| * @param <U> the type of final result | ||
| * @return PollerFlux | ||
| */ | ||
| public static <T, U> PollerFlux<PollResult<T>, U> create( | ||
| SerializerAdapter serializerAdapter, | ||
| HttpPipeline pipeline, | ||
| Type pollResultType, | ||
| Type finalResultType, | ||
| Duration defaultPollInterval, | ||
| Mono<Response<Flux<ByteBuffer>>> lroInitMono) { | ||
| Objects.requireNonNull(serializerAdapter, "'serializerAdapter' cannot be null."); | ||
| Objects.requireNonNull(pipeline, "'pipeline' cannot be null."); | ||
| Objects.requireNonNull(pollResultType, "'pollResultType' cannot be null."); | ||
| Objects.requireNonNull(finalResultType, "'finalResultType' cannot be null."); | ||
| Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); | ||
| Objects.requireNonNull(lroInitMono, "'lroInitMono' cannot be null."); | ||
| Function<PollingContext<PollResult<T>>, Mono<PollResponse<PollResult<T>>>> defaultLroInitOperation = | ||
| context -> lroInitMono.flatMap(response -> FluxUtil.collectBytesInByteBufferStream(response.getValue()) | ||
| .map(contentBytes -> { | ||
| String content = new String(contentBytes, StandardCharsets.UTF_8); | ||
| PollingState state = PollingState.create(serializerAdapter, | ||
| response.getRequest(), | ||
| response.getStatusCode(), | ||
| response.getHeaders(), | ||
| content); | ||
| state.store(context); | ||
| T result = deserialize(serializerAdapter, content, pollResultType); | ||
| return new PollResponse<>(state.getOperationStatus(), new PollResult<>(result)); | ||
| })); | ||
| return PollerFlux.create(defaultPollInterval, | ||
| defaultLroInitOperation, | ||
| pollFunction(serializerAdapter, pipeline, pollResultType), | ||
| cancelFunction(), | ||
| fetchResultFunction(serializerAdapter, pipeline, finalResultType)); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a PollerFlux. | ||
| * | ||
| * @param serializerAdapter the serializer for any encoding and decoding | ||
| * @param pipeline the HttpPipeline for making any Http request (e.g. poll) | ||
| * @param pollResultType the type of the poll result, if no result is expecting then this should be Void.class | ||
| * @param finalResultType the type of the final result, if no result is expecting then this should be Void.class | ||
| * @param defaultPollInterval the default poll interval to use if service does not return retry-after | ||
| * @param lroInitOperation the function upon invoking should initiate the long-running-operation | ||
| * @param <T> the type of poll result | ||
| * @param <U> the type of final result | ||
| * @return PollerFlux | ||
| */ | ||
| public static <T, U> PollerFlux<PollResult<T>, U> create( | ||
| SerializerAdapter serializerAdapter, | ||
| HttpPipeline pipeline, | ||
| Type pollResultType, | ||
| Type finalResultType, | ||
| Duration defaultPollInterval, | ||
| Function<PollingContext<PollResult<T>>, Mono<PollResult<T>>> lroInitOperation) { | ||
| Objects.requireNonNull(serializerAdapter, "'serializerAdapter' cannot be null."); | ||
| Objects.requireNonNull(pipeline, "'pipeline' cannot be null."); | ||
| Objects.requireNonNull(pollResultType, "'pollResultType' cannot be null."); | ||
| Objects.requireNonNull(finalResultType, "'finalResultType' cannot be null."); | ||
| Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); | ||
| Objects.requireNonNull(lroInitOperation, "'lroInitOperation' cannot be null."); | ||
|
|
||
| return new PollerFlux<>(defaultPollInterval, | ||
| lroInitOperation, | ||
| pollFunction(serializerAdapter, pipeline, pollResultType), | ||
| cancelFunction(), | ||
| fetchResultFunction(serializerAdapter, pipeline, finalResultType)); | ||
| } | ||
|
|
||
| /** | ||
| * Dehydrate a PollerFlux from a string. | ||
| * | ||
| * @param serializerAdapter the serializer for any encoding and decoding | ||
| * @param pipeline the HttpPipeline for making any Http request (e.g. poll) | ||
| * @param pollResultType the type of the poll result, if no result is expecting then this should be Void.class | ||
| * @param finalResultType the type of the final result, if no result is expecting then this should be Void.class | ||
| * @param defaultPollInterval the default poll interval to use if service does not return retry-after | ||
| * @param pollingStateStr the string to dehydrate PollerFlux from | ||
| * @param <T> the type of poll result | ||
| * @param <U> the type of final result | ||
| * @return PollerFlux | ||
| */ | ||
| public static <T, U> PollerFlux<PollResult<T>, U> create(SerializerAdapter serializerAdapter, | ||
| HttpPipeline pipeline, | ||
| Type pollResultType, | ||
| Type finalResultType, | ||
| Duration defaultPollInterval, | ||
| String pollingStateStr) { | ||
| return create(serializerAdapter, pipeline, pollResultType, finalResultType, defaultPollInterval, | ||
| context -> { | ||
| PollingState.from(serializerAdapter, pollingStateStr).store(context); | ||
| return Mono.empty(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Get a Function that polls provisioning state of ARM resource. | ||
| * | ||
|
|
@@ -152,7 +38,7 @@ public static <T, U> PollerFlux<PollResult<T>, U> create(SerializerAdapter seria | |
| * @param <T> the type of poll result type | ||
| * @return the ARM poll function | ||
| */ | ||
| private static <T> Function<PollingContext<PollResult<T>>, Mono<PollResponse<PollResult<T>>>> pollFunction( | ||
| public static <T> Function<PollingContext<PollResult<T>>, Mono<PollResponse<PollResult<T>>>> pollFunction( | ||
| SerializerAdapter serializerAdapter, | ||
| HttpPipeline pipeline, | ||
| Type pollResultType) { | ||
|
|
@@ -198,7 +84,7 @@ private static <T> Function<PollingContext<PollResult<T>>, Mono<PollResponse<Pol | |
| * @param <T> the type of poll result type | ||
| * @return cancel Function | ||
| */ | ||
| private static <T> | ||
| public static <T> | ||
| BiFunction<PollingContext<PollResult<T>>, PollResponse<PollResult<T>>, Mono<PollResult<T>>> cancelFunction() { | ||
| return new BiFunction<PollingContext<PollResult<T>>, PollResponse<PollResult<T>>, Mono<PollResult<T>>>() { | ||
| @Override | ||
|
|
@@ -219,7 +105,7 @@ public Mono<PollResult<T>> apply(PollingContext<PollResult<T>> context, | |
| * @param <U> the poll result type | ||
| * @return retrieve final LRO result Function | ||
| */ | ||
| private static <T, U> Function<PollingContext<PollResult<T>>, Mono<U>> fetchResultFunction( | ||
| public static <T, U> Function<PollingContext<PollResult<T>>, Mono<U>> fetchResultFunction( | ||
| SerializerAdapter serializerAdapter, | ||
| HttpPipeline pipeline, | ||
| Type finalResultType) { | ||
|
|
@@ -307,7 +193,7 @@ private static Mono<PollingState> doSinglePoll(HttpPipeline pipeline, PollingSta | |
| * @return decoded value | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| private static <U> U deserialize(SerializerAdapter serializerAdapter, String value, Type type) { | ||
| public static <U> U deserialize(SerializerAdapter serializerAdapter, String value, Type type) { | ||
| if (value == null || value.equalsIgnoreCase("")) { | ||
| LOGGER.info("Ignoring decoding of null or empty value to:" + type.getTypeName()); | ||
| return null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ public PollResult(Error error) { | |
| * | ||
| * @return the value | ||
| */ | ||
| public T value() { | ||
| public T getValue() { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change according to java sdk guideline. |
||
| return this.value; | ||
| } | ||
|
|
||
|
|
@@ -47,7 +47,7 @@ public T value() { | |
| * | ||
| * @return the error | ||
| */ | ||
| public Error error() { | ||
| public Error getError() { | ||
| return this.error; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/CC @JonathanGiles
I'm curious. com.azure:azure-core-management has previously been released several times, is there any reason why the artifact ID is being changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @JimSuplizio for reviewing. Actually this is based on @JonathanGiles feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/CC @mitchdenny
Everything under sdk/core is azure-core-, and their directories match the artifact name. If this is being renamed then there probably should be more changes than just renaming the artifact. @JonathanGiles is this no longer a core artifact, is this supposed to moving somewhere else or is there a different naming convention happening for management?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JimSuplizio . Personal impression on current package: no lib other than mgmt SDK would benefit for including the azure-core-management lib. So it probably no very suitable for a core lib. Well, just my impression.
Yes, there are likely follow-up actions if we do change artifactId. For now this part is only trial on a suggestion. I won't merge the artifactId change without approval from you or Jonathon.