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..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,66 +3,113 @@ 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; +/** + * An immutable client-side representation of an Azure availability set. + */ public interface AvailabilitySet extends GroupableResource, Refreshable, - Wrapper { + Wrapper, + Updatable { /** - * 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 { } - interface DefinitionCreatable extends Creatable { - DefinitionCreatable withUpdateDomainCount(Integer updateDomainCount); - DefinitionCreatable withFaultDomainCount(Integer faultDomainCount); + /** + * 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, + Resource.DefinitionWithTags { + /** + * 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); + } + + /** + * 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/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..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; @@ -14,16 +19,18 @@ import com.microsoft.rest.ServiceResponse; import java.util.ArrayList; +import java.util.Collections; import java.util.List; class AvailabilitySetImpl - extends GroupableResourceImpl - implements + extends + GroupableResourceImpl + implements AvailabilitySet, AvailabilitySet.DefinitionBlank, AvailabilitySet.DefinitionWithGroup, - AvailabilitySet.DefinitionCreatable { - private String name; + AvailabilitySet.DefinitionCreatable, + AvailabilitySet.Update { private List idOfVMsInSet; private List vmsInSet; @@ -37,19 +44,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 +68,7 @@ public List virtualMachineIds() { } } - return idOfVMsInSet; + return Collections.unmodifiableList(idOfVMsInSet); } @Override @@ -75,18 +81,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 +99,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,11 +115,21 @@ 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; 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-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); } 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..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 @@ -7,12 +7,16 @@ 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; 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 +72,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 { @@ -107,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. *

@@ -116,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 */ @@ -153,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. *

@@ -162,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. @@ -170,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(); } @@ -197,31 +202,33 @@ 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 definition + * @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 definition + * @return The next stage of the resource update */ - T withoutReverseFqdn(); + Update withoutReverseFqdn(); } /** * 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, 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 @@ -232,17 +239,20 @@ interface DefinitionCreatable extends /** * The template for a public IP address update operation, containing all the settings that - * can be updated. + * can be modified. + *

+ * Call {@link Update#apply()} to apply the changes to the resource in Azure. */ interface Update extends Appliable, - UpdateWithIpAddress, - UpdateWithLeafDomainLabel, - UpdateWithReverseFQDN { + UpdateWithIpAddress, + UpdateWithLeafDomainLabel, + UpdateWithReverseFQDN, + Resource.UpdateWithTags { /** * 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..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 @@ -18,20 +18,20 @@ * 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 */ public interface InGroup extends SupportsListing, - SupportsCreating, + SupportsCreating, SupportsDeleting { } } 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..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; @@ -21,15 +20,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,13 +34,22 @@ 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 = this.client.get(this.resourceGroupName(), this.name()); PublicIPAddressInner inner = response.getBody(); this.setInner(inner); - clearWrapperProperties(); return this; } @@ -52,16 +58,11 @@ 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; } - private void clearWrapperProperties() { - - } - /***************************************** * Setters (fluent) *****************************************/ @@ -87,7 +88,7 @@ public PublicIpAddressImpl withDynamicIp() { @Override public PublicIpAddressImpl withLeafDomainLabel(String dnsName) { - ensureDnsSettings().setDomainNameLabel(dnsName.toLowerCase()); + this.inner().dnsSettings().setDomainNameLabel(dnsName.toLowerCase()); return this; } @@ -98,7 +99,7 @@ public PublicIpAddressImpl withoutLeafDomainLabel() { @Override public PublicIpAddressImpl withReverseFqdn(String reverseFqdn) { - ensureDnsSettings().setReverseFqdn(reverseFqdn.toLowerCase()); + this.inner().dnsSettings().setReverseFqdn(reverseFqdn.toLowerCase()); return this; } @@ -107,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 **********************************************/ @@ -141,11 +132,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 +145,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-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..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; @@ -33,8 +34,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 +53,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 +61,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 +77,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); } @@ -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); } 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/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..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 @@ -17,22 +17,69 @@ public interface Resource extends Indexable { */ interface DefinitionWithRegion { /** - * @param regionName The name of the location for the resource - * @return The next stage of the resource definition + * @param regionName The name of the region for the resource + * @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/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") 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-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 { /** 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/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index 9d4b40ef1057..3a42e6339e18 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,21 @@ 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()); + new TestPublicIpAddress().runTest(azure2, azure2.publicIpAddresses()); } - 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()); + /** + * 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()); + } +} 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..cea491d18b3d --- /dev/null +++ b/azure/src/test/java/com/microsoft/azure/TestPublicIpAddress.java @@ -0,0 +1,61 @@ +/** + * 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) + .withTag("tag1", "value1") + .withTag("tag2", "value2") + .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\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()) + .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(); + } +}