diff --git a/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/ApplicationPackagesImpl.java b/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/ApplicationPackagesImpl.java index 9c8edd4b6d22..deb2109c762c 100644 --- a/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/ApplicationPackagesImpl.java +++ b/azure-mgmt-batch/src/main/java/com/microsoft/azure/management/batch/implementation/ApplicationPackagesImpl.java @@ -9,7 +9,7 @@ import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.batch.Application; import com.microsoft.azure.management.batch.ApplicationPackage; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesCachedImpl; import java.util.List; import java.util.Map; @@ -22,7 +22,7 @@ */ @LangDefinition class ApplicationPackagesImpl extends - ExternalChildResourcesImpl asMap() { diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionsImpl.java index 12a5cfaf712a..ffee13ebb66c 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineExtensionsImpl.java @@ -2,7 +2,7 @@ import com.microsoft.azure.management.compute.VirtualMachine; import com.microsoft.azure.management.compute.VirtualMachineExtension; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesCachedImpl; import java.util.ArrayList; import java.util.Collections; @@ -14,11 +14,11 @@ * Represents a extension collection associated with a virtual machine. */ class VirtualMachineExtensionsImpl extends - ExternalChildResourcesImpl { + ExternalChildResourcesCachedImpl { private final VirtualMachineExtensionsInner client; /** @@ -30,7 +30,7 @@ class VirtualMachineExtensionsImpl extends VirtualMachineExtensionsImpl(VirtualMachineExtensionsInner client, VirtualMachineImpl parent) { super(parent, "VirtualMachineExtension"); this.client = client; - this.initializeCollection(); + this.cacheCollection(); } /** diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/ARecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/ARecordSet.java new file mode 100644 index 000000000000..acbf36f7ce16 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/ARecordSet.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.dns; + +import java.util.List; + +/** + * An immutable client-side representation of a A (Ipv4) record set in Azure Dns Zone. + */ +public interface ARecordSet extends DnsRecordSet { + /** + * @return the Ipv4 addresses of A records in this record set + */ + List ipv4Addresses(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/ARecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/ARecordSets.java new file mode 100644 index 000000000000..8a17035ee8b1 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/ARecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to A record sets in a Dns zone. + */ +@Fluent +public interface ARecordSets extends + SupportsListing, + SupportsGettingByName { +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/AaaaRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/AaaaRecordSet.java new file mode 100644 index 000000000000..0cc728116607 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/AaaaRecordSet.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.dns; + +import java.util.List; + +/** + * An immutable client-side representation of a Aaaa (Ipv6) record set in Azure Dns Zone. + */ +public interface AaaaRecordSet extends DnsRecordSet { + /** + * @return the IPv6 addresses of Aaaa records in this record set + */ + List ipv6Addresses(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/AaaaRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/AaaaRecordSets.java new file mode 100644 index 000000000000..cf025c9fcac4 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/AaaaRecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Aaaa record sets in a Dns zone. + */ +@Fluent +public interface AaaaRecordSets extends + SupportsListing, + SupportsGettingByName { +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/CnameRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/CnameRecordSet.java new file mode 100644 index 000000000000..952b1b9c2b9b --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/CnameRecordSet.java @@ -0,0 +1,11 @@ +package com.microsoft.azure.management.dns; + +/** + * An immutable client-side representation of a CName (canonical name) record set in Azure Dns Zone. + */ +public interface CnameRecordSet extends DnsRecordSet { + /** + * @return the canonical name (without a terminating dot) of CName record in this record set + */ + String canonicalName(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/CnameRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/CnameRecordSets.java new file mode 100644 index 000000000000..7105aefb793b --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/CnameRecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Cname record sets in a Dns zone. + */ +@Fluent +public interface CnameRecordSets extends + SupportsListing, + SupportsGettingByName { +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsRecordSet.java new file mode 100644 index 000000000000..9f6e68f3e2aa --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsRecordSet.java @@ -0,0 +1,998 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.dns.implementation.RecordSetInner; +import com.microsoft.azure.management.resources.fluentcore.arm.models.ExternalChildResource; +import com.microsoft.azure.management.resources.fluentcore.model.Attachable; +import com.microsoft.azure.management.resources.fluentcore.model.Settable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.Map; + +/** + * An immutable client-side representation of a record set in Azure Dns Zone. + */ +public interface DnsRecordSet extends + ExternalChildResource, + Wrapper { + + /** + * @return the type of records in this record set + */ + RecordType recordType(); + + /** + * @return TTL of the records in this record set + */ + long timeToLive(); + + /** + * @return the metadata associated with this record set. + */ + Map metadata(); + + /** + * The entirety of a Dns zone record set definition as a part of parent definition. + * + * @param the return type of the final {@link Attachable#attach()} + */ + interface Definition extends + DefinitionStages.ARecordSetBlank, + DefinitionStages.WithARecordIpv4Address, + DefinitionStages.WithARecordIpv4AddressOrAttachable, + DefinitionStages.AaaaRecordSetBlank, + DefinitionStages.WithAaaaRecordIpv6Address, + DefinitionStages.WithAaaaRecordIpv6AddressOrAttachable, + DefinitionStages.MxRecordSetBlank, + DefinitionStages.WithMxRecordMailExchange, + DefinitionStages.WithMxRecordMailExchangeOrAttachable, + DefinitionStages.NsRecordSetBlank, + DefinitionStages.WithNsRecordNameServer, + DefinitionStages.WithNsRecordNameServerOrAttachable, + DefinitionStages.PtrRecordSetBlank, + DefinitionStages.WithPtrRecordTargetDomainName, + DefinitionStages.WithPtrRecordTargetDomainNameOrAttachable, + DefinitionStages.SrvRecordSetBlank, + DefinitionStages.WithSrvRecordEntry, + DefinitionStages.WithSrvRecordEntryOrAttachable, + DefinitionStages.TxtRecordSetBlank, + DefinitionStages.WithTxtRecordTextValue, + DefinitionStages.WithTxtRecordTextValueOrAttachable, + DefinitionStages.WithAttach { + } + + /** + * Grouping of Dns zone record set definition stages as a part of parent Dns zone definition. + */ + interface DefinitionStages { + /** + * The first stage of a A record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface ARecordSetBlank extends WithARecordIpv4Address { + } + + /** + * The stage of the A record set definition allowing to add first A record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithARecordIpv4Address { + /** + * Creates an A record with the provided Ipv4 address in this record set. + * + * @param ipv4Address the Ipv4 address + * @return the next stage of the record set definition + */ + WithARecordIpv4AddressOrAttachable withIpv4Address(String ipv4Address); + } + + /** + * The stage of the A record set definition allowing to add additional A records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithARecordIpv4AddressOrAttachable + extends WithARecordIpv4Address, WithAttach { + } + + /** + * The first stage of a Aaaa record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface AaaaRecordSetBlank extends WithAaaaRecordIpv6Address { + } + + /** + * The stage of the Aaaa record set definition allowing to add first Aaaa record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAaaaRecordIpv6Address { + /** + * Creates an Aaaa record with the provided Ipv6 address in this record set. + * + * @param ipv6Address the Ipv6 address + * @return the next stage of the record set definition + */ + WithAaaaRecordIpv6AddressOrAttachable withIpv6Address(String ipv6Address); + } + + /** + * The stage of the Aaaa record set definition allowing to add additional A records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAaaaRecordIpv6AddressOrAttachable + extends WithAaaaRecordIpv6Address, WithAttach { + } + + /** + * The first stage of a Mx record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface MxRecordSetBlank extends WithMxRecordMailExchange { + } + + /** + * The stage of the Mx record set definition allowing to add first Mx record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithMxRecordMailExchange { + /** + * Creates and assigns priority to a Mx record with the provided mail exchange server in this record set. + * + * @param mailExchangeHostName the host name of the mail exchange server + * @param priority the priority for the mail exchange host, lower the value higher the priority + * @return the next stage of the record set definition + */ + WithMxRecordMailExchangeOrAttachable withMailExchange(String mailExchangeHostName, int priority); + } + + /** + * The stage of the Mx record set definition allowing to add additional Mx records or attach the record set + * to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithMxRecordMailExchangeOrAttachable + extends WithMxRecordMailExchange, WithAttach { + } + + /** + * The first stage of a Ns record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface NsRecordSetBlank extends WithNsRecordNameServer { + } + + /** + * The stage of the Ns record set definition allowing to add a Ns record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithNsRecordNameServer { + /** + * Creates a Ns record with the provided name server in this record set. + * + * @param nameServerHostName the name server host name + * @return the next stage of the record set definition + */ + WithNsRecordNameServerOrAttachable withNameServer(String nameServerHostName); + } + + /** + * The stage of the Ns record set definition allowing to add additional Ns records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithNsRecordNameServerOrAttachable + extends WithNsRecordNameServer, WithAttach { + } + + /** + * The first stage of a Ptr record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface PtrRecordSetBlank extends WithPtrRecordTargetDomainName { + } + + /** + * The stage of the Ptr record set definition allowing to add first Cname record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPtrRecordTargetDomainName { + /** + * Creates a Ptr record with the provided target domain name in this record set. + * + * @param targetDomainName the target domain name + * @return the next stage of the record set definition + */ + WithPtrRecordTargetDomainNameOrAttachable withTargetDomainName(String targetDomainName); + } + + /** + * The stage of the Ptr record set definition allowing to add additional Ptr records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPtrRecordTargetDomainNameOrAttachable + extends WithPtrRecordTargetDomainName, WithAttach { + } + + /** + * The first stage of a Srv record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface SrvRecordSetBlank extends WithSrvRecordEntry { + } + + /** + * The stage of the Srv record definition allowing to add first service record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSrvRecordEntry { + /** + * Specifies a service record for a service. + * + * @param target the canonical name of the target host running the service + * @param port the port on which the service is bounded + * @param priority the priority of the target host, lower the value higher the priority + * @param weight the relative weight (preference) of the records with the same priority, higher the value more the preference + * @return the next stage of the record set definition + */ + WithSrvRecordEntryOrAttachable withRecord(String target, int port, int priority, int weight); + } + + /** + * The stage of the Srv record set definition allowing to add additional Srv records or attach the record set + * to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSrvRecordEntryOrAttachable + extends WithSrvRecordEntry, WithAttach { + } + + /** + * The first stage of a Txt record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface TxtRecordSetBlank extends WithTxtRecordTextValue { + } + + /** + * The stage of the Srv record definition allowing to add first Txt record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithTxtRecordTextValue { + /** + * Creates a Txt record with the given text in this record set. + * + * @param text the text value + * @return the next stage of the record set definition + */ + WithTxtRecordTextValueOrAttachable withText(String text); + } + + /** + * The stage of the Txt record set definition allowing to add additional Txt records or attach the record set + * to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithTxtRecordTextValueOrAttachable + extends WithTxtRecordTextValue, WithAttach { + } + + /** + * The stage of the record set definition allowing to specify Ttl for the records in this record set. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithTtl { + /** + * Specifies the Ttl for the records in the record set. + * + * @param ttlInSeconds ttl in seconds + * @return the next stage of the record set definition + */ + WithAttach withTimeToLive(long ttlInSeconds); + } + + /** + * The stage of the record set definition allowing to specify metadata. + * + * @param the return type of {@link UpdateDefinitionStages.WithAttach#attach()} + */ + interface WithMetadata { + /** + * Adds a metadata to the resource. + * + * @param key the key for the metadata + * @param value the value for the metadata + * @return the next stage of the record set definition + */ + WithAttach withMetadata(String key, String value); + } + + /** The final stage of the Dns zone record set definition. + *

+ * At this stage, any remaining optional settings can be specified, or the Dns zone record set + * definition can be attached to the parent traffic manager profile definition using {@link DnsRecordSet.DefinitionStages.WithAttach#attach()}. + * @param the return type of {@link DnsRecordSet.DefinitionStages.WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InDefinition, + WithMetadata, + DefinitionStages.WithTtl { + } + } + + /** + * The entirety of a Dns zone record set definition as a part of parent update. + * + * @param the return type of the final {@link Attachable#attach()} + */ + interface UpdateDefinition extends + UpdateDefinitionStages.ARecordSetBlank, + UpdateDefinitionStages.WithARecordIpv4Address, + UpdateDefinitionStages.WithARecordIpv4AddressOrAttachable, + UpdateDefinitionStages.AaaaRecordSetBlank, + UpdateDefinitionStages.WithAaaaRecordIpv6Address, + UpdateDefinitionStages.WithAaaaRecordIpv6AddressOrAttachable, + UpdateDefinitionStages.MxRecordSetBlank, + UpdateDefinitionStages.WithMxRecordMailExchange, + UpdateDefinitionStages.WithMxRecordMailExchangeOrAttachable, + UpdateDefinitionStages.NsRecordSetBlank, + UpdateDefinitionStages.WithNsRecordNameServer, + UpdateDefinitionStages.WithNsRecordNameServerOrAttachable, + UpdateDefinitionStages.PtrRecordSetBlank, + UpdateDefinitionStages.WithPtrRecordTargetDomainName, + UpdateDefinitionStages.WithPtrRecordTargetDomainNameOrAttachable, + UpdateDefinitionStages.SrvRecordSetBlank, + UpdateDefinitionStages.WithSrvRecordEntry, + UpdateDefinitionStages.WithSrvRecordEntryOrAttachable, + UpdateDefinitionStages.TxtRecordSetBlank, + UpdateDefinitionStages.WithTxtRecordTextValue, + UpdateDefinitionStages.WithTxtRecordTextValueOrAttachable, + UpdateDefinitionStages.WithAttach { + } + + /** + * Grouping of Dns zone record set definition stages as a part of parent Dns zone update. + */ + interface UpdateDefinitionStages { + /** + * The first stage of a A record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface ARecordSetBlank extends WithARecordIpv4Address { + } + + /** + * The stage of the A record set definition allowing to add first A record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithARecordIpv4Address { + /** + * Creates an A record with the provided Ipv4 address in this record set. + * + * @param ipv4Address the Ipv4 address + * @return the next stage of the record set definition + */ + WithARecordIpv4AddressOrAttachable withIpv4Address(String ipv4Address); + } + + /** + * The stage of the A record set definition allowing to add additional A records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithARecordIpv4AddressOrAttachable + extends WithARecordIpv4Address, WithAttach { + } + + /** + * The first stage of a Aaaa record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface AaaaRecordSetBlank extends WithAaaaRecordIpv6Address { + } + + /** + * The stage of the Aaaa record set definition allowing to add first Aaaa record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAaaaRecordIpv6Address { + /** + * Creates an Aaaa record with the provided Ipv6 address in this record set. + * + * @param ipv6Address the Ipv6 address + * @return the next stage of the record set definition + */ + WithAaaaRecordIpv6AddressOrAttachable withIpv6Address(String ipv6Address); + } + + /** + * The stage of the Aaaa record set definition allowing to add additional A records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAaaaRecordIpv6AddressOrAttachable + extends WithAaaaRecordIpv6Address, WithAttach { + } + + /** + * The first stage of a Mx record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface MxRecordSetBlank extends WithMxRecordMailExchange { + } + + /** + * The stage of the Mx record set definition allowing to add first Mx record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithMxRecordMailExchange { + /** + * Creates and assigns priority to a Mx record with the provided mail exchange server in this record set. + * + * @param mailExchangeHostName the host name of the mail exchange server + * @param priority the priority for the mail exchange host, lower the value higher the priority + * @return the next stage of the record set definition + */ + WithMxRecordMailExchangeOrAttachable withMailExchange(String mailExchangeHostName, int priority); + } + + /** + * The stage of the Mx record set definition allowing to add additional Mx records or attach the record set + * to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithMxRecordMailExchangeOrAttachable + extends WithMxRecordMailExchange, WithAttach { + } + + /** + * The first stage of a Ns record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface NsRecordSetBlank extends WithNsRecordNameServer { + } + + /** + * The stage of the Ns record set definition allowing to add a Ns record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithNsRecordNameServer { + /** + * Creates a Ns record with the provided name server in this record set. + * + * @param nameServerHostName the name server host name + * @return the next stage of the record set definition + */ + WithNsRecordNameServerOrAttachable withNameServer(String nameServerHostName); + } + + /** + * The stage of the Ns record set definition allowing to add additional Ns records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithNsRecordNameServerOrAttachable + extends WithNsRecordNameServer, WithAttach { + } + + /** + * The first stage of a Ptr record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface PtrRecordSetBlank extends WithPtrRecordTargetDomainName { + } + + /** + * The stage of the Ptr record set definition allowing to add first Cname record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPtrRecordTargetDomainName { + /** + * Creates a Ptr record with the provided target domain name in this record set. + * + * @param targetDomainName the target domain name + * @return the next stage of the record set definition + */ + WithPtrRecordTargetDomainNameOrAttachable withTargetDomainName(String targetDomainName); + } + + /** + * The stage of the Ptr record set definition allowing to add additional Ptr records or + * attach the record set to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPtrRecordTargetDomainNameOrAttachable + extends WithPtrRecordTargetDomainName, WithAttach { + } + + /** + * The first stage of a Srv record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface SrvRecordSetBlank extends WithSrvRecordEntry { + } + + /** + * The stage of the Srv record definition allowing to add first service record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSrvRecordEntry { + /** + * Specifies a service record for a service. + * + * @param target the canonical name of the target host running the service + * @param port the port on which the service is bounded + * @param priority the priority of the target host, lower the value higher the priority + * @param weight the relative weight (preference) of the records with the same priority, higher the value more the preference + * @return the next stage of the record set definition + */ + WithSrvRecordEntryOrAttachable withRecord(String target, int port, int priority, int weight); + } + + /** + * The stage of the Srv record set definition allowing to add additional Srv records or attach the record set + * to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSrvRecordEntryOrAttachable + extends WithSrvRecordEntry, WithAttach { + } + + /** + * The first stage of a Txt record definition. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface TxtRecordSetBlank extends WithTxtRecordTextValue { + } + + /** + * The stage of the Srv record definition allowing to add first Txt record. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithTxtRecordTextValue { + /** + * Creates a Txt record with the given text in this record set. + * + * @param text the text value + * @return the next stage of the record set definition + */ + WithTxtRecordTextValueOrAttachable withText(String text); + } + + /** + * The stage of the Txt record set definition allowing to add additional Txt records or attach the record set + * to the parent. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithTxtRecordTextValueOrAttachable + extends WithTxtRecordTextValue, WithAttach { + } + + /** + * The stage of the record set definition allowing to specify Ttl for the records in this record set. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithTtl { + /** + * Specifies the Ttl for the records in the record set. + * + * @param ttlInSeconds ttl in seconds + * @return the next stage of the record set definition + */ + WithAttach withTimeToLive(long ttlInSeconds); + } + + /** + * The stage of the record set definition allowing to specify metadata. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithMetadata { + /** + * Adds a tag to the resource. + * + * @param key the key for the metadata + * @param value the value for the metadata + * @return the next stage of the record set definition + */ + WithAttach withMetadata(String key, String value); + } + + /** The final stage of the Dns zone record set definition. + *

+ * At this stage, any remaining optional settings can be specified, or the Dns zone record set + * definition can be attached to the parent traffic manager profile definition + * using {@link DnsRecordSet.UpdateDefinitionStages.WithAttach#attach()}. + * @param the return type of {@link DnsRecordSet.UpdateDefinitionStages.WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InUpdate, + UpdateDefinitionStages.WithMetadata, + UpdateDefinitionStages.WithTtl { + } + } + + /** + * The entirety of a record sets update as a part of parent Dns zone update. + */ + interface UpdateCombined extends + UpdateARecordSet, + UpdateAaaaRecordSet, + UpdatePtrRecordSet, + UpdateMxRecordSet, + UpdateNsRecordSet, + UpdateSrvRecordSet, + UpdateTxtRecordSet, + UpdateSoaRecord, + Update { + } + + /** + * The entirety of an A record set update as a part of parent Dns zone update. + */ + interface UpdateARecordSet extends + UpdateStages.WithARecordIpv4Address, + Update { + } + + /** + * The entirety of an Aaaa record set update as a part of parent Dns zone update. + */ + interface UpdateAaaaRecordSet extends + UpdateStages.WithAaaaRecordIpv6Address, + Update { + } + + /** + * The entirety of a Mx record set update as a part of parent Dns zone update. + */ + interface UpdateMxRecordSet extends + UpdateStages.WithMxRecordMailExchange, + Update { + } + + /** + * The entirety of a Ns record set update as a part of parent Dns zone update. + */ + interface UpdateNsRecordSet extends + UpdateStages.WithNsRecordNameServer, + Update { + } + + /** + * The entirety of a Ptr record set update as a part of parent Dns zone update. + */ + interface UpdatePtrRecordSet extends + UpdateStages.WithPtrRecordTargetDomainName, + Update { + } + + /** + * The entirety of a Srv record set update as a part of parent Dns zone update. + */ + interface UpdateSrvRecordSet extends + UpdateStages.WithSrvRecordEntry, + Update { + } + + /** + * The entirety of a txt record set update as a part of parent Dns zone update. + */ + interface UpdateTxtRecordSet extends + UpdateStages.WithTxtRecordTextValue, + Update { + } + + /** + * The entirety of a Soa record update as a part of parent Dns zone update. + */ + interface UpdateSoaRecord extends + UpdateStages.WithSoaRecordAttributes, + Update { + } + + /** + * the set of configurations that can be updated for Dns record set irrespective of their type {@link RecordType}. + */ + interface Update extends + Settable, + UpdateStages.WithMetadata, + UpdateStages.WithTtl { + } + + /** + * Grouping of Dns zone record set update stages. + */ + interface UpdateStages { + /** + * The stage of the A record set update allowing to add or remove A record. + */ + interface WithARecordIpv4Address { + /** + * Creates an A record with the provided Ipv4 address in the record set. + * + * @param ipv4Address the Ipv4 address + * @return the next stage of the record set update + */ + UpdateARecordSet withIpv4Address(String ipv4Address); + + /** + * Removes the A record with the provided Ipv4 address from the record set. + * + * @param ipv4Address the Ipv4 address + * @return the next stage of the record set update + */ + UpdateARecordSet withoutIpv4Address(String ipv4Address); + } + + /** + * The stage of the Aaaa record set update allowing to add or remove Aaaa record. + */ + interface WithAaaaRecordIpv6Address { + /** + * Creates an Aaaa record with the provided Ipv6 address in this record set. + * + * @param ipv6Address the Ipv6 address + * @return the next stage of the record set update + */ + UpdateAaaaRecordSet withIpv6Address(String ipv6Address); + + /** + * Removes an Aaaa record with the provided Ipv6 address from this record set. + * + * @param ipv6Address the Ipv6 address + * @return the next stage of the record set update + */ + UpdateAaaaRecordSet withoutIpv6Address(String ipv6Address); + } + + /** + * The stage of the Mx record set definition allowing to add or remove Mx record. + */ + interface WithMxRecordMailExchange { + /** + * Creates and assigns priority to a Mx record with the provided mail exchange server in this record set. + * + * @param mailExchangeHostName the host name of the mail exchange server + * @param priority the priority for the mail exchange host, lower the value higher the priority + * @return the next stage of the record set update + */ + UpdateMxRecordSet withMailExchange(String mailExchangeHostName, int priority); + + /** + * Removes Mx record with the provided mail exchange server and priority from this record set. + * + * @param mailExchangeHostName the host name of the mail exchange server + * @param priority the priority for the mail exchange host, lower the value higher the priority + * @return the next stage of the record set update + */ + UpdateMxRecordSet withoutMailExchange(String mailExchangeHostName, int priority); + } + + /** + * The stage of the Ns record set definition allowing to add or remove a Ns record. + */ + interface WithNsRecordNameServer { + /** + * Creates a Ns record with the provided name server in this record set. + * + * @param nameServerHostName the name server host name + * @return the next stage of the record set update + */ + UpdateNsRecordSet withNameServer(String nameServerHostName); + + /** + * Rmoves a Ns record with the provided name server from this record set. + * + * @param nameServerHostName the name server host name + * @return the next stage of the record set update + */ + UpdateNsRecordSet withoutNameServer(String nameServerHostName); + } + + /** + * The stage of the CName record set definition allowing to add or remove Cname record. + */ + interface WithPtrRecordTargetDomainName { + /** + * Creates a CName record with the provided canonical name in this record set. + * + * @param targetDomainName the target domain name + * @return the next stage of the record set update + */ + UpdatePtrRecordSet withTargetDomainName(String targetDomainName); + + /** + * Removes the CName record with the provided canonical name from this record set. + * + * @param targetDomainName the target domain name + * @return the next stage of the record set update + */ + UpdatePtrRecordSet withoutTargetDomainName(String targetDomainName); + } + + /** + * The stage of the Srv record definition allowing to add or remove service record. + */ + interface WithSrvRecordEntry { + /** + * Specifies a service record for a service. + * + * @param target the canonical name of the target host running the service + * @param port the port on which the service is bounded + * @param priority the priority of the target host, lower the value higher the priority + * @param weight the relative weight (preference) of the records with the same priority, higher the value more the preference + * @return the next stage of the record set update + */ + UpdateSrvRecordSet withRecord(String target, int port, int priority, int weight); + + /** + * Removes a service record for a service. + * + * @param target the canonical name of the target host running the service + * @param port the port on which the service is bounded + * @param priority the priority of the target host + * @param weight the relative weight (preference) of the records + * @return the next stage of the record set update + */ + UpdateSrvRecordSet withoutRecord(String target, int port, int priority, int weight); + } + + /** + * The stage of the Srv record definition allowing to add or remove Txt record. + */ + interface WithTxtRecordTextValue { + /** + * Creates a Txt record with the given text in this record set. + * + * @param text the text value + * @return the next stage of the record set update + */ + UpdateTxtRecordSet withText(String text); + + /** + * Removes a Txt record with the given text from this record set. + * + * @param text the text value + * @return the next stage of the record set update + */ + UpdateTxtRecordSet withoutText(String text); + } + + /** + * The stage of the Soa record definition allowing to update its attributes. + */ + interface WithSoaRecordAttributes { + /** + * Specifies the email server associated with the Soa record. + * + * @param emailServerHostName the email server + * @return the next stage of the record set update + */ + UpdateSoaRecord withEmailServer(String emailServerHostName); + + /** + * Specifies time in seconds that a secondary name server should wait before trying to contact the + * the primary name server for a zone file update. + * + * @param refreshTimeInSeconds the refresh time in seconds + * @return the next stage of the record set update + */ + UpdateSoaRecord withRefreshTimeInSeconds(long refreshTimeInSeconds); + + /** + * Specifies the time in seconds that a secondary name server should wait before trying to contact + * the primary name server again after a failed attempt to check for a zone file update. + * + * @param refreshTimeInSeconds the retry time in seconds + * @return the next stage of the record set update + */ + UpdateSoaRecord withRetryTimeInSeconds(long refreshTimeInSeconds); + + /** + * Specifies the time in seconds that a secondary name server will treat its cached zone file as valid + * when the primary name server cannot be contacted. + * + * @param expireTimeInSeconds the expire time in seconds + * @return the next stage of the record set update + */ + UpdateSoaRecord withExpireTimeInSeconds(long expireTimeInSeconds); + + /** + * Specifies the time in seconds that any name server or resolver should cache a negative response. + * + * @param negativeCachingTimeToLive the Ttl for cached negative response + * @return the next stage of the record set update + */ + UpdateSoaRecord withNegativeResponseCachingTimeToLiveInSeconds(long negativeCachingTimeToLive); + + /** + * Specifies the serial number for the zone file. + * + * @param serialNumber the serial number + * @return the next stage of the record set update + */ + UpdateSoaRecord withSerialNumber(long serialNumber); + } + + /** + * The stage of the record set update allowing to specify Ttl for the records in this record set. + */ + interface WithTtl { + /** + * Specifies the Ttl for the records in the record set. + * + * @param ttlInSeconds ttl in seconds + * @return the next stage of the record set update + */ + Update withTimeToLive(long ttlInSeconds); + } + + /** + * An update allowing metadata to be modified for the resource. + */ + interface WithMetadata { + /** + * Adds a metadata to the record set. + * + * @param key the key for the metadata + * @param value the value for the metadata + * @return the next stage of the record set update + */ + Update withMetadata(String key, String value); + + /** + * Removes a metadata from the record set. + * + * @param key the key of the metadata to remove + * @return the next stage of the record set update + */ + Update withoutMetadata(String key); + } + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsZone.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsZone.java new file mode 100644 index 000000000000..4a04cd9cb122 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsZone.java @@ -0,0 +1,395 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.dns.implementation.ZoneInner; +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 DNS Zone. + */ +@Fluent +public interface DnsZone extends + GroupableResource, + Refreshable, + Wrapper, + Updatable { + /** + * @return the maximum number of record sets that can be created in this zone. + */ + long maxNumberOfRecordSets(); + + /** + * @return the current number of record sets in this zone. + */ + long numberOfRecordSets(); + + /** + * @return name servers assigned for this zone. + */ + List nameServers(); + + /** + * @return entry point to manage record sets in this zone containing A (Ipv4 address) records + */ + ARecordSets aRecordSets(); + + /** + * @return entry point to manage record sets in this zone containing AAAA (IPv6 address) records + */ + AaaaRecordSets aaaaRecordSets(); + + /** + * @return entry point to manage record sets in this zone containing CName (canonical name) records + */ + CnameRecordSets cnameRecordSets(); + + /** + * @return entry point to manage record sets in this zone containing Mx (mail exchange) records + */ + MxRecordSets mxRecordSets(); + + /** + * @return entry point to manage record sets in this zone containing Ns (name server) records + */ + NsRecordSets nsRecordSets(); + + /** + * @return entry point to manage record sets in this zone containing Ptr (pointer) records + */ + PtrRecordSets ptrRecordSets(); + + /** + * @return entry point to manage record sets in this zone containing Srv (service) records + */ + SrvRecordSets srvRecordSets(); + + /** + * @return entry point to manage record sets in this zone containing Txt (text) records + */ + TxtRecordSets txtRecordSets(); + + /** + * @return the record set containing Soa (start of authority) record associated with this Dns zone + */ + SoaRecordSet getSoaRecordSet(); + + /** + * The entirety of the Dns zone definition. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithCreate { + } + + /** + * Grouping of Dns zone definition stages. + */ + interface DefinitionStages { + /** + * The stage of the Dns zone definition allowing to specify the resource group. + */ + interface Blank extends GroupableResource.DefinitionStages.WithGroupAndRegion { + } + + /** + * The stage of the Dns zone definition allowing to specify record set. + */ + interface WithRecordSet { + /** + * Specifies definition of an A record set. + * + * @param name name of the A record set + * @return the stage representing configuration for the A record set + */ + DnsRecordSet.DefinitionStages.ARecordSetBlank defineARecordSet(String name); + + /** + * Specifies definition of an Aaaa record set. + * + * @param name name of the Aaaa record set + * @return the stage representing configuration for the Aaaa record set + */ + DnsRecordSet.DefinitionStages.AaaaRecordSetBlank defineAaaaRecordSet(String name); + + /** + * Specifies definition of a Cname record set. + * + * @param name name of the Cname record set + * @param alias the Cname record alias + * @return the next stage of Dns zone definition + */ + WithCreate withCnameRecordSet(String name, String alias); + + /** + * Specifies definition of a Mx record set. + * + * @param name name of the Mx record set + * @return the stage representing configuration for the Mx record set + */ + DnsRecordSet.DefinitionStages.MxRecordSetBlank defineMxRecordSet(String name); + + /** + * Specifies definition of an Ns record set. + * + * @param name name of the Ns record set + * @return the stage representing configuration for the Ns record set + */ + DnsRecordSet.DefinitionStages.NsRecordSetBlank defineNsRecordSet(String name); + + /** + * Specifies definition of a Ptr record set. + * + * @param name name of the Ptr record set + * @return the stage representing configuration for the Ptr record set + */ + DnsRecordSet.DefinitionStages.PtrRecordSetBlank definePtrRecordSet(String name); + + /** + * Specifies definition of a Srv record set. + * + * @param name the name of the Srv record set + * @return the stage representing configuration for the Srv record set + */ + DnsRecordSet.DefinitionStages.SrvRecordSetBlank defineSrvRecordSet(String name); + + /** + * Specifies definition of a Txt record set. + * + * @param name the name of the Txt record set + * @return the stage representing configuration for the Txt record set + */ + DnsRecordSet.DefinitionStages.TxtRecordSetBlank defineTxtRecordSet(String name); + } + + /** + * The stage of the definition which contains all the minimum required inputs for the resource to be created + * (via {@link WithCreate#create()}), but also allows for any other optional settings to be specified. + */ + interface WithCreate extends + Creatable, + DefinitionStages.WithRecordSet, + Resource.DefinitionWithTags { + } + } + + /** + * Grouping of Dns zone update stages. + */ + interface UpdateStages { + /** + * The stage of the Dns zone update allowing to specify record set. + */ + interface WithRecordSet { + /** + * Specifies definition of an A record set to be attached to the Dns zone. + * + * @param name name of the A record set + * @return the stage representing configuration for the A record set + */ + DnsRecordSet.UpdateDefinitionStages.ARecordSetBlank defineARecordSet(String name); + + /** + * Specifies definition of an Aaaa record set to be attached to the Dns zone. + * + * @param name name of the Aaaa record set + * @return the stage representing configuration for the Aaaa record set + */ + DnsRecordSet.UpdateDefinitionStages.AaaaRecordSetBlank defineAaaaRecordSet(String name); + + /** + * Specifies definition of a Cname record set to be attached to the Dns zone. + * + * @param name name of the Cname record set + * @param alias the Cname record alias + * @return the next stage of Dns zone definition + */ + Update withCnameRecordSet(String name, String alias); + + /** + * Specifies definition of a Mx record set to be attached to the Dns zone. + * + * @param name name of the Mx record set + * @return the stage representing configuration for the Mx record set + */ + DnsRecordSet.UpdateDefinitionStages.MxRecordSetBlank defineMxRecordSet(String name); + + /** + * Specifies definition of an Ns record set to be attached to the Dns zone. + * + * @param name name of the Ns record set + * @return the stage representing configuration for the Ns record set + */ + DnsRecordSet.UpdateDefinitionStages.NsRecordSetBlank defineNsRecordSet(String name); + + /** + * Specifies definition of a Ptr record set to be attached to the Dns zone. + * + * @param name name of the Ptr record set + * @return the stage representing configuration for the Ptr record set + */ + DnsRecordSet.UpdateDefinitionStages.PtrRecordSetBlank definePtrRecordSet(String name); + + /** + * Specifies definition of a Srv record set to be attached to the Dns zone. + * + * @param name the name of the Srv record set + * @return the stage representing configuration for the Srv record set + */ + DnsRecordSet.UpdateDefinitionStages.SrvRecordSetBlank defineSrvRecordSet(String name); + + /** + * Specifies definition of a Txt record set to be attached to the Dns zone. + * + * @param name the name of the Txt record set + * @return the stage representing configuration for the Txt record set + */ + DnsRecordSet.UpdateDefinitionStages.TxtRecordSetBlank defineTxtRecordSet(String name); + + /** + * Begins the description of an update of an existing A record set in this Dns zone. + * + * @param name name of the A record set + * @return the stage representing configuration for the A record set + */ + DnsRecordSet.UpdateARecordSet updateARecordSet(String name); + + /** + * Begins the description of an update of an existing Aaaa record set in this Dns zone. + * + * @param name name of the Aaaa record set + * @return the stage representing configuration for the Aaaa record set + */ + DnsRecordSet.UpdateAaaaRecordSet updateAaaaRecordSet(String name); + + /** + * Begins the description of an update of an existing Mx record set in this Dns zone. + * + * @param name name of the Mx record set + * @return the stage representing configuration for the Mx record set + */ + DnsRecordSet.UpdateMxRecordSet updateMxRecordSet(String name); + + /** + * Begins the description of an update of an existing Ns record set in this Dns zone. + * + * @param name name of the Ns record set + * @return the stage representing configuration for the Ns record set + */ + DnsRecordSet.UpdateNsRecordSet updateNsRecordSet(String name); + + /** + * Begins the description of an update of an existing Ptr record set in this Dns zone. + * + * @param name name of the Ptr record set + * @return the stage representing configuration for the Ptr record set + */ + DnsRecordSet.UpdatePtrRecordSet updatePtrRecordSet(String name); + + /** + * Begins the description of an update of an existing Srv record set in this Dns zone. + * + * @param name the name of the Srv record set + * @return the stage representing configuration for the Srv record set + */ + DnsRecordSet.UpdateSrvRecordSet updateSrvRecordSet(String name); + + /** + * Begins the description of an update of an existing Txt record set in this Dns zone. + * + * @param name the name of the Txt record set + * @return the stage representing configuration for the Txt record set + */ + DnsRecordSet.UpdateTxtRecordSet updateTxtRecordSet(String name); + + /** + * Begins the description of an update of the Soa record in this Dns zone. + * + * @return the stage representing configuration for the Txt record set + */ + DnsRecordSet.UpdateSoaRecord updateSoaRecord(); + + /** + * Removes a A record set in the Dns zone. + * + * @param name name of the A record set + * @return the next stage of Dns zone update + */ + Update withoutARecordSet(String name); + + /** + * Removes a Aaaa record set in the Dns zone. + * + * @param name name of the Aaaa record set + * @return the next stage of Dns zone update + */ + Update withoutAaaaRecordSet(String name); + + /** + * Removes a Cname record set in the Dns zone. + * + * @param name name of the Cname record set + * @return the next stage of Dns zone update + */ + Update withoutCnameRecordSet(String name); + + /** + * Removes a Mx record set in the Dns zone. + * + * @param name name of the Mx record set + * @return the next stage of Dns zone update + */ + Update withoutMxRecordSet(String name); + + /** + * Removes a Ns record set in the Dns zone. + * + * @param name name of the Ns record set + * @return the next stage of Dns zone update + */ + Update withoutNsRecordSet(String name); + + /** + * Removes a Ptr record set in the Dns zone. + * + * @param name name of the Ptr record set + * @return the next stage of Dns zone update + */ + Update withoutPtrRecordSet(String name); + + /** + * Removes a Srv record set in the Dns zone. + * + * @param name name of the Srv record set + * @return the next stage of Dns zone update + */ + Update withoutSrvRecordSet(String name); + + /** + * Removes a Txt record set in the Dns zone. + * + * @param name name of the Txt record set + * @return the next stage of Dns zone update + */ + Update withoutTxtRecordSet(String name); + } + } + + /** + * The template for an 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, + UpdateStages.WithRecordSet, + Resource.UpdateWithTags { + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsZones.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsZones.java new file mode 100644 index 000000000000..e1af3df42380 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/DnsZones.java @@ -0,0 +1,26 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeletingById; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Dns zone management API in Azure. + */ +@Fluent() +public interface DnsZones extends + SupportsCreating, + SupportsListing, + SupportsListingByGroup, + SupportsGettingByGroup, + SupportsGettingById, + SupportsDeletingById, + SupportsDeletingByGroup, + SupportsBatchCreation { +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/MxRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/MxRecordSet.java new file mode 100644 index 000000000000..bf8cc8df96e1 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/MxRecordSet.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.dns; + +import java.util.List; + +/** + * An immutable client-side representation of a Mx (mail exchange) record set in Azure Dns Zone. + */ +public interface MxRecordSet extends DnsRecordSet { + /** + * @return the Mx records in this record set + */ + List records(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/MxRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/MxRecordSets.java new file mode 100644 index 000000000000..e6aeb3442b7e --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/MxRecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Mx record sets in a Dns zone. + */ +@Fluent +public interface MxRecordSets extends + SupportsListing, + SupportsGettingByName { +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/NsRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/NsRecordSet.java new file mode 100644 index 000000000000..a6dec486ae60 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/NsRecordSet.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.dns; + +import java.util.List; + +/** + * An immutable client-side representation of an Ns (name server) record set in Azure Dns Zone. + */ +public interface NsRecordSet extends DnsRecordSet { + /** + * @return the name server names of Ns (name server) records in this record set + */ + List nameServers(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/NsRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/NsRecordSets.java new file mode 100644 index 000000000000..f2e8242c0dfe --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/NsRecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Ns record sets in a Dns zone. + */ +@Fluent +public interface NsRecordSets extends + SupportsListing, + SupportsGettingByName { +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/PtrRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/PtrRecordSet.java new file mode 100644 index 000000000000..7e3536d9d4be --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/PtrRecordSet.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.dns; + +import java.util.List; + +/** + * An immutable client-side representation of a Ptr (pointer) record set in Azure Dns Zone. + */ +public interface PtrRecordSet extends DnsRecordSet { + /** + * @return the target domain names of Ptr records in this record set + */ + List targetDomainNames(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/PtrRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/PtrRecordSets.java new file mode 100644 index 000000000000..8c1a4b92c986 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/PtrRecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Ptr record sets in a Dns zone. + */ +@Fluent +public interface PtrRecordSets extends + SupportsListing, + SupportsGettingByName { +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SoaRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SoaRecordSet.java new file mode 100644 index 000000000000..2abfd6731766 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SoaRecordSet.java @@ -0,0 +1,11 @@ +package com.microsoft.azure.management.dns; + +/** + * An immutable client-side representation of a Soa (start of authority) record set in Azure Dns Zone. + */ +public interface SoaRecordSet extends DnsRecordSet { + /** + * @return the Soa record in this record set + */ + SoaRecord record(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SoaRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SoaRecordSets.java new file mode 100644 index 000000000000..313c4b8e130d --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SoaRecordSets.java @@ -0,0 +1,15 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Soa record sets in a Dns zone. + */ +@Fluent +public interface SoaRecordSets extends + SupportsListing, + SupportsGettingById { +} + diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SrvRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SrvRecordSet.java new file mode 100644 index 000000000000..1688ffcf2227 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SrvRecordSet.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.dns; + +import java.util.List; + +/** + * An immutable client-side representation of a Srv (service) record set in Azure Dns Zone. + */ +public interface SrvRecordSet extends DnsRecordSet { + /** + * @return the Srv records in this record set + */ + List records(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SrvRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SrvRecordSets.java new file mode 100644 index 000000000000..e3051edd40fb --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/SrvRecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Srv record sets in a Dns zone. + */ +@Fluent +public interface SrvRecordSets extends + SupportsListing, + SupportsGettingByName { +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/TxtRecordSet.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/TxtRecordSet.java new file mode 100644 index 000000000000..aa7281a7efa5 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/TxtRecordSet.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.management.dns; + +import java.util.List; + +/** + * An immutable client-side representation of a Txt (text) record set in Azure Dns Zone. + */ +public interface TxtRecordSet extends DnsRecordSet { + /** + * @return the Txt records in this record set + */ + List records(); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/TxtRecordSets.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/TxtRecordSets.java new file mode 100644 index 000000000000..1b91a7465878 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/TxtRecordSets.java @@ -0,0 +1,14 @@ +package com.microsoft.azure.management.dns; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to Txt record sets in a Dns zone. + */ +@Fluent +public interface TxtRecordSets extends + SupportsListing, + SupportsGettingByName { +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/ARecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/ARecordSetImpl.java new file mode 100644 index 000000000000..c48328b5c322 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/ARecordSetImpl.java @@ -0,0 +1,67 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.ARecord; +import com.microsoft.azure.management.dns.ARecordSet; +import com.microsoft.azure.management.dns.RecordType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of {@link ARecordSet}. + */ +class ARecordSetImpl + extends DnsRecordSetImpl + implements ARecordSet { + ARecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static ARecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new ARecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.A.toString()) + .withARecords(new ArrayList()), + client); + } + + @Override + public List ipv4Addresses() { + List ipv4Addresses = new ArrayList<>(); + if (this.inner().aRecords() != null) { + for (ARecord aRecord : this.inner().aRecords()) { + ipv4Addresses.add(aRecord.ipv4Address()); + } + } + return Collections.unmodifiableList(ipv4Addresses); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (this.inner().aRecords() != null && this.inner().aRecords().size() > 0) { + if (resource.aRecords() == null) { + resource.withARecords(new ArrayList()); + } + + resource.aRecords().addAll(this.inner().aRecords()); + this.inner().aRecords().clear(); + } + + if (this.recordSetRemoveInfo.aRecords().size() > 0) { + if (resource.aRecords() != null) { + for (ARecord recordToRemove : this.recordSetRemoveInfo.aRecords()) { + for (ARecord record : resource.aRecords()) { + if (record.ipv4Address().equalsIgnoreCase(recordToRemove.ipv4Address())) { + resource.aRecords().remove(record); + break; + } + } + } + } + this.recordSetRemoveInfo.aRecords().clear(); + } + return resource; + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/ARecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/ARecordSetsImpl.java new file mode 100644 index 000000000000..d763f8504164 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/ARecordSetsImpl.java @@ -0,0 +1,44 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.ARecordSet; +import com.microsoft.azure.management.dns.ARecordSets; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link ARecordSets}. + */ +class ARecordSetsImpl + extends ReadableWrappersImpl + implements ARecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + ARecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public ARecordSetImpl getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.A); + return new ARecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + RecordType.A)); + } + + @Override + protected ARecordSetImpl wrapModel(RecordSetInner inner) { + return new ARecordSetImpl(this.dnsZone, inner, this.client); + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/AaaaRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/AaaaRecordSetImpl.java new file mode 100644 index 000000000000..bb9bd0f86cd7 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/AaaaRecordSetImpl.java @@ -0,0 +1,68 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.AaaaRecord; +import com.microsoft.azure.management.dns.AaaaRecordSet; +import com.microsoft.azure.management.dns.RecordType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of {@link AaaaRecordSet}. + */ +class AaaaRecordSetImpl + extends DnsRecordSetImpl + implements AaaaRecordSet { + + AaaaRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static AaaaRecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new AaaaRecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.AAAA.toString()) + .withAaaaRecords(new ArrayList()), + client); + } + + @Override + public List ipv6Addresses() { + List ipv6Addresses = new ArrayList<>(); + if (this.inner().aaaaRecords() != null) { + for (AaaaRecord aaaaRecord : this.inner().aaaaRecords()) { + ipv6Addresses.add(aaaaRecord.ipv6Address()); + } + } + return Collections.unmodifiableList(ipv6Addresses); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (this.inner().aaaaRecords() != null && this.inner().aaaaRecords().size() > 0) { + if (resource.aaaaRecords() == null) { + resource.withAaaaRecords(new ArrayList()); + } + + resource.aaaaRecords().addAll(this.inner().aaaaRecords()); + this.inner().aaaaRecords().clear(); + } + + if (this.recordSetRemoveInfo.aaaaRecords().size() > 0) { + if (resource.aaaaRecords() != null) { + for (AaaaRecord recordToRemove : this.recordSetRemoveInfo.aaaaRecords()) { + for (AaaaRecord record : resource.aaaaRecords()) { + if (record.ipv6Address().equalsIgnoreCase(recordToRemove.ipv6Address())) { + resource.aaaaRecords().remove(record); + break; + } + } + } + } + this.recordSetRemoveInfo.aaaaRecords().clear(); + } + return resource; + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/AaaaRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/AaaaRecordSetsImpl.java new file mode 100644 index 000000000000..da13001bfd0b --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/AaaaRecordSetsImpl.java @@ -0,0 +1,44 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.AaaaRecordSet; +import com.microsoft.azure.management.dns.AaaaRecordSets; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link AaaaRecordSets}. + */ +class AaaaRecordSetsImpl + extends ReadableWrappersImpl + implements AaaaRecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + AaaaRecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public AaaaRecordSetImpl getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.AAAA); + return new AaaaRecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + RecordType.AAAA)); + } + + @Override + protected AaaaRecordSetImpl wrapModel(RecordSetInner inner) { + return new AaaaRecordSetImpl(this.dnsZone, inner, this.client); + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/CnameRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/CnameRecordSetImpl.java new file mode 100644 index 000000000000..e6c7fd560d57 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/CnameRecordSetImpl.java @@ -0,0 +1,38 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.CnameRecord; +import com.microsoft.azure.management.dns.CnameRecordSet; +import com.microsoft.azure.management.dns.RecordType; + +/** + * Implementation of {@link CnameRecordSet}. + */ +class CnameRecordSetImpl + extends DnsRecordSetImpl + implements CnameRecordSet { + CnameRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static CnameRecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new CnameRecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.CNAME.toString()) + .withCnameRecord(new CnameRecord()), + client); + } + + @Override + public String canonicalName() { + if (this.inner().cnameRecord() != null) { + return this.inner().cnameRecord().cname(); + } + return null; + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + return resource; + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/CnameRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/CnameRecordSetsImpl.java new file mode 100644 index 000000000000..90c1eeaec1d8 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/CnameRecordSetsImpl.java @@ -0,0 +1,44 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.CnameRecordSet; +import com.microsoft.azure.management.dns.CnameRecordSets; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link CnameRecordSets}. + */ +class CnameRecordSetsImpl + extends ReadableWrappersImpl + implements CnameRecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + CnameRecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public CnameRecordSet getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.CNAME); + return new CnameRecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + RecordType.CNAME)); + } + + @Override + protected CnameRecordSetImpl wrapModel(RecordSetInner inner) { + return new CnameRecordSetImpl(this.dnsZone, inner, this.client); + } +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsRecordSetImpl.java new file mode 100644 index 000000000000..4d81416ed065 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsRecordSetImpl.java @@ -0,0 +1,348 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.ARecord; +import com.microsoft.azure.management.dns.AaaaRecord; +import com.microsoft.azure.management.dns.CnameRecord; +import com.microsoft.azure.management.dns.DnsRecordSet; +import com.microsoft.azure.management.dns.DnsZone; +import com.microsoft.azure.management.dns.MxRecord; +import com.microsoft.azure.management.dns.NsRecord; +import com.microsoft.azure.management.dns.PtrRecord; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.dns.SrvRecord; +import com.microsoft.azure.management.dns.TxtRecord; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ExternalChildResourceImpl; +import rx.Observable; +import rx.functions.Func1; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Implementation of {@link DnsRecordSet}. + */ +abstract class DnsRecordSetImpl extends ExternalChildResourceImpl + implements DnsRecordSet, + DnsRecordSet.Definition, + DnsRecordSet.UpdateDefinition, + DnsRecordSet.UpdateCombined { + protected final RecordSetsInner client; + protected final RecordSetInner recordSetRemoveInfo; + + protected DnsRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(innerModel.name(), parent, innerModel); + this.client = client; + this.recordSetRemoveInfo = new RecordSetInner() + .withName(innerModel.name()) + .withType(innerModel.type()) + .withARecords(new ArrayList()) + .withAaaaRecords(new ArrayList()) + .withCnameRecord(new CnameRecord()) + .withMxRecords(new ArrayList()) + .withNsRecords(new ArrayList()) + .withPtrRecords(new ArrayList()) + .withSrvRecords(new ArrayList()) + .withTxtRecords(new ArrayList()) + .withMetadata(new LinkedHashMap()); + } + + @Override + public String id() { + return inner().id(); + } + + @Override + public RecordType recordType() { + return RecordType.fromString(this.inner().type()); + } + + @Override + public long timeToLive() { + return this.inner().tTL(); + } + + @Override + public Map metadata() { + if (this.inner().metadata() == null) { + return Collections.unmodifiableMap(new LinkedHashMap()); + } + return Collections.unmodifiableMap(this.inner().metadata()); + } + + // Setters + + @Override + public DnsRecordSetImpl withIpv4Address(String ipv4Address) { + this.inner() + .aRecords() + .add(new ARecord().withIpv4Address(ipv4Address)); + return this; + } + + @Override + public DnsRecordSetImpl withoutIpv4Address(String ipv4Address) { + this.recordSetRemoveInfo + .aRecords() + .add(new ARecord().withIpv4Address(ipv4Address)); + return this; + } + + @Override + public DnsRecordSetImpl withIpv6Address(String ipv6Address) { + this.inner() + .aaaaRecords() + .add(new AaaaRecord().withIpv6Address(ipv6Address)); + return this; + } + + @Override + public DnsRecordSetImpl withoutIpv6Address(String ipv6Address) { + this.recordSetRemoveInfo + .aaaaRecords() + .add(new AaaaRecord().withIpv6Address(ipv6Address)); + return this; + } + + @Override + public DnsRecordSetImpl withMailExchange(String mailExchangeHostName, int priority) { + this.inner() + .mxRecords() + .add(new MxRecord().withExchange(mailExchangeHostName).withPreference(priority)); + return this; + } + + @Override + public DnsRecordSetImpl withoutMailExchange(String mailExchangeHostName, int priority) { + this.recordSetRemoveInfo + .mxRecords() + .add(new MxRecord().withExchange(mailExchangeHostName).withPreference(priority)); + return this; + } + + @Override + public DnsRecordSetImpl withNameServer(String nameServerHostName) { + this.inner() + .nsRecords() + .add(new NsRecord().withNsdname(nameServerHostName)); + return this; + } + + @Override + public DnsRecordSetImpl withoutNameServer(String nameServerHostName) { + this.recordSetRemoveInfo + .nsRecords() + .add(new NsRecord().withNsdname(nameServerHostName)); + return this; + } + + @Override + public DnsRecordSetImpl withTargetDomainName(String targetDomainName) { + this.inner() + .ptrRecords() + .add(new PtrRecord().withPtrdname(targetDomainName)); + return this; + } + + @Override + public DnsRecordSetImpl withoutTargetDomainName(String targetDomainName) { + this.recordSetRemoveInfo + .ptrRecords() + .add(new PtrRecord().withPtrdname(targetDomainName)); + return this; + } + + @Override + public DnsRecordSetImpl withRecord(String target, int port, int priority, int weight) { + this.inner().srvRecords().add(new SrvRecord() + .withTarget(target) + .withPort(port) + .withPriority(priority) + .withWeight(weight)); + return this; + } + + @Override + public DnsRecordSetImpl withoutRecord(String target, int port, int priority, int weight) { + this.recordSetRemoveInfo. + srvRecords().add(new SrvRecord() + .withTarget(target) + .withPort(port) + .withPriority(priority) + .withWeight(weight)); + return this; + } + + @Override + public DnsRecordSetImpl withText(String text) { + List value = new ArrayList<>(); + value.add(text); + this.inner().txtRecords().add(new TxtRecord().withValue(value)); + return this; + } + + @Override + public DnsRecordSetImpl withoutText(String text) { + List value = new ArrayList<>(); + value.add(text); + this.recordSetRemoveInfo + .txtRecords().add(new TxtRecord().withValue(value)); + return this; + } + + @Override + public DnsRecordSetImpl withEmailServer(String emailServerHostName) { + this.inner().soaRecord().withEmail(emailServerHostName); + return this; + } + + @Override + public DnsRecordSetImpl withRefreshTimeInSeconds(long refreshTimeInSeconds) { + this.inner().soaRecord().withRefreshTime(refreshTimeInSeconds); + return this; + } + + @Override + public DnsRecordSetImpl withRetryTimeInSeconds(long retryTimeInSeconds) { + this.inner().soaRecord().withRetryTime(retryTimeInSeconds); + return this; + } + + @Override + public DnsRecordSetImpl withExpireTimeInSeconds(long expireTimeInSeconds) { + this.inner().soaRecord().withExpireTime(expireTimeInSeconds); + return this; + } + + @Override + public DnsRecordSetImpl withNegativeResponseCachingTimeToLiveInSeconds(long negativeCachingTimeToLive) { + this.inner().soaRecord().withMinimumTtl(negativeCachingTimeToLive); + return this; + } + + @Override + public DnsRecordSetImpl withSerialNumber(long serialNumber) { + this.inner().soaRecord().withSerialNumber(serialNumber); + return this; + } + + @Override + public DnsRecordSetImpl withTimeToLive(long ttlInSeconds) { + this.inner().withTTL(ttlInSeconds); + return this; + } + + @Override + public DnsRecordSetImpl withMetadata(String key, String value) { + if (this.inner().metadata() == null) { + this.inner().withMetadata(new LinkedHashMap()); + } + this.inner().metadata().put(key, value); + return this; + } + + @Override + public DnsRecordSetImpl withoutMetadata(String key) { + this.recordSetRemoveInfo + .metadata().put(key, null); + return this; + } + + // + + @Override + public Observable createAsync() { + return createOrUpdateAsync(this.inner()); + } + + @Override + public Observable updateAsync() { + return this.client.getAsync(this.parent().resourceGroupName(), + this.parent().name(), this.name(), this.recordType()) + .map(new Func1() { + public RecordSetInner call(RecordSetInner resource) { + return prepare(resource); + } + }).flatMap(new Func1>() { + @Override + public Observable call(RecordSetInner resource) { + return createOrUpdateAsync(resource); + } + }); + } + + @Override + public Observable deleteAsync() { + return this.client.deleteAsync(this.parent().resourceGroupName(), + this.parent().name(), this.name(), this.recordType()); + } + + @Override + public DnsZoneImpl attach() { + return this.parent(); + } + + @Override + public String childResourceKey() { + return this.name() + "_" + this.recordType().toString(); + } + + @Override + public DnsRecordSetImpl refresh() { + this.setInner(this.client.get(this.parent().resourceGroupName(), + this.parent().name(), + this.name(), + this.recordType())); + return this; + } + + private Observable createOrUpdateAsync(RecordSetInner resource) { + final DnsRecordSetImpl self = this; + return this.client.createOrUpdateAsync(this.parent().resourceGroupName(), + this.parent().name(), + this.name(), + this.recordType(), + resource) + .map(new Func1() { + @Override + public DnsRecordSet call(RecordSetInner inner) { + setInner(inner); + return self; + } + }); + } + + private RecordSetInner prepare(RecordSetInner resource) { + if (this.recordSetRemoveInfo.metadata().size() > 0) { + if (resource.metadata() != null) { + for (String key : this.recordSetRemoveInfo.metadata().keySet()) { + resource.metadata().remove(key); + } + } + this.recordSetRemoveInfo.metadata().clear(); + } + if (this.inner().metadata() != null && this.inner().metadata().size() > 0) { + if (resource.metadata() == null) { + resource.withMetadata(new LinkedHashMap()); + } + for (Map.Entry keyVal : this.inner().metadata().entrySet()) { + resource.metadata().put(keyVal.getKey(), keyVal.getValue()); + } + this.inner().metadata().clear(); + } + + if (this.inner().tTL() != null) { + resource.withTTL(this.inner().tTL()); + this.inner().withTTL(null); + } + + return prepareForUpdate(resource); + } + + protected abstract RecordSetInner prepareForUpdate(RecordSetInner resource); +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsRecordSetsImpl.java new file mode 100644 index 000000000000..68d0987eab91 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsRecordSetsImpl.java @@ -0,0 +1,138 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.DnsRecordSet; +import com.microsoft.azure.management.dns.DnsZone; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesNonCachedImpl; + +/** + * Represents an record set collection associated with a Dns zone. + */ +class DnsRecordSetsImpl extends + ExternalChildResourcesNonCachedImpl { + private final RecordSetsInner client; + /** + * The default record set ttl in seconds. + */ + private final long defaultTtlInSeconds = 3600; + + /** + * Creates new DnsRecordSetsImpl. + * + * @param client the client to perform REST calls on record sets + * @param parent the parent Dns zone of the record set + */ + DnsRecordSetsImpl(RecordSetsInner client, DnsZoneImpl parent) { + super(parent, "RecordSet"); + this.client = client; + } + + DnsRecordSetImpl defineARecordSet(String name) { + return setDefaults(prepareDefine(ARecordSetImpl.newRecordSet(name, this.parent(), this.client))); + } + + DnsRecordSetImpl defineAaaaRecordSet(String name) { + return setDefaults(prepareDefine(AaaaRecordSetImpl.newRecordSet(name, this.parent(), this.client))); + } + + void withCnameRecordSet(String name, String alias) { + CnameRecordSetImpl recordSet = CnameRecordSetImpl.newRecordSet(name, this.parent(), this.client); + recordSet.inner().cnameRecord().withCname(alias); + setDefaults(prepareDefine(recordSet.withTimeToLive(defaultTtlInSeconds))); + } + + DnsRecordSetImpl defineMxRecordSet(String name) { + return setDefaults(prepareDefine(MxRecordSetImpl.newRecordSet(name, this.parent(), this.client))); + } + + DnsRecordSetImpl defineNsRecordSet(String name) { + return setDefaults(prepareDefine(NsRecordSetImpl.newRecordSet(name, this.parent(), this.client))); + } + + DnsRecordSetImpl definePtrRecordSet(String name) { + return setDefaults(prepareDefine(PtrRecordSetImpl.newRecordSet(name, this.parent(), this.client))); + } + + DnsRecordSetImpl defineSrvRecordSet(String name) { + return setDefaults(prepareDefine(SrvRecordSetImpl.newRecordSet(name, this.parent(), this.client))); + } + + DnsRecordSetImpl defineTxtRecordSet(String name) { + return setDefaults(prepareDefine(TxtRecordSetImpl.newRecordSet(name, this.parent(), this.client))); + } + + DnsRecordSetImpl updateARecordSet(String name) { + return prepareUpdate(ARecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + DnsRecordSetImpl updateAaaaRecordSet(String name) { + return prepareUpdate(AaaaRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + DnsRecordSetImpl updateMxRecordSet(String name) { + return prepareUpdate(MxRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + DnsRecordSetImpl updateNsRecordSet(String name) { + return prepareUpdate(NsRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + DnsRecordSetImpl updatePtrRecordSet(String name) { + return prepareUpdate(PtrRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + DnsRecordSetImpl updateSrvRecordSet(String name) { + return prepareUpdate(SrvRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + DnsRecordSetImpl updateTxtRecordSet(String name) { + return prepareUpdate(TxtRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + DnsRecordSetImpl updateSoaRecordSet() { + return prepareUpdate(SoaRecordSetImpl.newRecordSet(this.parent(), this.client)); + } + + void withoutARecordSet(String name) { + prepareRemove(ARecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + void withoutAaaaRecordSet(String name) { + prepareRemove(AaaaRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + void withoutCnameRecordSet(String name) { + prepareRemove(CnameRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + void withoutMxRecordSet(String name) { + prepareRemove(MxRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + void withoutNsRecordSet(String name) { + prepareRemove(NsRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + void withoutPtrRecordSet(String name) { + prepareRemove(PtrRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + void withoutSrvRecordSet(String name) { + prepareRemove(SrvRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + void withoutTxtRecordSet(String name) { + prepareRemove(TxtRecordSetImpl.newRecordSet(name, this.parent(), this.client)); + } + + final void clearPendingOperations() { + this.childCollection.clear(); + } + + private DnsRecordSetImpl setDefaults(DnsRecordSetImpl recordSet) { + return recordSet.withTimeToLive(defaultTtlInSeconds); + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZoneImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZoneImpl.java new file mode 100644 index 000000000000..9f71182348f3 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZoneImpl.java @@ -0,0 +1,288 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.ARecordSets; +import com.microsoft.azure.management.dns.AaaaRecordSets; +import com.microsoft.azure.management.dns.CnameRecordSets; +import com.microsoft.azure.management.dns.DnsZone; +import com.microsoft.azure.management.dns.MxRecordSets; +import com.microsoft.azure.management.dns.NsRecordSets; +import com.microsoft.azure.management.dns.PtrRecordSets; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.dns.SoaRecordSet; +import com.microsoft.azure.management.dns.SrvRecordSets; +import com.microsoft.azure.management.dns.TxtRecordSets; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; +import rx.Observable; +import rx.functions.Func1; + +import java.util.List; + +/** + * Implementation for {@link DnsZone}. + */ +public class DnsZoneImpl + extends GroupableResourceImpl< + DnsZone, + ZoneInner, + DnsZoneImpl, + DnsZoneManager> + implements + DnsZone, + DnsZone.Definition, + DnsZone.Update { + private final ZonesInner innerCollection; + private final RecordSetsInner recordSetsClient; + + private ARecordSets aRecordSets; + private AaaaRecordSets aaaaRecordSets; + private CnameRecordSets cnameRecordSets; + private MxRecordSets mxRecordSets; + private NsRecordSets nsRecordSets; + private PtrRecordSets ptrRecordSets; + private SrvRecordSets srvRecordSets; + private TxtRecordSets txtRecordSets; + private DnsRecordSetsImpl recordSetsImpl; + + DnsZoneImpl(String name, + final ZoneInner innerModel, + final ZonesInner innerCollection, + final RecordSetsInner recordSetsClient, + final DnsZoneManager trafficManager) { + super(name, innerModel, trafficManager); + this.innerCollection = innerCollection; + this.recordSetsClient = recordSetsClient; + this.recordSetsImpl = new DnsRecordSetsImpl(recordSetsClient, this); + initRecordSets(); + } + + @Override + public long maxNumberOfRecordSets() { + return this.inner().maxNumberOfRecordSets(); + } + + @Override + public long numberOfRecordSets() { + return this.inner().numberOfRecordSets(); + } + + @Override + public List nameServers() { + return this.inner().nameServers(); + } + + @Override + public ARecordSets aRecordSets() { + return this.aRecordSets; + } + + @Override + public AaaaRecordSets aaaaRecordSets() { + return this.aaaaRecordSets; + } + + @Override + public CnameRecordSets cnameRecordSets() { + return this.cnameRecordSets; + } + + @Override + public MxRecordSets mxRecordSets() { + return this.mxRecordSets; + } + + @Override + public NsRecordSets nsRecordSets() { + return this.nsRecordSets; + } + + @Override + public PtrRecordSets ptrRecordSets() { + return this.ptrRecordSets; + } + + @Override + public SrvRecordSets srvRecordSets() { + return this.srvRecordSets; + } + + @Override + public TxtRecordSets txtRecordSets() { + return this.txtRecordSets; + } + + @Override + public SoaRecordSet getSoaRecordSet() { + RecordSetInner inner = this.recordSetsClient.get(this.resourceGroupName(), this.name(), "@", RecordType.SOA); + return new SoaRecordSetImpl(this, inner, this.recordSetsClient); + } + + // Setters + + @Override + public DnsRecordSetImpl defineARecordSet(String name) { + return recordSetsImpl.defineARecordSet(name); + } + + @Override + public DnsRecordSetImpl defineAaaaRecordSet(String name) { + return recordSetsImpl.defineAaaaRecordSet(name); + } + + @Override + public DnsZoneImpl withCnameRecordSet(String name, String alias) { + recordSetsImpl.withCnameRecordSet(name, alias); + return this; + } + + @Override + public DnsRecordSetImpl defineMxRecordSet(String name) { + return recordSetsImpl.defineMxRecordSet(name); + } + + @Override + public DnsRecordSetImpl defineNsRecordSet(String name) { + return recordSetsImpl.defineNsRecordSet(name); + } + + @Override + public DnsRecordSetImpl definePtrRecordSet(String name) { + return recordSetsImpl.definePtrRecordSet(name); + } + + @Override + public DnsRecordSetImpl defineSrvRecordSet(String name) { + return recordSetsImpl.defineSrvRecordSet(name); + } + + @Override + public DnsRecordSetImpl defineTxtRecordSet(String name) { + return recordSetsImpl.defineTxtRecordSet(name); + } + + @Override + public DnsRecordSetImpl updateARecordSet(String name) { + return recordSetsImpl.updateARecordSet(name); + } + + @Override + public DnsRecordSetImpl updateAaaaRecordSet(String name) { + return recordSetsImpl.updateAaaaRecordSet(name); + } + + @Override + public DnsRecordSetImpl updateMxRecordSet(String name) { + return recordSetsImpl.updateMxRecordSet(name); + } + + @Override + public DnsRecordSetImpl updateNsRecordSet(String name) { + return recordSetsImpl.updateNsRecordSet(name); + } + + @Override + public DnsRecordSetImpl updatePtrRecordSet(String name) { + return recordSetsImpl.updatePtrRecordSet(name); + } + + @Override + public DnsRecordSetImpl updateSrvRecordSet(String name) { + return recordSetsImpl.updateSrvRecordSet(name); + } + + @Override + public DnsRecordSetImpl updateTxtRecordSet(String name) { + return recordSetsImpl.updateTxtRecordSet(name); + } + + @Override + public DnsRecordSetImpl updateSoaRecord() { + return recordSetsImpl.updateSoaRecordSet(); + } + + @Override + public DnsZoneImpl withoutARecordSet(String name) { + recordSetsImpl.withoutARecordSet(name); + return this; + } + + @Override + public DnsZoneImpl withoutAaaaRecordSet(String name) { + recordSetsImpl.withoutAaaaRecordSet(name); + return this; + } + + @Override + public DnsZoneImpl withoutCnameRecordSet(String name) { + recordSetsImpl.withoutCnameRecordSet(name); + return this; + } + + @Override + public DnsZoneImpl withoutMxRecordSet(String name) { + recordSetsImpl.withoutMxRecordSet(name); + return this; + } + + @Override + public DnsZoneImpl withoutNsRecordSet(String name) { + recordSetsImpl.withoutNsRecordSet(name); + return this; + } + + @Override + public DnsZoneImpl withoutPtrRecordSet(String name) { + recordSetsImpl.withoutPtrRecordSet(name); + return this; + } + + @Override + public DnsZoneImpl withoutSrvRecordSet(String name) { + recordSetsImpl.withoutSrvRecordSet(name); + return this; + } + + @Override + public DnsZoneImpl withoutTxtRecordSet(String name) { + recordSetsImpl.withoutTxtRecordSet(name); + return this; + } + + @Override + public Observable createResourceAsync() { + final DnsZoneImpl self = this; + return this.innerCollection.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(innerToFluentMap(this)) + .flatMap(new Func1>() { + @Override + public Observable call(DnsZone dnsZone) { + return self.recordSetsImpl.commitAndGetAllAsync() + .map(new Func1, DnsZone>() { + @Override + public DnsZone call(List recordSets) { + return self; + } + }); + } + }); + } + + @Override + public DnsZone refresh() { + ZoneInner inner = this.innerCollection.get(this.resourceGroupName(), this.name()); + this.setInner(inner); + this.initRecordSets(); + return this; + } + + private void initRecordSets() { + this.aRecordSets = new ARecordSetsImpl(this, this.recordSetsClient); + this.aaaaRecordSets = new AaaaRecordSetsImpl(this, this.recordSetsClient); + this.cnameRecordSets = new CnameRecordSetsImpl(this, this.recordSetsClient); + this.mxRecordSets = new MxRecordSetsImpl(this, this.recordSetsClient); + this.nsRecordSets = new NsRecordSetsImpl(this, this.recordSetsClient); + this.ptrRecordSets = new PtrRecordSetsImpl(this, this.recordSetsClient); + this.srvRecordSets = new SrvRecordSetsImpl(this, this.recordSetsClient); + this.txtRecordSets = new TxtRecordSetsImpl(this, this.recordSetsClient); + this.recordSetsImpl.clearPendingOperations(); + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZoneManager.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZoneManager.java new file mode 100644 index 000000000000..8c555f99503e --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZoneManager.java @@ -0,0 +1,94 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.AzureTokenCredentials; +import com.microsoft.azure.management.dns.DnsZones; +import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; + +/** + * Entry point to Azure Dns zone manager management. + */ +public final class DnsZoneManager extends Manager { + // Collections + private DnsZones zones; + + /** + * Get a Configurable instance that can be used to create {@link DnsZoneManager} + * with optional configuration. + * + * @return the instance allowing configurations + */ + public static Configurable configure() { + return new DnsZoneManager.ConfigurableImpl(); + } + + /** + * Creates an instance of DnsZoneManager that exposes Dns zone manager management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the DnsZoneManager + */ + public static DnsZoneManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new DnsZoneManager(credentials.getEnvironment().newRestClientBuilder() + .withCredentials(credentials) + .build(), subscriptionId); + } + + /** + * Creates an instance of DnsZoneManager that exposes Dns zone manager management API entry points. + * + * @param restClient the RestClient to be used for API calls. + * @param subscriptionId the subscription UUID + * @return the DnsZoneManager + */ + public static DnsZoneManager authenticate(RestClient restClient, String subscriptionId) { + return new DnsZoneManager(restClient, subscriptionId); + } + + /** + * The interface allowing configurations to be set. + */ + public interface Configurable extends AzureConfigurable { + /** + * Creates an instance of DnsZoneManager that exposes Dns zone API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the interface exposing Dns zone manager management API entry points that work across subscriptions + */ + DnsZoneManager authenticate(AzureTokenCredentials credentials, String subscriptionId); + } + + /** + * The implementation for Configurable interface. + */ + private static class ConfigurableImpl + extends AzureConfigurableImpl + implements Configurable { + + public DnsZoneManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return DnsZoneManager.authenticate(buildRestClient(credentials), subscriptionId); + } + } + + private DnsZoneManager(RestClient restClient, String subscriptionId) { + super(restClient, + subscriptionId, + new DnsManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); + } + + /** + * @return entry point to Dns zone manager zone management + */ + public DnsZones zones() { + if (this.zones == null) { + this.zones = new DnsZonesImpl( + super.innerManagementClient, + this); + } + return this.zones; + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZonesImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZonesImpl.java new file mode 100644 index 000000000000..4f715c01d45f --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/DnsZonesImpl.java @@ -0,0 +1,83 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.DnsZone; +import com.microsoft.azure.management.dns.DnsZones; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; +import rx.Observable; +import rx.functions.Func1; + +/** + * Implementation of {@link DnsZones}. + */ +class DnsZonesImpl extends GroupableResourcesImpl< + DnsZone, + DnsZoneImpl, + ZoneInner, + ZonesInner, + DnsZoneManager> + implements DnsZones { + private final RecordSetsInner recordSetsClient; + + DnsZonesImpl( + final DnsManagementClientImpl dnsManagementClient, + final DnsZoneManager dnsZoneManager) { + super(dnsManagementClient.zones(), dnsZoneManager); + this.recordSetsClient = dnsManagementClient.recordSets(); + } + + @Override + public PagedList list() { + return wrapList(this.innerCollection.listInSubscription()); + } + + @Override + public PagedList listByGroup(String groupName) { + return wrapList(this.innerCollection.listInResourceGroup(groupName)); + } + + @Override + public DnsZone getByGroup(String groupName, String name) { + return wrapModel(this.innerCollection.get(groupName, name)); + } + + @Override + public Observable deleteByGroupAsync(String groupName, String name) { + return this.innerCollection.deleteAsync(groupName, name) + .map(new Func1() { + @Override + public Void call(ZoneDeleteResultInner zoneDeleteResultInner) { + return null; + } + }); + } + + @Override + public DnsZoneImpl define(String name) { + return setDefaults(wrapModel(name)); + } + + @Override + protected DnsZoneImpl wrapModel(String name) { + return new DnsZoneImpl(name, + new ZoneInner(), + this.innerCollection, + this.recordSetsClient, + this.myManager); + } + + @Override + protected DnsZoneImpl wrapModel(ZoneInner inner) { + return new DnsZoneImpl(inner.name(), + inner, + this.innerCollection, + this.recordSetsClient, + this.myManager); + } + + private DnsZoneImpl setDefaults(DnsZoneImpl dnsZone) { + // Zone location must be 'global' irrespective of region of the resource group it resides. + dnsZone.inner().withLocation("global"); + return dnsZone; + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/MxRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/MxRecordSetImpl.java new file mode 100644 index 000000000000..43bee9ca95db --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/MxRecordSetImpl.java @@ -0,0 +1,66 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.MxRecord; +import com.microsoft.azure.management.dns.MxRecordSet; +import com.microsoft.azure.management.dns.RecordType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of {@link MxRecordSet}. + */ +class MxRecordSetImpl + extends DnsRecordSetImpl + implements MxRecordSet { + MxRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static MxRecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new MxRecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.MX.toString()) + .withMxRecords(new ArrayList()), + client); + } + + @Override + public List records() { + if (this.inner().mxRecords() != null) { + return Collections.unmodifiableList(this.inner().mxRecords()); + } + return Collections.unmodifiableList(new ArrayList()); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (this.inner().mxRecords() != null && this.inner().mxRecords().size() > 0) { + if (resource.mxRecords() == null) { + resource.withMxRecords(new ArrayList()); + } + + resource.mxRecords().addAll(this.inner().mxRecords()); + this.inner().mxRecords().clear(); + } + + if (this.recordSetRemoveInfo.mxRecords().size() > 0) { + if (resource.mxRecords() != null) { + for (MxRecord recordToRemove : this.recordSetRemoveInfo.mxRecords()) { + for (MxRecord record : resource.mxRecords()) { + if (record.exchange().equalsIgnoreCase(recordToRemove.exchange()) + && (record.preference() == recordToRemove.preference())) { + resource.mxRecords().remove(record); + break; + } + } + } + } + this.recordSetRemoveInfo.mxRecords().clear(); + } + return resource; + } +} + diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/MxRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/MxRecordSetsImpl.java new file mode 100644 index 000000000000..0e6d7bb20c15 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/MxRecordSetsImpl.java @@ -0,0 +1,42 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.MxRecordSet; +import com.microsoft.azure.management.dns.MxRecordSets; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link MxRecordSets}. + */ +class MxRecordSetsImpl + extends ReadableWrappersImpl + implements MxRecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + MxRecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public MxRecordSetImpl getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.MX); + return new MxRecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), this.dnsZone.name(), RecordType.MX)); + } + + @Override + protected MxRecordSetImpl wrapModel(RecordSetInner inner) { + return new MxRecordSetImpl(this.dnsZone, inner, this.client); + } +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/NsRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/NsRecordSetImpl.java new file mode 100644 index 000000000000..df49221f83b0 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/NsRecordSetImpl.java @@ -0,0 +1,70 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.NsRecord; +import com.microsoft.azure.management.dns.NsRecordSet; +import com.microsoft.azure.management.dns.RecordType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of {@link NsRecordSet}. + */ +class NsRecordSetImpl + extends DnsRecordSetImpl + implements NsRecordSet { + NsRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static NsRecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new NsRecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.NS.toString()) + .withNsRecords(new ArrayList()), + client); + } + + @Override + public List nameServers() { + List nameServers = new ArrayList<>(); + if (this.inner().nsRecords() != null) { + for (NsRecord nsRecord : this.inner().nsRecords()) { + nameServers.add(nsRecord.nsdname()); + } + } + return Collections.unmodifiableList(nameServers); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (this.inner().nsRecords() != null && this.inner().nsRecords().size() > 0) { + if (resource.nsRecords() == null) { + resource.withNsRecords(new ArrayList()); + } + + for (NsRecord record : this.inner().nsRecords()) { + resource.nsRecords().add(record); + } + this.inner().nsRecords().clear(); + } + + if (this.recordSetRemoveInfo.nsRecords().size() > 0) { + if (resource.nsRecords() != null) { + for (NsRecord recordToRemove : this.recordSetRemoveInfo.nsRecords()) { + for (NsRecord record : resource.nsRecords()) { + if (record.nsdname().equalsIgnoreCase(recordToRemove.nsdname())) { + resource.nsRecords().remove(record); + break; + } + } + } + } + this.recordSetRemoveInfo.nsRecords().clear(); + } + return resource; + } +} + diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/NsRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/NsRecordSetsImpl.java new file mode 100644 index 000000000000..4b4b75da46bd --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/NsRecordSetsImpl.java @@ -0,0 +1,42 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.NsRecordSet; +import com.microsoft.azure.management.dns.NsRecordSets; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link NsRecordSets}. + */ +class NsRecordSetsImpl + extends ReadableWrappersImpl + implements NsRecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + NsRecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public NsRecordSetImpl getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.NS); + return new NsRecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), this.dnsZone.name(), RecordType.NS)); + } + + @Override + protected NsRecordSetImpl wrapModel(RecordSetInner inner) { + return new NsRecordSetImpl(this.dnsZone, inner, this.client); + } +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/PtrRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/PtrRecordSetImpl.java new file mode 100644 index 000000000000..bc82845d8037 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/PtrRecordSetImpl.java @@ -0,0 +1,68 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.PtrRecord; +import com.microsoft.azure.management.dns.PtrRecordSet; +import com.microsoft.azure.management.dns.RecordType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of {@link PtrRecordSet}. + */ +class PtrRecordSetImpl + extends DnsRecordSetImpl + implements PtrRecordSet { + PtrRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static PtrRecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new PtrRecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.PTR.toString()) + .withPtrRecords(new ArrayList()), + client); + } + + @Override + public List targetDomainNames() { + List targetDomainNames = new ArrayList<>(); + if (this.inner().ptrRecords() != null) { + for (PtrRecord ptrRecord : this.inner().ptrRecords()) { + targetDomainNames.add(ptrRecord.ptrdname()); + } + } + return Collections.unmodifiableList(targetDomainNames); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (this.inner().ptrRecords() != null && this.inner().ptrRecords().size() > 0) { + if (resource.ptrRecords() == null) { + resource.withPtrRecords(new ArrayList()); + } + + resource.ptrRecords().addAll(this.inner().ptrRecords()); + this.inner().ptrRecords().clear(); + } + + if (this.recordSetRemoveInfo.ptrRecords().size() > 0) { + if (resource.ptrRecords() != null) { + for (PtrRecord recordToRemove : this.recordSetRemoveInfo.ptrRecords()) { + for (PtrRecord record : resource.ptrRecords()) { + if (record.ptrdname().equalsIgnoreCase(recordToRemove.ptrdname())) { + resource.ptrRecords().remove(record); + break; + } + } + } + } + this.recordSetRemoveInfo.ptrRecords().clear(); + } + return resource; + } +} + diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/PtrRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/PtrRecordSetsImpl.java new file mode 100644 index 000000000000..2ec079d0383e --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/PtrRecordSetsImpl.java @@ -0,0 +1,42 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.PtrRecordSet; +import com.microsoft.azure.management.dns.PtrRecordSets; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link PtrRecordSets}. + */ +class PtrRecordSetsImpl + extends ReadableWrappersImpl + implements PtrRecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + PtrRecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public PtrRecordSetImpl getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.PTR); + return new PtrRecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), this.dnsZone.name(), RecordType.PTR)); + } + + @Override + protected PtrRecordSetImpl wrapModel(RecordSetInner inner) { + return new PtrRecordSetImpl(this.dnsZone, inner, this.client); + } +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SoaRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SoaRecordSetImpl.java new file mode 100644 index 000000000000..94378dbca846 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SoaRecordSetImpl.java @@ -0,0 +1,64 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.dns.SoaRecord; +import com.microsoft.azure.management.dns.SoaRecordSet; + +/** + * Implementation of {@link SoaRecordSet}. + */ +class SoaRecordSetImpl + extends DnsRecordSetImpl + implements SoaRecordSet { + SoaRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static SoaRecordSetImpl newRecordSet(final DnsZoneImpl parent, final RecordSetsInner client) { + return new SoaRecordSetImpl(parent, + new RecordSetInner() + .withName("@") + .withType(RecordType.SOA.toString()) + .withSoaRecord(new SoaRecord()), + client); + } + + @Override + public SoaRecord record() { + return this.inner().soaRecord(); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (resource.soaRecord() == null) { + resource.withSoaRecord(new SoaRecord()); + } + + if (this.inner().soaRecord().email() != null) { + resource.soaRecord().withEmail(this.inner().soaRecord().email()); + } + + if (this.inner().soaRecord().expireTime() != null) { + resource.soaRecord().withExpireTime(this.inner().soaRecord().expireTime()); + } + + if (this.inner().soaRecord().minimumTtl() != null) { + resource.soaRecord().withMinimumTtl(this.inner().soaRecord().minimumTtl()); + } + + if (this.inner().soaRecord().refreshTime() != null) { + resource.soaRecord().withRefreshTime(this.inner().soaRecord().refreshTime()); + } + + if (this.inner().soaRecord().retryTime() != null) { + resource.soaRecord().withRetryTime(this.inner().soaRecord().retryTime()); + } + + if (this.inner().soaRecord().serialNumber() != null) { + resource.soaRecord().withSerialNumber(this.inner().soaRecord().serialNumber()); + } + + this.inner().withSoaRecord(new SoaRecord()); + return resource; + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SrvRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SrvRecordSetImpl.java new file mode 100644 index 000000000000..558d2c7a8428 --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SrvRecordSetImpl.java @@ -0,0 +1,67 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.dns.SrvRecord; +import com.microsoft.azure.management.dns.SrvRecordSet; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of {@link SrvRecordSet}. + */ +class SrvRecordSetImpl + extends DnsRecordSetImpl + implements SrvRecordSet { + SrvRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static SrvRecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new SrvRecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.SRV.toString()) + .withSrvRecords(new ArrayList()), + client); + } + + @Override + public List records() { + if (this.inner().srvRecords() != null) { + return Collections.unmodifiableList(this.inner().srvRecords()); + } + return Collections.unmodifiableList(new ArrayList()); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (this.inner().srvRecords() != null && this.inner().srvRecords().size() > 0) { + if (resource.srvRecords() == null) { + resource.withSrvRecords(new ArrayList()); + } + + resource.srvRecords().addAll(this.inner().srvRecords()); + this.inner().srvRecords().clear(); + } + + if (this.recordSetRemoveInfo.srvRecords().size() > 0) { + if (resource.srvRecords() != null) { + for (SrvRecord recordToRemove : this.recordSetRemoveInfo.srvRecords()) { + for (SrvRecord record : resource.srvRecords()) { + if (record.target().equalsIgnoreCase(recordToRemove.target()) + && (record.port().intValue() == recordToRemove.port().intValue()) + && (record.weight().intValue() == recordToRemove.weight().intValue()) + && (record.priority().intValue() == recordToRemove.priority().intValue())) { + resource.srvRecords().remove(record); + break; + } + } + } + } + this.recordSetRemoveInfo.srvRecords().clear(); + } + return resource; + } +} diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SrvRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SrvRecordSetsImpl.java new file mode 100644 index 000000000000..16c744f6a91a --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/SrvRecordSetsImpl.java @@ -0,0 +1,42 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.dns.SrvRecordSet; +import com.microsoft.azure.management.dns.SrvRecordSets; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link SrvRecordSets}. + */ +class SrvRecordSetsImpl + extends ReadableWrappersImpl + implements SrvRecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + SrvRecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public SrvRecordSetImpl getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.SRV); + return new SrvRecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), this.dnsZone.name(), RecordType.SRV)); + } + + @Override + protected SrvRecordSetImpl wrapModel(RecordSetInner inner) { + return new SrvRecordSetImpl(this.dnsZone, inner, this.client); + } +} \ No newline at end of file diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/TxtRecordSetImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/TxtRecordSetImpl.java new file mode 100644 index 000000000000..5ce58aaedb3b --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/TxtRecordSetImpl.java @@ -0,0 +1,66 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.dns.TxtRecord; +import com.microsoft.azure.management.dns.TxtRecordSet; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Implementation of {@link TxtRecordSet}. + */ +class TxtRecordSetImpl + extends DnsRecordSetImpl + implements TxtRecordSet { + TxtRecordSetImpl(final DnsZoneImpl parent, final RecordSetInner innerModel, final RecordSetsInner client) { + super(parent, innerModel, client); + } + + static TxtRecordSetImpl newRecordSet(final String name, final DnsZoneImpl parent, final RecordSetsInner client) { + return new TxtRecordSetImpl(parent, + new RecordSetInner() + .withName(name) + .withType(RecordType.TXT.toString()) + .withTxtRecords(new ArrayList()), + client); + } + + @Override + public List records() { + if (this.inner().txtRecords() != null) { + return Collections.unmodifiableList(this.inner().txtRecords()); + } + return Collections.unmodifiableList(new ArrayList()); + } + + @Override + protected RecordSetInner prepareForUpdate(RecordSetInner resource) { + if (this.inner().txtRecords() != null && this.inner().txtRecords().size() > 0) { + if (resource.txtRecords() == null) { + resource.withTxtRecords(new ArrayList()); + } + + resource.txtRecords().addAll(this.inner().txtRecords()); + this.inner().txtRecords().clear(); + } + + if (this.recordSetRemoveInfo.txtRecords().size() > 0) { + if (resource.txtRecords() != null) { + for (TxtRecord recordToRemove : this.recordSetRemoveInfo.txtRecords()) { + for (TxtRecord record : resource.txtRecords()) { + if (record.value().size() != 0 && record.value().get(0).equalsIgnoreCase(recordToRemove.value().get(0))) { + resource.txtRecords().remove(record); + break; + } + } + } + } + this.recordSetRemoveInfo.txtRecords().clear(); + } + return resource; + } +} + + diff --git a/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/TxtRecordSetsImpl.java b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/TxtRecordSetsImpl.java new file mode 100644 index 000000000000..da01adc9454c --- /dev/null +++ b/azure-mgmt-dns/src/main/java/com/microsoft/azure/management/dns/implementation/TxtRecordSetsImpl.java @@ -0,0 +1,42 @@ +package com.microsoft.azure.management.dns.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.dns.RecordType; +import com.microsoft.azure.management.dns.TxtRecordSet; +import com.microsoft.azure.management.dns.TxtRecordSets; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * Implementation of {@link TxtRecordSets}. + */ +class TxtRecordSetsImpl + extends ReadableWrappersImpl + implements TxtRecordSets { + + private final DnsZoneImpl dnsZone; + private final RecordSetsInner client; + + TxtRecordSetsImpl(DnsZoneImpl dnsZone, RecordSetsInner client) { + this.dnsZone = dnsZone; + this.client = client; + } + + @Override + public TxtRecordSetImpl getByName(String name) { + RecordSetInner inner = this.client.get(this.dnsZone.resourceGroupName(), + this.dnsZone.name(), + name, + RecordType.TXT); + return new TxtRecordSetImpl(this.dnsZone, inner, this.client); + } + + @Override + public PagedList list() { + return super.wrapList(this.client.listByType(this.dnsZone.resourceGroupName(), this.dnsZone.name(), RecordType.TXT)); + } + + @Override + protected TxtRecordSetImpl wrapModel(RecordSetInner inner) { + return new TxtRecordSetImpl(this.dnsZone, inner, this.client); + } +} \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourceCollectionImpl.java similarity index 65% rename from azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesImpl.java rename to azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourceCollectionImpl.java index ef02604187e1..2512a2a0a027 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourceCollectionImpl.java @@ -19,7 +19,8 @@ import java.util.concurrent.ConcurrentMap; /** - * Externalized child resource collection abstract implementation. + * Base class for cached {@link ExternalChildResourcesCachedImpl} and non-cached {@link ExternalChildResourcesNonCachedImpl} + * externalized child resource collection. * (Internal use only) * * @param the implementation of {@param FluentModelT} @@ -28,7 +29,7 @@ * @param the parent Azure resource impl class type that implements {@link ParentT} * @param the parent interface */ -public abstract class ExternalChildResourcesImpl< +public abstract class ExternalChildResourceCollectionImpl< FluentModelTImpl extends ExternalChildResourceImpl, FluentModelT extends ExternalChildResource, InnerModelT, @@ -38,14 +39,16 @@ public abstract class ExternalChildResourcesImpl< * The parent resource of this collection of child resources. */ private final ParentImplT parent; + /** - * Used to construct error string, this is user friendly name of the child resource (e.g. Subnet, Extension). + * The child resource instances that this collection contains. */ - private final String childResourceName; + protected ConcurrentMap childCollection = new ConcurrentHashMap<>(); + /** - * The child resource instances that this collection contains. + * Used to construct error string, this is user friendly name of the child resource (e.g. Subnet, Extension). */ - private ConcurrentMap collection = new ConcurrentHashMap<>(); + protected final String childResourceName; /** * Creates a new ExternalChildResourcesImpl. @@ -53,32 +56,25 @@ public abstract class ExternalChildResourcesImpl< * @param parent the parent Azure resource * @param childResourceName the child resource name */ - protected ExternalChildResourcesImpl(ParentImplT parent, String childResourceName) { + protected ExternalChildResourceCollectionImpl(ParentImplT parent, String childResourceName) { this.parent = parent; this.childResourceName = childResourceName; } /** - * Refresh the collection. - */ - public void refresh() { - initializeCollection(); - } - - /** - * Commits the changes in the external child resource collection. + * Commits the changes in the external child resource childCollection. *

* This method returns an observable stream, its observer's onNext will be called for each successfully - * committed resource followed by 'one call to onCompleted' or one call to onError with a + * committed resource followed by one call to 'onCompleted' or one call to 'onError' with a * {@link CompositeException } containing the list of exceptions where each exception describes the reason * for failure of a resource commit. * * @return the observable stream */ public Observable commitAsync() { - final ExternalChildResourcesImpl self = this; + final ExternalChildResourceCollectionImpl self = this; List items = new ArrayList<>(); - for (FluentModelTImpl item : this.collection.values()) { + for (FluentModelTImpl item : this.childCollection.values()) { items.add(item); } @@ -102,7 +98,7 @@ public FluentModelTImpl call(Void response) { @Override public void call(FluentModelTImpl childResource) { childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.None); - self.collection.remove(childResource.name()); + self.childCollection.remove(childResource.name()); } }) .onErrorResumeNext(new Func1>() { @@ -140,7 +136,7 @@ public void call(FluentModelTImpl fluentModelT) { .onErrorResumeNext(new Func1>() { @Override public Observable call(Throwable throwable) { - self.collection.remove(childResource.name()); + self.childCollection.remove(childResource.name()); exceptionsList.add(throwable); return Observable.empty(); } @@ -184,22 +180,25 @@ public Observable call(Throwable throwable) { Observable operationsStream = Observable.merge(deleteStream, createStream, updateStream).doOnTerminate(new Action0() { - @Override - public void call() { - if (exceptionsList.isEmpty()) { - aggregatedErrorStream.onCompleted(); - } else { - aggregatedErrorStream.onError(new CompositeException(exceptionsList)); - } + @Override + public void call() { + if (clearAfterCommit()) { + self.childCollection.clear(); } - }); + if (exceptionsList.isEmpty()) { + aggregatedErrorStream.onCompleted(); + } else { + aggregatedErrorStream.onError(new CompositeException(exceptionsList)); + } + } + }); Observable stream = Observable.concat(operationsStream, aggregatedErrorStream); return stream; } /** - * Commits the changes in the external child resource collection. + * Commits the changes in the external child resource childCollection. *

* This method returns a observable stream, either its observer's onError will be called with * {@link CompositeException} if some resources failed to commit or onNext will be called if all resources @@ -210,9 +209,9 @@ public void call() { public Observable> commitAndGetAllAsync() { return commitAsync().collect( new Func0>() { - public List call() { - return new ArrayList<>(); - } + public List call() { + return new ArrayList<>(); + } }, new Action2, FluentModelTImpl>() { public void call(List state, FluentModelTImpl item) { @@ -221,114 +220,31 @@ public void call(List state, FluentModelTImpl item) { }); } - /** - * @return the parent Azure resource of the external child resource - */ - protected ParentImplT parent() { - return parent; - } - - /** - * @return the collection of external child resources. - */ - protected Map collection() { - return this.collection; - } - - /** - * Prepare for definition of a new external child resource. - * - * @param name the name for the new external child resource - * @return the child resource - */ - protected FluentModelTImpl prepareDefine(String name) { - if (find(name) != null) { - throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name '" + name + "' already exists"); - } - FluentModelTImpl childResource = newChildResource(name); - childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeCreated); - return childResource; - } /** - * Prepare for an external child resource update. + * Finds a child resource with the given key. * - * @param name the name of the external child resource - * @return the external child resource to be updated - */ - protected FluentModelTImpl prepareUpdate(String name) { - FluentModelTImpl childResource = find(name); - if (childResource == null - || childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeCreated) { - throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name '" + name + "' not found"); - } - if (childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeRemoved) { - throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name '" + name + "' is marked for deletion"); - } - childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeUpdated); - return childResource; - } - - /** - * Mark an external child resource with given name as to be removed. - * - * @param name the name of the external child resource + * @param key the child resource key + * @return null if no child resource exists with the given name else the child resource */ - protected void prepareRemove(String name) { - FluentModelTImpl childResource = find(name); - if (childResource == null - || childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeCreated) { - throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name '" + name + "' not found"); + protected FluentModelTImpl find(String key) { + for (Map.Entry entry : this.childCollection.entrySet()) { + if (entry.getKey().equalsIgnoreCase(key)) { + return entry.getValue(); + } } - childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeRemoved); - } - - /** - * Adds an external child resource to the collection. - * - * @param childResource the external child resource - */ - protected void addChildResource(FluentModelTImpl childResource) { - this.collection.put(childResource.name(), childResource); + return null; } /** - * Initializes the external child resource collection. + * @return the parent Azure resource of the external child resource */ - protected void initializeCollection() { - this.collection.clear(); - for (FluentModelTImpl childResource : this.listChildResources()) { - this.collection.put(childResource.name(), childResource); - } + protected ParentImplT parent() { + return parent; } /** - * Gets the list of external child resources. - * - * @return the list of external child resources - */ - protected abstract List listChildResources(); - - /** - * Gets a new external child resource model instance. - * - * @param name the name for the new child resource - * @return the new child resource - */ - protected abstract FluentModelTImpl newChildResource(String name); - - /** - * Finds a child resource with the given name. - * - * @param name the child resource name - * @return null if no child resource exists with the given name else the child resource + * @return true if the child resource collection needs to be cleared after the commit. */ - private FluentModelTImpl find(String name) { - for (Map.Entry entry : this.collection.entrySet()) { - if (entry.getKey().equalsIgnoreCase(name)) { - return entry.getValue(); - } - } - return null; - } + protected abstract boolean clearAfterCommit(); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesCachedImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesCachedImpl.java new file mode 100644 index 000000000000..3162cbb9474e --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesCachedImpl.java @@ -0,0 +1,183 @@ +package com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation; + +import com.microsoft.azure.management.resources.fluentcore.arm.models.ExternalChildResource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ExternalChildResourceImpl; +import java.util.List; +import java.util.Map; + +/** + * Externalized cache-able child resource collection abstract implementation. + * (Internal use only) + *

+ * An external child resource collection is considered as cache-able when it is present as an inline + * property of it's parent resource. + * Consider using non-cached version {@link ExternalChildResourcesNonCachedImpl} if the child resources + * are not present in the parent payload, using cached version in this case requires fetching the child resource + * using separate GET call, that can be expensive if the child resources are pagable. + * + * @param the implementation of {@param FluentModelT} + * @param the fluent model type of the child resource + * @param Azure inner resource class type representing the child resource + * @param the parent Azure resource impl class type that implements {@link ParentT} + * @param the parent interface + */ +public abstract class ExternalChildResourcesCachedImpl< + FluentModelTImpl extends ExternalChildResourceImpl, + FluentModelT extends ExternalChildResource, + InnerModelT, + ParentImplT extends ParentT, + ParentT> + extends ExternalChildResourceCollectionImpl { + /** + * Creates a new ExternalChildResourcesImpl. + * + * @param parent the parent Azure resource + * @param childResourceName the child resource name + */ + protected ExternalChildResourcesCachedImpl(ParentImplT parent, String childResourceName) { + super(parent, childResourceName); + } + + /** + * Refresh the child resource collection. + */ + public void refresh() { + cacheCollection(); + } + + /** + * @return the childCollection of external child resources. + */ + protected Map collection() { + return this.childCollection; + } + + /** + * Prepare for definition of a new external child resource. + * + * @param name the name for the new external child resource + * @return the child resource + */ + protected FluentModelTImpl prepareDefine(String name) { + return prepareDefine(name, name); + } + + /** + * Prepare for definition of a new external child resource. + * + * @param name the name of the new external child resource + * @param key the key + * @return the child resource + */ + protected final FluentModelTImpl prepareDefine(String name, String key) { + if (find(key) != null) { + throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' already exists"); + } + FluentModelTImpl childResource = newChildResource(name); + childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeCreated); + return childResource; + } + + /** + * Prepare for an external child resource update. + * + * @param name the name of the external child resource + * @return the external child resource to be updated + */ + protected final FluentModelTImpl prepareUpdate(String name) { + return prepareUpdate(name, name); + } + + /** + * Prepare for an external child resource update. + * + * @param name the name of the external child resource + * @param key the key + * @return the external child resource to be updated + */ + protected final FluentModelTImpl prepareUpdate(String name, String key) { + FluentModelTImpl childResource = find(key); + if (childResource == null + || childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeCreated) { + throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' not found"); + } + if (childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeRemoved) { + throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' is marked for deletion"); + } + childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeUpdated); + return childResource; + } + + /** + * Mark an external child resource with given name as to be removed. + * + * @param name the name of the external child resource + */ + protected final void prepareRemove(String name) { + prepareRemove(name, name); + } + + /** + * Mark an external child resource with given key as to be removed. + * + * @param name the name of the external child resource + * @param key the key + */ + protected final void prepareRemove(String name, String key) { + FluentModelTImpl childResource = find(key); + if (childResource == null + || childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeCreated) { + throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' not found"); + } + childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeRemoved); + } + + /** + * Adds an external child resource to the childCollection. + * + * @param childResource the external child resource + */ + protected void addChildResource(FluentModelTImpl childResource) { + this.addChildResource(childResource.name(), childResource); + } + + /** + * Adds an external child resource to the childCollection. + * + * @param key the key + * @param childResource the external child resource + */ + protected void addChildResource(String key, FluentModelTImpl childResource) { + this.childCollection.put(key, childResource); + } + + /** + * Initializes the external child resource collection. + */ + protected void cacheCollection() { + this.childCollection.clear(); + for (FluentModelTImpl childResource : this.listChildResources()) { + this.childCollection.put(childResource.childResourceKey(), childResource); + } + } + + @Override + protected final boolean clearAfterCommit() { + return false; + } + + /** + * Gets the list of external child resources. + * + * @return the list of external child resources + */ + protected abstract List listChildResources(); + + /** + * Gets a new external child resource model instance. + * + * @param name the name for the new child resource + * @return the new child resource + */ + protected abstract FluentModelTImpl newChildResource(String name); +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesNonCachedImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesNonCachedImpl.java new file mode 100644 index 000000000000..998b5ed835d5 --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ExternalChildResourcesNonCachedImpl.java @@ -0,0 +1,93 @@ +package com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation; + +import com.microsoft.azure.management.resources.fluentcore.arm.models.ExternalChildResource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ExternalChildResourceImpl; + +/** + * Externalized non cache-able child resource collection abstract implementation. + * (Internal use only) + *

+ * An external child resource collection is considered as non cache-able when it is not present as an inline + * property of its parent resource i.e. a separate call is required to fetch them. + * Consider using the cached version {@link ExternalChildResourcesCachedImpl} if the external child resources + * present in the parent payload, in case of update this can save addition GET operation required before the + * child resource PUT if PATCH is not supported. + * + * @param the implementation of {@param FluentModelT} + * @param the fluent model type of the child resource + * @param Azure inner resource class type representing the child resource + * @param the parent Azure resource impl class type that implements {@link ParentT} + * @param the parent interface + */ +public abstract class ExternalChildResourcesNonCachedImpl< + FluentModelTImpl extends ExternalChildResourceImpl, + FluentModelT extends ExternalChildResource, + InnerModelT, + ParentImplT extends ParentT, + ParentT> + extends ExternalChildResourceCollectionImpl { + /** + * Creates a new ExternalNonInlineChildResourcesImpl. + * + * @param parent the parent Azure resource + * @param childResourceName the child resource name + */ + protected ExternalChildResourcesNonCachedImpl(ParentImplT parent, String childResourceName) { + super(parent, childResourceName); + } + + /** + * Prepare a given model of an external child resource for create. + * + * @param model the model to track create changes + * @return the external child resource prepared for create + */ + protected final FluentModelTImpl prepareDefine(FluentModelTImpl model) { + FluentModelTImpl childResource = find(model.childResourceKey()); + if (childResource != null) { + throw new IllegalArgumentException(pendingOperationMessage(model.name(), model.childResourceKey())); + } + model.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeCreated); + this.childCollection.put(model.childResourceKey(), model); + return model; + } + + /** + * Prepare a given model of an external child resource for update. + * + * @param model the model to track update changes + * @return the external child resource prepared for update + */ + protected final FluentModelTImpl prepareUpdate(FluentModelTImpl model) { + FluentModelTImpl childResource = find(model.childResourceKey()); + if (childResource != null) { + throw new IllegalArgumentException(pendingOperationMessage(model.name(), model.childResourceKey())); + } + model.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeUpdated); + this.childCollection.put(model.childResourceKey(), model); + return model; + } + + /** + * Prepare a given model of an external child resource for remove. + * + * @param model the model representing child resource to remove + */ + protected final void prepareRemove(FluentModelTImpl model) { + FluentModelTImpl childResource = find(model.childResourceKey()); + if (childResource != null) { + throw new IllegalArgumentException(pendingOperationMessage(model.name(), model.childResourceKey())); + } + model.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeRemoved); + this.childCollection.put(model.childResourceKey(), model); + } + + @Override + protected final boolean clearAfterCommit() { + return true; + } + + private String pendingOperationMessage(String name, String key) { + return "There is already an operation pending on the child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")'"; + } +} 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 d309286c561b..c2eab0339fe7 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 @@ -13,13 +13,13 @@ import java.util.Map; /** -* Base interfaces for fluent resources. -*/ + * Base interfaces for fluent resources. + */ @LangDefinition() public interface Resource extends - Indexable, - HasId, - HasName { + Indexable, + HasId, + HasName { /** * @return the type of the resource @@ -115,4 +115,4 @@ interface UpdateWithTags { */ T withoutTag(String key); } -} +} \ No newline at end of file diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ExternalChildResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ExternalChildResourceImpl.java index aa787ce3e38d..4f6c82166cc1 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ExternalChildResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ExternalChildResourceImpl.java @@ -8,7 +8,7 @@ * Inorder to be eligible for an external child resource following criteria must be satisfied: * 1. It's is always associated with a parent resource and has no existence without parent * i.e. if you delete parent then child resource will be deleted automatically. - * 2. Parent will contain collection of child resources. this is not a hard requirement. + * 2. Parent may or may not contain collection of child resources (i.e. as inline collection property). * 3. It's has an ID and can be created, updated, fetched and deleted independent of the parent * i.e. CRUD on child resource does not require CRUD on the parent * (Internal use only) @@ -92,6 +92,13 @@ public void setPendingOperation(PendingOperation pendingOperation) { */ public abstract Observable deleteAsync(); + /** + * @return the key of this child resource in the collection maintained by ExternalChildResourceCollectionImpl + */ + public String childResourceKey() { + return name(); + } + /** * The possible operation pending on a child resource in-memory. */ diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/childresource/PulletsImpl.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/childresource/PulletsImpl.java index 94b110bca0ab..2779efd42cdb 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/childresource/PulletsImpl.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/childresource/PulletsImpl.java @@ -1,13 +1,13 @@ package com.microsoft.azure.management.resources.childresource; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesCachedImpl; import java.util.ArrayList; import java.util.List; -class PulletsImpl extends ExternalChildResourcesImpl { +class PulletsImpl extends ExternalChildResourcesCachedImpl { PulletsImpl(ChickenImpl parent) { super(parent, "Pullet"); - initializeCollection(); + cacheCollection(); } public PulletImpl define(String name) { diff --git a/azure-mgmt-trafficmanager/src/main/java/com/microsoft/azure/management/trafficmanager/implementation/TrafficManagerEndpointsImpl.java b/azure-mgmt-trafficmanager/src/main/java/com/microsoft/azure/management/trafficmanager/implementation/TrafficManagerEndpointsImpl.java index 842479fd1e0b..de6d419fe3ae 100644 --- a/azure-mgmt-trafficmanager/src/main/java/com/microsoft/azure/management/trafficmanager/implementation/TrafficManagerEndpointsImpl.java +++ b/azure-mgmt-trafficmanager/src/main/java/com/microsoft/azure/management/trafficmanager/implementation/TrafficManagerEndpointsImpl.java @@ -5,7 +5,7 @@ */ package com.microsoft.azure.management.trafficmanager.implementation; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesCachedImpl; import com.microsoft.azure.management.trafficmanager.TrafficManagerAzureEndpoint; import com.microsoft.azure.management.trafficmanager.TrafficManagerEndpoint; import com.microsoft.azure.management.trafficmanager.EndpointType; @@ -23,7 +23,7 @@ * Represents an endpoint collection associated with a traffic manager profile. */ class TrafficManagerEndpointsImpl extends - ExternalChildResourcesImpl { + @Override + public DnsZone createResource(DnsZones dnsZones) throws Exception { + final Region region = Region.US_EAST; + final String groupName = "rg" + this.testId; + final String topLevelDomain = "www.contoso" + this.testId + ".com"; + + DnsZone dnsZone = dnsZones.define(topLevelDomain) + .withNewResourceGroup(groupName, region) + .defineARecordSet("www") + .withIpv4Address("23.96.104.40") + .withIpv4Address("24.97.105.41") + .withTimeToLive(7200) // Overwrite default 3600 seconds + .attach() + .defineAaaaRecordSet("www") + .withIpv6Address("2001:0db8:85a3:0000:0000:8a2e:0370:7334") + .withIpv6Address("2002:0db9:85a4:0000:0000:8a2e:0371:7335") + .attach() + .defineMxRecordSet("email") + .withMailExchange("mail.contoso-mail-exchange1.com", 1) + .withMailExchange("mail.contoso-mail-exchange2.com", 2) + .withMetadata("mxa", "mxaa") + .withMetadata("mxb", "mxbb") + .attach() + .defineNsRecordSet("partners") + .withNameServer("ns1-05.azure-dns.com") + .withNameServer("ns2-05.azure-dns.net") + .withNameServer("ns3-05.azure-dns.org") + .withNameServer("ns4-05.azure-dns.info") + .attach() + .defineTxtRecordSet("@") + .withText("windows-apps-verification=2ZzjfideIJFLFje83") + .attach() + .defineTxtRecordSet("www") + .withText("some info about www.contoso.com") + .attach() + .defineSrvRecordSet("_sip._tcp") + .withRecord("bigbox.contoso-service.com", 5060, 10, 60) + .withRecord("smallbox1.contoso-service.com", 5060, 10, 20) + .withRecord("smallbox2.contoso-service.com", 5060, 10, 20) + .withRecord("backupbox.contoso-service.com", 5060, 10, 0) + .attach() + .definePtrRecordSet("40") + .withTargetDomainName("www.contoso.com") + .withTargetDomainName("mail.contoso.com") + .attach() + .definePtrRecordSet("41") + .withTargetDomainName("www.contoso.com") + .withTargetDomainName("mail.contoso.com") + .attach() + .withCnameRecordSet("documents", "doc.contoso.com") + .withCnameRecordSet("userguide", "doc.contoso.com") + .withTag("a", "aa") + .withTag("b", "bb") + .create(); + + // Check Dns zone properties + Assert.assertTrue(dnsZone.name().startsWith(topLevelDomain)); + Assert.assertTrue(dnsZone.nameServers().size() > 0); // Default '@' name servers + Assert.assertTrue(dnsZone.tags().size() == 2); + + // Check SOA record - external child resource (created by default) + SoaRecordSet soaRecordSet = dnsZone.getSoaRecordSet(); + Assert.assertTrue(soaRecordSet.name().startsWith("@")); + SoaRecord soaRecord = soaRecordSet.record(); + Assert.assertNotNull(soaRecord); + + // Check explicitly created external child resources [A, AAAA, MX, NS, TXT, SRV, PTR, CNAME] + // + + // Check A records + PagedList aRecordSets = dnsZone.aRecordSets().list(); + Assert.assertTrue(aRecordSets.size() == 1); + Assert.assertTrue(aRecordSets.get(0).timeToLive() == 7200); + + // Check AAAA records + PagedList aaaaRecordSets = dnsZone.aaaaRecordSets().list(); + Assert.assertTrue(aaaaRecordSets.size() == 1); + Assert.assertTrue(aaaaRecordSets.get(0).name().startsWith("www")); + Assert.assertTrue(aaaaRecordSets.get(0).ipv6Addresses().size() == 2); + + // Check MX records + PagedList mxRecordSets = dnsZone.mxRecordSets().list(); + Assert.assertTrue(mxRecordSets.size() == 1); + MxRecordSet mxRecordSet = mxRecordSets.get(0); + Assert.assertNotNull(mxRecordSet); + Assert.assertTrue(mxRecordSet.name().startsWith("email")); + Assert.assertTrue(mxRecordSet.metadata().size() == 2); + Assert.assertTrue(mxRecordSet.records().size() == 2); + for (MxRecord mxRecord : mxRecordSet.records()) { + Assert.assertTrue(mxRecord.exchange().startsWith("mail.contoso-mail-exchange1.com") + || mxRecord.exchange().startsWith("mail.contoso-mail-exchange2.com")); + Assert.assertTrue(mxRecord.preference() == 1 + || mxRecord.preference() == 2); + } + + // Check NS records + PagedList nsRecordSets = dnsZone.nsRecordSets().list(); + Assert.assertTrue(nsRecordSets.size() == 2); // One created above with name 'partners' + the default '@' + + // Check TXT records + PagedList txtRecordSets = dnsZone.txtRecordSets().list(); + Assert.assertTrue(txtRecordSets.size() == 2); + + // Check SRV records + PagedList srvRecordSets = dnsZone.srvRecordSets().list(); + Assert.assertTrue(srvRecordSets.size() == 1); + + // Check PTR records + PagedList ptrRecordSets = dnsZone.ptrRecordSets().list(); + Assert.assertTrue(ptrRecordSets.size() == 2); + + // Check CNAME records + PagedList cnameRecordSets = dnsZone.cnameRecordSets().list(); + Assert.assertTrue(cnameRecordSets.size() == 2); + return dnsZone; + } + + @Override + public DnsZone updateResource(DnsZone dnsZone) throws Exception { + dnsZone.update() + .withoutTxtRecordSet("www") + .withoutCnameRecordSet("userguide") + .withCnameRecordSet("help", "doc.contoso.com") + .updateNsRecordSet("partners") + .withoutNameServer("ns4-05.azure-dns.info") + .withNameServer("ns4-06.azure-dns.info") + .parent() + .updateARecordSet("www") + .withoutIpv4Address("23.96.104.40") + .withIpv4Address("23.96.104.42") + .parent() + .updateSrvRecordSet("_sip._tcp") + .withoutRecord("bigbox.contoso-service.com", 5060, 10, 60) + .withRecord("mainbox.contoso-service.com", 5060, 10, 60) + .parent() + .updateSoaRecord() + .withNegativeResponseCachingTimeToLiveInSeconds(600) + .withTimeToLive(7200) + .parent() + .defineMxRecordSet("email-internal") + .withMailExchange("mail.contoso-mail-exchange1.com", 1) + .withMailExchange("mail.contoso-mail-exchange2.com", 2) + .attach() + .apply(); + + // Check TXT records + PagedList txtRecordSets = dnsZone.txtRecordSets().list(); + Assert.assertEquals(txtRecordSets.size(), 1); + + // Check CNAME records + PagedList cnameRecordSets = dnsZone.cnameRecordSets().list(); + Assert.assertEquals(cnameRecordSets.size(), 2); + for (CnameRecordSet cnameRecordSet : cnameRecordSets) { + Assert.assertTrue(cnameRecordSet.canonicalName().startsWith("doc.contoso.com")); + Assert.assertTrue(cnameRecordSet.name().startsWith("documents") || cnameRecordSet.name().startsWith("help")); + } + + // Check NS records + PagedList nsRecordSets = dnsZone.nsRecordSets().list(); + Assert.assertTrue(nsRecordSets.size() == 2); // One created above with name 'partners' + the default '@' + for (NsRecordSet nsRecordSet : nsRecordSets) { + Assert.assertTrue(nsRecordSet.name().startsWith("partners") || nsRecordSet.name().startsWith("@")); + if (nsRecordSet.name().startsWith("partners")) { + Assert.assertEquals(nsRecordSet.nameServers().size(), 4); + for (String nameServer : nsRecordSet.nameServers()) { + Assert.assertFalse(nameServer.startsWith("ns4-05.azure-dns.info")); + } + } + } + + // Check A records + PagedList aRecordSets = dnsZone.aRecordSets().list(); + Assert.assertEquals(aRecordSets.size(), 1); + ARecordSet aRecordSet = aRecordSets.get(0); + Assert.assertEquals(aRecordSet.ipv4Addresses().size(), 2); + for (String ipV4Address : aRecordSet.ipv4Addresses()) { + Assert.assertFalse(ipV4Address.startsWith("23.96.104.40")); + } + + // Check SRV records + PagedList srvRecordSets = dnsZone.srvRecordSets().list(); + Assert.assertTrue(srvRecordSets.size() == 1); + SrvRecordSet srvRecordSet = srvRecordSets.get(0); + Assert.assertTrue(srvRecordSet.records().size() == 4); + for (SrvRecord srvRecord : srvRecordSet.records()) { + Assert.assertFalse(srvRecord.target().startsWith("bigbox.contoso-service.com")); + } + + // Check SOA Records + SoaRecordSet soaRecordSet = dnsZone.getSoaRecordSet(); + Assert.assertTrue(soaRecordSet.name().startsWith("@")); + SoaRecord soaRecord = soaRecordSet.record(); + Assert.assertNotNull(soaRecord); + Assert.assertEquals(soaRecord.minimumTtl(), Long.valueOf(600)); + Assert.assertTrue(soaRecordSet.timeToLive() == 7200); + + // Check MX records + PagedList mxRecordSets = dnsZone.mxRecordSets().list(); + Assert.assertTrue(mxRecordSets.size() == 2); + + dnsZone.update() + .updateMxRecordSet("email") + .withoutMailExchange("mail.contoso-mail-exchange2.com", 2) + .withoutMetadata("mxa") + .withMetadata("mxc", "mxcc") + .withMetadata("mxd", "mxdd") + .parent() + .withTag("d", "dd") + .apply(); + + Assert.assertTrue(dnsZone.tags().size() == 3); + // Check "mail" MX record + MxRecordSet mxRecordSet = dnsZone.mxRecordSets().getByName("email"); + Assert.assertTrue(mxRecordSet.records().size() == 1); + Assert.assertTrue(mxRecordSet.metadata().size() == 3); + Assert.assertTrue(mxRecordSet.records().get(0).exchange().startsWith("mail.contoso-mail-exchange1.com")); + + return dnsZone; + } + + @Override + public void print(DnsZone dnsZone) { + StringBuilder info = new StringBuilder(); + info.append("Dns Zone: ").append(dnsZone.id()) + .append("\n\tName (Top level domain): ").append(dnsZone.name()) + .append("\n\tResource group: ").append(dnsZone.resourceGroupName()) + .append("\n\tRegion: ").append(dnsZone.regionName()) + .append("\n\tTags: ").append(dnsZone.tags()) + .append("\n\tName servers:"); + for (String nameServer: dnsZone.nameServers()) { + info.append("\n\t\t").append(nameServer); + } + SoaRecordSet soaRecordSet = dnsZone.getSoaRecordSet(); + SoaRecord soaRecord = soaRecordSet.record(); + info.append("\n\tSOA Record:") + .append("\n\t\tHost:").append(soaRecord.host()) + .append("\n\t\tEmail:").append(soaRecord.email()) + .append("\n\t\tExpire time (seconds):").append(soaRecord.expireTime()) + .append("\n\t\tRefresh time (seconds):").append(soaRecord.refreshTime()) + .append("\n\t\tRetry time (seconds):").append(soaRecord.retryTime()) + .append("\n\t\tNegative response cache ttl (seconds):").append(soaRecord.minimumTtl()) + .append("\n\t\tTtl (seconds):").append(soaRecordSet.timeToLive()); + + PagedList aRecordSets = dnsZone.aRecordSets().list(); + info.append("\n\tA Record sets:"); + for (ARecordSet aRecordSet : aRecordSets) { + info.append("\n\t\tId: ").append(aRecordSet.id()) + .append("\n\t\tName: ").append(aRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(aRecordSet.timeToLive()) + .append("\n\t\tIp v4 addresses: "); + for (String ipAddress : aRecordSet.ipv4Addresses()) { + info.append("\n\t\t\t").append(ipAddress); + } + } + + PagedList aaaaRecordSets = dnsZone.aaaaRecordSets().list(); + info.append("\n\tAAAA Record sets:"); + for (AaaaRecordSet aaaaRecordSet : aaaaRecordSets) { + info.append("\n\t\tId: ").append(aaaaRecordSet.id()) + .append("\n\t\tName: ").append(aaaaRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(aaaaRecordSet.timeToLive()) + .append("\n\t\tIp v6 addresses: "); + for (String ipAddress : aaaaRecordSet.ipv6Addresses()) { + info.append("\n\t\t\t").append(ipAddress); + } + } + + PagedList cnameRecordSets = dnsZone.cnameRecordSets().list(); + info.append("\n\tCNAME Record sets:"); + for (CnameRecordSet cnameRecordSet : cnameRecordSets) { + info.append("\n\t\tId: ").append(cnameRecordSet.id()) + .append("\n\t\tName: ").append(cnameRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(cnameRecordSet.timeToLive()) + .append("\n\t\tCanonical name: ").append(cnameRecordSet.canonicalName()); + } + + PagedList mxRecordSets = dnsZone.mxRecordSets().list(); + info.append("\n\tMX Record sets:"); + for (MxRecordSet mxRecordSet : mxRecordSets) { + info.append("\n\t\tId: ").append(mxRecordSet.id()) + .append("\n\t\tName: ").append(mxRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(mxRecordSet.timeToLive()) + .append("\n\t\tRecords: "); + for (MxRecord mxRecord : mxRecordSet.records()) { + info.append("\n\t\t\tExchange server, Preference: ") + .append(mxRecord.exchange()) + .append(" ") + .append(mxRecord.preference()); + } + } + + PagedList nsRecordSets = dnsZone.nsRecordSets().list(); + info.append("\n\tNS Record sets:"); + for (NsRecordSet nsRecordSet : nsRecordSets) { + info.append("\n\t\tId: ").append(nsRecordSet.id()) + .append("\n\t\tName: ").append(nsRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(nsRecordSet.timeToLive()) + .append("\n\t\tName servers: "); + for (String nameServer : nsRecordSet.nameServers()) { + info.append("\n\t\t\t").append(nameServer); + } + } + + PagedList ptrRecordSets = dnsZone.ptrRecordSets().list(); + info.append("\n\tPTR Record sets:"); + for (PtrRecordSet ptrRecordSet : ptrRecordSets) { + info.append("\n\t\tId: ").append(ptrRecordSet.id()) + .append("\n\t\tName: ").append(ptrRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(ptrRecordSet.timeToLive()) + .append("\n\t\tTarget domain names: "); + for (String domainNames : ptrRecordSet.targetDomainNames()) { + info.append("\n\t\t\t").append(domainNames); + } + } + + PagedList srvRecordSets = dnsZone.srvRecordSets().list(); + info.append("\n\tSRV Record sets:"); + for (SrvRecordSet srvRecordSet : srvRecordSets) { + info.append("\n\t\tId: ").append(srvRecordSet.id()) + .append("\n\t\tName: ").append(srvRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(srvRecordSet.timeToLive()) + .append("\n\t\tRecords: "); + for (SrvRecord srvRecord : srvRecordSet.records()) { + info.append("\n\t\t\tTarget, Port, Priority, Weight: ") + .append(srvRecord.target()) + .append(", ") + .append(srvRecord.port()) + .append(", ") + .append(srvRecord.priority()) + .append(", ") + .append(srvRecord.weight()); + } + } + + PagedList txtRecordSets = dnsZone.txtRecordSets().list(); + info.append("\n\tTXT Record sets:"); + for (TxtRecordSet txtRecordSet : txtRecordSets) { + info.append("\n\t\tId: ").append(txtRecordSet.id()) + .append("\n\t\tName: ").append(txtRecordSet.name()) + .append("\n\t\tTtl (seconds): ").append(txtRecordSet.timeToLive()) + .append("\n\t\tRecords: "); + for (TxtRecord txtRecord : txtRecordSet.records()) { + if (txtRecord.value().size() > 0) { + info.append("\n\t\t\tValue: ").append(txtRecord.value().get(0)); + } + } + } + System.out.println(info.toString()); + } +} diff --git a/azure/src/test/java/com/microsoft/azure/management/TestTrafficManager.java b/azure/src/test/java/com/microsoft/azure/management/TestTrafficManager.java index 2addd76f404c..46f84c54e0c4 100644 --- a/azure/src/test/java/com/microsoft/azure/management/TestTrafficManager.java +++ b/azure/src/test/java/com/microsoft/azure/management/TestTrafficManager.java @@ -18,7 +18,7 @@ import java.util.Map; /** - * Test of virtual network management. + * Test of traffic manager management. */ public class TestTrafficManager extends TestTemplate {