Skip to content
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

mgmt, if service says 404 is error, it is error #13230

Merged
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.models.ActiveDirectoryApplication;
import com.azure.resourcemanager.authorization.models.ActiveDirectoryApplications;
import com.azure.resourcemanager.authorization.models.GraphErrorException;
import com.azure.resourcemanager.authorization.fluent.inner.ApplicationInner;
import com.azure.resourcemanager.authorization.fluent.ApplicationsClient;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.CreatableResourcesImpl;
Expand Down Expand Up @@ -72,7 +71,6 @@ public ActiveDirectoryApplicationImpl getById(String id) {
public Mono<ActiveDirectoryApplication> getByIdAsync(String id) {
return innerCollection
.getAsync(id)
.onErrorResume(GraphErrorException.class, e -> Mono.empty())
.flatMap(
applicationInner ->
new ActiveDirectoryApplicationImpl(applicationInner, manager()).refreshCredentialsAsync());
Expand All @@ -93,10 +91,13 @@ public Mono<ActiveDirectoryApplication> getByNameAsync(String name) {
Mono
.defer(
() -> {
UUID.fromString(trimmed);
return inner().listAsync(String.format("appId eq '%s'", trimmed)).singleOrEmpty();
try {
UUID.fromString(trimmed);
return inner().listAsync(String.format("appId eq '%s'", trimmed)).singleOrEmpty();
} catch (IllegalArgumentException e) {
return Mono.empty();
}
ChenTanyi marked this conversation as resolved.
Show resolved Hide resolved
}))
.onErrorResume(IllegalArgumentException.class, e -> Mono.empty())
.map(applicationInner -> new ActiveDirectoryApplicationImpl(applicationInner, manager()))
.flatMap(activeDirectoryApplication -> activeDirectoryApplication.refreshCredentialsAsync());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.models.ActiveDirectoryGroup;
import com.azure.resourcemanager.authorization.models.ActiveDirectoryGroups;
import com.azure.resourcemanager.authorization.models.GraphErrorException;
import com.azure.resourcemanager.authorization.fluent.inner.ADGroupInner;
import com.azure.resourcemanager.authorization.fluent.GroupsClient;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl;
Expand Down Expand Up @@ -48,7 +47,6 @@ public Mono<ActiveDirectoryGroup> getByIdAsync(String id) {
.inner()
.getGroups()
.getAsync(id)
.onErrorResume(GraphErrorException.class, e -> Mono.empty())
.map(groupInner -> new ActiveDirectoryGroupImpl(groupInner, manager()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public Mono<ActiveDirectoryUser> getByIdAsync(String id) {
.inner()
.getUsers()
.getAsync(id)
.onErrorResume(GraphErrorException.class, e -> Mono.empty())
.map(userInner -> new ActiveDirectoryUserImpl(userInner, manager()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public RoleAssignmentHelper withAccessTo(final String scope, final BuiltInRole a
.createAsync()
.last()
.onErrorResume(
(Function<Throwable, Mono<Indexable>>)
throwable -> {
if (isRoleAssignmentExists(throwable)) {
return cxt.voidMono();
Expand Down Expand Up @@ -150,7 +149,6 @@ public RoleAssignmentHelper withAccessTo(final String scope, final String roleDe
.createAsync()
.last()
.onErrorResume(
(Function<Throwable, Mono<Indexable>>)
throwable -> {
if (isRoleAssignmentExists(throwable)) {
return cxt.voidMono();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.exception.ManagementException;
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.models.RoleAssignment;
import com.azure.resourcemanager.authorization.models.RoleAssignments;
Expand Down Expand Up @@ -41,7 +40,6 @@ public RoleAssignmentImpl getById(String objectId) {
public Mono<RoleAssignment> getByIdAsync(String id) {
return inner()
.getByIdAsync(id)
.onErrorResume(ManagementException.class, e -> Mono.empty())
.map(
roleAssignmentInner ->
new RoleAssignmentImpl(roleAssignmentInner.name(), roleAssignmentInner, manager()));
Expand All @@ -66,7 +64,6 @@ public PagedIterable<RoleAssignment> listByScope(String scope) {
public Mono<RoleAssignment> getByScopeAsync(String scope, String name) {
return inner()
.getAsync(scope, name)
.onErrorResume(ManagementException.class, e -> Mono.empty())
.map(
roleAssignmentInner ->
new RoleAssignmentImpl(roleAssignmentInner.name(), roleAssignmentInner, manager()));
Expand All @@ -81,7 +78,6 @@ protected RoleAssignmentImpl wrapModel(String name) {
public Mono<RoleAssignment> deleteByIdAsync(String id) {
return inner()
.deleteByIdAsync(id)
.onErrorResume(ManagementException.class, e -> Mono.empty())
.map(
roleAssignmentInner ->
new RoleAssignmentImpl(roleAssignmentInner.name(), roleAssignmentInner, manager()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.exception.ManagementException;
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.models.RoleDefinition;
import com.azure.resourcemanager.authorization.models.RoleDefinitions;
Expand Down Expand Up @@ -41,7 +40,6 @@ public RoleDefinition getById(String objectId) {
public Mono<RoleDefinition> getByIdAsync(String id) {
return inner()
.getByIdAsync(id)
.onErrorResume(ManagementException.class, e -> Mono.empty())
.map(roleDefinitionInner -> new RoleDefinitionImpl(roleDefinitionInner, manager()));
}

Expand All @@ -54,7 +52,6 @@ public RoleDefinition getByScope(String scope, String name) {
public Mono<RoleDefinition> getByScopeAsync(String scope, String name) {
return inner()
.getAsync(scope, name)
.onErrorResume(ManagementException.class, e -> Mono.empty())
.map(roleDefinitionInner -> new RoleDefinitionImpl(roleDefinitionInner, manager()));
}

Expand All @@ -79,7 +76,6 @@ public PagedIterable<RoleDefinition> listByScope(String scope) {
public Mono<RoleDefinition> getByScopeAndRoleNameAsync(String scope, String roleName) {
return inner()
.listAsync(scope, String.format("roleName eq '%s'", roleName))
.onErrorResume(ManagementException.class, e -> Mono.empty())
.singleOrEmpty()
.map(roleDefinitionInner -> new RoleDefinitionImpl(roleDefinitionInner, manager()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.models.GraphErrorException;
import com.azure.resourcemanager.authorization.models.ServicePrincipal;
import com.azure.resourcemanager.authorization.models.ServicePrincipals;
import com.azure.resourcemanager.authorization.fluent.inner.ServicePrincipalInner;
Expand Down Expand Up @@ -69,7 +68,6 @@ public ServicePrincipalImpl getById(String id) {
public Mono<ServicePrincipal> getByIdAsync(String id) {
return innerCollection
.getAsync(id)
.onErrorResume(GraphErrorException.class, e -> Mono.empty())
.flatMap(
servicePrincipalInner ->
new ServicePrincipalImpl(servicePrincipalInner, manager()).refreshCredentialsAsync());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public Mono<String> grantAccessAsync(int accessDurationInSeconds) {
.inner()
.getDisks()
.grantAccessAsync(this.resourceGroupName(), this.name(), grantAccessDataInner)
.onErrorResume(e -> Mono.empty())
.map(accessUriInner -> accessUriInner.accessSas());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public Mono<GalleryImageVersion> getByGalleryImageAsync(
String resourceGroupName, String galleryName, String galleryImageName, String galleryImageVersionName) {
return inner()
.getAsync(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public PagedIterable<GalleryImage> listByGallery(String resourceGroupName, Strin
public Mono<GalleryImage> getByGalleryAsync(String resourceGroupName, String galleryName, String galleryImageName) {
return inner()
.getAsync(resourceGroupName, galleryName, galleryImageName)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ private Mono<VirtualMachineExtensionInner> retrieveExtensionWithInstanceViewAsyn
return computeManager
.inner()
.getVirtualMachineExtensions()
.getAsync(rgName, vmName, extension.name(), "instanceView")
.onErrorResume(e -> Mono.empty());
.getAsync(rgName, vmName, extension.name(), "instanceView");
}

/**
Expand All @@ -133,12 +132,7 @@ private Mono<VirtualMachineExtensionInner> retrieveEncryptExtensionWithInstanceV
.inner()
.getVirtualMachines()
.getByResourceGroupAsync(rgName, vmName)
.onErrorResume(
e ->
Mono
.error(
new Exception(
String.format("VM with name '%s' not found (resource group '%s')", vmName, rgName))))
// Exception if vm not found
.flatMap(
virtualMachine -> {
if (virtualMachine.resources() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,8 @@ private Mono<VirtualMachineInner> retrieveVirtualMachineAsync() {
return computeManager
.inner()
.getVirtualMachines()
.getByResourceGroupAsync(rgName, vmName)
.onErrorResume(
e ->
Mono
.error(
new Exception(
String.format("VM with name '%s' not found (resource group '%s')", vmName, rgName))));
.getByResourceGroupAsync(rgName, vmName);
// Exception if vm not found
}

private boolean hasEncryptionExtensionInstanceView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ private Mono<VirtualMachineInner> retrieveVirtualMachineAsync() {
return computeManager
.inner()
.getVirtualMachines()
.getByResourceGroupAsync(ResourceUtils.groupFromResourceId(vmId), ResourceUtils.nameFromResourceId(vmId))
.onErrorResume(e -> Mono.error(new Exception(String.format("VM with id '%s' not found.", vmId))));
.getByResourceGroupAsync(ResourceUtils.groupFromResourceId(vmId), ResourceUtils.nameFromResourceId(vmId));
// Exception if vm not found
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public Mono<String> grantAccessAsync(int accessDurationInSeconds) {
.inner()
.getSnapshots()
.grantAccessAsync(resourceGroupName(), name(), grantAccessDataInner)
.onErrorResume(e -> Mono.empty())
.map(accessUriInner -> accessUriInner.accessSas());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public Mono<String> grantAccessAsync(
grantAccessDataInner.withAccess(accessLevel).withDurationInSeconds(accessDuration);
return inner()
.grantAccessAsync(resourceGroupName, snapshotName, grantAccessDataInner)
.onErrorResume(e -> Mono.empty())
.map(accessUriInner -> accessUriInner.accessSas());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public Mono<VirtualMachineExtensionImage> getImageAsync() {
final VirtualMachineExtensionImageVersionImpl self = this;
return client
.getAsync(regionName(), type().publisher().name(), type().name(), name())
.onErrorResume(e -> Mono.empty())
.map(inner -> new VirtualMachineExtensionImageImpl(self, inner));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.exception.ManagementException;
import com.azure.resourcemanager.compute.models.VirtualMachineExtensionImage;
import com.azure.resourcemanager.compute.models.VirtualMachineExtensionImageVersion;
import com.azure.resourcemanager.compute.models.VirtualMachineExtensionImages;
import com.azure.resourcemanager.compute.models.VirtualMachinePublishers;
import com.azure.resourcemanager.resources.fluentcore.arm.Region;
import com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;

/** The implementation for {@link VirtualMachineExtensionImages}. */
public class VirtualMachineExtensionImagesImpl implements VirtualMachineExtensionImages {
Expand Down Expand Up @@ -44,9 +45,10 @@ public PagedFlux<VirtualMachineExtensionImage> listByRegionAsync(String regionNa
virtualMachinePublisher
.extensionTypes()
.listAsync()
.onErrorResume(e -> Mono.empty())
.flatMap(
virtualMachineExtensionImageType -> virtualMachineExtensionImageType.versions().listAsync())
.onErrorResume(ManagementException.class,
e -> e.getResponse().getStatusCode() == 404 ? Flux.empty() : Flux.error(e))
ChenTanyi marked this conversation as resolved.
Show resolved Hide resolved
.flatMap(virtualMachineExtensionImageType ->
virtualMachineExtensionImageType.versions().listAsync())
.flatMap(VirtualMachineExtensionImageVersion::getImageAsync));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public Mono<VirtualMachineExtensionInstanceView> getInstanceViewAsync() {
return this
.client
.getAsync(this.parent().resourceGroupName(), this.parent().name(), this.name(), "instanceView")
.onErrorResume(e -> Mono.empty())
.map(inner -> inner.instanceView());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.exception.ManagementException;
import com.azure.resourcemanager.compute.models.VirtualMachineImage;
import com.azure.resourcemanager.compute.models.VirtualMachineImages;
import com.azure.resourcemanager.compute.models.VirtualMachinePublishers;
Expand All @@ -12,8 +13,9 @@
import com.azure.resourcemanager.compute.fluent.VirtualMachineImagesClient;
import com.azure.resourcemanager.resources.fluentcore.arm.Region;
import com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter;
import reactor.core.publisher.Flux;

import java.util.List;
import reactor.core.publisher.Mono;

/** The implementation for {@link VirtualMachineImages}. */
public class VirtualMachineImagesImpl implements VirtualMachineImages {
Expand Down Expand Up @@ -85,7 +87,8 @@ public PagedFlux<VirtualMachineImage> listByRegionAsync(String regionName) {
virtualMachinePublisher
.offers()
.listAsync()
.onErrorResume(e -> Mono.empty())
.onErrorResume(ManagementException.class,
e -> e.getResponse().getStatusCode() == 404 ? Flux.empty() : Flux.error(e))
ChenTanyi marked this conversation as resolved.
Show resolved Hide resolved
.flatMap(virtualMachineOffer -> virtualMachineOffer.skus().listAsync())
.flatMap(virtualMachineSku -> virtualMachineSku.images().listAsync()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,8 @@ private Mono<VirtualMachineInner> retrieveVirtualMachineAsync() {
.computeManager
.inner()
.getVirtualMachines()
.getByResourceGroupAsync(rgName, vmName)
.onErrorResume(
e ->
Mono
.error(
new Exception(
String.format("VM with name '%s' not found (resource group '%s')", vmName, rgName))));
.getByResourceGroupAsync(rgName, vmName);
// Exception if vm not found
}

private boolean hasEncryptionDetails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,8 @@ private Mono<VirtualMachineInner> retrieveVirtualMachineAsync() {
.computeManager
.inner()
.getVirtualMachines()
.getByResourceGroupAsync(rgName, vmName)
.onErrorResume(
Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Jul 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Track1 does this

    private Observable<VirtualMachineInner> retrieveVirtualMachineAsync() {
        return this.computeManager
                .inner()
                .virtualMachines()
                .getByResourceGroupAsync(rgName, vmName, InstanceViewTypes.INSTANCE_VIEW)
                .flatMap(new Func1<VirtualMachineInner, Observable<VirtualMachineInner>>() {
                    @Override
                    public Observable<VirtualMachineInner> call(VirtualMachineInner virtualMachine) {
                        if (virtualMachine == null) {
                            return Observable.error(new Exception(String.format("VM with name '%s' not found (resource group '%s')",
                                    vmName, rgName)));
                        }
                        return Observable.just(virtualMachine);
                    }
                });
    }

Basically it convert null to Exception.

Since we already has Exception here, no need for this code.


I've added // Exception if vm not found comment in these locations, in case we need to switch back the GET 404 response to Mono.empty() without ManagementException.

e ->
Mono
.error(
new Exception(
String.format("VM with name '%s' not found (resource group '%s')", vmName, rgName))));
.getByResourceGroupAsync(rgName, vmName);
// Exception if vm not found
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Mono<ARecordSet> getByNameAsync(String name) {
.inner()
.getRecordSets()
.getAsync(this.dnsZone.resourceGroupName(), this.dnsZone.name(), name, this.recordType)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Mono<AaaaRecordSet> getByNameAsync(String name) {
.inner()
.getRecordSets()
.getAsync(this.dnsZone.resourceGroupName(), this.dnsZone.name(), name, this.recordType)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Mono<CNameRecordSet> getByNameAsync(String name) {
.inner()
.getRecordSets()
.getAsync(this.dnsZone.resourceGroupName(), this.dnsZone.name(), name, this.recordType)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Mono<CaaRecordSet> getByNameAsync(String name) {
.inner()
.getRecordSets()
.getAsync(this.dnsZone.resourceGroupName(), this.dnsZone.name(), name, this.recordType)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Mono<MXRecordSet> getByNameAsync(String name) {
.inner()
.getRecordSets()
.getAsync(this.dnsZone.resourceGroupName(), this.dnsZone.name(), name, this.recordType)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Mono<NSRecordSet> getByNameAsync(String name) {
.inner()
.getRecordSets()
.getAsync(this.dnsZone.resourceGroupName(), this.dnsZone.name(), name, this.recordType)
.onErrorResume(e -> Mono.empty())
.map(this::wrapModel);
}

Expand Down
Loading