diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java index 9212e926d0f2..0b1ea8485e0f 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySets.java @@ -4,6 +4,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -18,5 +19,6 @@ public interface AvailabilitySets extends SupportsListing, SupportsCreating, SupportsDeleting, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java index 0ebcb5d045e8..c6aed475629e 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachines.java @@ -5,6 +5,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -21,7 +22,8 @@ public interface VirtualMachines extends SupportsGettingById, SupportsCreating, SupportsDeleting, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { /** * @return entry point to virtual machine sizes diff --git a/azure-mgmt-network/pom.xml b/azure-mgmt-network/pom.xml index c18033a48316..0ea3ecac32d6 100644 --- a/azure-mgmt-network/pom.xml +++ b/azure-mgmt-network/pom.xml @@ -61,6 +61,12 @@ junit test + + com.microsoft.azure + azure-client-authentication + 1.0.0-SNAPSHOT + test + diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancers.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancers.java index 0518ad617d31..9d4f3ef831a9 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancers.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/LoadBalancers.java @@ -9,6 +9,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -24,5 +25,6 @@ public interface LoadBalancers extends SupportsGettingByGroup, SupportsGettingById, SupportsDeleting, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java index 4e6f5c84b71c..96e726f9f406 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterfaces.java @@ -4,6 +4,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -18,5 +19,6 @@ public interface NetworkInterfaces extends SupportsGettingByGroup, SupportsGettingById, SupportsDeleting, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java index 2e5be3680c3d..dd6e6bde8998 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkSecurityGroups.java @@ -9,6 +9,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -24,5 +25,6 @@ public interface NetworkSecurityGroups extends SupportsGettingByGroup, SupportsGettingById, SupportsDeleting, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java index 0d98140c9931..6795405c8b5b 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/Networks.java @@ -9,6 +9,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -24,5 +25,6 @@ public interface Networks extends SupportsGettingByGroup, SupportsGettingById, SupportsDeleting, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java index df988c66cf6b..ae434425751c 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java @@ -9,6 +9,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -24,5 +25,6 @@ public interface PublicIpAddresses extends SupportsListingByGroup, SupportsGettingByGroup, SupportsGettingById, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { } diff --git a/azure-mgmt-network/src/test/java/com.microsoft.azure.management.network/NetworkInterfaceOperationsTests.java b/azure-mgmt-network/src/test/java/com.microsoft.azure.management.network/NetworkInterfaceOperationsTests.java new file mode 100644 index 000000000000..08f965e201f7 --- /dev/null +++ b/azure-mgmt-network/src/test/java/com.microsoft.azure.management.network/NetworkInterfaceOperationsTests.java @@ -0,0 +1,105 @@ +package com.microsoft.azure.management.network; + +import com.microsoft.azure.management.resources.ResourceGroup; +import com.microsoft.azure.management.resources.ResourceGroups; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import com.microsoft.azure.management.resources.fluentcore.model.CreatedResources; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import java.util.HashMap; +import java.util.LinkedHashMap; + +public class NetworkInterfaceOperationsTests extends NetworkManagementTestBase { + private static String RG_NAME = "javanwmrg"; + private static String resourceGroupId = null; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + if (resourceGroupId != null) { + resourceManager.resourceGroups().delete(resourceGroupId); + } + } + + @Test + public void canCreateBatchOfNetworkInterfaces() throws Exception { + ResourceGroups resourceGroups = resourceManager.resourceGroups(); + Networks networks = networkManager.networks(); + NetworkInterfaces networkInterfaces = networkManager.networkInterfaces(); + + Creatable resourceGroupCreatable = resourceGroups + .define(RG_NAME) + .withRegion(Region.US_EAST); + + final String vnetName = "vnet1212"; + Creatable networkCreatable = networks + .define(vnetName) + .withRegion(Region.US_EAST) + .withNewResourceGroup(resourceGroupCreatable) + .withAddressSpace("10.0.0.0/28"); + + // Prepare a batch of nics + // + final String nic1Name = "nic1"; + Creatable networkInterface1Creatable = networkInterfaces + .define(nic1Name) + .withRegion(Region.US_EAST) + .withNewResourceGroup(resourceGroupCreatable) + .withNewPrimaryNetwork(networkCreatable) + .withPrimaryPrivateIpAddressStatic("10.0.0.5"); + + final String nic2Name = "nic2"; + Creatable networkInterface2Creatable = networkInterfaces + .define(nic2Name) + .withRegion(Region.US_EAST) + .withNewResourceGroup(resourceGroupCreatable) + .withNewPrimaryNetwork(networkCreatable) + .withPrimaryPrivateIpAddressStatic("10.0.0.6"); + + final String nic3Name = "nic3"; + Creatable networkInterface3Creatable = networkInterfaces + .define(nic3Name) + .withRegion(Region.US_EAST) + .withNewResourceGroup(resourceGroupCreatable) + .withNewPrimaryNetwork(networkCreatable) + .withPrimaryPrivateIpAddressStatic("10.0.0.7"); + + final String nic4Name = "nic4"; + Creatable networkInterface4Creatable = networkInterfaces + .define(nic4Name) + .withRegion(Region.US_EAST) + .withNewResourceGroup(resourceGroupCreatable) + .withNewPrimaryNetwork(networkCreatable) + .withPrimaryPrivateIpAddressStatic("10.0.0.8"); + + CreatedResources batchNics = networkInterfaces.create(networkInterface1Creatable, + networkInterface2Creatable, + networkInterface3Creatable, + networkInterface4Creatable); + + Assert.assertTrue(batchNics.size() == 4); + HashMap found = new LinkedHashMap<>(); + for(NetworkInterface nic : batchNics) { + if (nic.name().equalsIgnoreCase(nic1Name)) { + found.put(nic1Name, true); + } + if (nic.name().equalsIgnoreCase(nic2Name)) { + found.put(nic2Name, true); + } + if (nic.name().equalsIgnoreCase(nic3Name)) { + found.put(nic3Name, true); + } + if (nic.name().equalsIgnoreCase(nic4Name)) { + found.put(nic4Name, true); + } + } + Assert.assertTrue(found.size() == 4); + } +} diff --git a/azure-mgmt-network/src/test/java/com.microsoft.azure.management.network/NetworkManagementTestBase.java b/azure-mgmt-network/src/test/java/com.microsoft.azure.management.network/NetworkManagementTestBase.java new file mode 100644 index 000000000000..b9995111b0de --- /dev/null +++ b/azure-mgmt-network/src/test/java/com.microsoft.azure.management.network/NetworkManagementTestBase.java @@ -0,0 +1,32 @@ +package com.microsoft.azure.management.network; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.network.implementation.NetworkManager; +import com.microsoft.azure.management.resources.implementation.ResourceManager; +import com.microsoft.azure.RestClient; + +public abstract class NetworkManagementTestBase { + protected static ResourceManager resourceManager; + protected static NetworkManager networkManager; + + public static void createClients() { + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + null); + + RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() + .withCredentials(credentials) + //.withLogLevel(HttpLoggingInterceptor.Level.BASIC) + .build(); + + resourceManager = ResourceManager + .authenticate(restClient) + .withSubscription(System.getenv("arm.subscription-id")); + + networkManager = NetworkManager + .authenticate(restClient, System.getenv("arm.subscription-id")); + } +} \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java index c56712079edb..a39a0253329b 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroups.java @@ -8,6 +8,7 @@ import com.microsoft.azure.CloudException; 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.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; @@ -21,7 +22,8 @@ public interface ResourceGroups extends SupportsListing, SupportsGettingByName, SupportsCreating, - SupportsDeleting { + SupportsDeleting, + SupportsBatchCreation { /** * Checks whether resource group exists. * 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 new file mode 100644 index 000000000000..70685b4ba576 --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/CreatableResourcesImpl.java @@ -0,0 +1,343 @@ +package com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation; + +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.model.CreatedResources; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; + +/** + * Base class for creatable resource collection, i.e. those where the member of the collection is of Resource + * type {@link com.microsoft.azure.Resource } and are creatable. + * (Internal use only) + * + * @param the individual resource type returned + * @param the individual resource implementation + * @param the wrapper inner type + */ +public abstract class CreatableResourcesImpl + extends CreatableWrappersImpl + implements SupportsBatchCreation { + + protected CreatableResourcesImpl() { + } + + @Override + public CreatedResources create(Creatable ... creatables) throws Exception { + ServiceCall> serviceCall = createAsync(null, creatables); + serviceCall.wait(); + return serviceCall.get().getBody(); + } + + @Override + public ServiceCall> createAsync(final ServiceCallback> callback, + Creatable ... creatables) { + CreatableResourcesRootImpl rootResource = new CreatableResourcesRootImpl<>(); + rootResource.addCreatableDependencies(creatables); + + final CreateResourcesServiceCall createResourcesServiceCall = new CreateResourcesServiceCall(); + ServiceCall> serviceCall = rootResource.createAsync(createResourcesServiceCall.wrapCallback(callback)); + createResourcesServiceCall.setInnerServiceCall(serviceCall); + return createResourcesServiceCall; + } + + /** + * Implements {@link CreatedResources}. + * @param the type of the resources in the batch. + */ + private class CreatedResourcesImpl implements CreatedResources { + private CreatableResourcesRoot creatableResourcesRoot; + private final List list; + + CreatedResourcesImpl(CreatableResourcesRoot creatableResourcesRoot) { + this.creatableResourcesRoot = creatableResourcesRoot; + this.list = this.creatableResourcesRoot.createdTopLevelResources(); + } + + @Override + public Resource createdRelatedResource(String key) { + return this.creatableResourcesRoot.createdRelatedResource(key); + } + + @Override + public int size() { + return list.size(); + } + + @Override + public boolean isEmpty() { + return list.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return list.contains(o); + } + + @Override + public Iterator iterator() { + return list.iterator(); + } + + @Override + public Object[] toArray() { + return list.toArray(); + } + + @Override + public T[] toArray(T[] a) { + return list.toArray(a); + } + + @Override + public boolean add(ResourceT resourceT) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection c) { + return list.containsAll(c); + } + + @Override + public boolean addAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(int index, Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + @Override + public ResourceT get(int index) { + return this.list.get(index); + } + + @Override + public ResourceT set(int index, ResourceT element) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(int index, ResourceT element) { + throw new UnsupportedOperationException(); + } + + @Override + public ResourceT remove(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public int indexOf(Object o) { + return this.list.indexOf(o); + } + + @Override + public int lastIndexOf(Object o) { + return this.list.lastIndexOf(o); + } + + @Override + public ListIterator listIterator() { + return this.list.listIterator(); + } + + @Override + public ListIterator listIterator(int index) { + return this.list.listIterator(index); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return this.list.subList(fromIndex, toIndex); + } + } + + /** + * The local root resource that is used as dummy parent resource for the batch creatable resources + * added via {@link CreatableResourcesImpl#create} or {@link CreatableResourcesImpl#createAsync}. + * + * @param the type of the resources in the batch. + */ + interface CreatableResourcesRoot extends Resource { + List createdTopLevelResources(); + Resource createdRelatedResource(String key); + } + + /** + * Implementation of {@link CreatableResourcesRoot}. + * + * @param the type of the resources in the batch. + */ + private class CreatableResourcesRootImpl + extends CreatableImpl, Object, CreatableResourcesRootImpl, Resource> + implements CreatableResourcesRoot { + /** + * Collection of keys of top level resources in this batch. + */ + private List keys; + + CreatableResourcesRootImpl() { + super("CreatableResourcesRoot", null); + this.keys = new ArrayList<>(); + } + + @Override + public List createdTopLevelResources() { + List resources = new ArrayList<>(); + for (String resourceKey : keys) { + resources.add((ResourceT) creatorTaskGroup().createdResource(resourceKey)); + } + return Collections.unmodifiableList(resources); + } + + @Override + public Resource createdRelatedResource(String key) { + return (Resource) creatorTaskGroup().createdResource(key); + } + + void addCreatableDependencies(Creatable ... creatables) { + for (Creatable item : creatables) { + this.keys.add(item.key()); + this.addCreatableDependency((item)); + } + } + + @Override + public ServiceCall createResourceAsync(ServiceCallback serviceCallback) { + serviceCallback.success(new ServiceResponse(this, null)); + return null; + } + + @Override + public Resource createResource() throws Exception { + return this; + } + + // Below overrides returns null as this is not a real resource in Azure + // but a dummy resource representing parent of a batch of creatable Azure + // resources. + + @Override + public CreatableResourcesRoot refresh() throws Exception { + return null; + } + + @Override + public String id() { + return null; + } + + @Override + public String type() { + return null; + } + + @Override + public String regionName() { + return null; + } + + @Override + public Region region() { + return null; + } + + @Override + public Map tags() { + return null; + } + } + + /** + * Represents a collection of in-progress Create service calls in the batch. + */ + private class CreateResourcesServiceCall extends ServiceCall> { + private ServiceCall> innerServiceCall; + + /** + * Creates CreateResourcesServiceCall. + */ + CreateResourcesServiceCall() { + super(null); + } + + /** + * Sets the inner service call. + * + * @param inner the service call to wrap + */ + public void setInnerServiceCall(ServiceCall> inner) { + this.innerServiceCall = inner; + } + + /** + * Cancels all the service calls currently executing. + */ + public void cancel() { + this.innerServiceCall.cancel(); + } + + /** + * @return true if the call has been canceled; false otherwise. + */ + public boolean isCancelled() { + return this.innerServiceCall.isCancelled(); + } + + ServiceCallback> wrapCallback(final ServiceCallback> innerCallback) { + final CreateResourcesServiceCall self = this; + return new ServiceCallback>() { + @Override + public void failure(Throwable t) { + self.failure(t); + if (innerCallback != null) { + innerCallback.failure((t)); + } + } + + @Override + public void success(ServiceResponse> result) { + self.success(new ServiceResponse>(new CreatedResourcesImpl<>(result.getBody()), null)); + if (innerCallback != null) { + innerCallback.success(new ServiceResponse>(new CreatedResourcesImpl<>(result.getBody()), null)); + } + } + }; + } + } +} \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/GroupableResourcesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/GroupableResourcesImpl.java index 3e1abb830986..3cb20c9a11e6 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/GroupableResourcesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/GroupableResourcesImpl.java @@ -30,7 +30,7 @@ public abstract class GroupableResourcesImpl< InnerT extends Resource, InnerCollectionT, ManagerT extends ManagerBase> - extends CreatableWrappersImpl + extends CreatableResourcesImpl implements SupportsGettingById, SupportsGettingByGroup { 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 new file mode 100644 index 000000000000..336d1bdac1db --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsBatchCreation.java @@ -0,0 +1,35 @@ +package com.microsoft.azure.management.resources.fluentcore.collection; + + +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; +import com.microsoft.azure.management.resources.fluentcore.model.CreatedResources; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; + +/** + * Providing access to creating a batch of Azure top level resources of same type. + *

+ * (Note: this interface is not intended to be implemented by user code) + * @param the top level Azure resource type + */ +public interface SupportsBatchCreation { + /** + * Executes the create requests on a collection (batch) of resources. + * + * @param creatables the 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(Creatable... 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. + * + * @param callback the callback to handle success and failure + * @param creatables the creatables in the batch + * @return a handle to cancel the request + */ + ServiceCall> createAsync(ServiceCallback> callback, Creatable... creatables); +} \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/CreatedResources.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/CreatedResources.java new file mode 100644 index 000000000000..3e9487098a6d --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/CreatedResources.java @@ -0,0 +1,22 @@ +package com.microsoft.azure.management.resources.fluentcore.model; + + +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; + +import java.util.List; + +/** + * Represents result of batch of create operations. + *

+ * (Note: this interface is not intended to be implemented by user code) + * @param the type of the resource in this batch. + */ +public interface CreatedResources extends List { + /** + * Gets a created resource with the given key. + * + * @param key the key of the resource + * @return the created resource + */ + Resource createdRelatedResource(String key); +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java index a93dfe05db87..bb3202f8177e 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java @@ -9,7 +9,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.ResourceGroups; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableResourcesImpl; import com.microsoft.azure.management.resources.ResourceGroup; import java.io.IOException; @@ -18,7 +18,7 @@ * The implementation for {@link ResourceGroups} and its parent interfaces. */ final class ResourceGroupsImpl - extends CreatableWrappersImpl + extends CreatableResourcesImpl implements ResourceGroups { private final ResourceGroupsInner client; private final ResourceManagementClientImpl serviceClient; diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java index 7c3314b54c51..0e8804e86927 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java @@ -11,6 +11,7 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; 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; @@ -27,7 +28,8 @@ public interface StorageAccounts extends SupportsListingByGroup, SupportsGettingByGroup, SupportsGettingById, - SupportsDeletingByGroup { + SupportsDeletingByGroup, + SupportsBatchCreation { /** * Checks that account name is valid and is not in use. * diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java index f3a4b231c8e2..62bf4d2d7c63 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java @@ -165,8 +165,10 @@ public boolean isCancelled() { * * @param call the call */ - private void addCall(ServiceCall call) { - this.serviceCalls.add(call); + private void addCall(ServiceCall call) { + if (call != null) { + this.serviceCalls.add(call); + } } } }