Skip to content

Commit

Permalink
[#1078] Add async delete support
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Sep 23, 2016
1 parent 5508b42 commit bb9b68e
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import com.microsoft.azure.management.storage.implementation.StorageManager;
import rx.Observable;

/**
* Implementation for BatchAccounts and its parent interfaces.
Expand All @@ -27,13 +28,8 @@ protected BatchAccountsImpl(BatchAccountsInner innerCollection, BatchManager man
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.compute.AvailabilitySet;
import com.microsoft.azure.management.compute.AvailabilitySets;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupPagedList;
import rx.Observable;

import java.util.List;

Expand Down Expand Up @@ -61,13 +61,8 @@ public AvailabilitySetImpl define(String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

/**************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import com.microsoft.azure.management.storage.implementation.StorageManager;
import rx.Observable;

import java.util.ArrayList;

/**
Expand Down Expand Up @@ -55,13 +57,8 @@ public PagedList<VirtualMachineScaleSet> list() {
}

@Override
public void delete(String id) {
this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import com.microsoft.azure.management.storage.implementation.StorageManager;
import rx.Observable;
import rx.exceptions.Exceptions;

import java.util.ArrayList;
Expand Down Expand Up @@ -74,13 +75,8 @@ public VirtualMachine getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
public interface ServicePrincipals extends
SupportsCreating<ServicePrincipal.DefinitionStages.Blank>,
SupportsListing<ServicePrincipal>,
SupportsDeleting {
SupportsListing<ServicePrincipal> {
/**
* Gets the information about a service principal.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
public interface Users extends
SupportsCreating<User.DefinitionStages.Blank>,
SupportsListing<User>,
SupportsDeleting {
SupportsListing<User>{
/**
* Gets the information about a user.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public PagedList<ServicePrincipal> list() {
return wrapList(this.innerCollection.list());
}

@Override
public void delete(String id) {
innerCollection.delete(id);
}

@Override
public ServicePrincipalImpl define(String appId) {
return wrapModel(appId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ public PagedList<User> list() {
return wrapList(this.innerCollection.list());
}

@Override
public void delete(String id) {
innerCollection.delete(id);
}

@Override
public UserImpl define(String name) {
return wrapModel(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.microsoft.azure.management.keyvault.Vaults;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import rx.Observable;

import java.util.UUID;

Expand Down Expand Up @@ -57,13 +58,8 @@ public Vault getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.microsoft.azure.management.network.LoadBalancers;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import rx.Observable;

/**
* Implementation for {@link LoadBalancers}.
Expand Down Expand Up @@ -47,13 +48,8 @@ public LoadBalancerImpl getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.microsoft.azure.management.network.NetworkInterfaces;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import rx.Observable;

import java.util.ArrayList;

Expand Down Expand Up @@ -45,13 +46,8 @@ public NetworkInterface getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.microsoft.azure.management.network.NetworkSecurityGroups;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import rx.Observable;

import java.util.ArrayList;

Expand Down Expand Up @@ -49,13 +50,8 @@ public NetworkSecurityGroupImpl getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.microsoft.azure.management.network.Networks;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import rx.Observable;

import java.util.ArrayList;

Expand Down Expand Up @@ -51,13 +52,8 @@ public NetworkImpl getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import rx.Observable;

/**
* Implementation for {@link PublicIpAddresses}.
Expand Down Expand Up @@ -48,13 +49,8 @@ public PublicIpAddressImpl getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.microsoft.azure.management.redis.RedisCaches;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import rx.Observable;

/**
* The implementation of RedisCaches and its parent interfaces.
Expand Down Expand Up @@ -52,13 +53,8 @@ public RedisCache getByGroup(String groupName, String name) {
}

@Override
public void delete(String id) {
delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
}

@Override
public void delete(String groupName, String name) {
this.innerCollection.delete(groupName, name);
public Observable<Void> deleteAsync(String groupName, String name) {
return this.innerCollection.deleteAsync(groupName, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.apigeneration.LangDefinition.MethodConversion;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import rx.Observable;

/**
* Provides access to deleting a resource from Azure, identifying it by its name and its resource group.
Expand All @@ -23,4 +26,21 @@ public interface SupportsDeletingByGroup {
* @param name The name of the resource
*/
void delete(String groupName, String name);

/**
* Asynchronously delete a resource from Azure, identifying it by its name and its resource group.
*
* @param groupName The group the resource is part of
* @param name The name of the resource
* @param callback the callback to call on success or failure
*/
ServiceCall<Void> deleteAsync(String groupName, String name, ServiceCallback<Void> callback);

/**
* Asynchronously delete a resource from Azure, identifying it by its name and its resource group.
*
* @param groupName The group the resource is part of
* @param name The name of the resource
*/
Observable<Void> deleteAsync(String groupName, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import com.microsoft.azure.management.resources.fluentcore.model.CreatedResources;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl;
Expand Down Expand Up @@ -32,7 +33,10 @@
*/
public abstract class CreatableResourcesImpl<T extends Resource, ImplT extends T, InnerT>
extends CreatableWrappersImpl<T, ImplT, InnerT>
implements SupportsBatchCreation<T> {
implements
SupportsBatchCreation<T>,
// Assume anything creatable is deletable
SupportsDeleting {

protected CreatableResourcesImpl() {
}
Expand Down Expand Up @@ -100,6 +104,21 @@ public ServiceResponse<CreatedResources<T>> call(CreatedResources<T> ts) {
}), callback);
}

@Override
public void delete(String id) {
deleteAsync(id).toBlocking().subscribe();
}

@Override
public ServiceCall<Void> deleteAsync(String id, ServiceCallback<Void> callback) {
return ServiceCall.create(deleteAsync(id).map(new Func1<Void, ServiceResponse<Void>>() {
@Override
public ServiceResponse<Void> call(Void aVoid) {
return new ServiceResponse<>(aVoid, null);
}
}), callback);
}

/**
* Implements {@link CreatedResources}.
* @param <ResourceT> the type of the resources in the batch.
Expand Down
Loading

0 comments on commit bb9b68e

Please sign in to comment.