Skip to content

Commit

Permalink
add sample for cloning vm to new region (#31912)
Browse files Browse the repository at this point in the history
* add sample for cloning vm to new region

* refine awaitCopyStartCompletion implementation

* remove extension config

* println to printf
  • Loading branch information
XiaofeiCao authored Nov 4, 2022
1 parent 3f3889e commit 1907997
Show file tree
Hide file tree
Showing 6 changed files with 4,232 additions and 435 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
Expand Down Expand Up @@ -136,19 +137,19 @@ public Mono<Void> awaitCopyStartCompletionAsync() {
Mono<SnapshotInner> result = Mono.just(inner);
if (inner.copyCompletionError() != null) { // service error
result = Mono.error(new ManagementException(inner.copyCompletionError().errorMessage(), null));
} else if (inner.completionPercent() == null || inner.completionPercent() != 100) { // in progress
}
return result;
})
.repeatWhen(longFlux -> Flux.interval(manager().serviceClient().getDefaultPollInterval()))
.takeUntil(inner -> {
if (Float.valueOf(100).equals(inner.completionPercent())) {
return true;
} else { // in progress
logger.info("Wait for CopyStart complete for snapshot: {}. Complete percent: {}.",
inner.name(), inner.completionPercent());
result = Mono.empty();
return false;
}
return result;
})
.repeatWhenEmpty(longFlux ->
longFlux
.flatMap(
index ->
Mono.delay(ResourceManagerUtils.InternalRuntimeContext.getDelayDuration(
manager().serviceClient().getDefaultPollInterval()))))
.then();
}

Expand Down
Loading

0 comments on commit 1907997

Please sign in to comment.