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

Exposing Create and CreateAsync in collection that takes variable number of Creatables #1015

Merged
merged 7 commits into from
Aug 10, 2016
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 @@ -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;
Expand All @@ -18,5 +19,6 @@ public interface AvailabilitySets extends
SupportsListing<AvailabilitySet>,
SupportsCreating<AvailabilitySet.DefinitionStages.Blank>,
SupportsDeleting,
SupportsDeletingByGroup {
SupportsDeletingByGroup,
SupportsBatchCreation<AvailabilitySet> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,8 @@ public interface VirtualMachines extends
SupportsGettingById<VirtualMachine>,
SupportsCreating<VirtualMachine.DefinitionStages.Blank>,
SupportsDeleting,
SupportsDeletingByGroup {
SupportsDeletingByGroup,
SupportsBatchCreation<VirtualMachine> {

/**
* @return entry point to virtual machine sizes
Expand Down
6 changes: 6 additions & 0 deletions azure-mgmt-network/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,5 +25,6 @@ public interface LoadBalancers extends
SupportsGettingByGroup<LoadBalancer>,
SupportsGettingById<LoadBalancer>,
SupportsDeleting,
SupportsDeletingByGroup {
SupportsDeletingByGroup,
SupportsBatchCreation<LoadBalancer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,5 +19,6 @@ public interface NetworkInterfaces extends
SupportsGettingByGroup<NetworkInterface>,
SupportsGettingById<NetworkInterface>,
SupportsDeleting,
SupportsDeletingByGroup {
SupportsDeletingByGroup,
SupportsBatchCreation<NetworkInterface> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,5 +25,6 @@ public interface NetworkSecurityGroups extends
SupportsGettingByGroup<NetworkSecurityGroup>,
SupportsGettingById<NetworkSecurityGroup>,
SupportsDeleting,
SupportsDeletingByGroup {
SupportsDeletingByGroup,
SupportsBatchCreation<NetworkSecurityGroup> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,5 +25,6 @@ public interface Networks extends
SupportsGettingByGroup<Network>,
SupportsGettingById<Network>,
SupportsDeleting,
SupportsDeletingByGroup {
SupportsDeletingByGroup,
SupportsBatchCreation<Network> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,5 +25,6 @@ public interface PublicIpAddresses extends
SupportsListingByGroup<PublicIpAddress>,
SupportsGettingByGroup<PublicIpAddress>,
SupportsGettingById<PublicIpAddress>,
SupportsDeletingByGroup {
SupportsDeletingByGroup,
SupportsBatchCreation<PublicIpAddress> {
}
Original file line number Diff line number Diff line change
@@ -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<ResourceGroup> resourceGroupCreatable = resourceGroups
.define(RG_NAME)
.withRegion(Region.US_EAST);

final String vnetName = "vnet1212";
Creatable<Network> 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<NetworkInterface> networkInterface1Creatable = networkInterfaces
.define(nic1Name)
.withRegion(Region.US_EAST)
.withNewResourceGroup(resourceGroupCreatable)
.withNewPrimaryNetwork(networkCreatable)
.withPrimaryPrivateIpAddressStatic("10.0.0.5");

final String nic2Name = "nic2";
Creatable<NetworkInterface> networkInterface2Creatable = networkInterfaces
.define(nic2Name)
.withRegion(Region.US_EAST)
.withNewResourceGroup(resourceGroupCreatable)
.withNewPrimaryNetwork(networkCreatable)
.withPrimaryPrivateIpAddressStatic("10.0.0.6");

final String nic3Name = "nic3";
Creatable<NetworkInterface> networkInterface3Creatable = networkInterfaces
.define(nic3Name)
.withRegion(Region.US_EAST)
.withNewResourceGroup(resourceGroupCreatable)
.withNewPrimaryNetwork(networkCreatable)
.withPrimaryPrivateIpAddressStatic("10.0.0.7");

final String nic4Name = "nic4";
Creatable<NetworkInterface> networkInterface4Creatable = networkInterfaces
.define(nic4Name)
.withRegion(Region.US_EAST)
.withNewResourceGroup(resourceGroupCreatable)
.withNewPrimaryNetwork(networkCreatable)
.withPrimaryPrivateIpAddressStatic("10.0.0.8");

CreatedResources<NetworkInterface> batchNics = networkInterfaces.create(networkInterface1Creatable,
networkInterface2Creatable,
networkInterface3Creatable,
networkInterface4Creatable);

Assert.assertTrue(batchNics.size() == 4);
HashMap<String, Boolean> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,8 @@ public interface ResourceGroups extends
SupportsListing<ResourceGroup>,
SupportsGettingByName<ResourceGroup>,
SupportsCreating<ResourceGroup.DefinitionStages.Blank>,
SupportsDeleting {
SupportsDeleting,
SupportsBatchCreation<ResourceGroup> {
/**
* Checks whether resource group exists.
*
Expand Down
Loading