From d1560603bfbe02894d307b6ed97c4c6e7732dd90 Mon Sep 17 00:00:00 2001 From: anuchan Date: Tue, 30 Aug 2016 17:52:39 -0700 Subject: [PATCH] Expose overload of batch create that takes a list --- .../CreatableResourcesImpl.java | 37 +++++++++++++++++++ .../collection/SupportsBatchCreation.java | 30 +++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/CreatableResourcesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/CreatableResourcesImpl.java index 9e24f5a62c01..7ce888f985c7 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/CreatableResourcesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/CreatableResourcesImpl.java @@ -43,6 +43,11 @@ public final CreatedResources create(Creatable ... creatables) throws Exce return BlockingObservable.from(createAsync(creatables)).single(); } + @Override + public final CreatedResources create(List> creatables) throws Exception { + return BlockingObservable.from(createAsync(creatables)).single(); + } + @Override @SafeVarargs public final Observable> createAsync(Creatable ... creatables) { @@ -58,6 +63,20 @@ public CreatedResources call(CreatableResourcesRoot tCreatableResourcesRoo }); } + @Override + public final Observable> createAsync(List> creatables) { + CreatableResourcesRootImpl rootResource = new CreatableResourcesRootImpl<>(); + rootResource.addCreatableDependencies(creatables); + + return rootResource.createAsync() + .map(new Func1, CreatedResources>() { + @Override + public CreatedResources call(CreatableResourcesRoot tCreatableResourcesRoot) { + return new CreatedResourcesImpl(tCreatableResourcesRoot); + } + }); + } + @Override @SafeVarargs public final ServiceCall> createAsync(final ServiceCallback> callback, Creatable... creatables) { @@ -70,6 +89,17 @@ public ServiceResponse> call(CreatedResources ts) { }), callback); } + @Override + public final ServiceCall> createAsync(final ServiceCallback> callback, List> creatables) { + return ServiceCall.create(createAsync(creatables).map(new Func1, ServiceResponse>>() { + @Override + public ServiceResponse> call(CreatedResources ts) { + // TODO: When https://github.com/Azure/azure-sdk-for-java/issues/1029 is done, this map can be removed + return new ServiceResponse<>(ts, null); + } + }), callback); + } + /** * Implements {@link CreatedResources}. * @param the type of the resources in the batch. @@ -254,6 +284,13 @@ void addCreatableDependencies(Creatable ... creatables) { } } + void addCreatableDependencies(List> creatables) { + for (Creatable item : creatables) { + this.keys.add(item.key()); + this.addCreatableDependency((item)); + } + } + @Override public Observable> createResourceAsync() { return Observable.just((CreatableResourcesRoot) this); diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsBatchCreation.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsBatchCreation.java index aeeaa7f63730..6f16ee9311a6 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsBatchCreation.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsBatchCreation.java @@ -8,6 +8,8 @@ import com.microsoft.rest.ServiceCallback; import rx.Observable; +import java.util.List; + /** * Providing access to creating a batch of Azure top level resources of same type. *

@@ -24,6 +26,15 @@ public interface SupportsBatchCreation { */ CreatedResources create(Creatable... creatables) throws Exception; + /** + * Executes the create requests on a collection (batch) of resources. + * + * @param creatables the list of creatables in the batch + * @return the batch operation result from which created resources in this batch can be accessed. + * @throws Exception exceptions from Azure + */ + CreatedResources create(List> creatables) throws Exception; + /** * Puts the requests to create a batch of resources into the queue and allow the HTTP client to execute it when * system resources are available. @@ -33,6 +44,15 @@ public interface SupportsBatchCreation { */ Observable> createAsync(Creatable... creatables); + /** + * Puts the requests to create a batch of resources into the queue and allow the HTTP client to execute it when + * system resources are available. + * + * @param creatables the list of creatables in the batch + * @return an observable for the resources + */ + Observable> createAsync(List> creatables); + /** * Puts the requests to create a batch of resources into the queue and allow the HTTP client to execute it when * system resources are available. @@ -42,4 +62,14 @@ public interface SupportsBatchCreation { * @return a handle to cancel the request */ ServiceCall> createAsync(ServiceCallback> callback, Creatable... creatables); + + /** + * Puts the requests to create a batch of resources into the queue and allow the HTTP client to execute it when + * system resources are available. + * + * @param callback the callback to handle success and failure + * @param creatables the list of creatables in the batch + * @return a handle to cancel the request + */ + ServiceCall> createAsync(final ServiceCallback> callback, List> creatables); } \ No newline at end of file