From 7ed9047c39002d5e6925e1ce86ca45b97afbb38c Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 May 2016 14:56:11 -0700 Subject: [PATCH 1/9] AvailabilitySet refinements, javadocs, bug fixes --- .../management/compute/AvailabilitySet.java | 58 ++++++++++++++----- .../management/compute/AvailabilitySets.java | 6 ++ .../implementation/AvailabilitySetImpl.java | 27 ++++----- .../resources/fluentcore/arm/Region.java | 2 +- .../fluentcore/arm/models/Resource.java | 2 +- .../implementation/GroupableResourceImpl.java | 2 +- 6 files changed, 63 insertions(+), 34 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java index 8720685da641..b47330185188 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java @@ -9,60 +9,90 @@ import java.util.List; +/** + * An immutable client-side representation of an Azure availability set. + */ public interface AvailabilitySet extends GroupableResource, Refreshable, Wrapper { /** - * Get the update domain count of availability set, an update domain represents the group of virtual + * Returns the update domain count of an availability set. + *

+ * An update domain represents the group of virtual * machines and underlying physical hardware that can be rebooted at the same time. * - * @return the platformUpdateDomainCount value + * @return the update domain count */ - Integer updateDomainCount(); + int updateDomainCount(); /** - * Get the fault domain count of availability set., a fault domain represents the group of virtual + * Returns the fault domain count of availability set. + *

+ * A fault domain represents the group of virtual * machines that shares common power source and network switch. * - * @return the platformUpdateDomainCount value + * @return the fault domain count */ - Integer FaultDomainCount(); + int faultDomainCount(); /** - * Get the list of ids of virtual machines in the availability set. + * Lists the resource IDs of the virtual machines in the availability set. * - * @return the virtualMachineIds value + * @return list of resource ID strings */ List virtualMachineIds(); /** - * Get the list of virtual machines in the availability set. + * Lists the virtual machines in the availability set. * - * @return the virtualMachineIds value + * @return list of virtual machines */ List virtualMachines() throws Exception; /** - * Get the statuses value. + * Lists the statuses of the existing virtual machines in the availability set. * - * @return the statuses value + * @return list of virtual machine statuses */ List statuses(); + /************************************************************** * Fluent interfaces to provision an AvailabilitySet **************************************************************/ + /** + * The first stage of an availability set definition + */ interface DefinitionBlank extends GroupableResource.DefinitionWithRegion { } + /** + * The stage of the availability set definition allowing to specify the resource group + */ interface DefinitionWithGroup extends GroupableResource.DefinitionWithGroup { } + /** + * The stage of an availability set definition which contains all the minimum required inputs for + * the resource to be created (via {@link DefinitionCreatable#create()}), but also allows + * for any other optional settings to be specified. + */ interface DefinitionCreatable extends Creatable { - DefinitionCreatable withUpdateDomainCount(Integer updateDomainCount); - DefinitionCreatable withFaultDomainCount(Integer faultDomainCount); + /** + * Specifies the update domain count for the availability set. + * @param updateDomainCount update domain count + * @return the next stage of the resource definition + */ + DefinitionCreatable withUpdateDomainCount(int updateDomainCount); + + /** + * Specifies the fault domain count for the availability set. + * @param faultDomainCount fault domain count + * @return the next stage of the resource definition + */ + DefinitionCreatable withFaultDomainCount(int faultDomainCount); } } 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 59197b8baee4..50548277d186 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 @@ -7,6 +7,9 @@ import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; +/** + * Entry point to availability set management API. + */ public interface AvailabilitySets extends SupportsListing, SupportsListingByGroup, @@ -14,6 +17,9 @@ public interface AvailabilitySets extends SupportsCreating, SupportsDeleting, SupportsDeletingByGroup { + /** + * Entry point to availability set management API within a specific resource group. + */ interface InGroup extends SupportsListing, SupportsCreating, diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java index d6ecf1b48a92..d47862c5fbe9 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java @@ -14,6 +14,7 @@ import com.microsoft.rest.ServiceResponse; import java.util.ArrayList; +import java.util.Collections; import java.util.List; class AvailabilitySetImpl @@ -23,7 +24,6 @@ class AvailabilitySetImpl AvailabilitySet.DefinitionBlank, AvailabilitySet.DefinitionWithGroup, AvailabilitySet.DefinitionCreatable { - private String name; private List idOfVMsInSet; private List vmsInSet; @@ -37,19 +37,18 @@ class AvailabilitySetImpl final AvailabilitySetsInner client, final ResourceGroups resourceGroups, final VirtualMachines virtualMachines) { - super(innerModel.id(), innerModel, resourceGroups); - this.name = name; + super(name, innerModel, resourceGroups); this.client = client; this.virtualMachines = virtualMachines; } @Override - public Integer updateDomainCount() { + public int updateDomainCount() { return this.inner().platformUpdateDomainCount(); } @Override - public Integer FaultDomainCount() { + public int faultDomainCount() { return this.inner().platformFaultDomainCount(); } @@ -62,7 +61,7 @@ public List virtualMachineIds() { } } - return idOfVMsInSet; + return Collections.unmodifiableList(idOfVMsInSet); } @Override @@ -75,18 +74,12 @@ public VirtualMachine load(String resourceGroupName, String resourceName) throws } }); } - return vmsInSet; + return Collections.unmodifiableList(vmsInSet); } @Override public List statuses() { - return this.inner().statuses(); - } - - @Override - public String name() { - // TODO: This method should be removed once once Runtime::Resource::setName is available. - return this.name; + return Collections.unmodifiableList(this.inner().statuses()); } @Override @@ -99,13 +92,13 @@ public AvailabilitySet refresh() throws Exception { } @Override - public AvailabilitySetImpl withUpdateDomainCount(Integer updateDomainCount) { + public AvailabilitySetImpl withUpdateDomainCount(int updateDomainCount) { this.inner().setPlatformUpdateDomainCount(updateDomainCount); return this; } @Override - public AvailabilitySetImpl withFaultDomainCount(Integer faultDomainCount) { + public AvailabilitySetImpl withFaultDomainCount(int faultDomainCount) { this.inner().setPlatformFaultDomainCount(faultDomainCount); return this; } @@ -115,7 +108,7 @@ public AvailabilitySetImpl create() throws Exception { for (Creatable provisionable : prerequisites().values()) { provisionable.create(); } - ServiceResponse response = this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); + ServiceResponse response = this.client.createOrUpdate(this.resourceGroupName(), this.key, this.inner()); AvailabilitySetInner availabilitySetInner = response.getBody(); this.setInner(availabilitySetInner); this.idOfVMsInSet = null; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java index 0aedd4c77b83..db1d234251ea 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java @@ -8,7 +8,7 @@ public enum Region { US_CENTRAL("centralus", "Central US"), US_EAST("eastus", "East US"), US_EAST2("eastus2", "East US 2"), - US_NORTH_CENTRAL("nothcentralus", "North Central US"), + US_NORTH_CENTRAL("northcentralus", "North Central US"), US_SOUTH_CENTRAL("southcentralus", "South Central US"), EUROPE_NORTH("northeurope", "North Europe"), EUROPE_WEST("westeurope", "West Europe"), diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java index 4529b294175f..7f505b624793 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java @@ -17,7 +17,7 @@ public interface Resource extends Indexable { */ interface DefinitionWithRegion { /** - * @param regionName The name of the location for the resource + * @param regionName The name of the region for the resource * @return The next stage of the resource definition */ T withRegion(String regionName); diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java index a5817954eea9..ea5a4f34575b 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/GroupableResourceImpl.java @@ -63,7 +63,7 @@ public final FluentModelImplT withNewGroup(String groupName) { } public final FluentModelImplT withNewGroup() { - return this.withNewGroup(this.name() + "group"); + return this.withNewGroup(this.key() + "group"); } @SuppressWarnings("unchecked") From f0fac104d9807dcb857435434e1769de8e5878a4 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 May 2016 17:56:51 -0700 Subject: [PATCH 2/9] PublicIPAddress refinements, bug fixes, javadoc clean up --- .../management/network/PublicIpAddress.java | 15 +++++---- .../management/network/PublicIpAddresses.java | 14 ++++----- .../implementation/PublicIpAddressImpl.java | 31 +++++++------------ .../collection/SupportsCreating.java | 1 + 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java index 2891f1e272d4..3057518f008d 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java @@ -13,6 +13,9 @@ import com.microsoft.azure.management.resources.fluentcore.model.Appliable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +/** + * Public IP address + */ public interface PublicIpAddress extends GroupableResource, Refreshable, @@ -68,7 +71,7 @@ interface Definitions extends DefinitionCreatable {} /** - * The first stage of the public IP address definition + * The first stage of a public IP address definition */ interface DefinitionBlank extends GroupableResource.DefinitionWithRegion { @@ -201,13 +204,13 @@ interface UpdateWithReverseFQDN { /** * Specifies the reverse FQDN to assign to this public IP address * @param reverseFQDN the reverse FQDN to assign - * @return the next stage of the resource definition + * @return the next stage of the resource update */ T withReverseFqdn(String reverseFQDN); /** * Ensures that no reverse FQDN will be used. - * @return The next stage of the resource definition + * @return The next stage of the resource update */ T withoutReverseFqdn(); } @@ -215,7 +218,7 @@ interface UpdateWithReverseFQDN { /** * The stage of the public IP definition which contains all the minimum required inputs for * the resource to be created (via {@link DefinitionCreatable#create()}), but also allows - * for the remaining optional settings to be specified. + * for any other optional settings to be specified. */ interface DefinitionCreatable extends Creatable, @@ -232,7 +235,7 @@ interface DefinitionCreatable extends /** * The template for a public IP address update operation, containing all the settings that - * can be updated. + * can be modified. */ interface Update extends Appliable, @@ -242,7 +245,7 @@ interface Update extends /** * Specifies the timeout (in minutes) for an idle connection * @param minutes the length of the time out in minutes - * @return the next stage of the resource definition + * @return the next stage of the resource update */ Update withIdleTimeoutInMinutes(int minutes); } 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 ef1a7ff056d7..d7876a149c3d 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 @@ -18,13 +18,13 @@ * Entry point to public IP address management */ public interface PublicIpAddresses extends - SupportsCreating, - SupportsListing, - SupportsListingByGroup, - SupportsGetting, - SupportsGettingByGroup, - SupportsDeleting, - SupportsDeletingByGroup { + SupportsCreating, + SupportsListing, + SupportsListingByGroup, + SupportsGetting, + SupportsGettingByGroup, + SupportsDeleting, + SupportsDeletingByGroup { /** * Entry point to public IP address management within a specific resource group diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java index 84fca67d39b3..eda1c8db4e2e 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java @@ -21,15 +21,13 @@ class PublicIpAddressImpl PublicIpAddress.Definitions, PublicIpAddress.Update { - private String name; private final PublicIPAddressesInner client; PublicIpAddressImpl(String name, PublicIPAddressInner innerModel, final PublicIPAddressesInner client, final ResourceGroups resourceGroups) { - super(innerModel.id(), innerModel, resourceGroups); - this.name = name; + super(name, innerModel, resourceGroups); this.client = client; } @@ -37,6 +35,16 @@ class PublicIpAddressImpl * Verbs **************************************************/ + @Override + public PublicIpAddressImpl apply() throws Exception { + return this.create(); + } + + @Override + public PublicIpAddressImpl update() throws Exception { + return this; + } + @Override public PublicIpAddress refresh() throws Exception { ServiceResponse response = @@ -52,7 +60,7 @@ public PublicIpAddressImpl create() throws Exception { super.create(); ServiceResponse response = - this.client.createOrUpdate(this.resourceGroupName(), this.name(), this.inner()); + this.client.createOrUpdate(this.resourceGroupName(), this.key(), this.inner()); this.setInner(response.getBody()); clearWrapperProperties(); return this; @@ -141,11 +149,6 @@ public String reverseFqdn() { return this.inner().dnsSettings().reverseFqdn(); } - @Override - public String name() { - return this.name; - } - @Override public String ipAddress() { return this.inner().ipAddress(); @@ -159,14 +162,4 @@ public String leafDomainLabel() { return this.inner().dnsSettings().domainNameLabel(); } } - - @Override - public PublicIpAddressImpl apply() throws Exception { - return this.create(); - } - - @Override - public PublicIpAddressImpl update() throws Exception { - return this; - } } \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java index f05113b37625..9b0071e3e2ff 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/collection/SupportsCreating.java @@ -25,6 +25,7 @@ * Providing access to creating Azure top level resources *

* (Note: this interface is not intended to be implemented by user code) + * @param T the initial blank definition interface */ public interface SupportsCreating { /** From 6aaadad8bd565a0b997e9a6359941c614870bc2b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 May 2016 17:59:48 -0700 Subject: [PATCH 3/9] refactoring PublicIPAddress tests using an abstract TestTemplate class --- .../java/com/microsoft/azure/AzureTests.java | 60 ++-------- .../microsoft/azure/TestPublicIpAddress.java | 59 +++++++++ .../com/microsoft/azure/TestTemplate.java | 113 ++++++++++++++++++ 3 files changed, 179 insertions(+), 53 deletions(-) create mode 100644 azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java create mode 100644 azure/src/test/java/com/microsoft/azure/TestTemplate.java diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index 9d4b40ef1057..e8bc876f46d5 100644 --- a/azure/src/test/java/com/microsoft/azure/AzureTests.java +++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java @@ -1,8 +1,12 @@ +/** + * 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; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.implementation.Azure; -import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.resources.Subscriptions; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.storage.StorageAccount; @@ -59,63 +63,13 @@ public void setup() throws Exception { } /** - * Tests the Public IP Address implementation + * Tests the public IP address implementation * @throws Exception */ @Test public void testPublicIpAddresses() throws Exception { - // Verify creation of a new public IP address - String suffix = String.valueOf(System.currentTimeMillis()); - String newPipName = "pip" + suffix; - PublicIpAddress pip = azure2.publicIpAddresses().define(newPipName) - .withRegion(Region.US_WEST) - .withNewGroup() - .withDynamicIp() - .withLeafDomainLabel(newPipName) - .withIdleTimeoutInMinutes(10) - .create(); - - // Verify list - int publicIpAddressCount = azure2.publicIpAddresses().list().size(); - System.out.println(publicIpAddressCount); - Assert.assertTrue(0 < publicIpAddressCount); - - // Verify get - String resourceGroupName = pip.resourceGroupName(); - pip = azure2.publicIpAddresses().get(resourceGroupName, newPipName); - Assert.assertTrue(pip.name().equalsIgnoreCase(newPipName)); - printPublicIpAddress(pip); - - // Verify update - final String updatedDnsName = newPipName + "xx"; - final int updatedIdleTimeout = 15; - pip = pip.update() - .withStaticIp() - .withLeafDomainLabel(updatedDnsName) - .withReverseFqdn(pip.leafDomainLabel() + "." + pip.region() + ".cloudapp.azure.com") - .withIdleTimeoutInMinutes(updatedIdleTimeout) - .apply(); - printPublicIpAddress(pip); - Assert.assertTrue(pip.leafDomainLabel().equalsIgnoreCase(updatedDnsName)); - Assert.assertTrue(pip.idleTimeoutInMinutes()==updatedIdleTimeout); - - // Verify delete - azure2.publicIpAddresses().delete(pip.id()); - azure2.resourceGroups().delete(pip.resourceGroupName()); - } - - private void printPublicIpAddress(PublicIpAddress pip) { - System.out.println(new StringBuilder().append("Public IP Address: ").append(pip.id()) - .append("\n\tIP Address: ").append(pip.ipAddress()) - .append("\n\tLeaf domain label: ").append(pip.leafDomainLabel()) - .append("\n\tResource group: ").append(pip.resourceGroupName()) - .append("\n\tFQDN: ").append(pip.fqdn()) - .append("\n\tReverse FQDN: ").append(pip.reverseFqdn()) - .append("\n\tIdle timeout (minutes): ").append(pip.idleTimeoutInMinutes()) - .append("\n\tIP allocation method: ").append(pip.ipAllocationMethod()) - .toString()); + new TestPublicIpAddress().runTest(azure2, azure2.publicIpAddresses()); } - @Test public void listSubscriptions() throws Exception { Assert.assertTrue(0 < subscriptions.list().size()); diff --git a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java new file mode 100644 index 000000000000..3a3913542c30 --- /dev/null +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -0,0 +1,59 @@ +/** + * 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; + +import org.junit.Assert; + +import com.microsoft.azure.implementation.Azure; +import com.microsoft.azure.management.network.PublicIpAddress; +import com.microsoft.azure.management.network.PublicIpAddresses; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; + +public class TestPublicIpAddress extends TestTemplate { + + @Override + public PublicIpAddress createResource(Azure azure) throws Exception { + final String newPipName = "pip" + this.testId; + return azure.publicIpAddresses().define(newPipName) + .withRegion(Region.US_WEST) + .withNewGroup() + .withDynamicIp() + .withLeafDomainLabel(newPipName) + .withIdleTimeoutInMinutes(10) + .create(); + } + + @Override + public PublicIpAddress updateResource(PublicIpAddress resource) throws Exception { + final String updatedDnsName = resource.leafDomainLabel() + "xx"; + final int updatedIdleTimeout = 15; + resource = resource.update() + .withStaticIp() + .withLeafDomainLabel(updatedDnsName) + .withReverseFqdn(resource.leafDomainLabel() + "." + resource.region() + ".cloudapp.azure.com") + .withIdleTimeoutInMinutes(updatedIdleTimeout) + .apply(); + Assert.assertTrue(resource.leafDomainLabel().equalsIgnoreCase(updatedDnsName)); + Assert.assertTrue(resource.idleTimeoutInMinutes()==updatedIdleTimeout); + return resource; + } + + @Override + public void print(PublicIpAddress resource) { + System.out.println(new StringBuilder().append("Public IP Address: ").append(resource.id()) + .append("Name: ").append(resource.name()) + .append("\n\tResource group: ").append(resource.resourceGroupName()) + .append("\n\tRegion: ").append(resource.region()) + .append("\n\tIP Address: ").append(resource.ipAddress()) + .append("\n\tLeaf domain label: ").append(resource.leafDomainLabel()) + .append("\n\tFQDN: ").append(resource.fqdn()) + .append("\n\tReverse FQDN: ").append(resource.reverseFqdn()) + .append("\n\tIdle timeout (minutes): ").append(resource.idleTimeoutInMinutes()) + .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod()) + .toString()); + } + +} diff --git a/azure/src/test/java/com/microsoft/azure/TestTemplate.java b/azure/src/test/java/com/microsoft/azure/TestTemplate.java new file mode 100644 index 000000000000..75f822ad0932 --- /dev/null +++ b/azure/src/test/java/com/microsoft/azure/TestTemplate.java @@ -0,0 +1,113 @@ +/** + * 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; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +import com.microsoft.azure.implementation.Azure; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +public abstract class TestTemplate< + T extends GroupableResource, + C extends SupportsListing & SupportsGettingByGroup & SupportsDeleting> { + + protected String testId = String.valueOf(System.currentTimeMillis()); + private T resource; + private Azure azure; + private C collection; + + /** + * Resource creation logic + * @param azure authenticated Azure instance + * @return created resource + * @throws Exception + */ + public abstract T createResource(Azure azure) throws Exception; + + /** + * Resource update logic + * @param resource the resource to update + * @throws Exception + */ + public abstract T updateResource(T resource) throws Exception; + + /** + * Tests the listing logic + * @throws CloudException + * @throws IOException + */ + public void verifyListing() throws CloudException, IOException { + int count = this.collection.list().size(); + System.out.println("Collection size: " + count); + Assert.assertTrue(0 < count); + } + + /** + * Tests the getting logic + * @throws CloudException + * @throws IOException + */ + public T verifyGetting() throws CloudException, IOException { + return this.collection.get(this.resource.resourceGroupName(), this.resource.name()); + } + + /** + * Tests the deletion logic + * @throws Exception + */ + public void verifyDeleting() throws Exception { + final String groupName = this.resource.resourceGroupName(); + this.collection.delete(this.resource.id()); + this.azure.resourceGroups().delete(groupName); + } + + /** + * Prints information about the resource + * @param resource + */ + public abstract void print(T resource); + + /** + * Runs the test + * @param azure authenticated Azure instance + * @param collection collection of resources to test + * @throws Exception + */ + @Test + public void runTest(Azure azure, C collection) throws Exception { + this.azure = azure; + this.collection = collection; + + // Verify creation + this.resource = createResource(azure); + System.out.println("\n------------\nAfter creation:\n"); + print(this.resource); + + // Verify listing + verifyListing(); + + // Verify getting + this.resource = verifyGetting(); + Assert.assertTrue(this.resource != null); + System.out.println("\n------------\nRetrieved resource:\n"); + print(this.resource); + + // Verify update + this.resource = updateResource(this.resource); + Assert.assertTrue(this.resource != null); + System.out.println("\n------------\nUpdated resource:\n"); + print(this.resource); + + // Verify deletion + verifyDeleting(); + } +} From 22454c0a6abe6f5e0f565201b2876eb9829a5a2b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 May 2016 18:52:37 -0700 Subject: [PATCH 4/9] fixing tagging support (.tags()/.withTag()) --- .../management/network/PublicIpAddress.java | 8 ++- .../management/resources/GenericResource.java | 18 ++---- .../management/resources/ResourceGroup.java | 8 +-- .../management/resources/ResourceGroups.java | 2 +- .../fluentcore/arm/models/Resource.java | 55 +++++++++++++++++-- .../fluentcore/arm/models/Taggable.java | 9 --- .../models/implementation/ResourceImpl.java | 12 +++- .../microsoft/azure/implementation/Azure.java | 2 +- .../AzureResourceGroupsImpl.java | 2 +- .../microsoft/azure/TestPublicIpAddress.java | 4 +- 10 files changed, 83 insertions(+), 37 deletions(-) delete mode 100644 azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Taggable.java diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java index 3057518f008d..2aaa8ea9bd44 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java @@ -7,6 +7,7 @@ import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; import com.microsoft.azure.management.resources.fluentcore.model.Updatable; @@ -224,7 +225,9 @@ interface DefinitionCreatable extends Creatable, DefinitionWithLeafDomainLabel, DefinitionWithIpAddress, - DefinitionWithReverseFQDN { + DefinitionWithReverseFQDN, + Resource.DefinitionWithTags { + /** * Specifies the timeout (in minutes) for an idle connection * @param minutes the length of the time out in minutes @@ -241,7 +244,8 @@ interface Update extends Appliable, UpdateWithIpAddress, UpdateWithLeafDomainLabel, - UpdateWithReverseFQDN { + UpdateWithReverseFQDN, + Resource.UpdateWithTags { /** * Specifies the timeout (in minutes) for an idle connection * @param minutes the length of the time out in minutes diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java index 8cde0398eeca..10ba6f35cdec 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResource.java @@ -1,13 +1,11 @@ package com.microsoft.azure.management.resources; -import com.microsoft.azure.management.resources.fluentcore.arm.models.Taggable; import com.microsoft.azure.management.resources.fluentcore.model.*; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.implementation.api.GenericResourceInner; import com.microsoft.azure.management.resources.implementation.api.Plan; -import java.util.Map; - public interface GenericResource extends GroupableResource, Refreshable, @@ -43,16 +41,10 @@ interface DefinitionWithPlan { DefinitionCreatable withPlan(String name, String publisher, String product, String promotionCode); } - interface DefinitionCreatable extends Creatable { // Properties, tags are optional + interface DefinitionCreatable extends + Creatable, + Resource.DefinitionWithTags { + DefinitionCreatable withProperties(Object properties); - DefinitionCreatable withTags(Map tags); - DefinitionCreatable withTag(String key, String value); - } - - // TODO: Updatable properties needs to be revised. - interface Update extends UpdateBlank, Appliable { - } - - interface UpdateBlank extends Taggable { } } \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java index ff7dde3048f1..6d79c8b1e1cb 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceGroup.java @@ -1,7 +1,7 @@ package com.microsoft.azure.management.resources; import com.microsoft.azure.management.resources.fluentcore.arm.Region; -import com.microsoft.azure.management.resources.fluentcore.arm.models.Taggable; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.fluentcore.model.*; import com.microsoft.azure.management.resources.implementation.api.ResourceGroupInner; @@ -35,11 +35,11 @@ interface DefinitionCreatable extends Creatable { DefinitionCreatable withTag(String key, String value); } - interface Update extends UpdateBlank, Appliable { + interface Update extends + Appliable, + Resource.UpdateWithTags { } - interface UpdateBlank extends Taggable { - } /************************************************************** * Adapter to other resources 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 5caee92c14d0..a39d6ec331e7 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 @@ -10,6 +10,6 @@ public interface ResourceGroups extends SupportsGetting, SupportsCreating, SupportsDeleting, - SupportsUpdating { + SupportsUpdating { boolean checkExistence(String name) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java index 7f505b624793..f9fa15afd834 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Resource.java @@ -18,21 +18,68 @@ public interface Resource extends Indexable { interface DefinitionWithRegion { /** * @param regionName The name of the region for the resource - * @return The next stage of the resource definition + * @return the next stage of the resource definition */ T withRegion(String regionName); /** * @param region The location for the resource - * @return The next stage of the resource definition + * @return the next stage of the resource definition */ T withRegion(Region region); } + /** + * A resource definition allowing tags to be modified for the resource + */ + interface DefinitionWithTags { + /** + * Specifies tags for the resource as a {@link Map}. + * @param tags a {@link Map} of tags + * @return the next stage of the resource definition + */ + T withTags(Map tags); + + /** + * Adds a tag to the resource. + * @param key the key for the tag + * @param value the value for the tag + * @return the next stage of the resource definition + */ + T withTag(String key, String value); + + /** + * Removes a tag from the resource + * @param key the key of the tag to remove + * @return the next stage of the resource definition + */ + T withoutTag(String key); + } /** - * A resource definition allowing tags to be specified + * An update allowing tags to be modified for the resource */ - interface DefinitionWithTags extends Taggable { + interface UpdateWithTags { + /** + * Specifies tags for the resource as a {@link Map}. + * @param tags a {@link Map} of tags + * @return the next stage of the resource update + */ + T withTags(Map tags); + + /** + * Adds a tag to the resource. + * @param key the key for the tag + * @param value the value for the tag + * @return the next stage of the resource definition + */ + T withTag(String key, String value); + + /** + * Removes a tag from the resource + * @param key the key of the tag to remove + * @return the next stage of the resource definition + */ + T withoutTag(String key); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Taggable.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Taggable.java deleted file mode 100644 index ca8ea942d6ae..000000000000 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/Taggable.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.microsoft.azure.management.resources.fluentcore.arm.models; - -import java.util.Map; - -public interface Taggable { - T withTags(Map tags); - T withTag(String key, String value); - T withoutTag(String key); -} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java index 69fced1709bb..9e8c02f10010 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; public abstract class ResourceImpl< FluentModelT, @@ -20,6 +21,11 @@ public abstract class ResourceImpl< protected ResourceImpl(String key, InnerModelT innerObject) { super(key, innerObject); + + // Initialize tags + if(innerObject.getTags() == null) { + innerObject.setTags(new TreeMap()); + } } /******************************************* @@ -33,7 +39,11 @@ public String region() { @Override public Map tags() { - return Collections.unmodifiableMap(this.inner().getTags()); + Map tags = this.inner().getTags(); + if(tags == null) { + tags = new TreeMap(); + } + return Collections.unmodifiableMap(tags); } @Override diff --git a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java index d8f495a735cb..852d33834072 100644 --- a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java @@ -205,7 +205,7 @@ public interface ResourceGroups extends SupportsListing, SupportsGetting, SupportsCreating, SupportsDeleting, - SupportsUpdating { + SupportsUpdating { } public interface ResourceGroup extends com.microsoft.azure.management.resources.ResourceGroup { diff --git a/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java b/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java index 54aa961ab0f6..039e464baaa6 100644 --- a/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java +++ b/azure/src/main/java/com/microsoft/azure/implementation/AzureResourceGroupsImpl.java @@ -53,7 +53,7 @@ public void delete(String name) throws Exception { } @Override - public Azure.ResourceGroup.UpdateBlank update(String name) { + public Azure.ResourceGroup.Update update(String name) { return resourceGroupsCore.update(name); } diff --git a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java index 3a3913542c30..cea491d18b3d 100644 --- a/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -35,6 +35,8 @@ public PublicIpAddress updateResource(PublicIpAddress resource) throws Exception .withLeafDomainLabel(updatedDnsName) .withReverseFqdn(resource.leafDomainLabel() + "." + resource.region() + ".cloudapp.azure.com") .withIdleTimeoutInMinutes(updatedIdleTimeout) + .withTag("tag1", "value1") + .withTag("tag2", "value2") .apply(); Assert.assertTrue(resource.leafDomainLabel().equalsIgnoreCase(updatedDnsName)); Assert.assertTrue(resource.idleTimeoutInMinutes()==updatedIdleTimeout); @@ -47,6 +49,7 @@ public void print(PublicIpAddress resource) { .append("Name: ").append(resource.name()) .append("\n\tResource group: ").append(resource.resourceGroupName()) .append("\n\tRegion: ").append(resource.region()) + .append("\n\tTags: ").append(resource.tags()) .append("\n\tIP Address: ").append(resource.ipAddress()) .append("\n\tLeaf domain label: ").append(resource.leafDomainLabel()) .append("\n\tFQDN: ").append(resource.fqdn()) @@ -55,5 +58,4 @@ public void print(PublicIpAddress resource) { .append("\n\tIP allocation method: ").append(resource.ipAllocationMethod()) .toString()); } - } From 732953c18e434e0ea5e00115c49be16f4d526f83 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 May 2016 19:18:10 -0700 Subject: [PATCH 5/9] adding .update()/.apply() support to AvailabilitySet (includes unit test) --- .../management/compute/AvailabilitySet.java | 21 +++++++- .../implementation/AvailabilitySetImpl.java | 23 ++++++-- .../java/com/microsoft/azure/AzureTests.java | 8 +++ .../microsoft/azure/TestAvailabilitySet.java | 52 +++++++++++++++++++ 4 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 azure/src/test/java/com/microsoft/azure/TestAvailabilitySet.java diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java index b47330185188..8bf1aee963a9 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/AvailabilitySet.java @@ -3,8 +3,11 @@ import com.microsoft.azure.management.compute.implementation.api.AvailabilitySetInner; import com.microsoft.azure.management.compute.implementation.api.InstanceViewStatus; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; +import com.microsoft.azure.management.resources.fluentcore.model.Appliable; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; +import com.microsoft.azure.management.resources.fluentcore.model.Updatable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; import java.util.List; @@ -15,7 +18,8 @@ public interface AvailabilitySet extends GroupableResource, Refreshable, - Wrapper { + Wrapper, + Updatable { /** * Returns the update domain count of an availability set. @@ -80,7 +84,9 @@ interface DefinitionWithGroup extends GroupableResource.DefinitionWithGroup { + interface DefinitionCreatable extends + Creatable, + Resource.DefinitionWithTags { /** * Specifies the update domain count for the availability set. * @param updateDomainCount update domain count @@ -95,4 +101,15 @@ interface DefinitionCreatable extends Creatable { */ DefinitionCreatable withFaultDomainCount(int faultDomainCount); } + + /** + * The template for an availability set update operation, containing all the settings that + * can be modified. + *

+ * Call {@link Update#apply()} to apply the changes to the resource in Azure. + */ + interface Update extends + Appliable, + Resource.UpdateWithTags { + } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java index d47862c5fbe9..d8081dc2a48f 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java @@ -1,3 +1,8 @@ +/** + * 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.compute.implementation; import com.microsoft.azure.SubResource; @@ -18,12 +23,14 @@ import java.util.List; class AvailabilitySetImpl - extends GroupableResourceImpl - implements + extends + GroupableResourceImpl + implements AvailabilitySet, AvailabilitySet.DefinitionBlank, AvailabilitySet.DefinitionWithGroup, - AvailabilitySet.DefinitionCreatable { + AvailabilitySet.DefinitionCreatable, + AvailabilitySet.Update { private List idOfVMsInSet; private List vmsInSet; @@ -115,4 +122,14 @@ public AvailabilitySetImpl create() throws Exception { this.vmsInSet = null; return this; } + + @Override + public AvailabilitySetImpl update() throws Exception { + return this; + } + + @Override + public AvailabilitySetImpl apply() throws Exception { + return create(); + } } diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index e8bc876f46d5..3a42e6339e18 100644 --- a/azure/src/test/java/com/microsoft/azure/AzureTests.java +++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java @@ -70,6 +70,14 @@ public void setup() throws Exception { new TestPublicIpAddress().runTest(azure2, azure2.publicIpAddresses()); } + /** + * Tests the availability set implementation + * @throws Exception + */ + @Test public void testAvailabilitySets() throws Exception { + new TestAvailabilitySet().runTest(azure2, azure2.availabilitySets()); + } + @Test public void listSubscriptions() throws Exception { Assert.assertTrue(0 < subscriptions.list().size()); diff --git a/azure/src/test/java/com/microsoft/azure/TestAvailabilitySet.java b/azure/src/test/java/com/microsoft/azure/TestAvailabilitySet.java new file mode 100644 index 000000000000..54427f990097 --- /dev/null +++ b/azure/src/test/java/com/microsoft/azure/TestAvailabilitySet.java @@ -0,0 +1,52 @@ +/** + * 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; + +import org.junit.Assert; + +import com.microsoft.azure.implementation.Azure; +import com.microsoft.azure.management.compute.AvailabilitySet; +import com.microsoft.azure.management.compute.AvailabilitySets; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; + +public class TestAvailabilitySet extends TestTemplate { + + @Override + public AvailabilitySet createResource(Azure azure) throws Exception { + final String newName = "as" + this.testId; + return azure.availabilitySets().define(newName) + .withRegion(Region.US_WEST) + .withNewGroup() + .withFaultDomainCount(2) + .withUpdateDomainCount(4) + .withTag("tag1", "value1") + .create(); + } + + @Override + public AvailabilitySet updateResource(AvailabilitySet resource) throws Exception { + resource = resource.update() + .withTag("tag2", "value2") + .withTag("tag3", "value3") + .withoutTag("tag1") + .apply(); + Assert.assertTrue(resource.tags().containsKey("tag2")); + Assert.assertTrue(!resource.tags().containsKey("tag1")); + return resource; + } + + @Override + public void print(AvailabilitySet resource) { + System.out.println(new StringBuilder().append("Availability Set: ").append(resource.id()) + .append("Name: ").append(resource.name()) + .append("\n\tResource group: ").append(resource.resourceGroupName()) + .append("\n\tRegion: ").append(resource.region()) + .append("\n\tTags: ").append(resource.tags()) + .append("\n\tFault domain count: ").append(resource.faultDomainCount()) + .append("\n\tUpdate domain count: ").append(resource.updateDomainCount()) + .toString()); + } +} From 8471d7f548ca62882c322ea9e5422da65e37ac02 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 May 2016 07:58:03 -0700 Subject: [PATCH 6/9] minor corrections in public IP address support --- .../azure/management/network/PublicIpAddress.java | 2 ++ .../azure/management/network/PublicIpAddresses.java | 2 +- .../network/implementation/PublicIpAddressesImpl.java | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java index 2aaa8ea9bd44..572c6ed6ee9f 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java @@ -239,6 +239,8 @@ interface DefinitionCreatable extends /** * The template for a public IP address update operation, containing all the settings that * can be modified. + *

+ * Call {@link Update#apply()} to apply the changes to the resource in Azure. */ interface Update extends Appliable, 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 d7876a149c3d..43914a4b3f21 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 @@ -31,7 +31,7 @@ public interface PublicIpAddresses extends */ public interface InGroup extends SupportsListing, - SupportsCreating, + SupportsCreating, SupportsDeleting { } } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java index db57a1380f18..291983b6650e 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java @@ -33,8 +33,8 @@ class PublicIpAddressesImpl this.resourceGroups = resourceGroups; this.converter = new PagedListConverter() { @Override - public PublicIpAddress typeConvert(PublicIPAddressInner publicIpAddressInner) { - return createFluentModel(publicIpAddressInner); + public PublicIpAddress typeConvert(PublicIPAddressInner inner) { + return createFluentModel(inner); } }; } @@ -52,7 +52,7 @@ public PagedList list(String groupName) throws CloudException, } @Override - public PublicIpAddress get(String id) throws CloudException, IOException { + public PublicIpAddressImpl get(String id) throws CloudException, IOException { PublicIPAddressInner inner = client.get( ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)).getBody(); @@ -60,7 +60,7 @@ public PublicIpAddress get(String id) throws CloudException, IOException { } @Override - public PublicIpAddress get(String groupName, String name) throws CloudException, IOException { + public PublicIpAddressImpl get(String groupName, String name) throws CloudException, IOException { ServiceResponse serviceResponse = this.client.get(groupName, name); return createFluentModel(serviceResponse.getBody()); } @@ -76,7 +76,7 @@ public void delete(String groupName, String name) throws Exception { } @Override - public PublicIpAddress.DefinitionBlank define(String name) { + public PublicIpAddressImpl define(String name) { return createFluentModel(name); } From 1e7a6b670e52308ac31ecd7954477a40ab094669 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 May 2016 11:10:37 -0700 Subject: [PATCH 7/9] minor fixes to public IP adress --- .../implementation/PublicIpAddressImpl.java | 23 +++---------------- .../implementation/PublicIpAddressesImpl.java | 7 ++++++ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java index eda1c8db4e2e..643c1377f76b 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java @@ -7,7 +7,6 @@ import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.network.implementation.api.IPAllocationMethod; -import com.microsoft.azure.management.network.implementation.api.PublicIPAddressDnsSettings; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressesInner; import com.microsoft.azure.management.resources.ResourceGroups; @@ -51,7 +50,6 @@ public PublicIpAddress refresh() throws Exception { this.client.get(this.resourceGroupName(), this.name()); PublicIPAddressInner inner = response.getBody(); this.setInner(inner); - clearWrapperProperties(); return this; } @@ -62,14 +60,9 @@ public PublicIpAddressImpl create() throws Exception { ServiceResponse response = this.client.createOrUpdate(this.resourceGroupName(), this.key(), this.inner()); this.setInner(response.getBody()); - clearWrapperProperties(); return this; } - private void clearWrapperProperties() { - - } - /***************************************** * Setters (fluent) *****************************************/ @@ -95,7 +88,7 @@ public PublicIpAddressImpl withDynamicIp() { @Override public PublicIpAddressImpl withLeafDomainLabel(String dnsName) { - ensureDnsSettings().setDomainNameLabel(dnsName.toLowerCase()); + this.inner().dnsSettings().setDomainNameLabel(dnsName.toLowerCase()); return this; } @@ -106,7 +99,7 @@ public PublicIpAddressImpl withoutLeafDomainLabel() { @Override public PublicIpAddressImpl withReverseFqdn(String reverseFqdn) { - ensureDnsSettings().setReverseFqdn(reverseFqdn.toLowerCase()); + this.inner().dnsSettings().setReverseFqdn(reverseFqdn.toLowerCase()); return this; } @@ -115,17 +108,7 @@ public PublicIpAddressImpl withoutReverseFqdn() { return this.withReverseFqdn(null); } - - private PublicIPAddressDnsSettings ensureDnsSettings() { - PublicIPAddressDnsSettings dnsSettings; - if(null == (dnsSettings = this.inner().dnsSettings())) { - dnsSettings = new PublicIPAddressDnsSettings(); - this.inner().setDnsSettings(dnsSettings); - } - return dnsSettings; - } - - + /********************************************** * Getters **********************************************/ diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java index 291983b6650e..26815962f873 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java @@ -10,6 +10,7 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.network.PublicIpAddress; import com.microsoft.azure.management.network.PublicIpAddresses; +import com.microsoft.azure.management.network.implementation.api.PublicIPAddressDnsSettings; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner; import com.microsoft.azure.management.network.implementation.api.PublicIPAddressesInner; import com.microsoft.azure.management.resources.ResourceGroups; @@ -96,9 +97,15 @@ public Page nextPage(String nextPageLink) throws RestExcep private PublicIpAddressImpl createFluentModel(String name) { PublicIPAddressInner inner = new PublicIPAddressInner(); + + if(null == inner.dnsSettings()) { + inner.setDnsSettings(new PublicIPAddressDnsSettings()); + } + return new PublicIpAddressImpl(name, inner, this.client, this.resourceGroups); } + private PublicIpAddressImpl createFluentModel(PublicIPAddressInner inner) { return new PublicIpAddressImpl(inner.name(), inner, this.client, this.resourceGroups); } From 6911ed7904f49acc932698950d18f98c4014a70d Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 May 2016 11:12:12 -0700 Subject: [PATCH 8/9] minor corrections to availability set support --- .../compute/implementation/AvailabilitySetsImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java index 3913e887edf7..54330bdc38e3 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java @@ -33,8 +33,8 @@ public AvailabilitySetsImpl(final AvailabilitySetsInner client, this.virtualMachines = virtualMachines; this.converter = new PagedListConverter() { @Override - public AvailabilitySet typeConvert(AvailabilitySetInner availabilitySetInner) { - return createFluentModel(availabilitySetInner); + public AvailabilitySet typeConvert(AvailabilitySetInner inner) { + return createFluentModel(inner); } }; } @@ -71,13 +71,13 @@ public Page nextPage(String nextPageLink) throws RestExcep } @Override - public AvailabilitySet get(String groupName, String name) throws CloudException, IOException { + public AvailabilitySetImpl get(String groupName, String name) throws CloudException, IOException { ServiceResponse response = this.client.get(groupName, name); return createFluentModel(response.getBody()); } @Override - public AvailabilitySet.DefinitionBlank define(String name) { + public AvailabilitySetImpl define(String name) { return createFluentModel(name); } From 1270642f95d89a390870865cfae277189a5f603c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 23 May 2016 06:01:40 -0700 Subject: [PATCH 9/9] minor simplification to the Update interfaces on PublicIpAddress --- .../management/network/PublicIpAddress.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java index 572c6ed6ee9f..46529bbd6ecb 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java @@ -111,7 +111,7 @@ interface DefinitionWithIpAddress { /** * A public IP address update allowing to change the IP allocation method (static or dynamic) */ - interface UpdateWithIpAddress { + interface UpdateWithIpAddress { /** * Enables static IP address allocation. *

@@ -120,16 +120,17 @@ interface UpdateWithIpAddress { * * @return the next stage of the public IP address definition */ - T withStaticIp(); + Update withStaticIp(); /** * Enables dynamic IP address allocation. * * @return the next stage of the public IP address definition */ - T withDynamicIp(); + Update withDynamicIp(); } + /** * A public IP address definition allowing to specify the leaf domain label, if any */ @@ -157,7 +158,7 @@ interface DefinitionWithLeafDomainLabel { /** * A public IP address update allowing to change the leaf domain label, if any */ - interface UpdateWithLeafDomainLabel { + interface UpdateWithLeafDomainLabel { /** * Specifies the leaf domain label to associate with this public IP address. *

@@ -166,7 +167,7 @@ interface UpdateWithLeafDomainLabel { * @param dnsName the leaf domain label to use. This must follow the required naming convention for leaf domain names. * @return the next stage of the public IP address definition */ - T withLeafDomainLabel(String dnsName); + Update withLeafDomainLabel(String dnsName); /** * Ensures that no leaf domain label will be used. @@ -174,7 +175,7 @@ interface UpdateWithLeafDomainLabel { * This means that this public IP address will not be associated with a domain name. * @return the next stage of the resource definition */ - T withoutLeafDomainLabel(); + Update withoutLeafDomainLabel(); } @@ -201,19 +202,19 @@ interface DefinitionWithReverseFQDN { /** * A public IP address update allowing the reverse FQDN to be specified */ - interface UpdateWithReverseFQDN { + interface UpdateWithReverseFQDN { /** * Specifies the reverse FQDN to assign to this public IP address * @param reverseFQDN the reverse FQDN to assign * @return the next stage of the resource update */ - T withReverseFqdn(String reverseFQDN); + Update withReverseFqdn(String reverseFQDN); /** * Ensures that no reverse FQDN will be used. * @return The next stage of the resource update */ - T withoutReverseFqdn(); + Update withoutReverseFqdn(); } /** @@ -244,9 +245,9 @@ interface DefinitionCreatable extends */ interface Update extends Appliable, - UpdateWithIpAddress, - UpdateWithLeafDomainLabel, - UpdateWithReverseFQDN, + UpdateWithIpAddress, + UpdateWithLeafDomainLabel, + UpdateWithReverseFQDN, Resource.UpdateWithTags { /** * Specifies the timeout (in minutes) for an idle connection