Skip to content
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 @@ -11,6 +11,7 @@
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingInGroupByTag;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;

import java.util.List;
Expand All @@ -24,7 +25,8 @@ public interface GenericResources extends
SupportsListingByGroup<GenericResource>,
SupportsListingInGroupByTag<GenericResource>,
SupportsGettingById<GenericResource>,
SupportsCreating<GenericResource.DefinitionStages.Blank> {
SupportsCreating<GenericResource.DefinitionStages.Blank>,
SupportsDeleting {
/**
* Checks if a resource exists in a resource group.
*
Expand All @@ -44,6 +46,14 @@ boolean checkExistence(
String resourceName,
String apiVersion);

/**
* Checks if a resource exists.
*
* @param id the ID of the resource.
* @return true if the resource exists; false otherwise
*/
boolean checkExistenceById(String id);

/**
* Returns a resource belonging to a resource group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.microsoft.azure.management.apigeneration.Fluent;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBeginDeleting;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;
Expand All @@ -24,6 +25,7 @@ public interface ResourceGroups extends
SupportsGettingByName<ResourceGroup>,
SupportsCreating<ResourceGroup.DefinitionStages.Blank>,
SupportsDeleting,
SupportsBeginDeleting,
SupportsBatchCreation<ResourceGroup> {
/**
* Checks whether resource group exists.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.resources.fluentcore.collection;

import com.microsoft.azure.management.apigeneration.LangDefinition;
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 resource ID.
* <p>
* (Note: this interface is not intended to be implemented by user code)
*/
@LangDefinition(ContainerName = "CollectionActions", CreateAsyncMethods = true)
public interface SupportsBeginDeleting {
/**
* Begins deleting a resource from Azure, identifying it by its resource ID. The
* resource will stay until get() returns null.
*
* @param id the resource ID of the resource to delete
*/
void beginDelete(String id);

/**
* Asynchronously begins deleting a resource from Azure, identifying it by its resource ID.
* The resource will stay until get() returns null.
*
* @param id the resource ID of the resource to delete
* @param callback the callback on success or failure
* @return a handle to cancel the request
*/
ServiceCall<Void> beginDeleteAsync(String id, ServiceCallback<Void> callback);

/**
* Asynchronously begins deleting a resource from Azure, identifying it by its resource ID.
* The resource will stay until get() returns null.
*
* @param id the resource ID of the resource to delete
* @return an observable of the request
*/
Observable<Void> beginDeleteAsync(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import rx.Observable;
import rx.functions.Func1;

import java.util.List;

Expand Down Expand Up @@ -75,6 +76,12 @@ public boolean checkExistence(String resourceGroupName, String resourceProviderN
apiVersion);
}

@Override
public boolean checkExistenceById(String id) {
String apiVersion = getApiVersionFromId(id).toBlocking().single();
return innerCollection.checkExistenceById(id, apiVersion);
}

@Override
public GenericResource getById(String id) {
Provider provider = myManager.providers().getByName(ResourceUtils.resourceProviderFromResourceId(id));
Expand Down Expand Up @@ -193,4 +200,25 @@ public Observable<Void> deleteAsync(String groupName, String name) {
// Not needed, can't be supported, provided only to satisfy GroupableResourceImpl's requirements
throw new UnsupportedOperationException("Delete just by resource group and name is not supported. Please use other overloads.");
}

@Override
public Observable<Void> deleteAsync(final String id) {
return getApiVersionFromId(id)
.flatMap(new Func1<String, Observable<Void>>() {
@Override
public Observable<Void> call(String apiVersion) {
return innerCollection.deleteByIdAsync(id, apiVersion);
}
});
}

private Observable<String> getApiVersionFromId(final String id) {
return myManager.providers().getByNameAsync(ResourceUtils.resourceProviderFromResourceId(id))
.map(new Func1<Provider, String>() {
@Override
public String call(Provider provider) {
return ResourceUtils.defaultApiVersion(id, provider);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import com.microsoft.azure.management.resources.ResourceGroups;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableResourcesImpl;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;
import rx.Observable;
import rx.functions.Func1;

/**
* The implementation for {@link ResourceGroups} and its parent interfaces.
Expand Down Expand Up @@ -76,4 +80,25 @@ protected ResourceGroupImpl wrapModel(ResourceGroupInner inner) {
}
return new ResourceGroupImpl(inner, serviceClient);
}

@Override
public void beginDelete(String id) {
beginDeleteAsync(id).toBlocking().subscribe();
}

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

@Override
public Observable<Void> beginDeleteAsync(String name) {
return client.beginDeleteAsync(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static void setup() throws Exception {

@AfterClass
public static void cleanup() throws Exception {
resourceGroups.delete(newRgName);
resourceGroups.delete(rgName);
resourceGroups.beginDelete(newRgName);
resourceGroups.beginDelete(rgName);
}

@Test
Expand Down Expand Up @@ -72,5 +72,8 @@ public void canCreateUpdateMoveResource() throws Exception {
resource.update()
.withProperties(new ObjectMapper().readTree("{\"SiteMode\":\"Limited\",\"ComputeMode\":\"Dynamic\"}"))
.apply();
// Delete
genericResources.delete(resource.id());
Assert.assertFalse(genericResources.checkExistence(newRgName, resource.resourceProviderNamespace(), resource.parentResourcePath(), resource.resourceType(), resource.name(), resource.apiVersion()));
}
}