Skip to content

Commit

Permalink
Merge pull request Azure#131 from jianghaolu/pollingcase
Browse files Browse the repository at this point in the history
Fix casing in long running operation provisioning states
  • Loading branch information
jianghaolu authored Dec 28, 2016
2 parents 0fc8ab4 + 3d3591d commit c1c0ba8
Showing 1 changed file with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,38 @@ public Observable<?> call(Observable<? extends Void> observable) {
.flatMap(new Func1<PollingState<T>, Observable<PollingState<T>>>() {
@Override
public Observable<PollingState<T>> call(PollingState<T> pollingState) {
if (!AzureAsyncOperation.getTerminalStatuses().contains(pollingState.getStatus())) {
return putOrPatchPollingDispatcher(pollingState, url);
} else {
return Observable.just(pollingState);
for (String terminalStatus : AzureAsyncOperation.getTerminalStatuses()) {
if (terminalStatus.equalsIgnoreCase(pollingState.getStatus())) {
return Observable.just(pollingState);
}
}
return putOrPatchPollingDispatcher(pollingState, url);
}
})
// The above process continues until this filter passes
.filter(new Func1<PollingState<T>, Boolean>() {
@Override
public Boolean call(PollingState<T> pollingState) {
return AzureAsyncOperation.getTerminalStatuses().contains(pollingState.getStatus());
for (String terminalStatus : AzureAsyncOperation.getTerminalStatuses()) {
if (terminalStatus.equalsIgnoreCase(pollingState.getStatus())) {
return true;
}
}
return false;
}
})
.first()
// Possible extra get to receive the actual resource
.flatMap(new Func1<PollingState<T>, Observable<PollingState<T>>>() {
@Override
public Observable<PollingState<T>> call(PollingState<T> pollingState) {
if (AzureAsyncOperation.SUCCESS_STATUS.equals(pollingState.getStatus()) && pollingState.getResource() == null) {
if (AzureAsyncOperation.SUCCESS_STATUS.equalsIgnoreCase(pollingState.getStatus()) && pollingState.getResource() == null) {
return updateStateFromGetResourceOperationAsync(pollingState, url);
}
if (AzureAsyncOperation.getFailedStatuses().contains(pollingState.getStatus())) {
return Observable.error(new CloudException("Async operation failed with provisioning state: " + pollingState.getStatus()));
for (String failedStatus : AzureAsyncOperation.getFailedStatuses()) {
if (failedStatus.equalsIgnoreCase(pollingState.getStatus())) {
return Observable.error(new CloudException("Async operation failed with provisioning state: " + pollingState.getStatus()));
}
}
return Observable.just(pollingState);
}
Expand Down Expand Up @@ -296,28 +304,36 @@ public Observable<?> call(Observable<? extends Void> observable) {
.flatMap(new Func1<PollingState<T>, Observable<PollingState<T>>>() {
@Override
public Observable<PollingState<T>> call(PollingState<T> pollingState) {
if (!AzureAsyncOperation.getTerminalStatuses().contains(pollingState.getStatus())) {
return postOrDeletePollingDispatcher(pollingState);
for (String terminalStatus : AzureAsyncOperation.getTerminalStatuses()) {
if (terminalStatus.equalsIgnoreCase(pollingState.getStatus())) {
return Observable.just(pollingState);
}
}
return Observable.just(pollingState);
return postOrDeletePollingDispatcher(pollingState);
}
})
// The above process continues until this filter passes
.filter(new Func1<PollingState<T>, Boolean>() {
@Override
public Boolean call(PollingState<T> pollingState) {
return AzureAsyncOperation.getTerminalStatuses().contains(pollingState.getStatus());
for (String terminalStatus : AzureAsyncOperation.getTerminalStatuses()) {
if (terminalStatus.equalsIgnoreCase(pollingState.getStatus())) {
return true;
}
}
return false;
}
})
.first()
.flatMap(new Func1<PollingState<T>, Observable<ServiceResponse<T>>>() {
@Override
public Observable<ServiceResponse<T>> call(PollingState<T> pollingState) {
if (AzureAsyncOperation.getFailedStatuses().contains(pollingState.getStatus())) {
return Observable.error(new CloudException("Async operation failed with provisioning state: " + pollingState.getStatus()));
} else {
return Observable.just(new ServiceResponse<>(pollingState.getResource(), pollingState.getResponse()));
for (String failedStatus : AzureAsyncOperation.getFailedStatuses()) {
if (failedStatus.equalsIgnoreCase(pollingState.getStatus())) {
return Observable.error(new CloudException("Async operation failed with provisioning state: " + pollingState.getStatus()));
}
}
return Observable.just(new ServiceResponse<>(pollingState.getResource(), pollingState.getResponse()));
}
});
} catch (IOException e) {
Expand Down

0 comments on commit c1c0ba8

Please sign in to comment.