Search in sources :

Example 1 with CNameRecordSet

use of com.microsoft.azure.management.dns.CNameRecordSet in project azure-sdk-for-java by Azure.

the class Utils method print.

/**
     * Print a dns zone.
     * @param dnsZone a dns zone
     */
public static 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<ARecordSet> 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<AaaaRecordSet> 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<CNameRecordSet> 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<MXRecordSet> 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<NSRecordSet> 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<PtrRecordSet> 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<SrvRecordSet> 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<TxtRecordSet> 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());
}
Also used : ARecordSet(com.microsoft.azure.management.dns.ARecordSet) PtrRecordSet(com.microsoft.azure.management.dns.PtrRecordSet) NSRecordSet(com.microsoft.azure.management.dns.NSRecordSet) CNameRecordSet(com.microsoft.azure.management.dns.CNameRecordSet) SrvRecord(com.microsoft.azure.management.dns.SrvRecord) ConnectionString(com.microsoft.azure.management.appservice.ConnectionString) AaaaRecordSet(com.microsoft.azure.management.dns.AaaaRecordSet) SoaRecordSet(com.microsoft.azure.management.dns.SoaRecordSet) SoaRecord(com.microsoft.azure.management.dns.SoaRecord) MxRecord(com.microsoft.azure.management.dns.MxRecord) SrvRecordSet(com.microsoft.azure.management.dns.SrvRecordSet) TxtRecordSet(com.microsoft.azure.management.dns.TxtRecordSet) MXRecordSet(com.microsoft.azure.management.dns.MXRecordSet) TxtRecord(com.microsoft.azure.management.dns.TxtRecord)

Example 2 with CNameRecordSet

use of com.microsoft.azure.management.dns.CNameRecordSet in project azure-sdk-for-java by Azure.

the class TestDns method updateResource.

@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<TxtRecordSet> txtRecordSets = dnsZone.txtRecordSets().list();
    Assert.assertEquals(txtRecordSets.size(), 1);
    // Check CNAME records
    PagedList<CNameRecordSet> 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<NSRecordSet> nsRecordSets = dnsZone.nsRecordSets().list();
    // One created above with name 'partners' + the default '@'
    Assert.assertTrue(nsRecordSets.size() == 2);
    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<ARecordSet> 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<SrvRecordSet> 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<MXRecordSet> 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;
}
Also used : ARecordSet(com.microsoft.azure.management.dns.ARecordSet) NSRecordSet(com.microsoft.azure.management.dns.NSRecordSet) CNameRecordSet(com.microsoft.azure.management.dns.CNameRecordSet) SrvRecord(com.microsoft.azure.management.dns.SrvRecord) SoaRecordSet(com.microsoft.azure.management.dns.SoaRecordSet) SoaRecord(com.microsoft.azure.management.dns.SoaRecord) TxtRecordSet(com.microsoft.azure.management.dns.TxtRecordSet) SrvRecordSet(com.microsoft.azure.management.dns.SrvRecordSet) MXRecordSet(com.microsoft.azure.management.dns.MXRecordSet)

Example 3 with CNameRecordSet

use of com.microsoft.azure.management.dns.CNameRecordSet in project azure-sdk-for-java by Azure.

the class TestDns method createResource.

@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(// Overwrite default 3600 seconds
    7200).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));
    // Default '@' name servers
    Assert.assertTrue(dnsZone.nameServers().size() > 0);
    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<ARecordSet> aRecordSets = dnsZone.aRecordSets().list();
    Assert.assertTrue(aRecordSets.size() == 1);
    Assert.assertTrue(aRecordSets.get(0).timeToLive() == 7200);
    // Check AAAA records
    PagedList<AaaaRecordSet> 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<MXRecordSet> 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<NSRecordSet> nsRecordSets = dnsZone.nsRecordSets().list();
    // One created above with name 'partners' + the default '@'
    Assert.assertTrue(nsRecordSets.size() == 2);
    // Check TXT records
    PagedList<TxtRecordSet> txtRecordSets = dnsZone.txtRecordSets().list();
    Assert.assertTrue(txtRecordSets.size() == 2);
    // Check SRV records
    PagedList<SrvRecordSet> srvRecordSets = dnsZone.srvRecordSets().list();
    Assert.assertTrue(srvRecordSets.size() == 1);
    // Check PTR records
    PagedList<PtrRecordSet> ptrRecordSets = dnsZone.ptrRecordSets().list();
    Assert.assertTrue(ptrRecordSets.size() == 2);
    // Check CNAME records
    PagedList<CNameRecordSet> cnameRecordSets = dnsZone.cNameRecordSets().list();
    Assert.assertTrue(cnameRecordSets.size() == 2);
    return dnsZone;
}
Also used : ARecordSet(com.microsoft.azure.management.dns.ARecordSet) PtrRecordSet(com.microsoft.azure.management.dns.PtrRecordSet) NSRecordSet(com.microsoft.azure.management.dns.NSRecordSet) CNameRecordSet(com.microsoft.azure.management.dns.CNameRecordSet) AaaaRecordSet(com.microsoft.azure.management.dns.AaaaRecordSet) SoaRecordSet(com.microsoft.azure.management.dns.SoaRecordSet) SoaRecord(com.microsoft.azure.management.dns.SoaRecord) MxRecord(com.microsoft.azure.management.dns.MxRecord) DnsZone(com.microsoft.azure.management.dns.DnsZone) TxtRecordSet(com.microsoft.azure.management.dns.TxtRecordSet) SrvRecordSet(com.microsoft.azure.management.dns.SrvRecordSet) MXRecordSet(com.microsoft.azure.management.dns.MXRecordSet) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region)

Example 4 with CNameRecordSet

use of com.microsoft.azure.management.dns.CNameRecordSet in project azure-sdk-for-java by Azure.

the class TestDns method print.

@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<ARecordSet> 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<AaaaRecordSet> 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<CNameRecordSet> 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<MXRecordSet> 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<NSRecordSet> 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<PtrRecordSet> 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<SrvRecordSet> 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<TxtRecordSet> 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());
}
Also used : ARecordSet(com.microsoft.azure.management.dns.ARecordSet) PtrRecordSet(com.microsoft.azure.management.dns.PtrRecordSet) NSRecordSet(com.microsoft.azure.management.dns.NSRecordSet) CNameRecordSet(com.microsoft.azure.management.dns.CNameRecordSet) SrvRecord(com.microsoft.azure.management.dns.SrvRecord) AaaaRecordSet(com.microsoft.azure.management.dns.AaaaRecordSet) SoaRecordSet(com.microsoft.azure.management.dns.SoaRecordSet) SoaRecord(com.microsoft.azure.management.dns.SoaRecord) MxRecord(com.microsoft.azure.management.dns.MxRecord) SrvRecordSet(com.microsoft.azure.management.dns.SrvRecordSet) TxtRecordSet(com.microsoft.azure.management.dns.TxtRecordSet) MXRecordSet(com.microsoft.azure.management.dns.MXRecordSet) TxtRecord(com.microsoft.azure.management.dns.TxtRecord)

Example 5 with CNameRecordSet

use of com.microsoft.azure.management.dns.CNameRecordSet in project azure-sdk-for-java by Azure.

the class ManageDns method runSample.

/**
     * Main function which runs the actual sample.
     * @param azure instance of the azure client
     * @return true if sample runs successfully
     */
public static boolean runSample(Azure azure) {
    final String customDomainName = "THE CUSTOM DOMAIN THAT YOU OWN (e.g. contoso.com)";
    final String rgName = SdkContext.randomResourceName("rgNEMV_", 24);
    final String appServicePlanName = SdkContext.randomResourceName("jplan1_", 15);
    final String webAppName = SdkContext.randomResourceName("webapp1-", 20);
    try {
        ResourceGroup resourceGroup = azure.resourceGroups().define(rgName).withRegion(Region.US_EAST2).create();
        //============================================================
        // Creates root DNS Zone
        System.out.println("Creating root DNS zone " + customDomainName + "...");
        DnsZone rootDnsZone = azure.dnsZones().define(customDomainName).withExistingResourceGroup(resourceGroup).create();
        System.out.println("Created root DNS zone " + rootDnsZone.name());
        Utils.print(rootDnsZone);
        //============================================================
        // Sets NS records in the parent zone (hosting custom domain) to make Azure DNS the authoritative
        // source for name resolution for the zone
        System.out.println("Go to your registrar portal and configure your domain " + customDomainName + " with following name server addresses");
        for (String nameServer : rootDnsZone.nameServers()) {
            System.out.println(" " + nameServer);
        }
        System.out.println("Press a key after finishing above step");
        System.in.read();
        //============================================================
        // Creates a web App
        System.out.println("Creating Web App " + webAppName + "...");
        WebApp webApp = azure.webApps().define(webAppName).withRegion(Region.US_EAST2).withExistingResourceGroup(rgName).withNewWindowsPlan(PricingTier.BASIC_B1).defineSourceControl().withPublicGitRepository("https://github.com/jianghaolu/azure-site-test").withBranch("master").attach().create();
        System.out.println("Created web app " + webAppName);
        Utils.print(webApp);
        //============================================================
        // Creates a CName record and bind it with the web app
        // Step 1: Adds CName Dns record to root DNS zone that specify web app host domain as an
        // alias for www.[customDomainName]
        System.out.println("Updating DNS zone by adding a CName record...");
        rootDnsZone = rootDnsZone.update().withCNameRecordSet("www", webApp.defaultHostName()).apply();
        System.out.println("DNS zone updated");
        Utils.print(rootDnsZone);
        // Waiting for a minute for DNS CName entry to propagate
        System.out.println("Waiting a minute for CName record entry to propagate...");
        Thread.sleep(60 * 1000);
        // Step 2: Adds a web app host name binding for www.[customDomainName]
        //         This binding action will fail if the CName record propagation is not yet completed
        System.out.println("Updating Web app with host name binding...");
        webApp.update().defineHostnameBinding().withThirdPartyDomain(customDomainName).withSubDomain("www").withDnsRecordType(CustomHostNameDnsRecordType.CNAME).attach().apply();
        System.out.println("Web app updated");
        Utils.print(webApp);
        //============================================================
        // Creates a virtual machine with public IP
        System.out.println("Creating a virtual machine with public IP...");
        VirtualMachine virtualMachine1 = azure.virtualMachines().define(SdkContext.randomResourceName("employeesvm-", 20)).withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(SdkContext.randomResourceName("empip-", 20)).withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_D1_V2).create();
        System.out.println("Virtual machine created");
        //============================================================
        // Update DNS zone by adding a A record in root DNS zone pointing to virtual machine IPv4 address
        PublicIPAddress vm1PublicIPAddress = virtualMachine1.getPrimaryPublicIPAddress();
        System.out.println("Updating root DNS zone " + customDomainName + "...");
        rootDnsZone = rootDnsZone.update().defineARecordSet("employees").withIPv4Address(vm1PublicIPAddress.ipAddress()).attach().apply();
        System.out.println("Updated root DNS zone " + rootDnsZone.name());
        Utils.print(rootDnsZone);
        // Prints the CName and A Records in the root DNS zone
        //
        System.out.println("Getting CName record set in the root DNS zone " + customDomainName + "...");
        PagedList<CNameRecordSet> cnameRecordSets = rootDnsZone.cNameRecordSets().list();
        for (CNameRecordSet cnameRecordSet : cnameRecordSets) {
            System.out.println("Name: " + cnameRecordSet.name() + " Canonical Name: " + cnameRecordSet.canonicalName());
        }
        System.out.println("Getting ARecord record set in the root DNS zone " + customDomainName + "...");
        PagedList<ARecordSet> aRecordSets = rootDnsZone.aRecordSets().list();
        for (ARecordSet aRecordSet : aRecordSets) {
            System.out.println("Name: " + aRecordSet.name());
            for (String ipv4Address : aRecordSet.ipv4Addresses()) {
                System.out.println("  " + ipv4Address);
            }
        }
        //============================================================
        // Creates a child DNS zone
        String partnerSubDomainName = "partners." + customDomainName;
        System.out.println("Creating child DNS zone " + partnerSubDomainName + "...");
        DnsZone partnersDnsZone = azure.dnsZones().define(partnerSubDomainName).withExistingResourceGroup(resourceGroup).create();
        System.out.println("Created child DNS zone " + partnersDnsZone.name());
        Utils.print(partnersDnsZone);
        //============================================================
        // Adds NS records in the root dns zone to delegate partners.[customDomainName] to child dns zone
        System.out.println("Updating root DNS zone " + rootDnsZone + "...");
        DnsRecordSet.UpdateDefinitionStages.WithNSRecordNameServerOrAttachable<DnsZone.Update> nsRecordStage = rootDnsZone.update().defineNSRecordSet("partners").withNameServer(partnersDnsZone.nameServers().get(0));
        for (int i = 1; i < partnersDnsZone.nameServers().size(); i++) {
            nsRecordStage = nsRecordStage.withNameServer(partnersDnsZone.nameServers().get(i));
        }
        nsRecordStage.attach().apply();
        System.out.println("Root DNS zone updated");
        Utils.print(rootDnsZone);
        //============================================================
        // Creates a virtual machine with public IP
        System.out.println("Creating a virtual machine with public IP...");
        VirtualMachine virtualMachine2 = azure.virtualMachines().define(SdkContext.randomResourceName("partnersvm-", 20)).withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(SdkContext.randomResourceName("ptnerpip-", 20)).withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_D1_V2).create();
        System.out.println("Virtual machine created");
        //============================================================
        // Update child DNS zone by adding a A record pointing to virtual machine IPv4 address
        PublicIPAddress vm2PublicIPAddress = virtualMachine2.getPrimaryPublicIPAddress();
        System.out.println("Updating child DNS zone " + partnerSubDomainName + "...");
        partnersDnsZone = partnersDnsZone.update().defineARecordSet("@").withIPv4Address(vm2PublicIPAddress.ipAddress()).attach().apply();
        System.out.println("Updated child DNS zone " + partnersDnsZone.name());
        Utils.print(partnersDnsZone);
        //============================================================
        // Removes A record entry from the root DNS zone
        System.out.println("Removing A Record from root DNS zone " + rootDnsZone.name() + "...");
        rootDnsZone = rootDnsZone.update().withoutARecordSet("employees").apply();
        System.out.println("Removed A Record from root DNS zone");
        Utils.print(rootDnsZone);
        //============================================================
        // Deletes the DNS zone
        System.out.println("Deleting child DNS zone " + partnersDnsZone.name() + "...");
        azure.dnsZones().deleteById(partnersDnsZone.id());
        System.out.println("Deleted child DNS zone " + partnersDnsZone.name());
        return true;
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
    } finally {
        try {
            System.out.println("Deleting Resource Group: " + rgName);
            azure.resourceGroups().beginDeleteByName(rgName);
            System.out.println("Deleted Resource Group: " + rgName);
        } catch (NullPointerException npe) {
            System.out.println("Did not create any resources in Azure. No clean up is necessary");
        } catch (Exception g) {
            g.printStackTrace();
        }
    }
    return false;
}
Also used : ARecordSet(com.microsoft.azure.management.dns.ARecordSet) CNameRecordSet(com.microsoft.azure.management.dns.CNameRecordSet) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) DnsZone(com.microsoft.azure.management.dns.DnsZone) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) WebApp(com.microsoft.azure.management.appservice.WebApp) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

ARecordSet (com.microsoft.azure.management.dns.ARecordSet)5 CNameRecordSet (com.microsoft.azure.management.dns.CNameRecordSet)5 MXRecordSet (com.microsoft.azure.management.dns.MXRecordSet)4 NSRecordSet (com.microsoft.azure.management.dns.NSRecordSet)4 SoaRecord (com.microsoft.azure.management.dns.SoaRecord)4 SoaRecordSet (com.microsoft.azure.management.dns.SoaRecordSet)4 SrvRecordSet (com.microsoft.azure.management.dns.SrvRecordSet)4 TxtRecordSet (com.microsoft.azure.management.dns.TxtRecordSet)4 AaaaRecordSet (com.microsoft.azure.management.dns.AaaaRecordSet)3 MxRecord (com.microsoft.azure.management.dns.MxRecord)3 PtrRecordSet (com.microsoft.azure.management.dns.PtrRecordSet)3 SrvRecord (com.microsoft.azure.management.dns.SrvRecord)3 DnsZone (com.microsoft.azure.management.dns.DnsZone)2 TxtRecord (com.microsoft.azure.management.dns.TxtRecord)2 ConnectionString (com.microsoft.azure.management.appservice.ConnectionString)1 WebApp (com.microsoft.azure.management.appservice.WebApp)1 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)1 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)1 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1